1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #include "wx/dcscreen.h"
23 #include "wx/listctrl.h"
24 #include "wx/generic/imaglist.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
32 wxListItemData::wxListItemData()
43 wxListItemData::wxListItemData( const wxListItem
&info
)
47 m_colour
= info
.m_colour
;
51 void wxListItemData::SetItem( const wxListItem
&info
)
53 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
54 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
55 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
56 m_colour
= info
.m_colour
;
59 m_width
= info
.m_width
;
63 void wxListItemData::SetText( const wxString
&s
)
68 void wxListItemData::SetImage( int image
)
73 void wxListItemData::SetData( long data
)
78 void wxListItemData::SetPosition( int x
, int y
)
84 void wxListItemData::SetSize( int width
, int height
)
86 if (width
!= -1) m_width
= width
;
87 if (height
!= -1) m_height
= height
;
90 void wxListItemData::SetColour( wxColour
*col
)
95 bool wxListItemData::HasImage() const
97 return (m_image
>= 0);
100 bool wxListItemData::HasText() const
102 return (!m_text
.IsNull());
105 bool wxListItemData::IsHit( int x
, int y
) const
107 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
110 void wxListItemData::GetText( wxString
&s
)
115 int wxListItemData::GetX() const
120 int wxListItemData::GetY() const
125 int wxListItemData::GetWidth() const
130 int wxListItemData::GetHeight() const
135 int wxListItemData::GetImage() const
140 void wxListItemData::GetItem( wxListItem
&info
)
142 info
.m_text
= m_text
;
143 info
.m_image
= m_image
;
144 info
.m_data
= m_data
;
145 info
.m_colour
= m_colour
;
148 wxColour
*wxListItemData::GetColour()
153 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
157 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
159 wxListHeaderData::wxListHeaderData()
170 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
178 void wxListHeaderData::SetItem( const wxListItem
&item
)
180 m_mask
= item
.m_mask
;
181 m_text
= item
.m_text
;
182 m_image
= item
.m_image
;
183 m_format
= item
.m_format
;
184 m_width
= item
.m_width
;
185 if (m_width
< 0) m_width
= 80;
186 if (m_width
< 6) m_width
= 6;
189 void wxListHeaderData::SetPosition( int x
, int y
)
195 void wxListHeaderData::SetHeight( int h
)
200 void wxListHeaderData::SetWidth( int w
)
203 if (m_width
< 0) m_width
= 80;
204 if (m_width
< 6) m_width
= 6;
207 void wxListHeaderData::SetFormat( int format
)
212 bool wxListHeaderData::HasImage() const
214 return (m_image
!= 0);
217 bool wxListHeaderData::HasText() const
219 return (m_text
.Length() > 0);
222 bool wxListHeaderData::IsHit( int x
, int y
) const
224 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
227 void wxListHeaderData::GetItem( wxListItem
&item
)
229 item
.m_mask
= m_mask
;
230 item
.m_text
= m_text
;
231 item
.m_image
= m_image
;
232 item
.m_format
= m_format
;
233 item
.m_width
= m_width
;
236 void wxListHeaderData::GetText( wxString
&s
)
241 int wxListHeaderData::GetImage() const
246 int wxListHeaderData::GetWidth() const
251 int wxListHeaderData::GetFormat() const
256 //-----------------------------------------------------------------------------
258 //-----------------------------------------------------------------------------
260 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
262 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
267 m_hilightBrush
= hilightBrush
;
268 m_items
.DeleteContents( TRUE
);
272 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
279 m_bound_all
.width
= m_spacing
;
280 m_bound_all
.height
= m_spacing
+13;
281 wxNode
*node
= m_items
.First();
284 wxListItemData
*item
= (wxListItemData
*)node
->Data();
288 dc
->GetTextExtent( s
, &lw
, &lh
);
289 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
295 wxNode
*node
= m_items
.First();
298 wxListItemData
*item
= (wxListItemData
*)node
->Data();
302 dc
->GetTextExtent( s
, &lw
, &lh
);
303 m_bound_all
.width
= lw
;
304 m_bound_all
.height
= lh
;
305 if (item
->HasImage())
309 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
310 m_bound_all
.width
+= 4 + w
;
311 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
318 m_bound_all
.width
= 0;
319 m_bound_all
.height
= 0;
320 wxNode
*node
= m_items
.First();
323 wxListItemData
*item
= (wxListItemData
*)node
->Data();
326 if (s
.IsNull()) s
= "H";
328 dc
->GetTextExtent( s
, (long*) NULL
, &lh
);
329 item
->SetSize( item
->GetWidth(), lh
);
330 m_bound_all
.height
= lh
;
338 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
346 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
347 AssignRect( m_bound_label
, 0, 0, 0, 0 );
348 AssignRect( m_bound_hilight
, m_bound_all
);
349 wxNode
*node
= m_items
.First();
352 wxListItemData
*item
= (wxListItemData
*)node
->Data();
353 if (item
->HasImage())
355 wxListItemData
*item
= (wxListItemData
*)node
->Data();
358 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
359 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
360 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
361 m_bound_icon
.width
= w
;
362 m_bound_icon
.height
= h
;
363 if (!item
->HasText())
365 AssignRect( m_bound_hilight
, m_bound_icon
);
366 m_bound_hilight
.x
-= 5;
367 m_bound_hilight
.y
-= 5;
368 m_bound_hilight
.width
+= 9;
369 m_bound_hilight
.height
+= 9;
377 dc
->GetTextExtent( s
, &lw
, &lh
);
378 if (m_bound_all
.width
> m_spacing
)
379 m_bound_label
.x
= m_bound_all
.x
;
381 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
382 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
383 m_bound_label
.width
= lw
;
384 m_bound_label
.height
= lh
;
385 AssignRect( m_bound_hilight
, m_bound_label
);
386 m_bound_hilight
.x
-= 2;
387 m_bound_hilight
.y
-= 2;
388 m_bound_hilight
.width
+= 4;
389 m_bound_hilight
.height
+= 4;
396 AssignRect( m_bound_label
, m_bound_all
);
399 m_bound_all
.width
+= 4;
400 m_bound_all
.height
+= 3;
401 AssignRect( m_bound_hilight
, m_bound_all
);
402 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
403 wxNode
*node
= m_items
.First();
406 wxListItemData
*item
= (wxListItemData
*)node
->Data();
407 if (item
->HasImage())
409 m_bound_icon
.x
= m_bound_all
.x
+ 2;
410 m_bound_icon
.y
= m_bound_all
.y
+ 2;
413 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
414 m_bound_icon
.width
= w
;
415 m_bound_icon
.height
= h
;
416 m_bound_label
.x
+= 4 + w
;
417 m_bound_label
.width
-= 4 + w
;
425 dc
->GetTextExtent( "H", &lw
, &lh
);
428 m_bound_all
.height
= lh
+3;
429 m_bound_all
.width
= window_width
;
430 AssignRect( m_bound_hilight
, m_bound_all
);
431 AssignRect( m_bound_label
, m_bound_all
);
432 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
433 wxNode
*node
= m_items
.First();
436 wxListItemData
*item
= (wxListItemData
*)node
->Data();
439 if (s
.IsEmpty()) s
= _T("H");
441 dc
->GetTextExtent( s
, &lw
, &lh
);
442 m_bound_label
.width
= lw
;
443 m_bound_label
.height
= lh
;
444 if (item
->HasImage())
446 m_bound_icon
.x
= m_bound_all
.x
+ 2;
447 m_bound_icon
.y
= m_bound_all
.y
+ 2;
450 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
451 m_bound_icon
.width
= w
;
452 m_bound_icon
.height
= h
;
453 m_bound_label
.x
+= 4 + w
;
461 void wxListLineData::SetColumnPosition( int index
, int x
)
464 wxNode
*node
= m_items
.Nth( i
);
467 wxListItemData
*item
= (wxListItemData
*)node
->Data();
468 item
->SetPosition( x
, m_bound_all
.y
+1 );
472 void wxListLineData::GetSize( int &width
, int &height
)
474 width
= m_bound_all
.width
;
475 height
= m_bound_all
.height
;
478 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
482 width
= m_bound_all
.width
;
483 height
= m_bound_all
.height
;
486 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
490 width
= m_bound_label
.width
;
491 height
= m_bound_label
.height
;
494 void wxListLineData::GetRect( wxRect
&rect
)
496 AssignRect( rect
, m_bound_all
);
499 long wxListLineData::IsHit( int x
, int y
)
501 wxNode
*node
= m_items
.First();
504 wxListItemData
*item
= (wxListItemData
*)node
->Data();
505 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
506 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
507 // if (!(item->HasImage() || item->HasText())) return 0;
509 // if there is no icon or text = empty
510 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
514 void wxListLineData::InitItems( int num
)
516 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
519 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
521 wxNode
*node
= m_items
.Nth( index
);
524 wxListItemData
*item
= (wxListItemData
*)node
->Data();
525 item
->SetItem( info
);
529 void wxListLineData::GetItem( int index
, wxListItem
&info
)
532 wxNode
*node
= m_items
.Nth( i
);
535 wxListItemData
*item
= (wxListItemData
*)node
->Data();
536 item
->GetItem( info
);
540 void wxListLineData::GetText( int index
, wxString
&s
)
543 wxNode
*node
= m_items
.Nth( i
);
547 wxListItemData
*item
= (wxListItemData
*)node
->Data();
552 void wxListLineData::SetText( int index
, const wxString s
)
555 wxNode
*node
= m_items
.Nth( i
);
558 wxListItemData
*item
= (wxListItemData
*)node
->Data();
563 int wxListLineData::GetImage( int index
)
566 wxNode
*node
= m_items
.Nth( i
);
569 wxListItemData
*item
= (wxListItemData
*)node
->Data();
570 return item
->GetImage();
575 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
577 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
578 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
579 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
580 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
582 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
591 dc
->SetBrush( * m_hilightBrush
);
592 dc
->SetPen( * wxTRANSPARENT_PEN
);
596 dc
->SetBrush( * wxWHITE_BRUSH
);
597 dc
->SetPen( * wxTRANSPARENT_PEN
);
599 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
600 m_bound_hilight
.width
, m_bound_hilight
.height
);
603 dc
->SetBackgroundMode(wxTRANSPARENT
);
604 if (m_mode
== wxLC_REPORT
)
607 wxNode
*node
= m_items
.First();
610 wxListItemData
*item
= (wxListItemData
*)node
->Data();
611 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
612 int x
= item
->GetX();
613 if (item
->HasImage())
616 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
617 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
618 x
+= item
->GetX() + 5;
624 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
626 dc
->SetTextForeground( *item
->GetColour() );
627 dc
->DrawText( s
, x
, item
->GetY() );
629 dc
->DestroyClippingRegion();
635 wxNode
*node
= m_items
.First();
638 wxListItemData
*item
= (wxListItemData
*)node
->Data();
639 if (item
->HasImage())
641 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
648 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
650 dc
->SetTextForeground( * item
->GetColour() );
651 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
657 void wxListLineData::Hilight( bool on
)
659 if (on
== m_hilighted
) return;
661 m_owner
->SelectLine( this );
663 m_owner
->DeselectLine( this );
667 void wxListLineData::ReverseHilight( void )
669 m_hilighted
= !m_hilighted
;
671 m_owner
->SelectLine( this );
673 m_owner
->DeselectLine( this );
676 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
680 dc
->SetPen( * wxBLACK_PEN
);
681 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
682 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
683 m_bound_hilight
.width
, m_bound_hilight
.height
);
687 void wxListLineData::Draw( wxDC
*dc
)
689 DoDraw( dc
, m_hilighted
, m_hilighted
);
692 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
694 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
695 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
698 bool wxListLineData::IsHilighted( void )
703 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
708 dest
.height
= height
;
711 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
715 dest
.width
= source
.width
;
716 dest
.height
= source
.height
;
719 //-----------------------------------------------------------------------------
720 // wxListHeaderWindow
721 //-----------------------------------------------------------------------------
723 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
725 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
726 EVT_PAINT (wxListHeaderWindow::OnPaint
)
727 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
728 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
731 wxListHeaderWindow::wxListHeaderWindow( void )
733 m_owner
= (wxListMainWindow
*) NULL
;
734 m_currentCursor
= (wxCursor
*) NULL
;
735 m_resizeCursor
= (wxCursor
*) NULL
;
736 m_isDragging
= FALSE
;
739 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
740 const wxPoint
&pos
, const wxSize
&size
,
741 long style
, const wxString
&name
) :
742 wxWindow( win
, id
, pos
, size
, style
, name
)
745 // m_currentCursor = wxSTANDARD_CURSOR;
746 m_currentCursor
= (wxCursor
*) NULL
;
747 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
748 m_isDragging
= FALSE
;
749 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
752 wxListHeaderWindow::~wxListHeaderWindow( void )
754 delete m_resizeCursor
;
757 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
759 const int m_corner
= 1;
761 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
763 dc
->SetPen( *wxBLACK_PEN
);
764 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
765 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
767 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
770 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
771 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
773 dc
->SetPen( *wxWHITE_PEN
);
774 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
775 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
776 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
777 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
780 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
782 wxPaintDC
dc( this );
787 dc
.SetFont( GetFont() );
793 GetClientSize( &w
, &h
);
795 dc
.SetBackgroundMode(wxTRANSPARENT
);
796 dc
.SetTextForeground( *wxBLACK
);
797 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
801 int numColumns
= m_owner
->GetColumnCount();
803 for (int i
= 0; i
< numColumns
; i
++)
805 m_owner
->GetColumn( i
, item
);
806 int cw
= item
.m_width
-2;
807 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
808 dc
.SetPen( *wxWHITE_PEN
);
810 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
811 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
812 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
813 dc
.DestroyClippingRegion();
820 void wxListHeaderWindow::DrawCurrent()
824 int x2
= m_currentX
-1;
827 m_owner
->GetClientSize( &dummy
, &y2
);
828 ClientToScreen( &x1
, &y1
);
829 m_owner
->ClientToScreen( &x2
, &y2
);
832 dc
.SetLogicalFunction( wxINVERT
);
833 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
834 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
836 dc
.DrawLine( x1
, y1
, x2
, y2
);
838 dc
.SetLogicalFunction( wxCOPY
);
840 dc
.SetPen( wxNullPen
);
841 dc
.SetBrush( wxNullBrush
);
844 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
846 int x
= event
.GetX();
847 int y
= event
.GetY();
851 if (event
.ButtonUp())
854 m_isDragging
= FALSE
;
855 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
861 GetClientSize( &size_x
, & dummy
);
865 m_currentX
= m_minX
+7;
866 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
873 bool hit_border
= FALSE
;
875 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
877 xpos
+= m_owner
->GetColumnWidth( j
);
878 if ((abs(x
-xpos
) < 3) && (y
< 22))
887 if (event
.LeftDown() && hit_border
)
900 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
901 m_currentCursor
= m_resizeCursor
;
905 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
906 m_currentCursor
= wxSTANDARD_CURSOR
;
911 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
916 //-----------------------------------------------------------------------------
917 // wxListRenameTimer (internal)
918 //-----------------------------------------------------------------------------
920 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
925 void wxListRenameTimer::Notify()
927 m_owner
->OnRenameTimer();
930 //-----------------------------------------------------------------------------
931 // wxListTextCtrl (internal)
932 //-----------------------------------------------------------------------------
934 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
936 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
937 EVT_CHAR (wxListTextCtrl::OnChar
)
938 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
941 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
942 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
943 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
944 int style
, const wxValidator
& validator
, const wxString
&name
) :
945 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
952 m_startValue
= value
;
955 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
957 if (event
.m_keyCode
== WXK_RETURN
)
960 (*m_res
) = GetValue();
964 if (event
.m_keyCode
== WXK_ESCAPE
)
974 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
976 if (wxPendingDelete
.Member(this)) return;
978 wxPendingDelete
.Append(this);
980 if ((*m_accept
) && ((*m_res
) != m_startValue
))
981 m_owner
->OnRenameAccept();
984 //-----------------------------------------------------------------------------
986 //-----------------------------------------------------------------------------
988 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
990 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
991 EVT_PAINT (wxListMainWindow::OnPaint
)
992 EVT_SIZE (wxListMainWindow::OnSize
)
993 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
994 EVT_CHAR (wxListMainWindow::OnChar
)
995 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
996 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
997 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1000 wxListMainWindow::wxListMainWindow()
1003 m_lines
.DeleteContents( TRUE
);
1004 m_columns
.DeleteContents( TRUE
);
1005 m_current
= (wxListLineData
*) NULL
;
1007 m_hilightBrush
= (wxBrush
*) NULL
;
1011 m_small_image_list
= (wxImageList
*) NULL
;
1012 m_normal_image_list
= (wxImageList
*) NULL
;
1013 m_small_spacing
= 30;
1014 m_normal_spacing
= 40;
1017 m_lastOnSame
= FALSE
;
1018 m_renameTimer
= new wxListRenameTimer( this );
1019 m_isCreated
= FALSE
;
1023 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1024 const wxPoint
&pos
, const wxSize
&size
,
1025 long style
, const wxString
&name
) :
1026 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1029 m_lines
.DeleteContents( TRUE
);
1030 m_columns
.DeleteContents( TRUE
);
1031 m_current
= (wxListLineData
*) NULL
;
1034 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1035 m_small_image_list
= (wxImageList
*) NULL
;
1036 m_normal_image_list
= (wxImageList
*) NULL
;
1037 m_small_spacing
= 30;
1038 m_normal_spacing
= 40;
1041 m_isCreated
= FALSE
;
1045 if (m_mode
& wxLC_REPORT
)
1055 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1058 m_lastOnSame
= FALSE
;
1059 m_renameTimer
= new wxListRenameTimer( this );
1060 m_renameAccept
= FALSE
;
1062 SetBackgroundColour( *wxWHITE
);
1065 wxListMainWindow::~wxListMainWindow()
1067 if (m_hilightBrush
) delete m_hilightBrush
;
1069 delete m_renameTimer
;
1072 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1080 wxClientDC
dc(this);
1082 line
->GetExtent( x
, y
, w
, h
);
1084 dc
.LogicalToDeviceX(x
-3),
1085 dc
.LogicalToDeviceY(y
-3),
1086 dc
.LogicalToDeviceXRel(w
+6),
1087 dc
.LogicalToDeviceXRel(h
+6) );
1088 Refresh( TRUE
, &rect
);
1092 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1094 // Note: a wxPaintDC must be constructed even if no drawing is
1095 // done (a Windows requirement).
1096 wxPaintDC
dc( this );
1099 if (m_dirty
) return;
1101 if (m_lines
.GetCount() == 0) return;
1105 dc
.SetFont( GetFont() );
1107 if (m_mode
& wxLC_REPORT
)
1109 int lineSpacing
= 0;
1110 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1112 line
->GetSize( dummy
, lineSpacing
);
1115 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1117 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1118 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1122 line
= (wxListLineData
*)node
->Data();
1124 node
= node
->Next();
1129 wxNode
*node
= m_lines
.First();
1132 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1134 node
= node
->Next();
1138 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1143 void wxListMainWindow::HilightAll( bool on
)
1145 wxNode
*node
= m_lines
.First();
1148 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1149 if (line
->IsHilighted() != on
)
1151 line
->Hilight( on
);
1152 RefreshLine( line
);
1154 node
= node
->Next();
1158 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1160 wxListEvent
le( command
, GetParent()->GetId() );
1161 le
.SetEventObject( GetParent() );
1162 le
.m_itemIndex
= GetIndexOfLine( line
);
1163 line
->GetItem( 0, le
.m_item
);
1164 GetParent()->GetEventHandler()->ProcessEvent( le
);
1167 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1169 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1172 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1174 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1177 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1179 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1182 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1184 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1187 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1189 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1194 void wxListMainWindow::EditLabel( long item
)
1196 wxNode
*node
= m_lines
.Nth( item
);
1197 wxCHECK_RET( node
, _T("wrong index in wxListCtrl::Edit()") );
1199 m_currentEdit
= (wxListLineData
*) node
->Data();
1201 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1202 le
.SetEventObject( GetParent() );
1203 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1204 m_currentEdit
->GetItem( 0, le
.m_item
);
1205 GetParent()->GetEventHandler()->ProcessEvent( le
);
1207 if (!le
.IsAllowed())
1210 // We have to call this here because the label in
1211 // question might just have been added and no screen
1212 // update taken place.
1213 if (m_dirty
) wxYield();
1216 m_currentEdit
->GetText( 0, s
);
1221 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1223 wxClientDC
dc(this);
1225 x
= dc
.LogicalToDeviceX( x
);
1226 y
= dc
.LogicalToDeviceY( y
);
1228 wxListTextCtrl
*text
= new wxListTextCtrl(
1229 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1233 void wxListMainWindow::OnRenameTimer()
1235 wxCHECK_RET( m_current
, _T("invalid m_current") );
1237 Edit( m_lines
.IndexOf( m_current
) );
1240 void wxListMainWindow::OnRenameAccept()
1242 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1243 le
.SetEventObject( GetParent() );
1244 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1245 m_currentEdit
->GetItem( 0, le
.m_item
);
1246 le
.m_item
.m_text
= m_renameRes
;
1247 GetParent()->GetEventHandler()->ProcessEvent( le
);
1249 if (!le
.IsAllowed()) return;
1252 info
.m_mask
= wxLIST_MASK_TEXT
;
1253 info
.m_itemId
= le
.m_itemIndex
;
1254 info
.m_text
= m_renameRes
;
1255 info
.m_colour
= le
.m_item
.m_colour
;
1259 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1261 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1263 if (!m_current
) return;
1264 if (m_dirty
) return;
1265 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1267 wxClientDC
dc(this);
1269 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1270 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1272 /* Did we actually hit an item ? */
1274 wxNode
*node
= m_lines
.First();
1275 wxListLineData
*line
= (wxListLineData
*) NULL
;
1278 line
= (wxListLineData
*)node
->Data();
1279 hitResult
= line
->IsHit( x
, y
);
1280 if (hitResult
) break;
1281 line
= (wxListLineData
*) NULL
;
1282 node
= node
->Next();
1285 if (event
.Dragging())
1287 if (m_dragCount
== 0)
1288 m_dragStart
= wxPoint(x
,y
);
1292 if (m_dragCount
!= 3) return;
1294 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1295 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1297 wxListEvent
le( command
, GetParent()->GetId() );
1298 le
.SetEventObject( GetParent() );
1299 le
.m_pointDrag
= m_dragStart
;
1300 GetParent()->GetEventHandler()->ProcessEvent( le
);
1311 if (event
.ButtonDClick())
1314 m_lastOnSame
= FALSE
;
1315 m_renameTimer
->Stop();
1317 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1322 if (event
.LeftUp() && m_lastOnSame
)
1325 if ((line
== m_current
) &&
1326 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1327 (m_mode
& wxLC_EDIT_LABELS
) )
1329 m_renameTimer
->Start( 100, TRUE
);
1331 m_lastOnSame
= FALSE
;
1335 if (event
.RightDown())
1337 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1341 if (event
.MiddleDown())
1343 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1347 if (event
.LeftDown())
1350 wxListLineData
*oldCurrent
= m_current
;
1351 if (m_mode
& wxLC_SINGLE_SEL
)
1354 HilightAll( FALSE
);
1355 m_current
->ReverseHilight();
1356 RefreshLine( m_current
);
1360 if (event
.ShiftDown())
1363 m_current
->ReverseHilight();
1364 RefreshLine( m_current
);
1366 else if (event
.ControlDown())
1370 int numOfCurrent
= -1;
1371 node
= m_lines
.First();
1374 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1376 if (test_line
== oldCurrent
) break;
1377 node
= node
->Next();
1381 node
= m_lines
.First();
1384 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1386 if (test_line
== line
) break;
1387 node
= node
->Next();
1390 if (numOfLine
< numOfCurrent
)
1393 numOfLine
= numOfCurrent
;
1397 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1398 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1400 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1401 test_line
->Hilight(TRUE
);
1402 RefreshLine( test_line
);
1403 node
= node
->Next();
1409 HilightAll( FALSE
);
1410 m_current
->ReverseHilight();
1411 RefreshLine( m_current
);
1414 if (m_current
!= oldCurrent
)
1416 RefreshLine( oldCurrent
);
1417 UnfocusLine( oldCurrent
);
1418 FocusLine( m_current
);
1420 m_lastOnSame
= (m_current
== oldCurrent
);
1425 void wxListMainWindow::MoveToFocus()
1427 if (!m_current
) return;
1433 m_current
->GetExtent( x
, y
, w
, h
);
1437 GetClientSize( &w_p
, &h_p
);
1439 if (m_mode
& wxLC_REPORT
)
1441 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1442 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1443 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); Refresh(); }
1444 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); Refresh(); }
1448 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1449 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1450 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); Refresh(); }
1451 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); Refresh(); }
1455 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1457 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1458 wxListLineData
*oldCurrent
= m_current
;
1459 m_current
= newCurrent
;
1461 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1462 RefreshLine( m_current
);
1463 RefreshLine( oldCurrent
);
1464 FocusLine( m_current
);
1465 UnfocusLine( oldCurrent
);
1468 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1470 wxWindow
*parent
= GetParent();
1472 /* we propagate the key event up */
1473 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1474 ke
.m_shiftDown
= event
.m_shiftDown
;
1475 ke
.m_controlDown
= event
.m_controlDown
;
1476 ke
.m_altDown
= event
.m_altDown
;
1477 ke
.m_metaDown
= event
.m_metaDown
;
1478 ke
.m_keyCode
= event
.m_keyCode
;
1481 ke
.SetEventObject( parent
);
1482 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1487 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1489 wxWindow
*parent
= GetParent();
1491 /* we send a list_key event up */
1492 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1493 le
.m_code
= event
.KeyCode();
1494 le
.SetEventObject( parent
);
1495 parent
->GetEventHandler()->ProcessEvent( le
);
1497 /* we propagate the char event up */
1498 wxKeyEvent
ke( wxEVT_CHAR
);
1499 ke
.m_shiftDown
= event
.m_shiftDown
;
1500 ke
.m_controlDown
= event
.m_controlDown
;
1501 ke
.m_altDown
= event
.m_altDown
;
1502 ke
.m_metaDown
= event
.m_metaDown
;
1503 ke
.m_keyCode
= event
.m_keyCode
;
1506 ke
.SetEventObject( parent
);
1507 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1509 if (event
.KeyCode() == WXK_TAB
)
1511 wxNavigationKeyEvent nevent
;
1512 nevent
.SetDirection( !event
.ShiftDown() );
1513 nevent
.SetCurrentFocus( m_parent
);
1514 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1517 /* no item -> nothing to do */
1524 switch (event
.KeyCode())
1528 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1529 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1534 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1535 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1540 wxNode
*node
= m_lines
.Last();
1541 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1546 wxNode
*node
= m_lines
.First();
1547 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1553 if (m_mode
& wxLC_REPORT
)
1555 steps
= m_visibleLines
-1;
1560 wxNode
*node
= m_lines
.First();
1561 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1562 steps
= pos
% m_visibleLines
;
1564 wxNode
*node
= m_lines
.Member( m_current
);
1565 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1566 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1572 if (m_mode
& wxLC_REPORT
)
1574 steps
= m_visibleLines
-1;
1578 int pos
= 0; wxNode
*node
= m_lines
.First();
1579 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1580 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1582 wxNode
*node
= m_lines
.Member( m_current
);
1583 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1584 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1589 if (!(m_mode
& wxLC_REPORT
))
1591 wxNode
*node
= m_lines
.Member( m_current
);
1592 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1593 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1599 if (!(m_mode
& wxLC_REPORT
))
1601 wxNode
*node
= m_lines
.Member( m_current
);
1602 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1603 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1609 m_current
->ReverseHilight();
1610 RefreshLine( m_current
);
1615 if (!(m_mode
& wxLC_SINGLE_SEL
))
1617 wxListLineData
*oldCurrent
= m_current
;
1618 m_current
->ReverseHilight();
1619 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1620 if (node
) m_current
= (wxListLineData
*)node
->Data();
1622 RefreshLine( oldCurrent
);
1623 RefreshLine( m_current
);
1624 UnfocusLine( oldCurrent
);
1625 FocusLine( m_current
);
1632 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1633 le
.SetEventObject( GetParent() );
1634 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1635 m_current
->GetItem( 0, le
.m_item
);
1636 GetParent()->GetEventHandler()->ProcessEvent( le
);
1649 extern wxWindow
*g_focusWindow
;
1652 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1655 RefreshLine( m_current
);
1657 if (!GetParent()) return;
1660 g_focusWindow
= GetParent();
1663 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1664 event
.SetEventObject( GetParent() );
1665 GetParent()->GetEventHandler()->ProcessEvent( event
);
1668 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1671 RefreshLine( m_current
);
1674 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1677 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1682 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1684 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1686 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1689 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1691 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1693 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1695 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1697 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1699 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1704 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1706 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1708 m_normal_image_list
->GetSize( index
, width
, height
);
1711 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1713 m_small_image_list
->GetSize( index
, width
, height
);
1716 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1718 m_small_image_list
->GetSize( index
, width
, height
);
1721 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1723 m_small_image_list
->GetSize( index
, width
, height
);
1730 int wxListMainWindow::GetTextLength( wxString
&s
)
1732 wxClientDC
dc( this );
1735 dc
.GetTextExtent( s
, &lw
, &lh
);
1739 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1742 wxNode
*node
= m_lines
.First();
1745 if (line
== (wxListLineData
*)node
->Data()) return i
;
1747 node
= node
->Next();
1752 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1755 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1756 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1759 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1764 m_small_spacing
= spacing
;
1768 m_normal_spacing
= spacing
;
1772 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1774 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1777 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1780 wxNode
*node
= m_columns
.Nth( col
);
1783 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1784 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1785 column
->SetItem( item
);
1787 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1788 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1791 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1793 if (!(m_mode
& wxLC_REPORT
)) return;
1797 wxNode
*node
= (wxNode
*) NULL
;
1799 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1800 if (width
== wxLIST_AUTOSIZE
)
1802 wxClientDC
dc(this);
1803 dc
.SetFont( GetFont() );
1805 node
= m_lines
.First();
1808 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1809 wxNode
*n
= line
->m_items
.Nth( col
);
1812 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1813 int current
= 0, ix
= 0, iy
= 0;
1814 long lx
= 0, ly
= 0;
1815 if (item
->HasImage())
1817 GetImageSize( item
->GetImage(), ix
, iy
);
1820 if (item
->HasText())
1823 item
->GetText( str
);
1824 dc
.GetTextExtent( str
, &lx
, &ly
);
1827 if (current
> max
) max
= current
;
1829 node
= node
->Next();
1834 node
= m_columns
.Nth( col
);
1837 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1838 column
->SetWidth( width
);
1841 node
= m_lines
.First();
1844 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1845 wxNode
*n
= line
->m_items
.Nth( col
);
1848 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1849 item
->SetSize( width
, -1 );
1851 node
= node
->Next();
1854 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1855 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1858 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1860 wxNode
*node
= m_columns
.Nth( col
);
1863 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1864 column
->GetItem( item
);
1876 int wxListMainWindow::GetColumnWidth( int col
)
1878 wxNode
*node
= m_columns
.Nth( col
);
1881 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1882 return column
->GetWidth();
1890 int wxListMainWindow::GetColumnCount()
1892 return m_columns
.Number();
1895 int wxListMainWindow::GetCountPerPage()
1897 return m_visibleLines
;
1900 void wxListMainWindow::SetItem( wxListItem
&item
)
1903 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1906 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1907 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1908 line
->SetItem( item
.m_col
, item
);
1912 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1914 // m_dirty = TRUE; no recalcs needed
1916 wxListLineData
*oldCurrent
= m_current
;
1918 if (stateMask
& wxLIST_STATE_FOCUSED
)
1920 wxNode
*node
= m_lines
.Nth( item
);
1923 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1924 UnfocusLine( m_current
);
1926 FocusLine( m_current
);
1927 RefreshLine( m_current
);
1928 if (oldCurrent
) RefreshLine( oldCurrent
);
1932 if (stateMask
& wxLIST_STATE_SELECTED
)
1934 bool on
= state
& wxLIST_STATE_SELECTED
;
1935 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1937 wxNode
*node
= m_lines
.Nth( item
);
1940 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1941 if (m_mode
& wxLC_SINGLE_SEL
)
1943 UnfocusLine( m_current
);
1945 FocusLine( m_current
);
1946 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1947 RefreshLine( m_current
);
1948 if (oldCurrent
) RefreshLine( oldCurrent
);
1950 bool on
= state
& wxLIST_STATE_SELECTED
;
1951 if (on
!= line
->IsHilighted())
1953 line
->Hilight( on
);
1954 RefreshLine( line
);
1960 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1962 int ret
= wxLIST_STATE_DONTCARE
;
1963 if (stateMask
& wxLIST_STATE_FOCUSED
)
1965 wxNode
*node
= m_lines
.Nth( item
);
1968 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1969 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1972 if (stateMask
& wxLIST_STATE_SELECTED
)
1974 wxNode
*node
= m_lines
.Nth( item
);
1977 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1978 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1984 void wxListMainWindow::GetItem( wxListItem
&item
)
1986 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1989 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1990 line
->GetItem( item
.m_col
, item
);
2001 int wxListMainWindow::GetItemCount()
2003 return m_lines
.Number();
2006 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2008 wxNode
*node
= m_lines
.Nth( index
);
2011 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2012 line
->GetRect( rect
);
2023 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2025 wxNode
*node
= m_lines
.Nth( item
);
2029 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2030 line
->GetRect( rect
);
2042 int wxListMainWindow::GetSelectedItemCount()
2045 wxNode
*node
= m_lines
.First();
2048 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2049 if (line
->IsHilighted()) ret
++;
2050 node
= node
->Next();
2055 void wxListMainWindow::SetMode( long mode
)
2062 if (m_mode
& wxLC_REPORT
)
2074 long wxListMainWindow::GetMode() const
2079 void wxListMainWindow::CalculatePositions()
2081 if (!m_lines
.First()) return;
2083 wxClientDC
dc( this );
2084 dc
.SetFont( GetFont() );
2086 int iconSpacing
= 0;
2087 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2088 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2090 // we take the first line (which also can be an icon or
2091 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2092 // measure the size of the line
2096 int lineSpacing
= 0;
2098 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2099 line
->CalculateSize( &dc
, iconSpacing
);
2101 line
->GetSize( dummy
, lineSpacing
);
2104 int clientWidth
= 0;
2105 int clientHeight
= 0;
2107 if (m_mode
& wxLC_REPORT
)
2111 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2112 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2113 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2114 GetClientSize( &clientWidth
, &clientHeight
);
2116 wxNode
* node
= m_lines
.First();
2119 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2120 line
->CalculateSize( &dc
, iconSpacing
);
2121 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2123 for (int i
= 0; i
< GetColumnCount(); i
++)
2125 line
->SetColumnPosition( i
, col_x
);
2126 col_x
+= GetColumnWidth( i
);
2128 y
+= lineSpacing
; // one pixel blank line between items
2129 node
= node
->Next();
2131 m_visibleLines
= clientHeight
/ lineSpacing
;
2135 // at first we try without any scrollbar. if the items don't
2136 // fit into the window, we recalculate after subtracting an
2137 // approximated 15 pt for the horizontal scrollbar
2139 GetSize( &clientWidth
, &clientHeight
);
2140 clientHeight
-= 4; // sunken frame
2142 int entireWidth
= 0;
2144 for (int tries
= 0; tries
< 2; tries
++)
2147 int x
= 5; // painting is done at x-2
2148 int y
= 5; // painting is done at y-2
2151 int m_currentVisibleLines
= 0;
2152 wxNode
*node
= m_lines
.First();
2155 m_currentVisibleLines
++;
2156 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2157 line
->CalculateSize( &dc
, iconSpacing
);
2158 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2159 line
->GetSize( lineWidth
, lineHeight
);
2160 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2162 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2164 if (m_currentVisibleLines
> m_visibleLines
)
2165 m_visibleLines
= m_currentVisibleLines
;
2166 m_currentVisibleLines
= 0;
2169 entireWidth
+= maxWidth
+6;
2172 node
= node
->Next();
2173 if (!node
) entireWidth
+= maxWidth
;
2174 if ((tries
== 0) && (entireWidth
> clientWidth
))
2176 clientHeight
-= 15; // scrollbar height
2178 m_currentVisibleLines
= 0;
2181 if (!node
) tries
= 1; // everything fits, no second try required
2184 // m_visibleLines = (5+clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
2186 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2187 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2191 void wxListMainWindow::RealizeChanges( void )
2195 wxNode
*node
= m_lines
.First();
2196 if (node
) m_current
= (wxListLineData
*)node
->Data();
2200 FocusLine( m_current
);
2201 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2205 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2208 if (item
> 0) ret
= item
;
2209 if(ret
>= GetItemCount()) return -1;
2210 wxNode
*node
= m_lines
.Nth( ret
);
2213 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2214 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2215 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2216 if (!state
) return ret
;
2218 node
= node
->Next();
2223 void wxListMainWindow::DeleteItem( long index
)
2226 wxNode
*node
= m_lines
.Nth( index
);
2229 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2230 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2232 m_lines
.DeleteNode( node
);
2236 void wxListMainWindow::DeleteColumn( int col
)
2238 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2239 _T("attempting to delete inexistent column in wxListView") );
2242 wxNode
*node
= m_columns
.Nth( col
);
2243 if (node
) m_columns
.DeleteNode( node
);
2246 void wxListMainWindow::DeleteAllItems( void )
2249 m_current
= (wxListLineData
*) NULL
;
2250 wxNode
*node
= m_lines
.First();
2253 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2255 node
= node
->Next();
2260 void wxListMainWindow::DeleteEverything( void )
2263 m_current
= (wxListLineData
*) NULL
;
2264 wxNode
*node
= m_lines
.First();
2267 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2269 node
= node
->Next();
2272 m_current
= (wxListLineData
*) NULL
;
2276 void wxListMainWindow::EnsureVisible( long index
)
2278 // We have to call this here because the label in
2279 // question might just have been added and no screen
2280 // update taken place.
2281 if (m_dirty
) wxYield();
2283 wxListLineData
*oldCurrent
= m_current
;
2284 m_current
= (wxListLineData
*) NULL
;
2286 wxNode
*node
= m_lines
.Nth( i
);
2287 if (node
) m_current
= (wxListLineData
*)node
->Data();
2288 if (m_current
) MoveToFocus();
2289 m_current
= oldCurrent
;
2292 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2296 if (pos
< 0) pos
= 0;
2297 wxNode
*node
= m_lines
.Nth( pos
);
2300 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2302 line
->GetText( 0, s
);
2303 if (s
== tmp
) return pos
;
2304 node
= node
->Next();
2310 long wxListMainWindow::FindItem(long start
, long data
)
2313 if (pos
< 0) pos
= 0;
2314 wxNode
*node
= m_lines
.Nth( pos
);
2317 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2319 line
->GetItem( 0, item
);
2320 if (item
.m_data
== data
) return pos
;
2321 node
= node
->Next();
2327 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2329 wxNode
*node
= m_lines
.First();
2333 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2334 long ret
= line
->IsHit( x
, y
);
2340 node
= node
->Next();
2346 void wxListMainWindow::InsertItem( wxListItem
&item
)
2350 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2351 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2352 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2353 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2355 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2357 if (m_mode
& wxLC_REPORT
)
2359 line
->InitItems( GetColumnCount() );
2360 item
.m_width
= GetColumnWidth( 0 )-3;
2364 line
->InitItems( 1 );
2367 line
->SetItem( 0, item
);
2368 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2370 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2371 if (node
) m_lines
.Insert( node
, line
);
2375 m_lines
.Append( line
);
2379 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2382 if (m_mode
& wxLC_REPORT
)
2384 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2385 wxListHeaderData
*column
= new wxListHeaderData( item
);
2386 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2388 wxNode
*node
= m_columns
.Nth( col
);
2390 m_columns
.Insert( node
, column
);
2394 m_columns
.Append( column
);
2399 wxListCtrlCompare list_ctrl_compare_func_2
;
2400 long list_ctrl_compare_data
;
2402 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2404 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2405 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2407 line1
->GetItem( 0, item
);
2408 long data1
= item
.m_data
;
2409 line2
->GetItem( 0, item
);
2410 long data2
= item
.m_data
;
2411 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2414 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2416 list_ctrl_compare_func_2
= fn
;
2417 list_ctrl_compare_data
= data
;
2418 m_lines
.Sort( list_ctrl_compare_func_1
);
2421 // -------------------------------------------------------------------------------------
2423 // -------------------------------------------------------------------------------------
2425 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2427 wxListItem::wxListItem()
2436 m_format
= wxLIST_FORMAT_CENTRE
;
2441 // -------------------------------------------------------------------------------------
2443 // -------------------------------------------------------------------------------------
2445 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2447 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2448 wxNotifyEvent( commandType
, id
)
2454 m_cancelled
= FALSE
;
2459 // -------------------------------------------------------------------------------------
2461 // -------------------------------------------------------------------------------------
2463 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2465 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2466 EVT_SIZE (wxListCtrl::OnSize
)
2467 EVT_IDLE (wxListCtrl::OnIdle
)
2470 wxListCtrl::wxListCtrl()
2472 m_imageListNormal
= (wxImageList
*) NULL
;
2473 m_imageListSmall
= (wxImageList
*) NULL
;
2474 m_imageListState
= (wxImageList
*) NULL
;
2475 m_mainWin
= (wxListMainWindow
*) NULL
;
2476 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2479 wxListCtrl::~wxListCtrl()
2483 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2484 const wxPoint
&pos
, const wxSize
&size
,
2485 long style
, const wxValidator
&validator
,
2486 const wxString
&name
)
2488 m_imageListNormal
= (wxImageList
*) NULL
;
2489 m_imageListSmall
= (wxImageList
*) NULL
;
2490 m_imageListState
= (wxImageList
*) NULL
;
2491 m_mainWin
= (wxListMainWindow
*) NULL
;
2492 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2496 if ((s
& wxLC_REPORT
== 0) &&
2497 (s
& wxLC_LIST
== 0) &&
2498 (s
& wxLC_ICON
== 0))
2503 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2505 #if wxUSE_VALIDATORS
2506 SetValidator( validator
);
2509 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2511 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2513 if (HasFlag(wxLC_REPORT
))
2514 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2516 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2518 SetBackgroundColour( *wxWHITE
);
2523 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2525 /* handled in OnIdle */
2527 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2530 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2532 long flag
= GetWindowStyle();
2536 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2537 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2538 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2547 if (flag
& style
) flag
-= style
;
2550 SetWindowStyleFlag( flag
);
2553 void wxListCtrl::SetWindowStyleFlag( long flag
)
2557 m_mainWin
->DeleteEverything();
2561 GetClientSize( &width
, &height
);
2563 m_mainWin
->SetMode( flag
);
2565 if (flag
& wxLC_REPORT
)
2567 if (!HasFlag(wxLC_REPORT
))
2571 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2572 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2576 m_headerWin
->Show( TRUE
);
2582 if (HasFlag(wxLC_REPORT
))
2584 m_headerWin
->Show( FALSE
);
2589 wxWindow::SetWindowStyleFlag( flag
);
2592 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2594 m_mainWin
->GetColumn( col
, item
);
2598 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2600 m_mainWin
->SetColumn( col
, item
);
2604 int wxListCtrl::GetColumnWidth( int col
) const
2606 return m_mainWin
->GetColumnWidth( col
);
2609 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2611 m_mainWin
->SetColumnWidth( col
, width
);
2615 int wxListCtrl::GetCountPerPage() const
2617 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2620 bool wxListCtrl::GetItem( wxListItem
&info
) const
2622 m_mainWin
->GetItem( info
);
2626 bool wxListCtrl::SetItem( wxListItem
&info
)
2628 m_mainWin
->SetItem( info
);
2632 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2635 info
.m_text
= label
;
2636 info
.m_mask
= wxLIST_MASK_TEXT
;
2637 info
.m_itemId
= index
;
2641 info
.m_image
= imageId
;
2642 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2644 m_mainWin
->SetItem(info
);
2648 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2650 return m_mainWin
->GetItemState( item
, stateMask
);
2653 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2655 m_mainWin
->SetItemState( item
, state
, stateMask
);
2659 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2662 info
.m_image
= image
;
2663 info
.m_mask
= wxLIST_MASK_IMAGE
;
2664 info
.m_itemId
= item
;
2665 m_mainWin
->SetItem( info
);
2669 wxString
wxListCtrl::GetItemText( long item
) const
2672 info
.m_itemId
= item
;
2673 m_mainWin
->GetItem( info
);
2677 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2680 info
.m_mask
= wxLIST_MASK_TEXT
;
2681 info
.m_itemId
= item
;
2683 m_mainWin
->SetItem( info
);
2686 long wxListCtrl::GetItemData( long item
) const
2689 info
.m_itemId
= item
;
2690 m_mainWin
->GetItem( info
);
2694 bool wxListCtrl::SetItemData( long item
, long data
)
2697 info
.m_mask
= wxLIST_MASK_DATA
;
2698 info
.m_itemId
= item
;
2700 m_mainWin
->SetItem( info
);
2704 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2706 m_mainWin
->GetItemRect( item
, rect
);
2710 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2712 m_mainWin
->GetItemPosition( item
, pos
);
2716 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2721 int wxListCtrl::GetItemCount() const
2723 return m_mainWin
->GetItemCount();
2726 int wxListCtrl::GetColumnCount() const
2728 return m_mainWin
->GetColumnCount();
2731 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2733 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2736 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2738 return m_mainWin
->GetItemSpacing( isSmall
);
2741 int wxListCtrl::GetSelectedItemCount() const
2743 return m_mainWin
->GetSelectedItemCount();
2747 wxColour wxListCtrl::GetTextColour() const
2751 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2756 long wxListCtrl::GetTopItem() const
2761 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2763 return m_mainWin
->GetNextItem( item
, geom
, state
);
2766 wxImageList
*wxListCtrl::GetImageList(int which
) const
2768 if (which
== wxIMAGE_LIST_NORMAL
)
2770 return m_imageListNormal
;
2772 else if (which
== wxIMAGE_LIST_SMALL
)
2774 return m_imageListSmall
;
2776 else if (which
== wxIMAGE_LIST_STATE
)
2778 return m_imageListState
;
2780 return (wxImageList
*) NULL
;
2783 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2785 m_mainWin
->SetImageList( imageList
, which
);
2788 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2793 bool wxListCtrl::DeleteItem( long item
)
2795 m_mainWin
->DeleteItem( item
);
2799 bool wxListCtrl::DeleteAllItems()
2801 m_mainWin
->DeleteAllItems();
2805 bool wxListCtrl::DeleteAllColumns()
2807 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2813 void wxListCtrl::ClearAll()
2815 m_mainWin
->DeleteEverything();
2818 bool wxListCtrl::DeleteColumn( int col
)
2820 m_mainWin
->DeleteColumn( col
);
2824 void wxListCtrl::Edit( long item
)
2826 m_mainWin
->Edit( item
);
2829 bool wxListCtrl::EnsureVisible( long item
)
2831 m_mainWin
->EnsureVisible( item
);
2835 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2837 return m_mainWin
->FindItem( start
, str
, partial
);
2840 long wxListCtrl::FindItem( long start
, long data
)
2842 return m_mainWin
->FindItem( start
, data
);
2845 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2846 int WXUNUSED(direction
))
2851 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2853 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2856 long wxListCtrl::InsertItem( wxListItem
& info
)
2858 m_mainWin
->InsertItem( info
);
2862 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2865 info
.m_text
= label
;
2866 info
.m_mask
= wxLIST_MASK_TEXT
;
2867 info
.m_itemId
= index
;
2868 return InsertItem( info
);
2871 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2874 info
.m_mask
= wxLIST_MASK_IMAGE
;
2875 info
.m_image
= imageIndex
;
2876 info
.m_itemId
= index
;
2877 return InsertItem( info
);
2880 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2883 info
.m_text
= label
;
2884 info
.m_image
= imageIndex
;
2885 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2886 info
.m_itemId
= index
;
2887 return InsertItem( info
);
2890 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2892 m_mainWin
->InsertColumn( col
, item
);
2896 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2897 int format
, int width
)
2900 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2901 item
.m_text
= heading
;
2904 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2905 item
.m_width
= width
;
2907 item
.m_format
= format
;
2909 return InsertColumn( col
, item
);
2912 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2918 // fn is a function which takes 3 long arguments: item1, item2, data.
2919 // item1 is the long data associated with a first item (NOT the index).
2920 // item2 is the long data associated with a second item (NOT the index).
2921 // data is the same value as passed to SortItems.
2922 // The return value is a negative number if the first item should precede the second
2923 // item, a positive number of the second item should precede the first,
2924 // or zero if the two items are equivalent.
2925 // data is arbitrary data to be passed to the sort function.
2927 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2929 m_mainWin
->SortItems( fn
, data
);
2933 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2935 if (!m_mainWin
->m_dirty
) return;
2939 GetClientSize( &cw
, &ch
);
2946 if (HasFlag(wxLC_REPORT
))
2948 m_headerWin
->GetPosition( &x
, &y
);
2949 m_headerWin
->GetSize( &w
, &h
);
2950 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2951 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2953 m_mainWin
->GetPosition( &x
, &y
);
2954 m_mainWin
->GetSize( &w
, &h
);
2955 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2956 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2960 m_mainWin
->GetPosition( &x
, &y
);
2961 m_mainWin
->GetSize( &w
, &h
);
2962 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2963 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2966 m_mainWin
->CalculatePositions();
2967 m_mainWin
->RealizeChanges();
2968 m_mainWin
->m_dirty
= FALSE
;
2969 m_mainWin
->Refresh();
2972 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2974 if ( !wxWindow::SetBackgroundColour( colour
) )
2979 m_mainWin
->SetBackgroundColour( colour
);
2980 m_mainWin
->m_dirty
= TRUE
;
2985 // m_headerWin->SetBackgroundColour( colour );
2991 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
2993 if ( !wxWindow::SetForegroundColour( colour
) )
2998 m_mainWin
->SetForegroundColour( colour
);
2999 m_mainWin
->m_dirty
= TRUE
;
3004 m_headerWin
->SetForegroundColour( colour
);
3010 bool wxListCtrl::SetFont( const wxFont
&font
)
3012 if ( !wxWindow::SetFont( font
) )
3017 m_mainWin
->SetFont( font
);
3018 m_mainWin
->m_dirty
= TRUE
;
3023 m_headerWin
->SetFont( font
);