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 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
690 const int m_corner
= 1;
692 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
694 dc
->SetPen( *wxBLACK_PEN
);
695 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
696 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
698 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
699 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
700 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
702 dc
->SetPen( *wxWHITE_PEN
);
703 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
704 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
705 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
706 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
709 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
711 wxPaintDC
dc( this );
716 dc
.SetFont( *GetFont() );
722 GetClientSize( &w
, &h
);
724 dc
.SetTextForeground( *wxBLACK
);
725 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
729 int numColumns
= m_owner
->GetColumnCount();
731 for (int i
= 0; i
< numColumns
; i
++)
733 m_owner
->GetColumn( i
, item
);
734 int cw
= item
.m_width
-2;
735 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
736 dc
.SetPen( *wxWHITE_PEN
);
738 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
739 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
740 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
741 dc
.DestroyClippingRegion();
748 void wxListHeaderWindow::DrawCurrent()
752 int x2
= m_currentX
-1;
754 m_owner
->GetClientSize( (int*)NULL
, &y2
);
755 ClientToScreen( &x1
, &y1
);
756 m_owner
->ClientToScreen( &x2
, &y2
);
759 dc
.SetLogicalFunction( wxXOR
);
760 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
761 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
763 dc
.DrawLine( x1
, y1
, x2
, y2
);
765 dc
.SetLogicalFunction( wxCOPY
);
767 dc
.SetPen( wxNullPen
);
768 dc
.SetBrush( wxNullBrush
);
771 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
773 int x
= event
.GetX();
774 int y
= event
.GetY();
778 if (event
.ButtonUp())
782 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
787 GetClientSize( &size_x
, (int*) NULL
);
791 m_currentX
= m_minX
+7;
792 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
799 bool hit_border
= FALSE
;
801 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
803 xpos
+= m_owner
->GetColumnWidth( j
);
804 if ((abs(x
-xpos
) < 3) && (y
< 22))
813 if (event
.LeftDown() && hit_border
)
826 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
827 m_currentCursor
= m_resizeCursor
;
831 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
832 m_currentCursor
= wxSTANDARD_CURSOR
;
837 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
842 //-----------------------------------------------------------------------------
843 // wxListRenameTimer (internal)
844 //-----------------------------------------------------------------------------
846 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
851 void wxListRenameTimer::Notify()
853 m_owner
->OnRenameTimer();
856 //-----------------------------------------------------------------------------
857 // wxListTextCtrl (internal)
858 //-----------------------------------------------------------------------------
860 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
862 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
863 EVT_CHAR (wxListTextCtrl::OnChar
)
864 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
867 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
868 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
869 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
870 int style
, const wxValidator
& validator
, const wxString
&name
) :
871 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
878 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
880 if (event
.m_keyCode
== WXK_RETURN
)
883 (*m_res
) = GetValue();
884 m_owner
->OnRenameAccept();
889 if (event
.m_keyCode
== WXK_ESCAPE
)
900 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
909 //-----------------------------------------------------------------------------
911 //-----------------------------------------------------------------------------
913 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
915 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
916 EVT_PAINT (wxListMainWindow::OnPaint
)
917 EVT_SIZE (wxListMainWindow::OnSize
)
918 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
919 EVT_CHAR (wxListMainWindow::OnChar
)
920 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
921 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
924 wxListMainWindow::wxListMainWindow( void )
927 m_lines
.DeleteContents( TRUE
);
928 m_columns
.DeleteContents( TRUE
);
929 m_current
= (wxListLineData
*) NULL
;
931 m_hilightBrush
= (wxBrush
*) NULL
;
935 m_small_image_list
= (wxImageList
*) NULL
;
936 m_normal_image_list
= (wxImageList
*) NULL
;
937 m_small_spacing
= 30;
938 m_normal_spacing
= 40;
941 m_lastOnSame
= FALSE
;
942 m_renameTimer
= new wxListRenameTimer( this );
947 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
948 const wxPoint
&pos
, const wxSize
&size
,
949 long style
, const wxString
&name
) :
950 wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
953 m_lines
.DeleteContents( TRUE
);
954 m_columns
.DeleteContents( TRUE
);
955 m_current
= (wxListLineData
*) NULL
;
958 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
959 m_small_image_list
= (wxImageList
*) NULL
;
960 m_normal_image_list
= (wxImageList
*) NULL
;
961 m_small_spacing
= 30;
962 m_normal_spacing
= 40;
963 // AllowDoubleClick( TRUE );
970 if (m_mode
& wxLC_REPORT
)
980 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
983 m_lastOnSame
= FALSE
;
984 m_renameTimer
= new wxListRenameTimer( this );
985 m_renameAccept
= FALSE
;
986 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
987 // m_text->Show( FALSE );
989 SetBackgroundColour( *wxWHITE
);
992 wxListMainWindow::~wxListMainWindow( void )
994 if (m_hilightBrush
) delete m_hilightBrush
;
995 delete m_renameTimer
;
996 // if (m_hilightColour) delete m_hilightColour;
1000 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1008 wxClientDC
dc(this);
1010 line
->GetExtent( x
, y
, w
, h
);
1012 dc
.LogicalToDeviceX(x
-3),
1013 dc
.LogicalToDeviceY(y
-3),
1014 dc
.LogicalToDeviceXRel(w
+6),
1015 dc
.LogicalToDeviceXRel(h
+6) );
1016 Refresh( TRUE
, &rect
);
1020 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1022 if (m_dirty
) return;
1024 wxPaintDC
dc( this );
1029 dc
.SetFont( *GetFont() );
1031 wxNode
*node
= m_lines
.First();
1034 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1036 node
= node
->Next();
1038 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1043 void wxListMainWindow::HilightAll( bool on
)
1045 wxNode
*node
= m_lines
.First();
1048 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1049 if (line
->IsHilighted() != on
)
1051 line
->Hilight( on
);
1052 RefreshLine( line
);
1054 node
= node
->Next();
1058 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
1060 if (!GetParent()) return;
1061 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1062 le
.SetEventObject( GetParent() );
1064 le
.m_itemIndex
= GetIndexOfLine( line
);
1066 line
->GetItem( 0, le
.m_item
);
1070 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1072 if (!GetParent()) return;
1073 wxListEvent
le( command
, GetParent()->GetId() );
1074 le
.SetEventObject( GetParent() );
1076 le
.m_itemIndex
= GetIndexOfLine( line
);
1078 line
->GetItem( 0, le
.m_item
);
1082 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1084 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1087 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1089 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1092 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1094 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1097 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1099 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1102 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1104 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1107 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1109 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1112 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1114 if (!GetParent()) return;
1116 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1117 le
.SetEventObject( GetParent() );
1119 le
.m_itemIndex
= GetIndexOfLine( line
);
1121 line
->GetItem( 0, le
.m_item
);
1122 le
.m_item
.m_text
= newName
;
1126 void wxListMainWindow::OnRenameTimer()
1128 StartLabelEdit( m_current
);
1130 m_current
->GetText( 0, s
);
1135 m_current
->GetLabelExtent( x
, y
, w
, h
);
1137 wxClientDC
dc(this);
1139 x
= dc
.LogicalToDeviceX( x
);
1140 y
= dc
.LogicalToDeviceY( y
);
1142 wxListTextCtrl
*text
= new wxListTextCtrl(
1143 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1146 m_text->SetSize( x+3, y+3, w+6, h+6 );
1147 m_text->SetValue( s );
1148 m_text->Show( TRUE );
1152 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1157 RenameLine( m_current, s );
1162 void wxListMainWindow::OnRenameAccept()
1164 RenameLine( m_current
, m_renameRes
);
1167 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1169 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1171 if (!m_current
) return;
1172 if (m_dirty
) return;
1174 wxClientDC
dc(this);
1176 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1177 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1180 wxNode
*node
= m_lines
.First();
1181 wxListLineData
*line
= (wxListLineData
*) NULL
;
1184 line
= (wxListLineData
*)node
->Data();
1185 hitResult
= line
->IsHit( x
, y
);
1186 if (hitResult
) break;
1187 line
= (wxListLineData
*) NULL
;
1188 node
= node
->Next();
1191 if (!event
.Dragging())
1196 if (event
.Dragging() && (m_dragCount
> 3))
1199 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1200 le
.SetEventObject( this );
1209 if (event
.ButtonDClick())
1212 m_lastOnSame
= FALSE
;
1213 m_renameTimer
->Stop();
1214 ActivateLine( line
);
1218 if (event
.LeftUp() && m_lastOnSame
)
1221 if ((line
== m_current
) &&
1222 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1223 // (m_mode & wxLC_ICON) &&
1224 (m_mode
& wxLC_EDIT_LABELS
) )
1226 m_renameTimer
->Start( 100, TRUE
);
1228 m_lastOnSame
= FALSE
;
1232 if (event
.LeftDown())
1235 wxListLineData
*oldCurrent
= m_current
;
1236 if (m_mode
& wxLC_SINGLE_SEL
)
1239 HilightAll( FALSE
);
1240 m_current
->ReverseHilight();
1241 RefreshLine( m_current
);
1245 if (event
.ShiftDown())
1248 m_current
->ReverseHilight();
1249 RefreshLine( m_current
);
1251 else if (event
.ControlDown())
1254 int numOfCurrent
= -1;
1255 node
= m_lines
.First();
1258 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1260 if (test_line
== oldCurrent
) break;
1261 node
= node
->Next();
1264 node
= m_lines
.First();
1267 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1269 if (test_line
== line
) break;
1270 node
= node
->Next();
1273 if (numOfLine
< numOfCurrent
)
1274 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1275 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1276 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1278 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1279 test_line
->Hilight(TRUE
);
1280 RefreshLine( test_line
);
1281 node
= node
->Next();
1287 HilightAll( FALSE
);
1288 m_current
->ReverseHilight();
1289 RefreshLine( m_current
);
1292 if (m_current
!= oldCurrent
)
1294 RefreshLine( oldCurrent
);
1295 UnfocusLine( oldCurrent
);
1296 FocusLine( m_current
);
1298 m_lastOnSame
= (m_current
== oldCurrent
);
1304 void wxListMainWindow::MoveToFocus( void )
1306 if (!m_current
) return;
1312 m_current->GetExtent( x, y, w, h );
1315 GetClientSize( &w_p, &h_p );
1316 if (m_mode & wxLC_REPORT)
1318 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1319 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1320 if ((y > y_s) && (y+h < y_s+h_p)) return;
1321 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1322 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1326 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1327 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1328 if ((x > x_s) && (x+w < x_s+w_p)) return;
1329 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1330 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1335 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1337 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1338 wxListLineData
*oldCurrent
= m_current
;
1339 m_current
= newCurrent
;
1341 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1342 RefreshLine( m_current
);
1343 RefreshLine( oldCurrent
);
1344 FocusLine( m_current
);
1345 UnfocusLine( oldCurrent
);
1348 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1351 if (event.KeyCode() == WXK_TAB)
1353 if (event.ShiftDown())
1360 if (!m_current
) return;
1361 switch (event
.KeyCode())
1365 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1366 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1371 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1372 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1377 wxNode
*node
= m_lines
.Last();
1378 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1383 wxNode
*node
= m_lines
.First();
1384 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1390 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1394 wxNode
*node
= m_lines
.First();
1395 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1396 steps
= pos
% m_visibleLines
;
1398 wxNode
*node
= m_lines
.Member( m_current
);
1399 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1400 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1406 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1409 int pos
= 0; wxNode
*node
= m_lines
.First();
1410 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1411 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1413 wxNode
*node
= m_lines
.Member( m_current
);
1414 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1415 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1420 if (!(m_mode
& wxLC_REPORT
))
1422 wxNode
*node
= m_lines
.Member( m_current
);
1423 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1424 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
->Next()) node
= node
->Next();
1434 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1440 m_current
->ReverseHilight();
1441 RefreshLine( m_current
);
1446 if (!(m_mode
& wxLC_SINGLE_SEL
))
1448 wxListLineData
*oldCurrent
= m_current
;
1449 m_current
->ReverseHilight();
1450 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1451 if (node
) m_current
= (wxListLineData
*)node
->Data();
1453 RefreshLine( oldCurrent
);
1454 RefreshLine( m_current
);
1455 UnfocusLine( oldCurrent
);
1456 FocusLine( m_current
);
1463 ActivateLine( m_current
);
1475 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1478 RefreshLine( m_current
);
1480 if (!GetParent()) return;
1482 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1483 event
.SetEventObject( GetParent() );
1484 GetParent()->GetEventHandler()->ProcessEvent( event
);
1487 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1490 RefreshLine( m_current
);
1493 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1496 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1498 CalculatePositions();
1499 printf( "OnSize::Refresh.\n" );
1505 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1507 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1509 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1512 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1514 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1516 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1518 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1523 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1525 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1527 m_normal_image_list
->GetSize( index
, width
, height
);
1530 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1532 m_small_image_list
->GetSize( index
, width
, height
);
1535 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1537 m_small_image_list
->GetSize( index
, width
, height
);
1544 int wxListMainWindow::GetTextLength( wxString
&s
)
1546 wxPaintDC
dc( this );
1549 dc
.GetTextExtent( s
, &lw
, &lh
);
1553 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1556 wxNode
*node
= m_lines
.First();
1559 if (line
== (wxListLineData
*)node
->Data()) return i
;
1561 node
= node
->Next();
1566 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1569 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1570 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1573 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1578 m_small_spacing
= spacing
;
1582 m_normal_spacing
= spacing
;
1586 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1588 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1591 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1594 wxNode
*node
= m_columns
.Nth( col
);
1597 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1598 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1599 column
->SetItem( item
);
1601 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1602 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1605 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1607 if (!(m_mode
& wxLC_REPORT
)) return;
1611 wxNode
*node
= m_columns
.Nth( col
);
1614 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1615 column
->SetWidth( width
);
1618 node
= m_lines
.First();
1621 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1622 wxNode
*n
= line
->m_items
.Nth( col
);
1625 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1626 item
->SetSize( width
, -1 );
1628 node
= node
->Next();
1631 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1632 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1635 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1637 wxNode
*node
= m_columns
.Nth( col
);
1640 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1641 column
->GetItem( item
);
1653 int wxListMainWindow::GetColumnWidth( int col
)
1655 wxNode
*node
= m_columns
.Nth( col
);
1658 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1659 return column
->GetWidth();
1665 int wxListMainWindow::GetColumnCount( void )
1667 return m_columns
.Number();
1670 int wxListMainWindow::GetCountPerPage( void )
1672 return m_visibleLines
;
1675 void wxListMainWindow::SetItem( wxListItem
&item
)
1678 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1681 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1682 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1683 line
->SetItem( item
.m_col
, item
);
1687 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1689 // m_dirty = TRUE; no recalcs needed
1691 wxListLineData
*oldCurrent
= m_current
;
1693 if (stateMask
& wxLIST_STATE_FOCUSED
)
1695 wxNode
*node
= m_lines
.Nth( item
);
1698 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1699 UnfocusLine( m_current
);
1701 FocusLine( m_current
);
1702 RefreshLine( m_current
);
1703 RefreshLine( oldCurrent
);
1707 if (stateMask
& wxLIST_STATE_SELECTED
)
1709 bool on
= state
& wxLIST_STATE_SELECTED
;
1710 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1712 wxNode
*node
= m_lines
.Nth( item
);
1715 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1716 if (m_mode
& wxLC_SINGLE_SEL
)
1718 UnfocusLine( m_current
);
1720 FocusLine( m_current
);
1721 oldCurrent
->Hilight( FALSE
);
1722 RefreshLine( m_current
);
1723 RefreshLine( oldCurrent
);
1725 bool on
= state
& wxLIST_STATE_SELECTED
;
1726 line
->Hilight( on
);
1727 RefreshLine( line
);
1732 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1734 int ret
= wxLIST_STATE_DONTCARE
;
1735 if (stateMask
& wxLIST_STATE_FOCUSED
)
1737 wxNode
*node
= m_lines
.Nth( item
);
1740 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1741 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1744 if (stateMask
& wxLIST_STATE_SELECTED
)
1746 wxNode
*node
= m_lines
.Nth( item
);
1749 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1750 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1756 void wxListMainWindow::GetItem( wxListItem
&item
)
1758 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1761 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1762 line
->GetItem( item
.m_col
, item
);
1773 int wxListMainWindow::GetItemCount( void )
1775 return m_lines
.Number();
1778 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1780 wxNode
*node
= m_lines
.Nth( index
);
1783 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1784 line
->GetRect( rect
);
1795 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1797 wxNode
*node
= m_lines
.Nth( item
);
1801 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1802 line
->GetRect( rect
);
1814 int wxListMainWindow::GetSelectedItemCount( void )
1817 wxNode
*node
= m_lines
.First();
1820 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1821 if (line
->IsHilighted()) ret
++;
1822 node
= node
->Next();
1827 void wxListMainWindow::SetMode( long mode
)
1834 if (m_mode
& wxLC_REPORT
)
1846 long wxListMainWindow::GetMode( void ) const
1851 void wxListMainWindow::CalculatePositions( void )
1853 wxPaintDC
dc( this );
1854 dc
.SetFont( *GetFont() );
1856 int iconSpacing
= 0;
1857 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1858 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1859 wxNode
*node
= m_lines
.First();
1862 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1863 line
->CalculateSize( &dc
, iconSpacing
);
1864 node
= node
->Next();
1869 int lineSpacing
= 0;
1871 node
= m_lines
.First();
1874 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1876 line
->GetSize( dummy
, lineSpacing
);
1882 lineSpacing
= 4 + (int)dc
.GetCharHeight();
1885 int clientWidth
= 0;
1886 int clientHeight
= 0;
1888 if (m_mode
& wxLC_REPORT
)
1892 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1893 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1894 GetClientSize( &clientWidth
, &clientHeight
);
1896 node
= m_lines
.First();
1899 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1900 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1902 for (int i
= 0; i
< GetColumnCount(); i
++)
1904 line
->SetColumnPosition( i
, col_x
);
1905 col_x
+= GetColumnWidth( i
);
1908 node
= node
->Next();
1913 // At first, we try without any scrollbar
1914 GetSize( &clientWidth
, &clientHeight
);
1916 int entireWidth
= 0;
1918 for (int tries
= 0; tries
< 2; tries
++)
1924 node
= m_lines
.First();
1927 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1928 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1929 line
->GetSize( lineWidth
, lineHeight
);
1930 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1932 if (y
+lineHeight
> clientHeight
-4)
1936 entireWidth
+= maxWidth
+13;
1939 node
= node
->Next();
1940 if (!node
) entireWidth
+= maxWidth
;
1941 if ((tries
== 0) && (entireWidth
> clientWidth
))
1943 clientHeight
-= 14; // scrollbar height
1946 if (!node
) tries
= 1;
1949 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1951 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1954 void wxListMainWindow::RealizeChanges( void )
1958 wxNode
*node
= m_lines
.First();
1959 if (node
) m_current
= (wxListLineData
*)node
->Data();
1963 FocusLine( m_current
);
1964 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1968 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1971 if (item
> 0) ret
= item
;
1972 wxNode
*node
= m_lines
.Nth( ret
);
1975 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1976 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1977 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1978 if (!state
) return ret
;
1980 node
= node
->Next();
1985 void wxListMainWindow::DeleteItem( long index
)
1988 wxNode
*node
= m_lines
.Nth( index
);
1991 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1992 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
1994 m_lines
.DeleteNode( node
);
1998 void wxListMainWindow::DeleteColumn( int col
)
2001 wxNode
*node
= m_columns
.Nth( col
);
2002 if (node
) m_columns
.DeleteNode( node
);
2005 void wxListMainWindow::DeleteAllItems( void )
2008 m_current
= (wxListLineData
*) NULL
;
2009 wxNode
*node
= m_lines
.First();
2012 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2014 node
= node
->Next();
2019 void wxListMainWindow::DeleteEverything( void )
2022 m_current
= (wxListLineData
*) NULL
;
2023 wxNode
*node
= m_lines
.First();
2026 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2028 node
= node
->Next();
2031 m_current
= (wxListLineData
*) NULL
;
2035 void wxListMainWindow::EnsureVisible( long index
)
2037 wxListLineData
*oldCurrent
= m_current
;
2038 m_current
= (wxListLineData
*) NULL
;
2040 wxNode
*node
= m_lines
.Nth( i
);
2041 if (node
) m_current
= (wxListLineData
*)node
->Data();
2042 if (m_current
) MoveToFocus();
2043 m_current
= oldCurrent
;
2046 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2050 if (pos
< 0) pos
= 0;
2051 wxNode
*node
= m_lines
.Nth( pos
);
2054 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2056 line
->GetText( 0, s
);
2057 if (s
== tmp
) return pos
;
2058 node
= node
->Next();
2064 long wxListMainWindow::FindItem(long start
, long data
)
2067 if (pos
< 0) pos
= 0;
2068 wxNode
*node
= m_lines
.Nth( pos
);
2071 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2073 line
->GetItem( 0, item
);
2074 if (item
.m_data
== data
) return pos
;
2075 node
= node
->Next();
2081 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2083 wxNode
*node
= m_lines
.First();
2087 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2088 long ret
= line
->IsHit( x
, y
);
2094 node
= node
->Next();
2100 void wxListMainWindow::InsertItem( wxListItem
&item
)
2104 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2105 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2106 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2107 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2108 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2109 if (m_mode
& wxLC_REPORT
)
2111 line
->InitItems( GetColumnCount() );
2112 item
.m_width
= GetColumnWidth( 0 )-3;
2115 line
->InitItems( 1 );
2116 line
->SetItem( 0, item
);
2117 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2119 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2120 if (node
) m_lines
.Insert( node
, line
);
2124 m_lines
.Append( line
);
2128 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2131 if (m_mode
& wxLC_REPORT
)
2133 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2134 wxListHeaderData
*column
= new wxListHeaderData( item
);
2135 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2137 wxNode
*node
= m_columns
.Nth( col
);
2139 m_columns
.Insert( node
, column
);
2143 m_columns
.Append( column
);
2148 wxListCtrlCompare list_ctrl_compare_func_2
;
2149 long list_ctrl_compare_data
;
2151 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2153 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2154 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2156 line1
->GetItem( 0, item
);
2157 long data1
= item
.m_data
;
2158 line2
->GetItem( 0, item
);
2159 long data2
= item
.m_data
;
2160 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2163 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2165 list_ctrl_compare_func_2
= fn
;
2166 list_ctrl_compare_data
= data
;
2167 m_lines
.Sort( list_ctrl_compare_func_1
);
2170 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2172 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2176 // -------------------------------------------------------------------------------------
2178 // -------------------------------------------------------------------------------------
2180 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2182 wxListItem::wxListItem(void)
2191 m_format
= wxLIST_FORMAT_CENTRE
;
2196 // -------------------------------------------------------------------------------------
2198 // -------------------------------------------------------------------------------------
2200 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2202 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2203 wxCommandEvent( commandType
, id
)
2208 m_cancelled
= FALSE
;
2211 // -------------------------------------------------------------------------------------
2213 // -------------------------------------------------------------------------------------
2215 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2217 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2218 EVT_SIZE (wxListCtrl::OnSize
)
2219 EVT_IDLE (wxListCtrl::OnIdle
)
2222 wxListCtrl::wxListCtrl(void)
2224 m_imageListNormal
= (wxImageList
*) NULL
;
2225 m_imageListSmall
= (wxImageList
*) NULL
;
2226 m_imageListState
= (wxImageList
*) NULL
;
2229 wxListCtrl::~wxListCtrl(void)
2233 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2234 const wxPoint
&pos
, const wxSize
&size
,
2235 long style
, const wxValidator
&validator
,
2236 const wxString
&name
)
2238 m_imageListNormal
= (wxImageList
*) NULL
;
2239 m_imageListSmall
= (wxImageList
*) NULL
;
2240 m_imageListState
= (wxImageList
*) NULL
;
2244 if ((s
& wxLC_REPORT
== 0) &&
2245 (s
& wxLC_LIST
== 0) &&
2246 (s
& wxLC_ICON
== 0))
2249 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2251 SetValidator( validator
);
2253 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2255 if (GetWindowStyleFlag() & wxLC_REPORT
)
2256 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2258 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2263 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2265 // handled in OnIdle
2267 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2270 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2272 long flag
= GetWindowStyleFlag();
2276 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2277 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2278 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2287 if (flag
& style
) flag
-= style
;
2290 SetWindowStyleFlag( flag
);
2293 void wxListCtrl::SetWindowStyleFlag( long flag
)
2295 m_mainWin
->DeleteEverything();
2299 GetClientSize( &width
, &height
);
2301 m_mainWin
->SetMode( flag
);
2303 if (flag
& wxLC_REPORT
)
2305 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2307 // m_mainWin->SetSize( 0, 24, width, height-24 );
2310 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2314 // m_headerWin->SetSize( 0, 0, width, 23 );
2315 m_headerWin
->Show( TRUE
);
2321 if (GetWindowStyleFlag() & wxLC_REPORT
)
2323 // m_mainWin->SetSize( 0, 0, width, height );
2324 m_headerWin
->Show( FALSE
);
2328 wxWindow::SetWindowStyleFlag( flag
);
2331 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2333 m_mainWin
->GetColumn( col
, item
);
2337 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2339 m_mainWin
->SetColumn( col
, item
);
2343 int wxListCtrl::GetColumnWidth( int col
)
2345 return m_mainWin
->GetColumnWidth( col
);
2348 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2350 m_mainWin
->SetColumnWidth( col
, width
);
2354 int wxListCtrl::GetCountPerPage(void)
2356 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2360 wxText& wxListCtrl::GetEditControl(void) const
2365 bool wxListCtrl::GetItem( wxListItem
&info
)
2367 m_mainWin
->GetItem( info
);
2371 bool wxListCtrl::SetItem( wxListItem
&info
)
2373 m_mainWin
->SetItem( info
);
2377 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2380 info
.m_text
= label
;
2381 info
.m_mask
= wxLIST_MASK_TEXT
;
2382 info
.m_itemId
= index
;
2386 info
.m_image
= imageId
;
2387 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2390 m_mainWin
->SetItem(info
);
2394 int wxListCtrl::GetItemState( long item
, long stateMask
)
2396 return m_mainWin
->GetItemState( item
, stateMask
);
2399 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2401 m_mainWin
->SetItemState( item
, state
, stateMask
);
2405 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2408 info
.m_image
= image
;
2409 info
.m_mask
= wxLIST_MASK_IMAGE
;
2410 info
.m_itemId
= item
;
2411 m_mainWin
->SetItem( info
);
2415 wxString
wxListCtrl::GetItemText( long item
)
2418 info
.m_itemId
= item
;
2419 m_mainWin
->GetItem( info
);
2423 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2426 info
.m_mask
= wxLIST_MASK_TEXT
;
2427 info
.m_itemId
= item
;
2429 m_mainWin
->SetItem( info
);
2432 long wxListCtrl::GetItemData( long item
)
2435 info
.m_itemId
= item
;
2436 m_mainWin
->GetItem( info
);
2440 bool wxListCtrl::SetItemData( long item
, long data
)
2443 info
.m_mask
= wxLIST_MASK_DATA
;
2444 info
.m_itemId
= item
;
2446 m_mainWin
->SetItem( info
);
2450 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2452 m_mainWin
->GetItemRect( item
, rect
);
2456 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2458 m_mainWin
->GetItemPosition( item
, pos
);
2462 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2467 int wxListCtrl::GetItemCount(void)
2469 return m_mainWin
->GetItemCount();
2472 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2474 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2477 int wxListCtrl::GetItemSpacing( bool isSmall
)
2479 return m_mainWin
->GetItemSpacing( isSmall
);
2482 int wxListCtrl::GetSelectedItemCount(void)
2484 return m_mainWin
->GetSelectedItemCount();
2488 wxColour wxListCtrl::GetTextColour(void) const
2492 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2497 long wxListCtrl::GetTopItem(void)
2502 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2504 return m_mainWin
->GetNextItem( item
, geom
, state
);
2507 wxImageList
*wxListCtrl::GetImageList(int which
)
2509 if (which
== wxIMAGE_LIST_NORMAL
)
2511 return m_imageListNormal
;
2513 else if (which
== wxIMAGE_LIST_SMALL
)
2515 return m_imageListSmall
;
2517 else if (which
== wxIMAGE_LIST_STATE
)
2519 return m_imageListState
;
2521 return (wxImageList
*) NULL
;
2524 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2526 m_mainWin
->SetImageList( imageList
, which
);
2529 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2534 bool wxListCtrl::DeleteItem( long item
)
2536 m_mainWin
->DeleteItem( item
);
2540 bool wxListCtrl::DeleteAllItems(void)
2542 m_mainWin
->DeleteAllItems();
2546 bool wxListCtrl::DeleteColumn( int col
)
2548 m_mainWin
->DeleteColumn( col
);
2553 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2558 bool wxListCtrl::EnsureVisible( long item
)
2560 m_mainWin
->EnsureVisible( item
);
2564 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2566 return m_mainWin
->FindItem( start
, str
, partial
);
2569 long wxListCtrl::FindItem( long start
, long data
)
2571 return m_mainWin
->FindItem( start
, data
);
2574 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2575 int WXUNUSED(direction
))
2580 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2582 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2585 long wxListCtrl::InsertItem( wxListItem
& info
)
2587 m_mainWin
->InsertItem( info
);
2591 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2594 info
.m_text
= label
;
2595 info
.m_mask
= wxLIST_MASK_TEXT
;
2596 info
.m_itemId
= index
;
2597 return InsertItem( info
);
2600 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2603 info
.m_mask
= wxLIST_MASK_IMAGE
;
2604 info
.m_image
= imageIndex
;
2605 info
.m_itemId
= index
;
2606 return InsertItem( info
);
2609 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2612 info
.m_text
= label
;
2613 info
.m_image
= imageIndex
;
2614 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2615 info
.m_itemId
= index
;
2616 return InsertItem( info
);
2619 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2621 m_mainWin
->InsertColumn( col
, item
);
2625 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2626 int format
, int width
)
2629 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2630 item
.m_text
= heading
;
2633 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2634 item
.m_width
= width
;
2637 item
.m_format
= format
;
2639 return InsertColumn( col
, item
);
2642 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2648 // fn is a function which takes 3 long arguments: item1, item2, data.
2649 // item1 is the long data associated with a first item (NOT the index).
2650 // item2 is the long data associated with a second item (NOT the index).
2651 // data is the same value as passed to SortItems.
2652 // The return value is a negative number if the first item should precede the second
2653 // item, a positive number of the second item should precede the first,
2654 // or zero if the two items are equivalent.
2655 // data is arbitrary data to be passed to the sort function.
2657 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2659 m_mainWin
->SortItems( fn
, data
);
2663 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2665 if (!m_mainWin
->m_dirty
) return;
2669 GetClientSize( &cw
, &ch
);
2676 if (GetWindowStyleFlag() & wxLC_REPORT
)
2678 m_headerWin
->GetPosition( &x
, &y
);
2679 m_headerWin
->GetSize( &w
, &h
);
2680 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2681 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2683 m_mainWin
->GetPosition( &x
, &y
);
2684 m_mainWin
->GetSize( &w
, &h
);
2685 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2686 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2690 m_mainWin
->GetPosition( &x
, &y
);
2691 m_mainWin
->GetSize( &w
, &h
);
2692 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2693 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2696 m_mainWin
->CalculatePositions();
2697 m_mainWin
->RealizeChanges();
2698 m_mainWin
->m_dirty
= FALSE
;
2699 m_mainWin
->Refresh();
2702 void wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2704 m_mainWin
->SetBackgroundColour( colour
);
2705 m_headerWin
->SetBackgroundColour( colour
);
2706 m_mainWin
->m_dirty
= TRUE
;
2709 void wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2711 m_mainWin
->SetForegroundColour( colour
);
2712 m_headerWin
->SetForegroundColour( colour
);
2713 m_mainWin
->m_dirty
= TRUE
;
2716 void wxListCtrl::SetFont( const wxFont
&font
)
2718 m_mainWin
->SetFont( font
);
2719 m_headerWin
->SetFont( font
);
2720 m_mainWin
->m_dirty
= TRUE
;