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
= wxT("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()-1; 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
,
960 # if defined(__VISAGECPP__)
961 int style
, const wxValidator
* validator
, const wxString
&name
) :
963 int style
, const wxValidator
& validator
, const wxString
&name
) :
966 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
973 m_startValue
= value
;
976 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
978 if (event
.m_keyCode
== WXK_RETURN
)
981 (*m_res
) = GetValue();
985 if (event
.m_keyCode
== WXK_ESCAPE
)
995 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
997 if (wxPendingDelete
.Member(this)) return;
999 wxPendingDelete
.Append(this);
1001 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1002 m_owner
->OnRenameAccept();
1005 //-----------------------------------------------------------------------------
1007 //-----------------------------------------------------------------------------
1009 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1011 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1012 EVT_PAINT (wxListMainWindow::OnPaint
)
1013 EVT_SIZE (wxListMainWindow::OnSize
)
1014 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1015 EVT_CHAR (wxListMainWindow::OnChar
)
1016 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1017 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1018 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1021 wxListMainWindow::wxListMainWindow()
1024 m_lines
.DeleteContents( TRUE
);
1025 m_columns
.DeleteContents( TRUE
);
1026 m_current
= (wxListLineData
*) NULL
;
1028 m_hilightBrush
= (wxBrush
*) NULL
;
1032 m_small_image_list
= (wxImageList
*) NULL
;
1033 m_normal_image_list
= (wxImageList
*) NULL
;
1034 m_small_spacing
= 30;
1035 m_normal_spacing
= 40;
1038 m_lastOnSame
= FALSE
;
1039 m_renameTimer
= new wxListRenameTimer( this );
1040 m_isCreated
= FALSE
;
1044 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1045 const wxPoint
&pos
, const wxSize
&size
,
1046 long style
, const wxString
&name
) :
1047 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1050 m_lines
.DeleteContents( TRUE
);
1051 m_columns
.DeleteContents( TRUE
);
1052 m_current
= (wxListLineData
*) NULL
;
1055 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1056 m_small_image_list
= (wxImageList
*) NULL
;
1057 m_normal_image_list
= (wxImageList
*) NULL
;
1058 m_small_spacing
= 30;
1059 m_normal_spacing
= 40;
1062 m_isCreated
= FALSE
;
1066 if (m_mode
& wxLC_REPORT
)
1076 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1079 m_lastOnSame
= FALSE
;
1080 m_renameTimer
= new wxListRenameTimer( this );
1081 m_renameAccept
= FALSE
;
1083 SetBackgroundColour( *wxWHITE
);
1086 wxListMainWindow::~wxListMainWindow()
1088 if (m_hilightBrush
) delete m_hilightBrush
;
1090 delete m_renameTimer
;
1093 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1101 wxClientDC
dc(this);
1103 line
->GetExtent( x
, y
, w
, h
);
1105 dc
.LogicalToDeviceX(x
-3),
1106 dc
.LogicalToDeviceY(y
-3),
1107 dc
.LogicalToDeviceXRel(w
+6),
1108 dc
.LogicalToDeviceXRel(h
+6) );
1109 Refresh( TRUE
, &rect
);
1113 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1115 // Note: a wxPaintDC must be constructed even if no drawing is
1116 // done (a Windows requirement).
1117 wxPaintDC
dc( this );
1120 if (m_dirty
) return;
1122 if (m_lines
.GetCount() == 0) return;
1126 dc
.SetFont( GetFont() );
1128 if (m_mode
& wxLC_REPORT
)
1130 int lineSpacing
= 0;
1131 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1133 line
->GetSize( dummy
, lineSpacing
);
1136 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1138 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1139 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1143 line
= (wxListLineData
*)node
->Data();
1145 node
= node
->Next();
1150 wxNode
*node
= m_lines
.First();
1153 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1155 node
= node
->Next();
1159 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1164 void wxListMainWindow::HilightAll( bool on
)
1166 wxNode
*node
= m_lines
.First();
1169 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1170 if (line
->IsHilighted() != on
)
1172 line
->Hilight( on
);
1173 RefreshLine( line
);
1175 node
= node
->Next();
1179 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1181 wxListEvent
le( command
, GetParent()->GetId() );
1182 le
.SetEventObject( GetParent() );
1183 le
.m_itemIndex
= GetIndexOfLine( line
);
1184 line
->GetItem( 0, le
.m_item
);
1185 GetParent()->GetEventHandler()->ProcessEvent( le
);
1188 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1190 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1193 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1195 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1198 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1200 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1203 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1205 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1208 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1210 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1215 void wxListMainWindow::EditLabel( long item
)
1217 wxNode
*node
= m_lines
.Nth( item
);
1218 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1220 m_currentEdit
= (wxListLineData
*) node
->Data();
1222 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1223 le
.SetEventObject( GetParent() );
1224 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1225 m_currentEdit
->GetItem( 0, le
.m_item
);
1226 GetParent()->GetEventHandler()->ProcessEvent( le
);
1228 if (!le
.IsAllowed())
1231 // We have to call this here because the label in
1232 // question might just have been added and no screen
1233 // update taken place.
1234 if (m_dirty
) wxYield();
1237 m_currentEdit
->GetText( 0, s
);
1242 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1244 wxClientDC
dc(this);
1246 x
= dc
.LogicalToDeviceX( x
);
1247 y
= dc
.LogicalToDeviceY( y
);
1249 wxListTextCtrl
*text
= new wxListTextCtrl(
1250 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1254 void wxListMainWindow::OnRenameTimer()
1256 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1258 Edit( m_lines
.IndexOf( m_current
) );
1261 void wxListMainWindow::OnRenameAccept()
1263 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1264 le
.SetEventObject( GetParent() );
1265 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1266 m_currentEdit
->GetItem( 0, le
.m_item
);
1267 le
.m_item
.m_text
= m_renameRes
;
1268 GetParent()->GetEventHandler()->ProcessEvent( le
);
1270 if (!le
.IsAllowed()) return;
1273 info
.m_mask
= wxLIST_MASK_TEXT
;
1274 info
.m_itemId
= le
.m_itemIndex
;
1275 info
.m_text
= m_renameRes
;
1276 info
.m_colour
= le
.m_item
.m_colour
;
1280 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1282 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1284 if (!m_current
) return;
1285 if (m_dirty
) return;
1286 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1288 wxClientDC
dc(this);
1290 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1291 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1293 /* Did we actually hit an item ? */
1295 wxNode
*node
= m_lines
.First();
1296 wxListLineData
*line
= (wxListLineData
*) NULL
;
1299 line
= (wxListLineData
*)node
->Data();
1300 hitResult
= line
->IsHit( x
, y
);
1301 if (hitResult
) break;
1302 line
= (wxListLineData
*) NULL
;
1303 node
= node
->Next();
1306 if (event
.Dragging())
1308 if (m_dragCount
== 0)
1309 m_dragStart
= wxPoint(x
,y
);
1313 if (m_dragCount
!= 3) return;
1315 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1316 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1318 wxListEvent
le( command
, GetParent()->GetId() );
1319 le
.SetEventObject( GetParent() );
1320 le
.m_pointDrag
= m_dragStart
;
1321 GetParent()->GetEventHandler()->ProcessEvent( le
);
1332 if (event
.ButtonDClick())
1335 m_lastOnSame
= FALSE
;
1336 m_renameTimer
->Stop();
1338 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1343 if (event
.LeftUp() && m_lastOnSame
)
1346 if ((line
== m_current
) &&
1347 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1348 (m_mode
& wxLC_EDIT_LABELS
) )
1350 m_renameTimer
->Start( 100, TRUE
);
1352 m_lastOnSame
= FALSE
;
1356 if (event
.RightDown())
1358 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1362 if (event
.MiddleDown())
1364 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1368 if (event
.LeftDown())
1371 wxListLineData
*oldCurrent
= m_current
;
1372 if (m_mode
& wxLC_SINGLE_SEL
)
1375 HilightAll( FALSE
);
1376 m_current
->ReverseHilight();
1377 RefreshLine( m_current
);
1381 if (event
.ShiftDown())
1384 m_current
->ReverseHilight();
1385 RefreshLine( m_current
);
1387 else if (event
.ControlDown())
1391 int numOfCurrent
= -1;
1392 node
= m_lines
.First();
1395 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1397 if (test_line
== oldCurrent
) break;
1398 node
= node
->Next();
1402 node
= m_lines
.First();
1405 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1407 if (test_line
== line
) break;
1408 node
= node
->Next();
1411 if (numOfLine
< numOfCurrent
)
1414 numOfLine
= numOfCurrent
;
1418 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1419 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1421 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1422 test_line
->Hilight(TRUE
);
1423 RefreshLine( test_line
);
1424 node
= node
->Next();
1430 HilightAll( FALSE
);
1431 m_current
->ReverseHilight();
1432 RefreshLine( m_current
);
1435 if (m_current
!= oldCurrent
)
1437 RefreshLine( oldCurrent
);
1438 UnfocusLine( oldCurrent
);
1439 FocusLine( m_current
);
1441 m_lastOnSame
= (m_current
== oldCurrent
);
1446 void wxListMainWindow::MoveToFocus()
1448 if (!m_current
) return;
1454 m_current
->GetExtent( x
, y
, w
, h
);
1458 GetClientSize( &w_p
, &h_p
);
1460 if (m_mode
& wxLC_REPORT
)
1462 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1463 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1464 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1465 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1469 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1470 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1471 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1472 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1476 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1478 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1479 wxListLineData
*oldCurrent
= m_current
;
1480 m_current
= newCurrent
;
1482 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1483 RefreshLine( m_current
);
1484 RefreshLine( oldCurrent
);
1485 FocusLine( m_current
);
1486 UnfocusLine( oldCurrent
);
1489 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1491 wxWindow
*parent
= GetParent();
1493 /* we propagate the key event up */
1494 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1495 ke
.m_shiftDown
= event
.m_shiftDown
;
1496 ke
.m_controlDown
= event
.m_controlDown
;
1497 ke
.m_altDown
= event
.m_altDown
;
1498 ke
.m_metaDown
= event
.m_metaDown
;
1499 ke
.m_keyCode
= event
.m_keyCode
;
1502 ke
.SetEventObject( parent
);
1503 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1508 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1510 wxWindow
*parent
= GetParent();
1512 /* we send a list_key event up */
1513 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1514 le
.m_code
= event
.KeyCode();
1515 le
.SetEventObject( parent
);
1516 parent
->GetEventHandler()->ProcessEvent( le
);
1518 /* we propagate the char event up */
1519 wxKeyEvent
ke( wxEVT_CHAR
);
1520 ke
.m_shiftDown
= event
.m_shiftDown
;
1521 ke
.m_controlDown
= event
.m_controlDown
;
1522 ke
.m_altDown
= event
.m_altDown
;
1523 ke
.m_metaDown
= event
.m_metaDown
;
1524 ke
.m_keyCode
= event
.m_keyCode
;
1527 ke
.SetEventObject( parent
);
1528 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1530 if (event
.KeyCode() == WXK_TAB
)
1532 wxNavigationKeyEvent nevent
;
1533 nevent
.SetDirection( !event
.ShiftDown() );
1534 nevent
.SetCurrentFocus( m_parent
);
1535 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1538 /* no item -> nothing to do */
1545 switch (event
.KeyCode())
1549 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1550 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1555 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1556 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1561 wxNode
*node
= m_lines
.Last();
1562 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1567 wxNode
*node
= m_lines
.First();
1568 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1574 if (m_mode
& wxLC_REPORT
)
1576 steps
= m_visibleLines
-1;
1581 wxNode
*node
= m_lines
.First();
1582 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1583 steps
= pos
% m_visibleLines
;
1585 wxNode
*node
= m_lines
.Member( m_current
);
1586 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1587 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1593 if (m_mode
& wxLC_REPORT
)
1595 steps
= m_visibleLines
-1;
1599 int pos
= 0; wxNode
*node
= m_lines
.First();
1600 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1601 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1603 wxNode
*node
= m_lines
.Member( m_current
);
1604 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1605 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1610 if (!(m_mode
& wxLC_REPORT
))
1612 wxNode
*node
= m_lines
.Member( m_current
);
1613 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1614 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1620 if (!(m_mode
& wxLC_REPORT
))
1622 wxNode
*node
= m_lines
.Member( m_current
);
1623 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1624 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1630 m_current
->ReverseHilight();
1631 RefreshLine( m_current
);
1636 if (!(m_mode
& wxLC_SINGLE_SEL
))
1638 wxListLineData
*oldCurrent
= m_current
;
1639 m_current
->ReverseHilight();
1640 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1641 if (node
) m_current
= (wxListLineData
*)node
->Data();
1643 RefreshLine( oldCurrent
);
1644 RefreshLine( m_current
);
1645 UnfocusLine( oldCurrent
);
1646 FocusLine( m_current
);
1653 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1654 le
.SetEventObject( GetParent() );
1655 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1656 m_current
->GetItem( 0, le
.m_item
);
1657 GetParent()->GetEventHandler()->ProcessEvent( le
);
1670 extern wxWindow
*g_focusWindow
;
1673 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1676 RefreshLine( m_current
);
1678 if (!GetParent()) return;
1681 g_focusWindow
= GetParent();
1684 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1685 event
.SetEventObject( GetParent() );
1686 GetParent()->GetEventHandler()->ProcessEvent( event
);
1689 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1692 RefreshLine( m_current
);
1695 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1698 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1703 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1705 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1707 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1710 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1712 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1714 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1716 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1718 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1720 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1725 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1727 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1729 m_normal_image_list
->GetSize( index
, width
, height
);
1732 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1734 m_small_image_list
->GetSize( index
, width
, height
);
1737 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1739 m_small_image_list
->GetSize( index
, width
, height
);
1742 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1744 m_small_image_list
->GetSize( index
, width
, height
);
1751 int wxListMainWindow::GetTextLength( wxString
&s
)
1753 wxClientDC
dc( this );
1756 dc
.GetTextExtent( s
, &lw
, &lh
);
1760 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1763 wxNode
*node
= m_lines
.First();
1766 if (line
== (wxListLineData
*)node
->Data()) return i
;
1768 node
= node
->Next();
1773 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1776 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1777 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1780 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1785 m_small_spacing
= spacing
;
1789 m_normal_spacing
= spacing
;
1793 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1795 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1798 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1801 wxNode
*node
= m_columns
.Nth( col
);
1804 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1805 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1806 column
->SetItem( item
);
1808 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1809 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1812 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1814 if (!(m_mode
& wxLC_REPORT
)) return;
1818 wxNode
*node
= (wxNode
*) NULL
;
1820 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1821 if (width
== wxLIST_AUTOSIZE
)
1823 wxClientDC
dc(this);
1824 dc
.SetFont( GetFont() );
1826 node
= m_lines
.First();
1829 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1830 wxNode
*n
= line
->m_items
.Nth( col
);
1833 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1834 int current
= 0, ix
= 0, iy
= 0;
1835 long lx
= 0, ly
= 0;
1836 if (item
->HasImage())
1838 GetImageSize( item
->GetImage(), ix
, iy
);
1841 if (item
->HasText())
1844 item
->GetText( str
);
1845 dc
.GetTextExtent( str
, &lx
, &ly
);
1848 if (current
> max
) max
= current
;
1850 node
= node
->Next();
1855 node
= m_columns
.Nth( col
);
1858 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1859 column
->SetWidth( width
);
1862 node
= m_lines
.First();
1865 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1866 wxNode
*n
= line
->m_items
.Nth( col
);
1869 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1870 item
->SetSize( width
, -1 );
1872 node
= node
->Next();
1875 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1876 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1879 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1881 wxNode
*node
= m_columns
.Nth( col
);
1884 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1885 column
->GetItem( item
);
1897 int wxListMainWindow::GetColumnWidth( int col
)
1899 wxNode
*node
= m_columns
.Nth( col
);
1902 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1903 return column
->GetWidth();
1911 int wxListMainWindow::GetColumnCount()
1913 return m_columns
.Number();
1916 int wxListMainWindow::GetCountPerPage()
1918 return m_visibleLines
;
1921 void wxListMainWindow::SetItem( wxListItem
&item
)
1924 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1927 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1928 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1929 line
->SetItem( item
.m_col
, item
);
1933 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1935 // m_dirty = TRUE; no recalcs needed
1937 wxListLineData
*oldCurrent
= m_current
;
1939 if (stateMask
& wxLIST_STATE_FOCUSED
)
1941 wxNode
*node
= m_lines
.Nth( item
);
1944 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1945 UnfocusLine( m_current
);
1947 FocusLine( m_current
);
1948 RefreshLine( m_current
);
1949 if (oldCurrent
) RefreshLine( oldCurrent
);
1953 if (stateMask
& wxLIST_STATE_SELECTED
)
1955 bool on
= state
& wxLIST_STATE_SELECTED
;
1956 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1958 wxNode
*node
= m_lines
.Nth( item
);
1961 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1962 if (m_mode
& wxLC_SINGLE_SEL
)
1964 UnfocusLine( m_current
);
1966 FocusLine( m_current
);
1967 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1968 RefreshLine( m_current
);
1969 if (oldCurrent
) RefreshLine( oldCurrent
);
1971 bool on
= state
& wxLIST_STATE_SELECTED
;
1972 if (on
!= line
->IsHilighted())
1974 line
->Hilight( on
);
1975 RefreshLine( line
);
1981 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1983 int ret
= wxLIST_STATE_DONTCARE
;
1984 if (stateMask
& wxLIST_STATE_FOCUSED
)
1986 wxNode
*node
= m_lines
.Nth( item
);
1989 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1990 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1993 if (stateMask
& wxLIST_STATE_SELECTED
)
1995 wxNode
*node
= m_lines
.Nth( item
);
1998 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1999 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2005 void wxListMainWindow::GetItem( wxListItem
&item
)
2007 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2010 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2011 line
->GetItem( item
.m_col
, item
);
2022 int wxListMainWindow::GetItemCount()
2024 return m_lines
.Number();
2027 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2029 wxNode
*node
= m_lines
.Nth( index
);
2032 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2033 line
->GetRect( rect
);
2044 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2046 wxNode
*node
= m_lines
.Nth( item
);
2050 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2051 line
->GetRect( rect
);
2063 int wxListMainWindow::GetSelectedItemCount()
2066 wxNode
*node
= m_lines
.First();
2069 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2070 if (line
->IsHilighted()) ret
++;
2071 node
= node
->Next();
2076 void wxListMainWindow::SetMode( long mode
)
2083 if (m_mode
& wxLC_REPORT
)
2095 long wxListMainWindow::GetMode() const
2100 void wxListMainWindow::CalculatePositions()
2102 if (!m_lines
.First()) return;
2104 wxClientDC
dc( this );
2105 dc
.SetFont( GetFont() );
2107 int iconSpacing
= 0;
2108 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2109 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2111 // we take the first line (which also can be an icon or
2112 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2113 // measure the size of the line
2117 int lineSpacing
= 0;
2119 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2120 line
->CalculateSize( &dc
, iconSpacing
);
2122 line
->GetSize( dummy
, lineSpacing
);
2125 int clientWidth
= 0;
2126 int clientHeight
= 0;
2128 if (m_mode
& wxLC_REPORT
)
2132 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2133 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2134 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2135 GetClientSize( &clientWidth
, &clientHeight
);
2137 wxNode
* node
= m_lines
.First();
2140 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2141 line
->CalculateSize( &dc
, iconSpacing
);
2142 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2144 for (int i
= 0; i
< GetColumnCount(); i
++)
2146 line
->SetColumnPosition( i
, col_x
);
2147 col_x
+= GetColumnWidth( i
);
2149 y
+= lineSpacing
; // one pixel blank line between items
2150 node
= node
->Next();
2152 m_visibleLines
= clientHeight
/ lineSpacing
;
2156 // at first we try without any scrollbar. if the items don't
2157 // fit into the window, we recalculate after subtracting an
2158 // approximated 15 pt for the horizontal scrollbar
2160 GetSize( &clientWidth
, &clientHeight
);
2161 clientHeight
-= 4; // sunken frame
2163 int entireWidth
= 0;
2165 for (int tries
= 0; tries
< 2; tries
++)
2168 int x
= 5; // painting is done at x-2
2169 int y
= 5; // painting is done at y-2
2172 int m_currentVisibleLines
= 0;
2173 wxNode
*node
= m_lines
.First();
2176 m_currentVisibleLines
++;
2177 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2178 line
->CalculateSize( &dc
, iconSpacing
);
2179 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2180 line
->GetSize( lineWidth
, lineHeight
);
2181 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2183 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2185 if (m_currentVisibleLines
> m_visibleLines
)
2186 m_visibleLines
= m_currentVisibleLines
;
2187 m_currentVisibleLines
= 0;
2190 entireWidth
+= maxWidth
+6;
2193 node
= node
->Next();
2194 if (!node
) entireWidth
+= maxWidth
;
2195 if ((tries
== 0) && (entireWidth
> clientWidth
))
2197 clientHeight
-= 15; // scrollbar height
2199 m_currentVisibleLines
= 0;
2202 if (!node
) tries
= 1; // everything fits, no second try required
2205 // m_visibleLines = (5+clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
2207 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2208 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2212 void wxListMainWindow::RealizeChanges( void )
2216 wxNode
*node
= m_lines
.First();
2217 if (node
) m_current
= (wxListLineData
*)node
->Data();
2221 FocusLine( m_current
);
2222 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2226 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2229 if (item
> 0) ret
= item
;
2230 if(ret
>= GetItemCount()) return -1;
2231 wxNode
*node
= m_lines
.Nth( ret
);
2234 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2235 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2236 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2237 if (!state
) return ret
;
2239 node
= node
->Next();
2244 void wxListMainWindow::DeleteItem( long index
)
2247 wxNode
*node
= m_lines
.Nth( index
);
2250 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2251 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2253 m_lines
.DeleteNode( node
);
2257 void wxListMainWindow::DeleteColumn( int col
)
2259 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2260 wxT("attempting to delete inexistent column in wxListView") );
2263 wxNode
*node
= m_columns
.Nth( col
);
2264 if (node
) m_columns
.DeleteNode( node
);
2267 void wxListMainWindow::DeleteAllItems( void )
2270 m_current
= (wxListLineData
*) NULL
;
2271 wxNode
*node
= m_lines
.First();
2274 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2276 node
= node
->Next();
2281 void wxListMainWindow::DeleteEverything( void )
2284 m_current
= (wxListLineData
*) NULL
;
2285 wxNode
*node
= m_lines
.First();
2288 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2290 node
= node
->Next();
2293 m_current
= (wxListLineData
*) NULL
;
2297 void wxListMainWindow::EnsureVisible( long index
)
2299 // We have to call this here because the label in
2300 // question might just have been added and no screen
2301 // update taken place.
2302 if (m_dirty
) wxYield();
2304 wxListLineData
*oldCurrent
= m_current
;
2305 m_current
= (wxListLineData
*) NULL
;
2307 wxNode
*node
= m_lines
.Nth( i
);
2308 if (node
) m_current
= (wxListLineData
*)node
->Data();
2309 if (m_current
) MoveToFocus();
2310 m_current
= oldCurrent
;
2313 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2317 if (pos
< 0) pos
= 0;
2318 wxNode
*node
= m_lines
.Nth( pos
);
2321 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2323 line
->GetText( 0, s
);
2324 if (s
== tmp
) return pos
;
2325 node
= node
->Next();
2331 long wxListMainWindow::FindItem(long start
, long data
)
2334 if (pos
< 0) pos
= 0;
2335 wxNode
*node
= m_lines
.Nth( pos
);
2338 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2340 line
->GetItem( 0, item
);
2341 if (item
.m_data
== data
) return pos
;
2342 node
= node
->Next();
2348 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2350 wxNode
*node
= m_lines
.First();
2354 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2355 long ret
= line
->IsHit( x
, y
);
2361 node
= node
->Next();
2367 void wxListMainWindow::InsertItem( wxListItem
&item
)
2371 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2372 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2373 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2374 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2376 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2378 if (m_mode
& wxLC_REPORT
)
2380 line
->InitItems( GetColumnCount() );
2381 item
.m_width
= GetColumnWidth( 0 )-3;
2385 line
->InitItems( 1 );
2388 line
->SetItem( 0, item
);
2389 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2391 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2392 if (node
) m_lines
.Insert( node
, line
);
2396 m_lines
.Append( line
);
2400 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2403 if (m_mode
& wxLC_REPORT
)
2405 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2406 wxListHeaderData
*column
= new wxListHeaderData( item
);
2407 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2409 wxNode
*node
= m_columns
.Nth( col
);
2411 m_columns
.Insert( node
, column
);
2415 m_columns
.Append( column
);
2420 wxListCtrlCompare list_ctrl_compare_func_2
;
2421 long list_ctrl_compare_data
;
2423 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2425 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2426 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2428 line1
->GetItem( 0, item
);
2429 long data1
= item
.m_data
;
2430 line2
->GetItem( 0, item
);
2431 long data2
= item
.m_data
;
2432 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2435 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2437 list_ctrl_compare_func_2
= fn
;
2438 list_ctrl_compare_data
= data
;
2439 m_lines
.Sort( list_ctrl_compare_func_1
);
2442 // -------------------------------------------------------------------------------------
2444 // -------------------------------------------------------------------------------------
2446 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2448 wxListItem::wxListItem()
2457 m_format
= wxLIST_FORMAT_CENTRE
;
2462 // -------------------------------------------------------------------------------------
2464 // -------------------------------------------------------------------------------------
2466 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2468 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2469 wxNotifyEvent( commandType
, id
)
2475 m_cancelled
= FALSE
;
2480 // -------------------------------------------------------------------------------------
2482 // -------------------------------------------------------------------------------------
2484 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2486 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2487 EVT_SIZE (wxListCtrl::OnSize
)
2488 EVT_IDLE (wxListCtrl::OnIdle
)
2491 wxListCtrl::wxListCtrl()
2493 m_imageListNormal
= (wxImageList
*) NULL
;
2494 m_imageListSmall
= (wxImageList
*) NULL
;
2495 m_imageListState
= (wxImageList
*) NULL
;
2496 m_mainWin
= (wxListMainWindow
*) NULL
;
2497 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2500 wxListCtrl::~wxListCtrl()
2504 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2505 const wxPoint
&pos
, const wxSize
&size
,
2506 #if wxUSE_VALIDATORS
2507 # if defined(__VISAGECPP__)
2508 long style
, const wxValidator
*validator
,
2510 long style
, const wxValidator
&validator
,
2513 const wxString
&name
)
2515 m_imageListNormal
= (wxImageList
*) NULL
;
2516 m_imageListSmall
= (wxImageList
*) NULL
;
2517 m_imageListState
= (wxImageList
*) NULL
;
2518 m_mainWin
= (wxListMainWindow
*) NULL
;
2519 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2523 if ((s
& wxLC_REPORT
== 0) &&
2524 (s
& wxLC_LIST
== 0) &&
2525 (s
& wxLC_ICON
== 0))
2530 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2532 #if wxUSE_VALIDATORS
2533 SetValidator( validator
);
2536 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2538 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2540 if (HasFlag(wxLC_REPORT
))
2541 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2543 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2545 SetBackgroundColour( *wxWHITE
);
2550 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2552 /* handled in OnIdle */
2554 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2557 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2559 long flag
= GetWindowStyle();
2563 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2564 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2565 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2574 if (flag
& style
) flag
-= style
;
2577 SetWindowStyleFlag( flag
);
2580 void wxListCtrl::SetWindowStyleFlag( long flag
)
2584 m_mainWin
->DeleteEverything();
2588 GetClientSize( &width
, &height
);
2590 m_mainWin
->SetMode( flag
);
2592 if (flag
& wxLC_REPORT
)
2594 if (!HasFlag(wxLC_REPORT
))
2598 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2599 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2600 if (HasFlag(wxLC_NO_HEADER
))
2601 m_headerWin
->Show( FALSE
);
2605 if (flag
& wxLC_NO_HEADER
)
2606 m_headerWin
->Show( FALSE
);
2608 m_headerWin
->Show( TRUE
);
2614 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2616 m_headerWin
->Show( FALSE
);
2621 wxWindow::SetWindowStyleFlag( flag
);
2624 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2626 m_mainWin
->GetColumn( col
, item
);
2630 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2632 m_mainWin
->SetColumn( col
, item
);
2636 int wxListCtrl::GetColumnWidth( int col
) const
2638 return m_mainWin
->GetColumnWidth( col
);
2641 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2643 m_mainWin
->SetColumnWidth( col
, width
);
2647 int wxListCtrl::GetCountPerPage() const
2649 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2652 bool wxListCtrl::GetItem( wxListItem
&info
) const
2654 m_mainWin
->GetItem( info
);
2658 bool wxListCtrl::SetItem( wxListItem
&info
)
2660 m_mainWin
->SetItem( info
);
2664 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2667 info
.m_text
= label
;
2668 info
.m_mask
= wxLIST_MASK_TEXT
;
2669 info
.m_itemId
= index
;
2673 info
.m_image
= imageId
;
2674 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2676 m_mainWin
->SetItem(info
);
2680 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2682 return m_mainWin
->GetItemState( item
, stateMask
);
2685 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2687 m_mainWin
->SetItemState( item
, state
, stateMask
);
2691 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2694 info
.m_image
= image
;
2695 info
.m_mask
= wxLIST_MASK_IMAGE
;
2696 info
.m_itemId
= item
;
2697 m_mainWin
->SetItem( info
);
2701 wxString
wxListCtrl::GetItemText( long item
) const
2704 info
.m_itemId
= item
;
2705 m_mainWin
->GetItem( info
);
2709 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2712 info
.m_mask
= wxLIST_MASK_TEXT
;
2713 info
.m_itemId
= item
;
2715 m_mainWin
->SetItem( info
);
2718 long wxListCtrl::GetItemData( long item
) const
2721 info
.m_itemId
= item
;
2722 m_mainWin
->GetItem( info
);
2726 bool wxListCtrl::SetItemData( long item
, long data
)
2729 info
.m_mask
= wxLIST_MASK_DATA
;
2730 info
.m_itemId
= item
;
2732 m_mainWin
->SetItem( info
);
2736 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2738 m_mainWin
->GetItemRect( item
, rect
);
2742 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2744 m_mainWin
->GetItemPosition( item
, pos
);
2748 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2753 int wxListCtrl::GetItemCount() const
2755 return m_mainWin
->GetItemCount();
2758 int wxListCtrl::GetColumnCount() const
2760 return m_mainWin
->GetColumnCount();
2763 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2765 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2768 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2770 return m_mainWin
->GetItemSpacing( isSmall
);
2773 int wxListCtrl::GetSelectedItemCount() const
2775 return m_mainWin
->GetSelectedItemCount();
2779 wxColour wxListCtrl::GetTextColour() const
2783 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2788 long wxListCtrl::GetTopItem() const
2793 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2795 return m_mainWin
->GetNextItem( item
, geom
, state
);
2798 wxImageList
*wxListCtrl::GetImageList(int which
) const
2800 if (which
== wxIMAGE_LIST_NORMAL
)
2802 return m_imageListNormal
;
2804 else if (which
== wxIMAGE_LIST_SMALL
)
2806 return m_imageListSmall
;
2808 else if (which
== wxIMAGE_LIST_STATE
)
2810 return m_imageListState
;
2812 return (wxImageList
*) NULL
;
2815 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2817 m_mainWin
->SetImageList( imageList
, which
);
2820 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2825 bool wxListCtrl::DeleteItem( long item
)
2827 m_mainWin
->DeleteItem( item
);
2831 bool wxListCtrl::DeleteAllItems()
2833 m_mainWin
->DeleteAllItems();
2837 bool wxListCtrl::DeleteAllColumns()
2839 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2845 void wxListCtrl::ClearAll()
2847 m_mainWin
->DeleteEverything();
2850 bool wxListCtrl::DeleteColumn( int col
)
2852 m_mainWin
->DeleteColumn( col
);
2856 void wxListCtrl::Edit( long item
)
2858 m_mainWin
->Edit( item
);
2861 bool wxListCtrl::EnsureVisible( long item
)
2863 m_mainWin
->EnsureVisible( item
);
2867 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2869 return m_mainWin
->FindItem( start
, str
, partial
);
2872 long wxListCtrl::FindItem( long start
, long data
)
2874 return m_mainWin
->FindItem( start
, data
);
2877 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2878 int WXUNUSED(direction
))
2883 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2885 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2888 long wxListCtrl::InsertItem( wxListItem
& info
)
2890 m_mainWin
->InsertItem( info
);
2891 return info
.m_itemId
;
2894 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2897 info
.m_text
= label
;
2898 info
.m_mask
= wxLIST_MASK_TEXT
;
2899 info
.m_itemId
= index
;
2900 return InsertItem( info
);
2903 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2906 info
.m_mask
= wxLIST_MASK_IMAGE
;
2907 info
.m_image
= imageIndex
;
2908 info
.m_itemId
= index
;
2909 return InsertItem( info
);
2912 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2915 info
.m_text
= label
;
2916 info
.m_image
= imageIndex
;
2917 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2918 info
.m_itemId
= index
;
2919 return InsertItem( info
);
2922 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2924 m_mainWin
->InsertColumn( col
, item
);
2928 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2929 int format
, int width
)
2932 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2933 item
.m_text
= heading
;
2936 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2937 item
.m_width
= width
;
2939 item
.m_format
= format
;
2941 return InsertColumn( col
, item
);
2944 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2950 // fn is a function which takes 3 long arguments: item1, item2, data.
2951 // item1 is the long data associated with a first item (NOT the index).
2952 // item2 is the long data associated with a second item (NOT the index).
2953 // data is the same value as passed to SortItems.
2954 // The return value is a negative number if the first item should precede the second
2955 // item, a positive number of the second item should precede the first,
2956 // or zero if the two items are equivalent.
2957 // data is arbitrary data to be passed to the sort function.
2959 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2961 m_mainWin
->SortItems( fn
, data
);
2965 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2967 if (!m_mainWin
->m_dirty
) return;
2971 GetClientSize( &cw
, &ch
);
2978 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
2980 m_headerWin
->GetPosition( &x
, &y
);
2981 m_headerWin
->GetSize( &w
, &h
);
2982 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2983 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2985 m_mainWin
->GetPosition( &x
, &y
);
2986 m_mainWin
->GetSize( &w
, &h
);
2987 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2988 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2992 m_mainWin
->GetPosition( &x
, &y
);
2993 m_mainWin
->GetSize( &w
, &h
);
2994 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2995 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2998 m_mainWin
->CalculatePositions();
2999 m_mainWin
->RealizeChanges();
3000 m_mainWin
->m_dirty
= FALSE
;
3001 m_mainWin
->Refresh();
3004 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3006 if ( !wxWindow::SetBackgroundColour( colour
) )
3011 m_mainWin
->SetBackgroundColour( colour
);
3012 m_mainWin
->m_dirty
= TRUE
;
3017 // m_headerWin->SetBackgroundColour( colour );
3023 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3025 if ( !wxWindow::SetForegroundColour( colour
) )
3030 m_mainWin
->SetForegroundColour( colour
);
3031 m_mainWin
->m_dirty
= TRUE
;
3036 m_headerWin
->SetForegroundColour( colour
);
3042 bool wxListCtrl::SetFont( const wxFont
&font
)
3044 if ( !wxWindow::SetFont( font
) )
3049 m_mainWin
->SetFont( font
);
3050 m_mainWin
->m_dirty
= TRUE
;
3055 m_headerWin
->SetFont( font
);