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
);
879 if ((abs(x
-xpos
) < 3) && (y
< 22))
891 if (event
.LeftDown())
903 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
904 le
.SetEventObject( GetParent() );
906 GetParent()->GetEventHandler()->ProcessEvent( le
);
915 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
916 m_currentCursor
= m_resizeCursor
;
920 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
921 m_currentCursor
= wxSTANDARD_CURSOR
;
926 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
931 //-----------------------------------------------------------------------------
932 // wxListRenameTimer (internal)
933 //-----------------------------------------------------------------------------
935 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
940 void wxListRenameTimer::Notify()
942 m_owner
->OnRenameTimer();
945 //-----------------------------------------------------------------------------
946 // wxListTextCtrl (internal)
947 //-----------------------------------------------------------------------------
949 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
951 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
952 EVT_CHAR (wxListTextCtrl::OnChar
)
953 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
956 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
957 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
958 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
959 int style
, const wxValidator
& validator
, const wxString
&name
) :
960 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
967 m_startValue
= value
;
970 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
972 if (event
.m_keyCode
== WXK_RETURN
)
975 (*m_res
) = GetValue();
979 if (event
.m_keyCode
== WXK_ESCAPE
)
989 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
991 if (wxPendingDelete
.Member(this)) return;
993 wxPendingDelete
.Append(this);
995 if ((*m_accept
) && ((*m_res
) != m_startValue
))
996 m_owner
->OnRenameAccept();
999 //-----------------------------------------------------------------------------
1001 //-----------------------------------------------------------------------------
1003 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1005 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1006 EVT_PAINT (wxListMainWindow::OnPaint
)
1007 EVT_SIZE (wxListMainWindow::OnSize
)
1008 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1009 EVT_CHAR (wxListMainWindow::OnChar
)
1010 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1011 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1012 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1015 wxListMainWindow::wxListMainWindow()
1018 m_lines
.DeleteContents( TRUE
);
1019 m_columns
.DeleteContents( TRUE
);
1020 m_current
= (wxListLineData
*) NULL
;
1022 m_hilightBrush
= (wxBrush
*) NULL
;
1026 m_small_image_list
= (wxImageList
*) NULL
;
1027 m_normal_image_list
= (wxImageList
*) NULL
;
1028 m_small_spacing
= 30;
1029 m_normal_spacing
= 40;
1032 m_lastOnSame
= FALSE
;
1033 m_renameTimer
= new wxListRenameTimer( this );
1034 m_isCreated
= FALSE
;
1038 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1039 const wxPoint
&pos
, const wxSize
&size
,
1040 long style
, const wxString
&name
) :
1041 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1044 m_lines
.DeleteContents( TRUE
);
1045 m_columns
.DeleteContents( TRUE
);
1046 m_current
= (wxListLineData
*) NULL
;
1049 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1050 m_small_image_list
= (wxImageList
*) NULL
;
1051 m_normal_image_list
= (wxImageList
*) NULL
;
1052 m_small_spacing
= 30;
1053 m_normal_spacing
= 40;
1056 m_isCreated
= FALSE
;
1060 if (m_mode
& wxLC_REPORT
)
1070 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1073 m_lastOnSame
= FALSE
;
1074 m_renameTimer
= new wxListRenameTimer( this );
1075 m_renameAccept
= FALSE
;
1077 SetBackgroundColour( *wxWHITE
);
1080 wxListMainWindow::~wxListMainWindow()
1082 if (m_hilightBrush
) delete m_hilightBrush
;
1084 delete m_renameTimer
;
1087 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1095 wxClientDC
dc(this);
1097 line
->GetExtent( x
, y
, w
, h
);
1099 dc
.LogicalToDeviceX(x
-3),
1100 dc
.LogicalToDeviceY(y
-3),
1101 dc
.LogicalToDeviceXRel(w
+6),
1102 dc
.LogicalToDeviceXRel(h
+6) );
1103 Refresh( TRUE
, &rect
);
1107 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1109 // Note: a wxPaintDC must be constructed even if no drawing is
1110 // done (a Windows requirement).
1111 wxPaintDC
dc( this );
1114 if (m_dirty
) return;
1116 if (m_lines
.GetCount() == 0) return;
1120 dc
.SetFont( GetFont() );
1122 if (m_mode
& wxLC_REPORT
)
1124 int lineSpacing
= 0;
1125 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1127 line
->GetSize( dummy
, lineSpacing
);
1130 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1132 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1133 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1137 line
= (wxListLineData
*)node
->Data();
1139 node
= node
->Next();
1144 wxNode
*node
= m_lines
.First();
1147 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1149 node
= node
->Next();
1153 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1158 void wxListMainWindow::HilightAll( bool on
)
1160 wxNode
*node
= m_lines
.First();
1163 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1164 if (line
->IsHilighted() != on
)
1166 line
->Hilight( on
);
1167 RefreshLine( line
);
1169 node
= node
->Next();
1173 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1175 wxListEvent
le( command
, GetParent()->GetId() );
1176 le
.SetEventObject( GetParent() );
1177 le
.m_itemIndex
= GetIndexOfLine( line
);
1178 line
->GetItem( 0, le
.m_item
);
1179 GetParent()->GetEventHandler()->ProcessEvent( le
);
1182 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1184 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1187 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1189 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1192 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1194 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1197 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1199 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1202 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1204 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1209 void wxListMainWindow::EditLabel( long item
)
1211 wxNode
*node
= m_lines
.Nth( item
);
1212 wxCHECK_RET( node
, _T("wrong index in wxListCtrl::Edit()") );
1214 m_currentEdit
= (wxListLineData
*) node
->Data();
1216 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1217 le
.SetEventObject( GetParent() );
1218 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1219 m_currentEdit
->GetItem( 0, le
.m_item
);
1220 GetParent()->GetEventHandler()->ProcessEvent( le
);
1222 if (!le
.IsAllowed())
1225 // We have to call this here because the label in
1226 // question might just have been added and no screen
1227 // update taken place.
1228 if (m_dirty
) wxYield();
1231 m_currentEdit
->GetText( 0, s
);
1236 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1238 wxClientDC
dc(this);
1240 x
= dc
.LogicalToDeviceX( x
);
1241 y
= dc
.LogicalToDeviceY( y
);
1243 wxListTextCtrl
*text
= new wxListTextCtrl(
1244 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1248 void wxListMainWindow::OnRenameTimer()
1250 wxCHECK_RET( m_current
, _T("invalid m_current") );
1252 Edit( m_lines
.IndexOf( m_current
) );
1255 void wxListMainWindow::OnRenameAccept()
1257 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1258 le
.SetEventObject( GetParent() );
1259 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1260 m_currentEdit
->GetItem( 0, le
.m_item
);
1261 le
.m_item
.m_text
= m_renameRes
;
1262 GetParent()->GetEventHandler()->ProcessEvent( le
);
1264 if (!le
.IsAllowed()) return;
1267 info
.m_mask
= wxLIST_MASK_TEXT
;
1268 info
.m_itemId
= le
.m_itemIndex
;
1269 info
.m_text
= m_renameRes
;
1270 info
.m_colour
= le
.m_item
.m_colour
;
1274 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1276 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1278 if (!m_current
) return;
1279 if (m_dirty
) return;
1280 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1282 wxClientDC
dc(this);
1284 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1285 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1287 /* Did we actually hit an item ? */
1289 wxNode
*node
= m_lines
.First();
1290 wxListLineData
*line
= (wxListLineData
*) NULL
;
1293 line
= (wxListLineData
*)node
->Data();
1294 hitResult
= line
->IsHit( x
, y
);
1295 if (hitResult
) break;
1296 line
= (wxListLineData
*) NULL
;
1297 node
= node
->Next();
1300 if (event
.Dragging())
1302 if (m_dragCount
== 0)
1303 m_dragStart
= wxPoint(x
,y
);
1307 if (m_dragCount
!= 3) return;
1309 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1310 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1312 wxListEvent
le( command
, GetParent()->GetId() );
1313 le
.SetEventObject( GetParent() );
1314 le
.m_pointDrag
= m_dragStart
;
1315 GetParent()->GetEventHandler()->ProcessEvent( le
);
1326 if (event
.ButtonDClick())
1329 m_lastOnSame
= FALSE
;
1330 m_renameTimer
->Stop();
1332 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1337 if (event
.LeftUp() && m_lastOnSame
)
1340 if ((line
== m_current
) &&
1341 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1342 (m_mode
& wxLC_EDIT_LABELS
) )
1344 m_renameTimer
->Start( 100, TRUE
);
1346 m_lastOnSame
= FALSE
;
1350 if (event
.RightDown())
1352 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1356 if (event
.MiddleDown())
1358 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1362 if (event
.LeftDown())
1365 wxListLineData
*oldCurrent
= m_current
;
1366 if (m_mode
& wxLC_SINGLE_SEL
)
1369 HilightAll( FALSE
);
1370 m_current
->ReverseHilight();
1371 RefreshLine( m_current
);
1375 if (event
.ShiftDown())
1378 m_current
->ReverseHilight();
1379 RefreshLine( m_current
);
1381 else if (event
.ControlDown())
1385 int numOfCurrent
= -1;
1386 node
= m_lines
.First();
1389 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1391 if (test_line
== oldCurrent
) break;
1392 node
= node
->Next();
1396 node
= m_lines
.First();
1399 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1401 if (test_line
== line
) break;
1402 node
= node
->Next();
1405 if (numOfLine
< numOfCurrent
)
1408 numOfLine
= numOfCurrent
;
1412 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1413 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1415 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1416 test_line
->Hilight(TRUE
);
1417 RefreshLine( test_line
);
1418 node
= node
->Next();
1424 HilightAll( FALSE
);
1425 m_current
->ReverseHilight();
1426 RefreshLine( m_current
);
1429 if (m_current
!= oldCurrent
)
1431 RefreshLine( oldCurrent
);
1432 UnfocusLine( oldCurrent
);
1433 FocusLine( m_current
);
1435 m_lastOnSame
= (m_current
== oldCurrent
);
1440 void wxListMainWindow::MoveToFocus()
1442 if (!m_current
) return;
1448 m_current
->GetExtent( x
, y
, w
, h
);
1452 GetClientSize( &w_p
, &h_p
);
1454 if (m_mode
& wxLC_REPORT
)
1456 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1457 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1458 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1459 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1463 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1464 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1465 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1466 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1470 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1472 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1473 wxListLineData
*oldCurrent
= m_current
;
1474 m_current
= newCurrent
;
1476 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1477 RefreshLine( m_current
);
1478 RefreshLine( oldCurrent
);
1479 FocusLine( m_current
);
1480 UnfocusLine( oldCurrent
);
1483 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1485 wxWindow
*parent
= GetParent();
1487 /* we propagate the key event up */
1488 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1489 ke
.m_shiftDown
= event
.m_shiftDown
;
1490 ke
.m_controlDown
= event
.m_controlDown
;
1491 ke
.m_altDown
= event
.m_altDown
;
1492 ke
.m_metaDown
= event
.m_metaDown
;
1493 ke
.m_keyCode
= event
.m_keyCode
;
1496 ke
.SetEventObject( parent
);
1497 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1502 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1504 wxWindow
*parent
= GetParent();
1506 /* we send a list_key event up */
1507 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1508 le
.m_code
= event
.KeyCode();
1509 le
.SetEventObject( parent
);
1510 parent
->GetEventHandler()->ProcessEvent( le
);
1512 /* we propagate the char event up */
1513 wxKeyEvent
ke( wxEVT_CHAR
);
1514 ke
.m_shiftDown
= event
.m_shiftDown
;
1515 ke
.m_controlDown
= event
.m_controlDown
;
1516 ke
.m_altDown
= event
.m_altDown
;
1517 ke
.m_metaDown
= event
.m_metaDown
;
1518 ke
.m_keyCode
= event
.m_keyCode
;
1521 ke
.SetEventObject( parent
);
1522 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1524 if (event
.KeyCode() == WXK_TAB
)
1526 wxNavigationKeyEvent nevent
;
1527 nevent
.SetDirection( !event
.ShiftDown() );
1528 nevent
.SetCurrentFocus( m_parent
);
1529 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1532 /* no item -> nothing to do */
1539 switch (event
.KeyCode())
1543 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1544 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1549 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1550 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1555 wxNode
*node
= m_lines
.Last();
1556 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1561 wxNode
*node
= m_lines
.First();
1562 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1568 if (m_mode
& wxLC_REPORT
)
1570 steps
= m_visibleLines
-1;
1575 wxNode
*node
= m_lines
.First();
1576 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1577 steps
= pos
% m_visibleLines
;
1579 wxNode
*node
= m_lines
.Member( m_current
);
1580 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1581 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1587 if (m_mode
& wxLC_REPORT
)
1589 steps
= m_visibleLines
-1;
1593 int pos
= 0; wxNode
*node
= m_lines
.First();
1594 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1595 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1597 wxNode
*node
= m_lines
.Member( m_current
);
1598 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1599 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1604 if (!(m_mode
& wxLC_REPORT
))
1606 wxNode
*node
= m_lines
.Member( m_current
);
1607 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1608 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1614 if (!(m_mode
& wxLC_REPORT
))
1616 wxNode
*node
= m_lines
.Member( m_current
);
1617 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1618 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1624 m_current
->ReverseHilight();
1625 RefreshLine( m_current
);
1630 if (!(m_mode
& wxLC_SINGLE_SEL
))
1632 wxListLineData
*oldCurrent
= m_current
;
1633 m_current
->ReverseHilight();
1634 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1635 if (node
) m_current
= (wxListLineData
*)node
->Data();
1637 RefreshLine( oldCurrent
);
1638 RefreshLine( m_current
);
1639 UnfocusLine( oldCurrent
);
1640 FocusLine( m_current
);
1647 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1648 le
.SetEventObject( GetParent() );
1649 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1650 m_current
->GetItem( 0, le
.m_item
);
1651 GetParent()->GetEventHandler()->ProcessEvent( le
);
1664 extern wxWindow
*g_focusWindow
;
1667 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1670 RefreshLine( m_current
);
1672 if (!GetParent()) return;
1675 g_focusWindow
= GetParent();
1678 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1679 event
.SetEventObject( GetParent() );
1680 GetParent()->GetEventHandler()->ProcessEvent( event
);
1683 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1686 RefreshLine( m_current
);
1689 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1692 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1697 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1699 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1701 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1704 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1706 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1708 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1710 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1712 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1714 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1719 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1721 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1723 m_normal_image_list
->GetSize( index
, width
, height
);
1726 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1728 m_small_image_list
->GetSize( index
, width
, height
);
1731 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1733 m_small_image_list
->GetSize( index
, width
, height
);
1736 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1738 m_small_image_list
->GetSize( index
, width
, height
);
1745 int wxListMainWindow::GetTextLength( wxString
&s
)
1747 wxClientDC
dc( this );
1750 dc
.GetTextExtent( s
, &lw
, &lh
);
1754 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1757 wxNode
*node
= m_lines
.First();
1760 if (line
== (wxListLineData
*)node
->Data()) return i
;
1762 node
= node
->Next();
1767 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1770 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1771 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1774 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1779 m_small_spacing
= spacing
;
1783 m_normal_spacing
= spacing
;
1787 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1789 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1792 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1795 wxNode
*node
= m_columns
.Nth( col
);
1798 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1799 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1800 column
->SetItem( item
);
1802 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1803 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1806 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1808 if (!(m_mode
& wxLC_REPORT
)) return;
1812 wxNode
*node
= (wxNode
*) NULL
;
1814 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1815 if (width
== wxLIST_AUTOSIZE
)
1817 wxClientDC
dc(this);
1818 dc
.SetFont( GetFont() );
1820 node
= m_lines
.First();
1823 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1824 wxNode
*n
= line
->m_items
.Nth( col
);
1827 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1828 int current
= 0, ix
= 0, iy
= 0;
1829 long lx
= 0, ly
= 0;
1830 if (item
->HasImage())
1832 GetImageSize( item
->GetImage(), ix
, iy
);
1835 if (item
->HasText())
1838 item
->GetText( str
);
1839 dc
.GetTextExtent( str
, &lx
, &ly
);
1842 if (current
> max
) max
= current
;
1844 node
= node
->Next();
1849 node
= m_columns
.Nth( col
);
1852 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1853 column
->SetWidth( width
);
1856 node
= m_lines
.First();
1859 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1860 wxNode
*n
= line
->m_items
.Nth( col
);
1863 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1864 item
->SetSize( width
, -1 );
1866 node
= node
->Next();
1869 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1870 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1873 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1875 wxNode
*node
= m_columns
.Nth( col
);
1878 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1879 column
->GetItem( item
);
1891 int wxListMainWindow::GetColumnWidth( int col
)
1893 wxNode
*node
= m_columns
.Nth( col
);
1896 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1897 return column
->GetWidth();
1905 int wxListMainWindow::GetColumnCount()
1907 return m_columns
.Number();
1910 int wxListMainWindow::GetCountPerPage()
1912 return m_visibleLines
;
1915 void wxListMainWindow::SetItem( wxListItem
&item
)
1918 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1921 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1922 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1923 line
->SetItem( item
.m_col
, item
);
1927 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1929 // m_dirty = TRUE; no recalcs needed
1931 wxListLineData
*oldCurrent
= m_current
;
1933 if (stateMask
& wxLIST_STATE_FOCUSED
)
1935 wxNode
*node
= m_lines
.Nth( item
);
1938 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1939 UnfocusLine( m_current
);
1941 FocusLine( m_current
);
1942 RefreshLine( m_current
);
1943 if (oldCurrent
) RefreshLine( oldCurrent
);
1947 if (stateMask
& wxLIST_STATE_SELECTED
)
1949 bool on
= state
& wxLIST_STATE_SELECTED
;
1950 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1952 wxNode
*node
= m_lines
.Nth( item
);
1955 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1956 if (m_mode
& wxLC_SINGLE_SEL
)
1958 UnfocusLine( m_current
);
1960 FocusLine( m_current
);
1961 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1962 RefreshLine( m_current
);
1963 if (oldCurrent
) RefreshLine( oldCurrent
);
1965 bool on
= state
& wxLIST_STATE_SELECTED
;
1966 if (on
!= line
->IsHilighted())
1968 line
->Hilight( on
);
1969 RefreshLine( line
);
1975 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1977 int ret
= wxLIST_STATE_DONTCARE
;
1978 if (stateMask
& wxLIST_STATE_FOCUSED
)
1980 wxNode
*node
= m_lines
.Nth( item
);
1983 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1984 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1987 if (stateMask
& wxLIST_STATE_SELECTED
)
1989 wxNode
*node
= m_lines
.Nth( item
);
1992 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1993 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1999 void wxListMainWindow::GetItem( wxListItem
&item
)
2001 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2004 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2005 line
->GetItem( item
.m_col
, item
);
2016 int wxListMainWindow::GetItemCount()
2018 return m_lines
.Number();
2021 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2023 wxNode
*node
= m_lines
.Nth( index
);
2026 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2027 line
->GetRect( rect
);
2038 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2040 wxNode
*node
= m_lines
.Nth( item
);
2044 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2045 line
->GetRect( rect
);
2057 int wxListMainWindow::GetSelectedItemCount()
2060 wxNode
*node
= m_lines
.First();
2063 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2064 if (line
->IsHilighted()) ret
++;
2065 node
= node
->Next();
2070 void wxListMainWindow::SetMode( long mode
)
2077 if (m_mode
& wxLC_REPORT
)
2089 long wxListMainWindow::GetMode() const
2094 void wxListMainWindow::CalculatePositions()
2096 if (!m_lines
.First()) return;
2098 wxClientDC
dc( this );
2099 dc
.SetFont( GetFont() );
2101 int iconSpacing
= 0;
2102 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2103 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2105 // we take the first line (which also can be an icon or
2106 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2107 // measure the size of the line
2111 int lineSpacing
= 0;
2113 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2114 line
->CalculateSize( &dc
, iconSpacing
);
2116 line
->GetSize( dummy
, lineSpacing
);
2119 int clientWidth
= 0;
2120 int clientHeight
= 0;
2122 if (m_mode
& wxLC_REPORT
)
2126 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2127 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2128 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2129 GetClientSize( &clientWidth
, &clientHeight
);
2131 wxNode
* node
= m_lines
.First();
2134 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2135 line
->CalculateSize( &dc
, iconSpacing
);
2136 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2138 for (int i
= 0; i
< GetColumnCount(); i
++)
2140 line
->SetColumnPosition( i
, col_x
);
2141 col_x
+= GetColumnWidth( i
);
2143 y
+= lineSpacing
; // one pixel blank line between items
2144 node
= node
->Next();
2146 m_visibleLines
= clientHeight
/ lineSpacing
;
2150 // at first we try without any scrollbar. if the items don't
2151 // fit into the window, we recalculate after subtracting an
2152 // approximated 15 pt for the horizontal scrollbar
2154 GetSize( &clientWidth
, &clientHeight
);
2155 clientHeight
-= 4; // sunken frame
2157 int entireWidth
= 0;
2159 for (int tries
= 0; tries
< 2; tries
++)
2162 int x
= 5; // painting is done at x-2
2163 int y
= 5; // painting is done at y-2
2166 int m_currentVisibleLines
= 0;
2167 wxNode
*node
= m_lines
.First();
2170 m_currentVisibleLines
++;
2171 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2172 line
->CalculateSize( &dc
, iconSpacing
);
2173 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2174 line
->GetSize( lineWidth
, lineHeight
);
2175 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2177 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2179 if (m_currentVisibleLines
> m_visibleLines
)
2180 m_visibleLines
= m_currentVisibleLines
;
2181 m_currentVisibleLines
= 0;
2184 entireWidth
+= maxWidth
+6;
2187 node
= node
->Next();
2188 if (!node
) entireWidth
+= maxWidth
;
2189 if ((tries
== 0) && (entireWidth
> clientWidth
))
2191 clientHeight
-= 15; // scrollbar height
2193 m_currentVisibleLines
= 0;
2196 if (!node
) tries
= 1; // everything fits, no second try required
2199 // m_visibleLines = (5+clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
2201 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2202 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2206 void wxListMainWindow::RealizeChanges( void )
2210 wxNode
*node
= m_lines
.First();
2211 if (node
) m_current
= (wxListLineData
*)node
->Data();
2215 FocusLine( m_current
);
2216 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2220 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2223 if (item
> 0) ret
= item
;
2224 if(ret
>= GetItemCount()) return -1;
2225 wxNode
*node
= m_lines
.Nth( ret
);
2228 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2229 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2230 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2231 if (!state
) return ret
;
2233 node
= node
->Next();
2238 void wxListMainWindow::DeleteItem( long index
)
2241 wxNode
*node
= m_lines
.Nth( index
);
2244 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2245 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2247 m_lines
.DeleteNode( node
);
2251 void wxListMainWindow::DeleteColumn( int col
)
2253 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2254 _T("attempting to delete inexistent column in wxListView") );
2257 wxNode
*node
= m_columns
.Nth( col
);
2258 if (node
) m_columns
.DeleteNode( node
);
2261 void wxListMainWindow::DeleteAllItems( void )
2264 m_current
= (wxListLineData
*) NULL
;
2265 wxNode
*node
= m_lines
.First();
2268 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2270 node
= node
->Next();
2275 void wxListMainWindow::DeleteEverything( void )
2278 m_current
= (wxListLineData
*) NULL
;
2279 wxNode
*node
= m_lines
.First();
2282 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2284 node
= node
->Next();
2287 m_current
= (wxListLineData
*) NULL
;
2291 void wxListMainWindow::EnsureVisible( long index
)
2293 // We have to call this here because the label in
2294 // question might just have been added and no screen
2295 // update taken place.
2296 if (m_dirty
) wxYield();
2298 wxListLineData
*oldCurrent
= m_current
;
2299 m_current
= (wxListLineData
*) NULL
;
2301 wxNode
*node
= m_lines
.Nth( i
);
2302 if (node
) m_current
= (wxListLineData
*)node
->Data();
2303 if (m_current
) MoveToFocus();
2304 m_current
= oldCurrent
;
2307 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2311 if (pos
< 0) pos
= 0;
2312 wxNode
*node
= m_lines
.Nth( pos
);
2315 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2317 line
->GetText( 0, s
);
2318 if (s
== tmp
) return pos
;
2319 node
= node
->Next();
2325 long wxListMainWindow::FindItem(long start
, long data
)
2328 if (pos
< 0) pos
= 0;
2329 wxNode
*node
= m_lines
.Nth( pos
);
2332 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2334 line
->GetItem( 0, item
);
2335 if (item
.m_data
== data
) return pos
;
2336 node
= node
->Next();
2342 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2344 wxNode
*node
= m_lines
.First();
2348 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2349 long ret
= line
->IsHit( x
, y
);
2355 node
= node
->Next();
2361 void wxListMainWindow::InsertItem( wxListItem
&item
)
2365 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2366 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2367 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2368 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2370 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2372 if (m_mode
& wxLC_REPORT
)
2374 line
->InitItems( GetColumnCount() );
2375 item
.m_width
= GetColumnWidth( 0 )-3;
2379 line
->InitItems( 1 );
2382 line
->SetItem( 0, item
);
2383 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2385 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2386 if (node
) m_lines
.Insert( node
, line
);
2390 m_lines
.Append( line
);
2394 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2397 if (m_mode
& wxLC_REPORT
)
2399 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2400 wxListHeaderData
*column
= new wxListHeaderData( item
);
2401 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2403 wxNode
*node
= m_columns
.Nth( col
);
2405 m_columns
.Insert( node
, column
);
2409 m_columns
.Append( column
);
2414 wxListCtrlCompare list_ctrl_compare_func_2
;
2415 long list_ctrl_compare_data
;
2417 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2419 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2420 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2422 line1
->GetItem( 0, item
);
2423 long data1
= item
.m_data
;
2424 line2
->GetItem( 0, item
);
2425 long data2
= item
.m_data
;
2426 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2429 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2431 list_ctrl_compare_func_2
= fn
;
2432 list_ctrl_compare_data
= data
;
2433 m_lines
.Sort( list_ctrl_compare_func_1
);
2436 // -------------------------------------------------------------------------------------
2438 // -------------------------------------------------------------------------------------
2440 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2442 wxListItem::wxListItem()
2451 m_format
= wxLIST_FORMAT_CENTRE
;
2456 // -------------------------------------------------------------------------------------
2458 // -------------------------------------------------------------------------------------
2460 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2462 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2463 wxNotifyEvent( commandType
, id
)
2469 m_cancelled
= FALSE
;
2474 // -------------------------------------------------------------------------------------
2476 // -------------------------------------------------------------------------------------
2478 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2480 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2481 EVT_SIZE (wxListCtrl::OnSize
)
2482 EVT_IDLE (wxListCtrl::OnIdle
)
2485 wxListCtrl::wxListCtrl()
2487 m_imageListNormal
= (wxImageList
*) NULL
;
2488 m_imageListSmall
= (wxImageList
*) NULL
;
2489 m_imageListState
= (wxImageList
*) NULL
;
2490 m_mainWin
= (wxListMainWindow
*) NULL
;
2491 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2494 wxListCtrl::~wxListCtrl()
2498 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2499 const wxPoint
&pos
, const wxSize
&size
,
2500 long style
, const wxValidator
&validator
,
2501 const wxString
&name
)
2503 m_imageListNormal
= (wxImageList
*) NULL
;
2504 m_imageListSmall
= (wxImageList
*) NULL
;
2505 m_imageListState
= (wxImageList
*) NULL
;
2506 m_mainWin
= (wxListMainWindow
*) NULL
;
2507 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2511 if ((s
& wxLC_REPORT
== 0) &&
2512 (s
& wxLC_LIST
== 0) &&
2513 (s
& wxLC_ICON
== 0))
2518 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2520 #if wxUSE_VALIDATORS
2521 SetValidator( validator
);
2524 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2526 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2528 if (HasFlag(wxLC_REPORT
))
2529 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2531 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2533 SetBackgroundColour( *wxWHITE
);
2538 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2540 /* handled in OnIdle */
2542 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2545 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2547 long flag
= GetWindowStyle();
2551 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2552 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2553 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2562 if (flag
& style
) flag
-= style
;
2565 SetWindowStyleFlag( flag
);
2568 void wxListCtrl::SetWindowStyleFlag( long flag
)
2572 m_mainWin
->DeleteEverything();
2576 GetClientSize( &width
, &height
);
2578 m_mainWin
->SetMode( flag
);
2580 if (flag
& wxLC_REPORT
)
2582 if (!HasFlag(wxLC_REPORT
))
2586 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2587 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2588 if (HasFlag(wxLC_NO_HEADER
))
2589 m_headerWin
->Show( FALSE
);
2593 if (flag
& wxLC_NO_HEADER
)
2594 m_headerWin
->Show( FALSE
);
2596 m_headerWin
->Show( TRUE
);
2602 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2604 m_headerWin
->Show( FALSE
);
2609 wxWindow::SetWindowStyleFlag( flag
);
2612 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2614 m_mainWin
->GetColumn( col
, item
);
2618 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2620 m_mainWin
->SetColumn( col
, item
);
2624 int wxListCtrl::GetColumnWidth( int col
) const
2626 return m_mainWin
->GetColumnWidth( col
);
2629 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2631 m_mainWin
->SetColumnWidth( col
, width
);
2635 int wxListCtrl::GetCountPerPage() const
2637 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2640 bool wxListCtrl::GetItem( wxListItem
&info
) const
2642 m_mainWin
->GetItem( info
);
2646 bool wxListCtrl::SetItem( wxListItem
&info
)
2648 m_mainWin
->SetItem( info
);
2652 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2655 info
.m_text
= label
;
2656 info
.m_mask
= wxLIST_MASK_TEXT
;
2657 info
.m_itemId
= index
;
2661 info
.m_image
= imageId
;
2662 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2664 m_mainWin
->SetItem(info
);
2668 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2670 return m_mainWin
->GetItemState( item
, stateMask
);
2673 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2675 m_mainWin
->SetItemState( item
, state
, stateMask
);
2679 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2682 info
.m_image
= image
;
2683 info
.m_mask
= wxLIST_MASK_IMAGE
;
2684 info
.m_itemId
= item
;
2685 m_mainWin
->SetItem( info
);
2689 wxString
wxListCtrl::GetItemText( long item
) const
2692 info
.m_itemId
= item
;
2693 m_mainWin
->GetItem( info
);
2697 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2700 info
.m_mask
= wxLIST_MASK_TEXT
;
2701 info
.m_itemId
= item
;
2703 m_mainWin
->SetItem( info
);
2706 long wxListCtrl::GetItemData( long item
) const
2709 info
.m_itemId
= item
;
2710 m_mainWin
->GetItem( info
);
2714 bool wxListCtrl::SetItemData( long item
, long data
)
2717 info
.m_mask
= wxLIST_MASK_DATA
;
2718 info
.m_itemId
= item
;
2720 m_mainWin
->SetItem( info
);
2724 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2726 m_mainWin
->GetItemRect( item
, rect
);
2730 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2732 m_mainWin
->GetItemPosition( item
, pos
);
2736 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2741 int wxListCtrl::GetItemCount() const
2743 return m_mainWin
->GetItemCount();
2746 int wxListCtrl::GetColumnCount() const
2748 return m_mainWin
->GetColumnCount();
2751 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2753 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2756 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2758 return m_mainWin
->GetItemSpacing( isSmall
);
2761 int wxListCtrl::GetSelectedItemCount() const
2763 return m_mainWin
->GetSelectedItemCount();
2767 wxColour wxListCtrl::GetTextColour() const
2771 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2776 long wxListCtrl::GetTopItem() const
2781 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2783 return m_mainWin
->GetNextItem( item
, geom
, state
);
2786 wxImageList
*wxListCtrl::GetImageList(int which
) const
2788 if (which
== wxIMAGE_LIST_NORMAL
)
2790 return m_imageListNormal
;
2792 else if (which
== wxIMAGE_LIST_SMALL
)
2794 return m_imageListSmall
;
2796 else if (which
== wxIMAGE_LIST_STATE
)
2798 return m_imageListState
;
2800 return (wxImageList
*) NULL
;
2803 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2805 m_mainWin
->SetImageList( imageList
, which
);
2808 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2813 bool wxListCtrl::DeleteItem( long item
)
2815 m_mainWin
->DeleteItem( item
);
2819 bool wxListCtrl::DeleteAllItems()
2821 m_mainWin
->DeleteAllItems();
2825 bool wxListCtrl::DeleteAllColumns()
2827 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2833 void wxListCtrl::ClearAll()
2835 m_mainWin
->DeleteEverything();
2838 bool wxListCtrl::DeleteColumn( int col
)
2840 m_mainWin
->DeleteColumn( col
);
2844 void wxListCtrl::Edit( long item
)
2846 m_mainWin
->Edit( item
);
2849 bool wxListCtrl::EnsureVisible( long item
)
2851 m_mainWin
->EnsureVisible( item
);
2855 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2857 return m_mainWin
->FindItem( start
, str
, partial
);
2860 long wxListCtrl::FindItem( long start
, long data
)
2862 return m_mainWin
->FindItem( start
, data
);
2865 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2866 int WXUNUSED(direction
))
2871 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2873 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2876 long wxListCtrl::InsertItem( wxListItem
& info
)
2878 m_mainWin
->InsertItem( info
);
2882 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2885 info
.m_text
= label
;
2886 info
.m_mask
= wxLIST_MASK_TEXT
;
2887 info
.m_itemId
= index
;
2888 return InsertItem( info
);
2891 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2894 info
.m_mask
= wxLIST_MASK_IMAGE
;
2895 info
.m_image
= imageIndex
;
2896 info
.m_itemId
= index
;
2897 return InsertItem( info
);
2900 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2903 info
.m_text
= label
;
2904 info
.m_image
= imageIndex
;
2905 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2906 info
.m_itemId
= index
;
2907 return InsertItem( info
);
2910 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2912 m_mainWin
->InsertColumn( col
, item
);
2916 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2917 int format
, int width
)
2920 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2921 item
.m_text
= heading
;
2924 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2925 item
.m_width
= width
;
2927 item
.m_format
= format
;
2929 return InsertColumn( col
, item
);
2932 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2938 // fn is a function which takes 3 long arguments: item1, item2, data.
2939 // item1 is the long data associated with a first item (NOT the index).
2940 // item2 is the long data associated with a second item (NOT the index).
2941 // data is the same value as passed to SortItems.
2942 // The return value is a negative number if the first item should precede the second
2943 // item, a positive number of the second item should precede the first,
2944 // or zero if the two items are equivalent.
2945 // data is arbitrary data to be passed to the sort function.
2947 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2949 m_mainWin
->SortItems( fn
, data
);
2953 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2955 if (!m_mainWin
->m_dirty
) return;
2959 GetClientSize( &cw
, &ch
);
2966 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
2968 m_headerWin
->GetPosition( &x
, &y
);
2969 m_headerWin
->GetSize( &w
, &h
);
2970 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2971 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2973 m_mainWin
->GetPosition( &x
, &y
);
2974 m_mainWin
->GetSize( &w
, &h
);
2975 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2976 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2980 m_mainWin
->GetPosition( &x
, &y
);
2981 m_mainWin
->GetSize( &w
, &h
);
2982 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2983 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2986 m_mainWin
->CalculatePositions();
2987 m_mainWin
->RealizeChanges();
2988 m_mainWin
->m_dirty
= FALSE
;
2989 m_mainWin
->Refresh();
2992 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
2994 if ( !wxWindow::SetBackgroundColour( colour
) )
2999 m_mainWin
->SetBackgroundColour( colour
);
3000 m_mainWin
->m_dirty
= TRUE
;
3005 // m_headerWin->SetBackgroundColour( colour );
3011 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3013 if ( !wxWindow::SetForegroundColour( colour
) )
3018 m_mainWin
->SetForegroundColour( colour
);
3019 m_mainWin
->m_dirty
= TRUE
;
3024 m_headerWin
->SetForegroundColour( colour
);
3030 bool wxListCtrl::SetFont( const wxFont
&font
)
3032 if ( !wxWindow::SetFont( font
) )
3037 m_mainWin
->SetFont( font
);
3038 m_mainWin
->m_dirty
= TRUE
;
3043 m_headerWin
->SetFont( font
);