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
-= 3;
351 m_bound_hilight
.y
-= 3;
352 m_bound_hilight
.width
+= 7;
353 m_bound_hilight
.height
+= 7;
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
);
376 AssignRect( m_bound_label
, m_bound_all
);
377 AssignRect( m_bound_hilight
, m_bound_all
);
378 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
384 dc
->GetTextExtent( "H", &lw
, &lh
);
385 m_bound_all
.height
= lh
;
386 m_bound_all
.width
= window_width
;
387 AssignRect( m_bound_label
, m_bound_all
);
388 AssignRect( m_bound_hilight
, m_bound_all
);
389 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
390 m_bound_hilight
.width
= window_width
-10;
391 m_bound_label
.width
= window_width
-10;
397 void wxListLineData::SetColumnPosition( int index
, int x
)
400 wxNode
*node
= m_items
.Nth( i
);
403 wxListItemData
*item
= (wxListItemData
*)node
->Data();
404 item
->SetPosition( x
, m_bound_all
.y
);
408 void wxListLineData::GetSize( int &width
, int &height
)
410 width
= m_bound_all
.width
;
411 height
= m_bound_all
.height
;
414 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
418 width
= m_bound_all
.width
;
419 height
= m_bound_all
.height
;
422 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
426 width
= m_bound_label
.width
;
427 height
= m_bound_label
.height
;
430 void wxListLineData::GetRect( wxRectangle
&rect
)
432 AssignRect( rect
, m_bound_all
);
435 long wxListLineData::IsHit( int x
, int y
)
437 wxNode
*node
= m_items
.First();
440 wxListItemData
*item
= (wxListItemData
*)node
->Data();
441 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
442 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
443 // if (!(item->HasImage() || item->HasText())) return 0;
445 // if there is no icon or text = empty
446 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
450 void wxListLineData::InitItems( int num
)
452 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
455 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
457 wxNode
*node
= m_items
.Nth( index
);
460 wxListItemData
*item
= (wxListItemData
*)node
->Data();
461 item
->SetItem( info
);
465 void wxListLineData::GetItem( int const index
, wxListItem
&info
)
468 wxNode
*node
= m_items
.Nth( i
);
471 wxListItemData
*item
= (wxListItemData
*)node
->Data();
472 item
->GetItem( info
);
476 void wxListLineData::GetText( int index
, wxString
&s
)
479 wxNode
*node
= m_items
.Nth( i
);
483 wxListItemData
*item
= (wxListItemData
*)node
->Data();
488 void wxListLineData::SetText( int index
, const wxString s
)
491 wxNode
*node
= m_items
.Nth( i
);
494 wxListItemData
*item
= (wxListItemData
*)node
->Data();
499 int wxListLineData::GetImage( int index
)
502 wxNode
*node
= m_items
.Nth( i
);
505 wxListItemData
*item
= (wxListItemData
*)node
->Data();
506 return item
->GetImage();
511 void wxListLineData::DoDraw( wxPaintDC
*dc
, bool hilight
, bool paintBG
)
513 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
514 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
515 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
516 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
517 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
) ) return;
523 dc
->SetBrush( m_hilightBrush
);
524 dc
->SetPen( wxTRANSPARENT_PEN
);
528 dc
->SetBrush( wxWHITE_BRUSH
);
529 dc
->SetPen( wxTRANSPARENT_PEN
);
531 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
532 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
534 if (m_mode
== wxLC_REPORT
)
537 wxNode
*node
= m_items
.First();
540 wxListItemData
*info
= (wxListItemData
*)node
->Data();
541 dc
->SetClippingRegion( info
->GetX(), info
->GetY(), info
->GetWidth()-3, info
->GetHeight() );
544 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
546 dc
->SetTextForeground( * info
->GetColour() );
547 dc
->DrawText( s
, info
->GetX()+2, info
->GetY() );
548 dc
->DestroyClippingRegion();
554 wxNode
*node
= m_items
.First();
557 wxListItemData
*item
= (wxListItemData
*)node
->Data();
558 if (item
->HasImage())
560 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
567 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
569 dc
->SetTextForeground( * item
->GetColour() );
570 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
576 void wxListLineData::Hilight( bool on
)
578 if (on
== m_hilighted
) return;
580 m_owner
->SelectLine( this );
582 m_owner
->DeselectLine( this );
586 void wxListLineData::ReverseHilight( void )
588 m_hilighted
= !m_hilighted
;
590 m_owner
->SelectLine( this );
592 m_owner
->DeselectLine( this );
595 void wxListLineData::DrawRubberBand( wxPaintDC
*dc
, bool on
)
599 dc
->SetPen( wxBLACK_PEN
);
600 dc
->SetBrush( wxTRANSPARENT_BRUSH
);
601 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
602 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
606 void wxListLineData::Draw( wxPaintDC
*dc
)
608 DoDraw( dc
, m_hilighted
, m_hilighted
);
611 bool wxListLineData::IsInRect( int x
, int y
, const wxRectangle
&rect
)
613 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) && (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
616 bool wxListLineData::IsHilighted( void )
621 void wxListLineData::AssignRect( wxRectangle
&dest
, int x
, int y
, int width
, int height
)
626 dest
.height
= height
;
629 void wxListLineData::AssignRect( wxRectangle
&dest
, const wxRectangle
&source
)
633 dest
.width
= source
.width
;
634 dest
.height
= source
.height
;
637 //-----------------------------------------------------------------------------
638 // wxListHeaderWindow
639 //-----------------------------------------------------------------------------
641 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
643 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
644 EVT_PAINT (wxListHeaderWindow::OnPaint
)
645 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
646 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
649 wxListHeaderWindow::wxListHeaderWindow( void )
651 m_owner
= (wxListMainWindow
*) NULL
;
652 m_currentCursor
= (wxCursor
*) NULL
;
653 m_resizeCursor
= (wxCursor
*) NULL
;
657 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
658 const wxPoint
&pos
, const wxSize
&size
,
659 long style
, const wxString
&name
) :
660 wxWindow( win
, id
, pos
, size
, style
, name
)
663 // m_currentCursor = wxSTANDARD_CURSOR;
664 m_currentCursor
= (wxCursor
*) NULL
;
665 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
668 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
670 const int m_corner
= 1;
672 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
674 dc
->SetPen( *wxBLACK_PEN
);
675 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
676 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
678 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
679 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
680 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
682 dc
->SetPen( *wxWHITE_PEN
);
683 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
684 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
685 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
686 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
689 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
691 wxPaintDC
dc( this );
696 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
702 GetClientSize( &w
, &h
);
704 dc
.SetTextForeground( *wxBLACK
);
708 int numColumns
= m_owner
->GetColumnCount();
710 for (int i
= 0; i
< numColumns
; i
++)
712 m_owner
->GetColumn( i
, item
);
713 int cw
= item
.m_width
-2;
714 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
715 dc
.SetPen( *wxWHITE_PEN
);
717 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
718 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
719 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
720 dc
.DestroyClippingRegion();
727 void wxListHeaderWindow::DrawCurrent()
731 int x2
= m_currentX
-1;
733 m_owner
->GetClientSize( (int*)NULL
, &y2
);
734 ClientToScreen( &x1
, &y1
);
735 m_owner
->ClientToScreen( &x2
, &y2
);
738 dc
.SetLogicalFunction( wxXOR
);
739 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
740 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
742 dc
.DrawLine( x1
, y1
, x2
, y2
);
744 dc
.SetLogicalFunction( wxCOPY
);
746 dc
.SetPen( wxNullPen
);
747 dc
.SetBrush( wxNullBrush
);
750 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
752 int x
= event
.GetX();
753 int y
= event
.GetY();
757 if (event
.ButtonUp())
759 // wxScreenDC::EndDrawingOnTop();
761 wxYield(); // for debugging
763 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
768 GetClientSize( &size_x
, (int*) NULL
);
772 m_currentX
= m_minX
+7;
773 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
780 bool hit_border
= FALSE
;
782 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
784 xpos
+= m_owner
->GetColumnWidth( j
);
785 if ((abs(x
-xpos
) < 3) && (y
< 22))
794 if (event
.LeftDown() && hit_border
)
798 // wxScreenDC::StartDrawingOnTop( m_owner );
808 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
809 m_currentCursor
= m_resizeCursor
;
813 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
814 m_currentCursor
= wxSTANDARD_CURSOR
;
819 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
824 //-----------------------------------------------------------------------------
825 // wxListRenameTimer (internal)
826 //-----------------------------------------------------------------------------
828 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
833 void wxListRenameTimer::Notify()
835 m_owner
->OnRenameTimer();
838 //-----------------------------------------------------------------------------
839 // wxListTextCtrl (internal)
840 //-----------------------------------------------------------------------------
842 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
844 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
845 EVT_CHAR (wxListTextCtrl::OnChar
)
846 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
849 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
850 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
851 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
852 int style
, const wxValidator
& validator
, const wxString
&name
) :
853 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
860 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
862 if (event
.m_keyCode
== WXK_RETURN
)
865 (*m_res
) = GetValue();
866 m_owner
->OnRenameAccept();
871 if (event
.m_keyCode
== WXK_ESCAPE
)
882 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
891 //-----------------------------------------------------------------------------
893 //-----------------------------------------------------------------------------
895 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
897 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
898 EVT_PAINT (wxListMainWindow::OnPaint
)
899 EVT_SIZE (wxListMainWindow::OnSize
)
900 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
901 EVT_CHAR (wxListMainWindow::OnChar
)
902 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
903 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
906 wxListMainWindow::wxListMainWindow( void )
909 m_lines
.DeleteContents( TRUE
);
910 m_columns
.DeleteContents( TRUE
);
911 m_current
= (wxListLineData
*) NULL
;
913 m_hilightBrush
= (wxBrush
*) NULL
;
914 m_myFont
= (wxFont
*) NULL
;
918 m_small_image_list
= (wxImageList
*) NULL
;
919 m_normal_image_list
= (wxImageList
*) NULL
;
920 m_small_spacing
= 30;
921 m_normal_spacing
= 40;
924 m_lastOnSame
= FALSE
;
925 m_renameTimer
= new wxListRenameTimer( this );
930 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
931 const wxPoint
&pos
, const wxSize
&size
,
932 long style
, const wxString
&name
) :
933 wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
936 m_lines
.DeleteContents( TRUE
);
937 m_columns
.DeleteContents( TRUE
);
938 m_current
= (wxListLineData
*) NULL
;
941 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
942 m_small_image_list
= (wxImageList
*) NULL
;
943 m_normal_image_list
= (wxImageList
*) NULL
;
944 m_small_spacing
= 30;
945 m_normal_spacing
= 40;
946 // AllowDoubleClick( TRUE );
947 m_myFont
= wxNORMAL_FONT
;
954 if (m_mode
& wxLC_REPORT
)
964 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
967 m_lastOnSame
= FALSE
;
968 m_renameTimer
= new wxListRenameTimer( this );
969 m_renameAccept
= FALSE
;
970 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
971 // m_text->Show( FALSE );
973 SetBackgroundColour( *wxWHITE
);
976 wxListMainWindow::~wxListMainWindow( void )
978 if (m_hilightBrush
) delete m_hilightBrush
;
979 delete m_renameTimer
;
980 // if (m_hilightColour) delete m_hilightColour;
981 // if (m_myFont) delete m_myFont;
985 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
995 line
->GetExtent( x
, y
, w
, h
);
997 dc
.LogicalToDeviceX(x
-3),
998 dc
.LogicalToDeviceY(y
-3),
999 dc
.LogicalToDeviceXRel(w
+6),
1000 dc
.LogicalToDeviceXRel(h
+6) );
1001 Refresh( TRUE
, &rect
);
1005 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1007 if (m_dirty
) return;
1009 wxPaintDC
dc( this );
1014 // dc.SetFont( *m_myFont );
1015 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1017 wxNode
*node
= m_lines
.First();
1020 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1022 node
= node
->Next();
1024 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1029 void wxListMainWindow::HilightAll( bool on
)
1031 wxNode
*node
= m_lines
.First();
1034 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1035 if (line
->IsHilighted() != on
)
1037 line
->Hilight( on
);
1038 RefreshLine( line
);
1040 node
= node
->Next();
1044 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
1046 if (!GetParent()) return;
1047 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1048 le
.SetEventObject( GetParent() );
1050 le
.m_itemIndex
= GetIndexOfLine( line
);
1052 line
->GetItem( 0, le
.m_item
);
1056 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1058 if (!GetParent()) return;
1059 wxListEvent
le( command
, GetParent()->GetId() );
1060 le
.SetEventObject( GetParent() );
1062 le
.m_itemIndex
= GetIndexOfLine( line
);
1064 line
->GetItem( 0, le
.m_item
);
1068 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1070 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1073 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1075 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1078 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1080 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1083 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1085 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1088 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1090 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1093 void wxListMainWindow::StartLabelEdit( wxListLineData
*line
)
1095 SendNotify( line
, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
);
1098 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
1100 if (!GetParent()) return;
1102 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1103 le
.SetEventObject( GetParent() );
1105 le
.m_itemIndex
= GetIndexOfLine( line
);
1107 line
->GetItem( 0, le
.m_item
);
1108 le
.m_item
.m_text
= newName
;
1112 void wxListMainWindow::OnRenameTimer()
1114 StartLabelEdit( m_current
);
1116 m_current
->GetText( 0, s
);
1121 m_current
->GetLabelExtent( x
, y
, w
, h
);
1123 wxClientDC
dc(this);
1125 x
= dc
.LogicalToDeviceX( x
);
1126 y
= dc
.LogicalToDeviceY( y
);
1128 wxListTextCtrl
*text
= new wxListTextCtrl(
1129 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1132 m_text->SetSize( x+3, y+3, w+6, h+6 );
1133 m_text->SetValue( s );
1134 m_text->Show( TRUE );
1138 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1143 RenameLine( m_current, s );
1148 void wxListMainWindow::OnRenameAccept()
1150 RenameLine( m_current
, m_renameRes
);
1153 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1155 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1157 if (!m_current
) return;
1158 if (m_dirty
) return;
1160 wxClientDC
dc(this);
1162 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1163 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1166 wxNode
*node
= m_lines
.First();
1167 wxListLineData
*line
= (wxListLineData
*) NULL
;
1170 line
= (wxListLineData
*)node
->Data();
1171 hitResult
= line
->IsHit( x
, y
);
1172 if (hitResult
) break;
1173 line
= (wxListLineData
*) NULL
;
1174 node
= node
->Next();
1177 if (!event
.Dragging())
1182 if (event
.Dragging() && (m_dragCount
> 3))
1185 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, GetParent()->GetId() );
1186 le
.SetEventObject( this );
1195 if (event
.ButtonDClick())
1198 m_lastOnSame
= FALSE
;
1199 m_renameTimer
->Stop();
1200 ActivateLine( line
);
1204 if (event
.LeftUp() && m_lastOnSame
)
1207 if ((line
== m_current
) &&
1208 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1209 // (m_mode & wxLC_ICON) &&
1210 (m_mode
& wxLC_EDIT_LABELS
) )
1212 m_renameTimer
->Start( 100, TRUE
);
1214 m_lastOnSame
= FALSE
;
1218 if (event
.LeftDown())
1221 wxListLineData
*oldCurrent
= m_current
;
1222 if (m_mode
& wxLC_SINGLE_SEL
)
1225 HilightAll( FALSE
);
1226 m_current
->ReverseHilight();
1227 RefreshLine( m_current
);
1231 if (event
.ShiftDown())
1234 m_current
->ReverseHilight();
1235 RefreshLine( m_current
);
1237 else if (event
.ControlDown())
1240 int numOfCurrent
= -1;
1241 node
= m_lines
.First();
1244 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1246 if (test_line
== oldCurrent
) break;
1247 node
= node
->Next();
1250 node
= m_lines
.First();
1253 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1255 if (test_line
== line
) break;
1256 node
= node
->Next();
1259 if (numOfLine
< numOfCurrent
)
1260 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1261 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1262 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1264 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1265 test_line
->Hilight(TRUE
);
1266 RefreshLine( test_line
);
1267 node
= node
->Next();
1273 HilightAll( FALSE
);
1274 m_current
->ReverseHilight();
1275 RefreshLine( m_current
);
1278 if (m_current
!= oldCurrent
)
1280 RefreshLine( oldCurrent
);
1281 UnfocusLine( oldCurrent
);
1282 FocusLine( m_current
);
1284 m_lastOnSame
= (m_current
== oldCurrent
);
1290 void wxListMainWindow::MoveToFocus( void )
1292 if (!m_current
) return;
1298 m_current->GetExtent( x, y, w, h );
1301 GetClientSize( &w_p, &h_p );
1302 if (m_mode & wxLC_REPORT)
1304 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1305 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1306 if ((y > y_s) && (y+h < y_s+h_p)) return;
1307 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1308 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1312 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1313 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1314 if ((x > x_s) && (x+w < x_s+w_p)) return;
1315 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1316 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1321 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1323 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1324 wxListLineData
*oldCurrent
= m_current
;
1325 m_current
= newCurrent
;
1327 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1328 RefreshLine( m_current
);
1329 RefreshLine( oldCurrent
);
1330 FocusLine( m_current
);
1331 UnfocusLine( oldCurrent
);
1334 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1337 if (event.KeyCode() == WXK_TAB)
1339 if (event.ShiftDown())
1346 if (!m_current
) return;
1347 switch (event
.KeyCode())
1351 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1352 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1357 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1358 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1363 wxNode
*node
= m_lines
.Last();
1364 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1369 wxNode
*node
= m_lines
.First();
1370 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1376 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1380 wxNode
*node
= m_lines
.First();
1381 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1382 steps
= pos
% m_visibleLines
;
1384 wxNode
*node
= m_lines
.Member( m_current
);
1385 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1386 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1392 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1395 int pos
= 0; wxNode
*node
= m_lines
.First();
1396 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1397 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1399 wxNode
*node
= m_lines
.Member( m_current
);
1400 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1401 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1406 if (!(m_mode
& wxLC_REPORT
))
1408 wxNode
*node
= m_lines
.Member( m_current
);
1409 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1410 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1416 if (!(m_mode
& wxLC_REPORT
))
1418 wxNode
*node
= m_lines
.Member( m_current
);
1419 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1420 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1426 m_current
->ReverseHilight();
1427 RefreshLine( m_current
);
1432 if (!(m_mode
& wxLC_SINGLE_SEL
))
1434 wxListLineData
*oldCurrent
= m_current
;
1435 m_current
->ReverseHilight();
1436 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1437 if (node
) m_current
= (wxListLineData
*)node
->Data();
1439 RefreshLine( oldCurrent
);
1440 RefreshLine( m_current
);
1441 UnfocusLine( oldCurrent
);
1442 FocusLine( m_current
);
1449 ActivateLine( m_current
);
1461 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1464 RefreshLine( m_current
);
1466 if (!GetParent()) return;
1468 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1469 event
.SetEventObject( GetParent() );
1470 GetParent()->GetEventHandler()->ProcessEvent( event
);
1473 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1476 RefreshLine( m_current
);
1479 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1482 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1484 CalculatePositions();
1485 printf( "OnSize::Refresh.\n" );
1491 wxFont
*wxListMainWindow::GetMyFont( void )
1496 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1498 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1500 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1503 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1505 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1509 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1511 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1513 m_normal_image_list
->GetSize( index
, width
, height
);
1516 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1518 m_small_image_list
->GetSize( index
, width
, height
);
1525 int wxListMainWindow::GetTextLength( wxString
&s
)
1527 wxPaintDC
dc( this );
1530 dc
.GetTextExtent( s
, &lw
, &lh
);
1534 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1537 wxNode
*node
= m_lines
.First();
1540 if (line
== (wxListLineData
*)node
->Data()) return i
;
1542 node
= node
->Next();
1547 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1550 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1551 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1554 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1559 m_small_spacing
= spacing
;
1563 m_normal_spacing
= spacing
;
1567 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1569 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1572 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1575 wxNode
*node
= m_columns
.Nth( col
);
1578 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1579 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1580 column
->SetItem( item
);
1582 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1583 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1586 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1588 if (!(m_mode
& wxLC_REPORT
)) return;
1592 wxNode
*node
= m_columns
.Nth( col
);
1595 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1596 column
->SetWidth( width
);
1599 node
= m_lines
.First();
1602 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1603 wxNode
*n
= line
->m_items
.Nth( col
);
1606 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1607 item
->SetSize( width
, -1 );
1609 node
= node
->Next();
1612 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1613 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1616 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1618 wxNode
*node
= m_columns
.Nth( col
);
1621 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1622 column
->GetItem( item
);
1634 int wxListMainWindow::GetColumnWidth( int col
)
1636 wxNode
*node
= m_columns
.Nth( col
);
1639 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1640 return column
->GetWidth();
1646 int wxListMainWindow::GetColumnCount( void )
1648 return m_columns
.Number();
1651 int wxListMainWindow::GetCountPerPage( void )
1653 return m_visibleLines
;
1656 void wxListMainWindow::SetItem( wxListItem
&item
)
1659 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1662 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1663 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1664 line
->SetItem( item
.m_col
, item
);
1668 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1670 // m_dirty = TRUE; no recalcs needed
1672 wxListLineData
*oldCurrent
= m_current
;
1674 if (stateMask
& wxLIST_STATE_FOCUSED
)
1676 wxNode
*node
= m_lines
.Nth( item
);
1679 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1680 UnfocusLine( m_current
);
1682 FocusLine( m_current
);
1683 RefreshLine( m_current
);
1684 RefreshLine( oldCurrent
);
1688 if (stateMask
& wxLIST_STATE_SELECTED
)
1690 bool on
= state
& wxLIST_STATE_SELECTED
;
1691 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1693 wxNode
*node
= m_lines
.Nth( item
);
1696 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1697 if (m_mode
& wxLC_SINGLE_SEL
)
1699 UnfocusLine( m_current
);
1701 FocusLine( m_current
);
1702 oldCurrent
->Hilight( FALSE
);
1703 RefreshLine( m_current
);
1704 RefreshLine( oldCurrent
);
1706 bool on
= state
& wxLIST_STATE_SELECTED
;
1707 line
->Hilight( on
);
1708 RefreshLine( line
);
1713 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1715 int ret
= wxLIST_STATE_DONTCARE
;
1716 if (stateMask
& wxLIST_STATE_FOCUSED
)
1718 wxNode
*node
= m_lines
.Nth( item
);
1721 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1722 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1725 if (stateMask
& wxLIST_STATE_SELECTED
)
1727 wxNode
*node
= m_lines
.Nth( item
);
1730 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1731 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1737 void wxListMainWindow::GetItem( wxListItem
&item
)
1739 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1742 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1743 line
->GetItem( item
.m_col
, item
);
1754 int wxListMainWindow::GetItemCount( void )
1756 return m_lines
.Number();
1759 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1761 wxNode
*node
= m_lines
.Nth( index
);
1764 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1765 line
->GetRect( rect
);
1776 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1778 wxNode
*node
= m_lines
.Nth( item
);
1782 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1783 line
->GetRect( rect
);
1795 int wxListMainWindow::GetSelectedItemCount( void )
1798 wxNode
*node
= m_lines
.First();
1801 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1802 if (line
->IsHilighted()) ret
++;
1803 node
= node
->Next();
1808 void wxListMainWindow::SetMode( long mode
)
1815 if (m_mode
& wxLC_REPORT
)
1827 long wxListMainWindow::GetMode( void ) const
1832 void wxListMainWindow::CalculatePositions( void )
1834 wxPaintDC
dc( this );
1835 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1837 int iconSpacing
= 0;
1838 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1839 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1840 wxNode
*node
= m_lines
.First();
1843 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1844 line
->CalculateSize( &dc
, iconSpacing
);
1845 node
= node
->Next();
1850 int lineSpacing
= 0;
1852 node
= m_lines
.First();
1855 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1857 line
->GetSize( dummy
, lineSpacing
);
1863 lineSpacing
= 6 + (int)dc
.GetCharHeight();
1866 int clientWidth
= 0;
1867 int clientHeight
= 0;
1869 if (m_mode
& wxLC_REPORT
)
1873 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1874 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1875 GetClientSize( &clientWidth
, &clientHeight
);
1876 node
= m_lines
.First();
1879 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1880 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1882 for (int i
= 0; i
< GetColumnCount(); i
++)
1884 line
->SetColumnPosition( i
, col_x
);
1885 col_x
+= GetColumnWidth( i
);
1888 node
= node
->Next();
1893 // At first, we try without any scrollbar
1894 GetSize( &clientWidth
, &clientHeight
);
1896 int entireWidth
= 0;
1898 for (int tries
= 0; tries
< 2; tries
++)
1904 node
= m_lines
.First();
1907 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1908 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1909 line
->GetSize( lineWidth
, lineHeight
);
1910 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1912 if (y
+lineHeight
> clientHeight
-4)
1916 entireWidth
+= maxWidth
+13;
1919 node
= node
->Next();
1920 if (!node
) entireWidth
+= maxWidth
;
1921 if ((tries
== 0) && (entireWidth
> clientWidth
))
1923 clientHeight
-= 14; // scrollbar height
1926 if (!node
) tries
= 1;
1929 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1931 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1934 void wxListMainWindow::RealizeChanges( void )
1938 wxNode
*node
= m_lines
.First();
1939 if (node
) m_current
= (wxListLineData
*)node
->Data();
1943 FocusLine( m_current
);
1944 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1948 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1951 if (item
> 0) ret
= item
;
1952 wxNode
*node
= m_lines
.Nth( ret
);
1955 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1956 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1957 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1958 if (!state
) return ret
;
1960 node
= node
->Next();
1965 void wxListMainWindow::DeleteItem( long index
)
1968 wxNode
*node
= m_lines
.Nth( index
);
1971 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1972 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
1974 m_lines
.DeleteNode( node
);
1978 void wxListMainWindow::DeleteColumn( int col
)
1981 wxNode
*node
= m_columns
.Nth( col
);
1982 if (node
) m_columns
.DeleteNode( node
);
1985 void wxListMainWindow::DeleteAllItems( void )
1988 m_current
= (wxListLineData
*) NULL
;
1989 wxNode
*node
= m_lines
.First();
1992 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1994 node
= node
->Next();
1999 void wxListMainWindow::DeleteEverything( void )
2002 m_current
= (wxListLineData
*) NULL
;
2003 wxNode
*node
= m_lines
.First();
2006 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2008 node
= node
->Next();
2011 m_current
= (wxListLineData
*) NULL
;
2015 void wxListMainWindow::EnsureVisible( long index
)
2017 wxListLineData
*oldCurrent
= m_current
;
2018 m_current
= (wxListLineData
*) NULL
;
2020 wxNode
*node
= m_lines
.Nth( i
);
2021 if (node
) m_current
= (wxListLineData
*)node
->Data();
2022 if (m_current
) MoveToFocus();
2023 m_current
= oldCurrent
;
2026 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2030 if (pos
< 0) pos
= 0;
2031 wxNode
*node
= m_lines
.Nth( pos
);
2034 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2036 line
->GetText( 0, s
);
2037 if (s
== tmp
) return pos
;
2038 node
= node
->Next();
2044 long wxListMainWindow::FindItem(long start
, long data
)
2047 if (pos
< 0) pos
= 0;
2048 wxNode
*node
= m_lines
.Nth( pos
);
2051 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2053 line
->GetItem( 0, item
);
2054 if (item
.m_data
== data
) return pos
;
2055 node
= node
->Next();
2061 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2063 wxNode
*node
= m_lines
.First();
2067 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2068 long ret
= line
->IsHit( x
, y
);
2074 node
= node
->Next();
2080 void wxListMainWindow::InsertItem( wxListItem
&item
)
2084 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2085 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2086 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2087 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2088 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2089 if (m_mode
& wxLC_REPORT
)
2091 line
->InitItems( GetColumnCount() );
2092 item
.m_width
= GetColumnWidth( 0 )-3;
2095 line
->InitItems( 1 );
2096 line
->SetItem( 0, item
);
2097 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2099 m_lines
.Insert( node
, line
);
2101 m_lines
.Append( line
);
2104 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2107 if (m_mode
& wxLC_REPORT
)
2109 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2110 wxListHeaderData
*column
= new wxListHeaderData( item
);
2111 wxNode
*node
= m_columns
.Nth( col
);
2113 m_columns
.Insert( node
, column
);
2115 m_columns
.Append( column
);
2119 wxListCtrlCompare list_ctrl_compare_func_2
;
2120 long list_ctrl_compare_data
;
2122 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2124 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2125 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2127 line1
->GetItem( 0, item
);
2128 long data1
= item
.m_data
;
2129 line2
->GetItem( 0, item
);
2130 long data2
= item
.m_data
;
2131 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2134 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2136 list_ctrl_compare_func_2
= fn
;
2137 list_ctrl_compare_data
= data
;
2138 m_lines
.Sort( list_ctrl_compare_func_1
);
2141 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
2143 if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event
);
2147 // -------------------------------------------------------------------------------------
2149 // -------------------------------------------------------------------------------------
2151 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2153 wxListItem::wxListItem(void)
2162 m_format
= wxLIST_FORMAT_CENTRE
;
2167 // -------------------------------------------------------------------------------------
2169 // -------------------------------------------------------------------------------------
2171 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2173 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2174 wxCommandEvent( commandType
, id
)
2179 m_cancelled
= FALSE
;
2182 // -------------------------------------------------------------------------------------
2184 // -------------------------------------------------------------------------------------
2186 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2188 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2189 EVT_SIZE (wxListCtrl::OnSize
)
2190 EVT_IDLE (wxListCtrl::OnIdle
)
2193 wxListCtrl::wxListCtrl(void)
2195 m_imageListNormal
= (wxImageList
*) NULL
;
2196 m_imageListSmall
= (wxImageList
*) NULL
;
2197 m_imageListState
= (wxImageList
*) NULL
;
2200 wxListCtrl::~wxListCtrl(void)
2204 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2205 const wxPoint
&pos
, const wxSize
&size
,
2206 long style
, const wxValidator
&validator
,
2207 const wxString
&name
)
2209 m_imageListNormal
= (wxImageList
*) NULL
;
2210 m_imageListSmall
= (wxImageList
*) NULL
;
2211 m_imageListState
= (wxImageList
*) NULL
;
2215 if ((s
& wxLC_REPORT
== 0) &&
2216 (s
& wxLC_LIST
== 0) &&
2217 (s
& wxLC_ICON
== 0))
2220 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2222 SetValidator( validator
);
2224 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2226 if (GetWindowStyleFlag() & wxLC_REPORT
)
2227 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2229 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2234 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2236 // handled in OnIdle
2238 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2241 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2243 long flag
= GetWindowStyleFlag();
2247 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2248 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2249 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2258 if (flag
& style
) flag
-= style
;
2261 SetWindowStyleFlag( flag
);
2264 void wxListCtrl::SetWindowStyleFlag( long flag
)
2266 m_mainWin
->DeleteEverything();
2270 GetClientSize( &width
, &height
);
2272 m_mainWin
->SetMode( flag
);
2274 if (flag
& wxLC_REPORT
)
2276 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2278 // m_mainWin->SetSize( 0, 24, width, height-24 );
2281 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2285 // m_headerWin->SetSize( 0, 0, width, 23 );
2286 m_headerWin
->Show( TRUE
);
2292 if (GetWindowStyleFlag() & wxLC_REPORT
)
2294 // m_mainWin->SetSize( 0, 0, width, height );
2295 m_headerWin
->Show( FALSE
);
2299 wxWindow::SetWindowStyleFlag( flag
);
2302 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2304 m_mainWin
->GetColumn( col
, item
);
2308 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2310 m_mainWin
->SetColumn( col
, item
);
2314 int wxListCtrl::GetColumnWidth( int col
)
2316 return m_mainWin
->GetColumnWidth( col
);
2319 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2321 m_mainWin
->SetColumnWidth( col
, width
);
2325 int wxListCtrl::GetCountPerPage(void)
2327 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2331 wxText& wxListCtrl::GetEditControl(void) const
2336 bool wxListCtrl::GetItem( wxListItem
&info
)
2338 m_mainWin
->GetItem( info
);
2342 bool wxListCtrl::SetItem( wxListItem
&info
)
2344 m_mainWin
->SetItem( info
);
2348 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2351 info
.m_text
= label
;
2352 info
.m_mask
= wxLIST_MASK_TEXT
;
2353 info
.m_itemId
= index
;
2357 info
.m_image
= imageId
;
2358 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2361 m_mainWin
->SetItem(info
);
2365 int wxListCtrl::GetItemState( long item
, long stateMask
)
2367 return m_mainWin
->GetItemState( item
, stateMask
);
2370 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2372 m_mainWin
->SetItemState( item
, state
, stateMask
);
2376 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2379 info
.m_image
= image
;
2380 info
.m_mask
= wxLIST_MASK_IMAGE
;
2381 info
.m_itemId
= item
;
2382 m_mainWin
->SetItem( info
);
2386 wxString
wxListCtrl::GetItemText( long item
)
2389 info
.m_itemId
= item
;
2390 m_mainWin
->GetItem( info
);
2394 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2397 info
.m_mask
= wxLIST_MASK_TEXT
;
2398 info
.m_itemId
= item
;
2400 m_mainWin
->SetItem( info
);
2403 long wxListCtrl::GetItemData( long item
)
2406 info
.m_itemId
= item
;
2407 m_mainWin
->GetItem( info
);
2411 bool wxListCtrl::SetItemData( long item
, long data
)
2414 info
.m_mask
= wxLIST_MASK_DATA
;
2415 info
.m_itemId
= item
;
2417 m_mainWin
->SetItem( info
);
2421 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2423 m_mainWin
->GetItemRect( item
, rect
);
2427 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2429 m_mainWin
->GetItemPosition( item
, pos
);
2433 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2438 int wxListCtrl::GetItemCount(void)
2440 return m_mainWin
->GetItemCount();
2443 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2445 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2448 int wxListCtrl::GetItemSpacing( bool isSmall
)
2450 return m_mainWin
->GetItemSpacing( isSmall
);
2453 int wxListCtrl::GetSelectedItemCount(void)
2455 return m_mainWin
->GetSelectedItemCount();
2459 wxColour wxListCtrl::GetTextColour(void) const
2463 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2468 long wxListCtrl::GetTopItem(void)
2473 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2475 return m_mainWin
->GetNextItem( item
, geom
, state
);
2478 wxImageList
*wxListCtrl::GetImageList(int which
)
2480 if (which
== wxIMAGE_LIST_NORMAL
)
2482 return m_imageListNormal
;
2484 else if (which
== wxIMAGE_LIST_SMALL
)
2486 return m_imageListSmall
;
2488 else if (which
== wxIMAGE_LIST_STATE
)
2490 return m_imageListState
;
2492 return (wxImageList
*) NULL
;
2495 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2497 m_mainWin
->SetImageList( imageList
, which
);
2500 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2505 bool wxListCtrl::DeleteItem( long item
)
2507 m_mainWin
->DeleteItem( item
);
2511 bool wxListCtrl::DeleteAllItems(void)
2513 m_mainWin
->DeleteAllItems();
2517 bool wxListCtrl::DeleteColumn( int col
)
2519 m_mainWin
->DeleteColumn( col
);
2524 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2529 bool wxListCtrl::EnsureVisible( long item
)
2531 m_mainWin
->EnsureVisible( item
);
2535 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2537 return m_mainWin
->FindItem( start
, str
, partial
);
2540 long wxListCtrl::FindItem( long start
, long data
)
2542 return m_mainWin
->FindItem( start
, data
);
2545 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2546 int WXUNUSED(direction
))
2551 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2553 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2556 long wxListCtrl::InsertItem( wxListItem
& info
)
2558 m_mainWin
->InsertItem( info
);
2562 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2565 info
.m_text
= label
;
2566 info
.m_mask
= wxLIST_MASK_TEXT
;
2567 info
.m_itemId
= index
;
2568 return InsertItem( info
);
2571 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2574 info
.m_mask
= wxLIST_MASK_IMAGE
;
2575 info
.m_image
= imageIndex
;
2576 info
.m_itemId
= index
;
2577 return InsertItem( info
);
2580 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2583 info
.m_text
= label
;
2584 info
.m_image
= imageIndex
;
2585 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2586 info
.m_itemId
= index
;
2587 return InsertItem( info
);
2590 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2592 m_mainWin
->InsertColumn( col
, item
);
2596 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2597 int format
, int width
)
2600 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2601 item
.m_text
= heading
;
2604 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2605 item
.m_width
= width
;
2608 item
.m_format
= format
;
2610 return InsertColumn( col
, item
);
2613 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2619 // fn is a function which takes 3 long arguments: item1, item2, data.
2620 // item1 is the long data associated with a first item (NOT the index).
2621 // item2 is the long data associated with a second item (NOT the index).
2622 // data is the same value as passed to SortItems.
2623 // The return value is a negative number if the first item should precede the second
2624 // item, a positive number of the second item should precede the first,
2625 // or zero if the two items are equivalent.
2626 // data is arbitrary data to be passed to the sort function.
2628 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2630 m_mainWin
->SortItems( fn
, data
);
2634 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2636 if (!m_mainWin
->m_dirty
) return;
2640 GetClientSize( &cw
, &ch
);
2647 if (GetWindowStyleFlag() & wxLC_REPORT
)
2649 m_headerWin
->GetPosition( &x
, &y
);
2650 m_headerWin
->GetSize( &w
, &h
);
2651 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2652 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2654 m_mainWin
->GetPosition( &x
, &y
);
2655 m_mainWin
->GetSize( &w
, &h
);
2656 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2657 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2661 m_mainWin
->GetPosition( &x
, &y
);
2662 m_mainWin
->GetSize( &w
, &h
);
2663 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2664 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2667 m_mainWin
->CalculatePositions();
2668 m_mainWin
->RealizeChanges();
2669 m_mainWin
->m_dirty
= FALSE
;
2670 m_mainWin
->Refresh();