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 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
27 #define wxUSE_GENERIC_LIST_EXTENSIONS 0
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
36 wxListItemData::wxListItemData()
47 wxListItemData::wxListItemData( const wxListItem
&info
)
51 m_colour
= info
.m_colour
;
55 void wxListItemData::SetItem( const wxListItem
&info
)
57 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
58 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
59 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
60 m_colour
= info
.m_colour
;
63 m_width
= info
.m_width
;
67 void wxListItemData::SetText( const wxString
&s
)
72 void wxListItemData::SetImage( int image
)
77 void wxListItemData::SetData( long data
)
82 void wxListItemData::SetPosition( int x
, int y
)
88 void wxListItemData::SetSize( int width
, int height
)
90 if (width
!= -1) m_width
= width
;
91 if (height
!= -1) m_height
= height
;
94 void wxListItemData::SetColour( wxColour
*col
)
99 bool wxListItemData::HasImage() const
101 return (m_image
>= 0);
104 bool wxListItemData::HasText() const
106 return (!m_text
.IsNull());
109 bool wxListItemData::IsHit( int x
, int y
) const
111 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
114 void wxListItemData::GetText( wxString
&s
)
119 int wxListItemData::GetX() const
124 int wxListItemData::GetY() const
129 int wxListItemData::GetWidth() const
134 int wxListItemData::GetHeight() const
139 int wxListItemData::GetImage() const
144 void wxListItemData::GetItem( wxListItem
&info
)
146 info
.m_text
= m_text
;
147 info
.m_image
= m_image
;
148 info
.m_data
= m_data
;
149 info
.m_colour
= m_colour
;
152 wxColour
*wxListItemData::GetColour()
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
161 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
163 wxListHeaderData::wxListHeaderData()
174 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
182 void wxListHeaderData::SetItem( const wxListItem
&item
)
184 m_mask
= item
.m_mask
;
185 m_text
= item
.m_text
;
186 m_image
= item
.m_image
;
187 m_format
= item
.m_format
;
188 m_width
= item
.m_width
;
189 if (m_width
< 0) m_width
= 80;
190 if (m_width
< 6) m_width
= 6;
193 void wxListHeaderData::SetPosition( int x
, int y
)
199 void wxListHeaderData::SetHeight( int h
)
204 void wxListHeaderData::SetWidth( int w
)
207 if (m_width
< 0) m_width
= 80;
208 if (m_width
< 6) m_width
= 6;
211 void wxListHeaderData::SetFormat( int format
)
216 bool wxListHeaderData::HasImage() const
218 return (m_image
!= 0);
221 bool wxListHeaderData::HasText() const
223 return (m_text
.Length() > 0);
226 bool wxListHeaderData::IsHit( int x
, int y
) const
228 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
231 void wxListHeaderData::GetItem( wxListItem
&item
)
233 item
.m_mask
= m_mask
;
234 item
.m_text
= m_text
;
235 item
.m_image
= m_image
;
236 item
.m_format
= m_format
;
237 item
.m_width
= m_width
;
240 void wxListHeaderData::GetText( wxString
&s
)
245 int wxListHeaderData::GetImage() const
250 int wxListHeaderData::GetWidth() const
255 int wxListHeaderData::GetFormat() const
260 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
264 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
266 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
271 m_hilightBrush
= hilightBrush
;
272 m_items
.DeleteContents( TRUE
);
276 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
283 m_bound_all
.width
= m_spacing
;
284 m_bound_all
.height
= m_spacing
+13;
285 wxNode
*node
= m_items
.First();
288 wxListItemData
*item
= (wxListItemData
*)node
->Data();
292 dc
->GetTextExtent( s
, &lw
, &lh
);
293 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
299 wxNode
*node
= m_items
.First();
302 wxListItemData
*item
= (wxListItemData
*)node
->Data();
306 dc
->GetTextExtent( s
, &lw
, &lh
);
307 m_bound_all
.width
= lw
;
308 m_bound_all
.height
= lh
;
309 if (item
->HasImage())
313 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
314 m_bound_all
.width
+= 4 + w
;
315 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
322 m_bound_all
.width
= 0;
323 m_bound_all
.height
= 0;
324 wxNode
*node
= m_items
.First();
327 wxListItemData
*item
= (wxListItemData
*)node
->Data();
330 if (s
.IsNull()) s
= "H";
332 dc
->GetTextExtent( s
, &lw
, &lh
);
333 item
->SetSize( item
->GetWidth(), lh
);
334 m_bound_all
.width
+= lw
;
335 m_bound_all
.height
= lh
;
343 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
351 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
352 AssignRect( m_bound_label
, 0, 0, 0, 0 );
353 AssignRect( m_bound_hilight
, m_bound_all
);
354 wxNode
*node
= m_items
.First();
357 wxListItemData
*item
= (wxListItemData
*)node
->Data();
358 if (item
->HasImage())
360 wxListItemData
*item
= (wxListItemData
*)node
->Data();
363 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
364 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
365 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
366 m_bound_icon
.width
= w
;
367 m_bound_icon
.height
= h
;
368 if (!item
->HasText())
370 AssignRect( m_bound_hilight
, m_bound_icon
);
371 m_bound_hilight
.x
-= 5;
372 m_bound_hilight
.y
-= 5;
373 m_bound_hilight
.width
+= 9;
374 m_bound_hilight
.height
+= 9;
382 dc
->GetTextExtent( s
, &lw
, &lh
);
383 if (m_bound_all
.width
> m_spacing
)
384 m_bound_label
.x
= m_bound_all
.x
;
386 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
387 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
388 m_bound_label
.width
= lw
;
389 m_bound_label
.height
= lh
;
390 AssignRect( m_bound_hilight
, m_bound_label
);
391 m_bound_hilight
.x
-= 2;
392 m_bound_hilight
.y
-= 2;
393 m_bound_hilight
.width
+= 4;
394 m_bound_hilight
.height
+= 4;
401 AssignRect( m_bound_label
, m_bound_all
);
404 m_bound_all
.width
+= 4;
405 m_bound_all
.height
+= 3;
406 AssignRect( m_bound_hilight
, m_bound_all
);
407 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
408 wxNode
*node
= m_items
.First();
411 wxListItemData
*item
= (wxListItemData
*)node
->Data();
412 if (item
->HasImage())
414 m_bound_icon
.x
= m_bound_all
.x
+ 2;
415 m_bound_icon
.y
= m_bound_all
.y
+ 2;
418 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
419 m_bound_icon
.width
= w
;
420 m_bound_icon
.height
= h
;
421 m_bound_label
.x
+= 4 + w
;
422 m_bound_label
.width
-= 4 + w
;
430 dc
->GetTextExtent( "H", &lw
, &lh
);
433 m_bound_all
.height
= lh
+3;
434 m_bound_all
.width
= window_width
;
435 AssignRect( m_bound_hilight
, m_bound_all
);
436 AssignRect( m_bound_label
, m_bound_all
);
437 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
438 wxNode
*node
= m_items
.First();
441 wxListItemData
*item
= (wxListItemData
*)node
->Data();
444 if (s
.IsEmpty()) s
= wxT("H");
446 dc
->GetTextExtent( s
, &lw
, &lh
);
447 m_bound_label
.width
= lw
;
448 m_bound_label
.height
= lh
;
449 if (item
->HasImage())
451 m_bound_icon
.x
= m_bound_all
.x
+ 2;
452 m_bound_icon
.y
= m_bound_all
.y
+ 2;
455 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
456 m_bound_icon
.width
= w
;
457 m_bound_icon
.height
= h
;
458 m_bound_label
.x
+= 4 + w
;
466 void wxListLineData::SetColumnPosition( int index
, int x
)
469 wxNode
*node
= m_items
.Nth( i
);
472 wxListItemData
*item
= (wxListItemData
*)node
->Data();
473 item
->SetPosition( x
, m_bound_all
.y
+1 );
477 void wxListLineData::GetSize( int &width
, int &height
)
479 width
= m_bound_all
.width
;
480 height
= m_bound_all
.height
;
483 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
487 width
= m_bound_all
.width
;
488 height
= m_bound_all
.height
;
491 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
495 width
= m_bound_label
.width
;
496 height
= m_bound_label
.height
;
499 void wxListLineData::GetRect( wxRect
&rect
)
501 AssignRect( rect
, m_bound_all
);
504 long wxListLineData::IsHit( int x
, int y
)
506 wxNode
*node
= m_items
.First();
509 wxListItemData
*item
= (wxListItemData
*)node
->Data();
510 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
511 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
512 // if (!(item->HasImage() || item->HasText())) return 0;
514 // if there is no icon or text = empty
515 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
519 void wxListLineData::InitItems( int num
)
521 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
524 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
526 wxNode
*node
= m_items
.Nth( index
);
529 wxListItemData
*item
= (wxListItemData
*)node
->Data();
530 item
->SetItem( info
);
534 void wxListLineData::GetItem( int index
, wxListItem
&info
)
537 wxNode
*node
= m_items
.Nth( i
);
540 wxListItemData
*item
= (wxListItemData
*)node
->Data();
541 item
->GetItem( info
);
545 void wxListLineData::GetText( int index
, wxString
&s
)
548 wxNode
*node
= m_items
.Nth( i
);
552 wxListItemData
*item
= (wxListItemData
*)node
->Data();
557 void wxListLineData::SetText( int index
, const wxString s
)
560 wxNode
*node
= m_items
.Nth( i
);
563 wxListItemData
*item
= (wxListItemData
*)node
->Data();
568 int wxListLineData::GetImage( int index
)
571 wxNode
*node
= m_items
.Nth( i
);
574 wxListItemData
*item
= (wxListItemData
*)node
->Data();
575 return item
->GetImage();
580 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
582 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
583 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
584 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
585 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
587 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
596 dc
->SetBrush( * m_hilightBrush
);
597 dc
->SetPen( * wxTRANSPARENT_PEN
);
601 dc
->SetBrush( * wxWHITE_BRUSH
);
602 dc
->SetPen( * wxTRANSPARENT_PEN
);
604 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
605 m_bound_hilight
.width
, m_bound_hilight
.height
);
608 dc
->SetBackgroundMode(wxTRANSPARENT
);
609 if (m_mode
== wxLC_REPORT
)
612 wxNode
*node
= m_items
.First();
615 wxListItemData
*item
= (wxListItemData
*)node
->Data();
616 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
617 int x
= item
->GetX();
618 if (item
->HasImage())
621 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
622 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
623 x
+= item
->GetX() + 5;
629 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
631 dc
->SetTextForeground( *item
->GetColour() );
632 dc
->DrawText( s
, x
, item
->GetY() );
634 dc
->DestroyClippingRegion();
640 wxNode
*node
= m_items
.First();
643 wxListItemData
*item
= (wxListItemData
*)node
->Data();
644 if (item
->HasImage())
646 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
653 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
655 dc
->SetTextForeground( * item
->GetColour() );
656 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
662 void wxListLineData::Hilight( bool on
)
664 if (on
== m_hilighted
) return;
666 m_owner
->SelectLine( this );
668 m_owner
->DeselectLine( this );
672 void wxListLineData::ReverseHilight( void )
674 m_hilighted
= !m_hilighted
;
676 m_owner
->SelectLine( this );
678 m_owner
->DeselectLine( this );
681 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
685 dc
->SetPen( * wxBLACK_PEN
);
686 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
687 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
688 m_bound_hilight
.width
, m_bound_hilight
.height
);
692 void wxListLineData::Draw( wxDC
*dc
)
694 DoDraw( dc
, m_hilighted
, m_hilighted
);
697 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
699 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
700 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
703 bool wxListLineData::IsHilighted( void )
708 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
713 dest
.height
= height
;
716 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
720 dest
.width
= source
.width
;
721 dest
.height
= source
.height
;
724 //-----------------------------------------------------------------------------
725 // wxListHeaderWindow
726 //-----------------------------------------------------------------------------
728 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
730 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
731 EVT_PAINT (wxListHeaderWindow::OnPaint
)
732 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
733 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
736 wxListHeaderWindow::wxListHeaderWindow( void )
738 m_owner
= (wxListMainWindow
*) NULL
;
739 m_currentCursor
= (wxCursor
*) NULL
;
740 m_resizeCursor
= (wxCursor
*) NULL
;
741 m_isDragging
= FALSE
;
744 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
745 const wxPoint
&pos
, const wxSize
&size
,
746 long style
, const wxString
&name
) :
747 wxWindow( win
, id
, pos
, size
, style
, name
)
750 // m_currentCursor = wxSTANDARD_CURSOR;
751 m_currentCursor
= (wxCursor
*) NULL
;
752 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
753 m_isDragging
= FALSE
;
754 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
757 wxListHeaderWindow::~wxListHeaderWindow( void )
759 delete m_resizeCursor
;
762 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
764 const int m_corner
= 1;
766 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
768 dc
->SetPen( *wxBLACK_PEN
);
769 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
770 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
772 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
775 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
776 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
778 dc
->SetPen( *wxWHITE_PEN
);
779 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
780 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
781 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
782 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
785 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
787 wxPaintDC
dc( this );
789 #if wxUSE_GENERIC_LIST_EXTENSIONS
790 if ( m_owner
->GetMode() & wxLC_REPORT
)
795 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
796 m_owner
->ViewStart( &x
, &y
) ;
797 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
802 dc
.SetFont( GetFont() );
808 GetClientSize( &w
, &h
);
810 dc
.SetBackgroundMode(wxTRANSPARENT
);
811 dc
.SetTextForeground( *wxBLACK
);
812 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
816 int numColumns
= m_owner
->GetColumnCount();
818 for (int i
= 0; i
< numColumns
; i
++)
820 m_owner
->GetColumn( i
, item
);
821 int cw
= item
.m_width
-2;
822 #if wxUSE_GENERIC_LIST_EXTENSIONS
823 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
824 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
826 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
828 dc
.SetPen( *wxWHITE_PEN
);
830 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
831 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
832 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
833 dc
.DestroyClippingRegion();
835 #if wxUSE_GENERIC_LIST_EXTENSIONS
836 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
844 void wxListHeaderWindow::DrawCurrent()
848 int x2
= m_currentX
-1;
851 m_owner
->GetClientSize( &dummy
, &y2
);
852 ClientToScreen( &x1
, &y1
);
853 m_owner
->ClientToScreen( &x2
, &y2
);
856 dc
.SetLogicalFunction( wxINVERT
);
857 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
858 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
860 dc
.DrawLine( x1
, y1
, x2
, y2
);
862 dc
.SetLogicalFunction( wxCOPY
);
864 dc
.SetPen( wxNullPen
);
865 dc
.SetBrush( wxNullBrush
);
868 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
870 int x
= event
.GetX();
871 int y
= event
.GetY();
875 if (event
.ButtonUp())
878 m_isDragging
= FALSE
;
879 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
885 GetClientSize( &size_x
, & dummy
);
889 m_currentX
= m_minX
+7;
890 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
897 bool hit_border
= FALSE
;
899 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
901 xpos
+= m_owner
->GetColumnWidth( j
);
903 if ((abs(x
-xpos
) < 3) && (y
< 22))
915 if (event
.LeftDown())
927 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
928 le
.SetEventObject( GetParent() );
930 GetParent()->GetEventHandler()->ProcessEvent( le
);
939 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
940 m_currentCursor
= m_resizeCursor
;
944 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
945 m_currentCursor
= wxSTANDARD_CURSOR
;
950 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
955 //-----------------------------------------------------------------------------
956 // wxListRenameTimer (internal)
957 //-----------------------------------------------------------------------------
959 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
964 void wxListRenameTimer::Notify()
966 m_owner
->OnRenameTimer();
969 //-----------------------------------------------------------------------------
970 // wxListTextCtrl (internal)
971 //-----------------------------------------------------------------------------
973 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
975 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
976 EVT_CHAR (wxListTextCtrl::OnChar
)
977 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
980 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
981 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
982 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
984 int style
, const wxValidator
& validator
, const wxString
&name
) :
986 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
993 m_startValue
= value
;
996 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
998 if (event
.m_keyCode
== WXK_RETURN
)
1001 (*m_res
) = GetValue();
1002 m_owner
->SetFocus();
1005 if (event
.m_keyCode
== WXK_ESCAPE
)
1007 (*m_accept
) = FALSE
;
1009 m_owner
->SetFocus();
1015 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1017 if (wxPendingDelete
.Member(this)) return;
1019 wxPendingDelete
.Append(this);
1021 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1022 m_owner
->OnRenameAccept();
1025 //-----------------------------------------------------------------------------
1027 //-----------------------------------------------------------------------------
1029 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1031 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1032 EVT_PAINT (wxListMainWindow::OnPaint
)
1033 EVT_SIZE (wxListMainWindow::OnSize
)
1034 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1035 EVT_CHAR (wxListMainWindow::OnChar
)
1036 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1037 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1038 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1039 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1042 wxListMainWindow::wxListMainWindow()
1045 m_lines
.DeleteContents( TRUE
);
1046 m_columns
.DeleteContents( TRUE
);
1047 m_current
= (wxListLineData
*) NULL
;
1049 m_hilightBrush
= (wxBrush
*) NULL
;
1053 m_small_image_list
= (wxImageList
*) NULL
;
1054 m_normal_image_list
= (wxImageList
*) NULL
;
1055 m_small_spacing
= 30;
1056 m_normal_spacing
= 40;
1059 m_lastOnSame
= FALSE
;
1060 m_renameTimer
= new wxListRenameTimer( this );
1061 m_isCreated
= FALSE
;
1065 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1066 const wxPoint
&pos
, const wxSize
&size
,
1067 long style
, const wxString
&name
) :
1068 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1071 m_lines
.DeleteContents( TRUE
);
1072 m_columns
.DeleteContents( TRUE
);
1073 m_current
= (wxListLineData
*) NULL
;
1076 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1077 m_small_image_list
= (wxImageList
*) NULL
;
1078 m_normal_image_list
= (wxImageList
*) NULL
;
1079 m_small_spacing
= 30;
1080 m_normal_spacing
= 40;
1083 m_isCreated
= FALSE
;
1087 if (m_mode
& wxLC_REPORT
)
1089 #if wxUSE_GENERIC_LIST_EXTENSIONS
1101 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1104 m_lastOnSame
= FALSE
;
1105 m_renameTimer
= new wxListRenameTimer( this );
1106 m_renameAccept
= FALSE
;
1108 SetBackgroundColour( *wxWHITE
);
1111 wxListMainWindow::~wxListMainWindow()
1113 if (m_hilightBrush
) delete m_hilightBrush
;
1115 delete m_renameTimer
;
1118 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1126 wxClientDC
dc(this);
1128 line
->GetExtent( x
, y
, w
, h
);
1130 dc
.LogicalToDeviceX(x
-3),
1131 dc
.LogicalToDeviceY(y
-3),
1132 dc
.LogicalToDeviceXRel(w
+6),
1133 dc
.LogicalToDeviceXRel(h
+6) );
1134 Refresh( TRUE
, &rect
);
1138 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1140 // Note: a wxPaintDC must be constructed even if no drawing is
1141 // done (a Windows requirement).
1142 wxPaintDC
dc( this );
1145 if (m_dirty
) return;
1147 if (m_lines
.GetCount() == 0) return;
1151 dc
.SetFont( GetFont() );
1153 if (m_mode
& wxLC_REPORT
)
1155 int lineSpacing
= 0;
1156 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1158 line
->GetSize( dummy
, lineSpacing
);
1161 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1163 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1164 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1168 line
= (wxListLineData
*)node
->Data();
1170 node
= node
->Next();
1175 wxNode
*node
= m_lines
.First();
1178 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1180 node
= node
->Next();
1184 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1189 void wxListMainWindow::HilightAll( bool on
)
1191 wxNode
*node
= m_lines
.First();
1194 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1195 if (line
->IsHilighted() != on
)
1197 line
->Hilight( on
);
1198 RefreshLine( line
);
1200 node
= node
->Next();
1204 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1206 wxListEvent
le( command
, GetParent()->GetId() );
1207 le
.SetEventObject( GetParent() );
1208 le
.m_itemIndex
= GetIndexOfLine( line
);
1209 line
->GetItem( 0, le
.m_item
);
1210 GetParent()->GetEventHandler()->ProcessEvent( le
);
1213 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1215 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1218 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1220 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1223 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1225 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1228 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1230 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1233 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1235 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1240 void wxListMainWindow::EditLabel( long item
)
1242 wxNode
*node
= m_lines
.Nth( item
);
1243 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1245 m_currentEdit
= (wxListLineData
*) node
->Data();
1247 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1248 le
.SetEventObject( GetParent() );
1249 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1250 m_currentEdit
->GetItem( 0, le
.m_item
);
1251 GetParent()->GetEventHandler()->ProcessEvent( le
);
1253 if (!le
.IsAllowed())
1256 // We have to call this here because the label in
1257 // question might just have been added and no screen
1258 // update taken place.
1259 if (m_dirty
) wxYield();
1262 m_currentEdit
->GetText( 0, s
);
1267 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1269 wxClientDC
dc(this);
1271 x
= dc
.LogicalToDeviceX( x
);
1272 y
= dc
.LogicalToDeviceY( y
);
1274 wxListTextCtrl
*text
= new wxListTextCtrl(
1275 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1279 void wxListMainWindow::OnRenameTimer()
1281 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1283 Edit( m_lines
.IndexOf( m_current
) );
1286 void wxListMainWindow::OnRenameAccept()
1288 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1289 le
.SetEventObject( GetParent() );
1290 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1291 m_currentEdit
->GetItem( 0, le
.m_item
);
1292 le
.m_item
.m_text
= m_renameRes
;
1293 GetParent()->GetEventHandler()->ProcessEvent( le
);
1295 if (!le
.IsAllowed()) return;
1298 info
.m_mask
= wxLIST_MASK_TEXT
;
1299 info
.m_itemId
= le
.m_itemIndex
;
1300 info
.m_text
= m_renameRes
;
1301 info
.m_colour
= le
.m_item
.m_colour
;
1305 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1307 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1309 if (!m_current
) return;
1310 if (m_dirty
) return;
1311 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1313 wxClientDC
dc(this);
1315 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1316 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1318 /* Did we actually hit an item ? */
1320 wxNode
*node
= m_lines
.First();
1321 wxListLineData
*line
= (wxListLineData
*) NULL
;
1324 line
= (wxListLineData
*)node
->Data();
1325 hitResult
= line
->IsHit( x
, y
);
1326 if (hitResult
) break;
1327 line
= (wxListLineData
*) NULL
;
1328 node
= node
->Next();
1331 if (event
.Dragging())
1333 if (m_dragCount
== 0)
1334 m_dragStart
= wxPoint(x
,y
);
1338 if (m_dragCount
!= 3) return;
1340 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1341 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1343 wxListEvent
le( command
, GetParent()->GetId() );
1344 le
.SetEventObject( GetParent() );
1345 le
.m_pointDrag
= m_dragStart
;
1346 GetParent()->GetEventHandler()->ProcessEvent( le
);
1357 if (event
.ButtonDClick())
1360 m_lastOnSame
= FALSE
;
1361 m_renameTimer
->Stop();
1363 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1368 if (event
.LeftUp() && m_lastOnSame
)
1371 if ((line
== m_current
) &&
1372 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1373 (m_mode
& wxLC_EDIT_LABELS
) )
1375 m_renameTimer
->Start( 100, TRUE
);
1377 m_lastOnSame
= FALSE
;
1381 if (event
.RightDown())
1383 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1387 if (event
.MiddleDown())
1389 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1393 if (event
.LeftDown())
1396 wxListLineData
*oldCurrent
= m_current
;
1397 if (m_mode
& wxLC_SINGLE_SEL
)
1400 HilightAll( FALSE
);
1401 m_current
->ReverseHilight();
1402 RefreshLine( m_current
);
1406 if (event
.ShiftDown())
1409 m_current
->ReverseHilight();
1410 RefreshLine( m_current
);
1412 else if (event
.ControlDown())
1416 int numOfCurrent
= -1;
1417 node
= m_lines
.First();
1420 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1422 if (test_line
== oldCurrent
) break;
1423 node
= node
->Next();
1427 node
= m_lines
.First();
1430 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1432 if (test_line
== line
) break;
1433 node
= node
->Next();
1436 if (numOfLine
< numOfCurrent
)
1439 numOfLine
= numOfCurrent
;
1443 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1444 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1446 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1447 test_line
->Hilight(TRUE
);
1448 RefreshLine( test_line
);
1449 node
= node
->Next();
1455 HilightAll( FALSE
);
1456 m_current
->ReverseHilight();
1457 RefreshLine( m_current
);
1460 if (m_current
!= oldCurrent
)
1462 RefreshLine( oldCurrent
);
1463 UnfocusLine( oldCurrent
);
1464 FocusLine( m_current
);
1466 m_lastOnSame
= (m_current
== oldCurrent
);
1471 void wxListMainWindow::MoveToFocus()
1473 if (!m_current
) return;
1479 m_current
->GetExtent( x
, y
, w
, h
);
1483 GetClientSize( &w_p
, &h_p
);
1485 if (m_mode
& wxLC_REPORT
)
1487 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1488 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1489 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1490 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1494 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1495 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1496 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1497 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1501 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1503 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1504 wxListLineData
*oldCurrent
= m_current
;
1505 m_current
= newCurrent
;
1507 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1508 RefreshLine( m_current
);
1509 RefreshLine( oldCurrent
);
1510 FocusLine( m_current
);
1511 UnfocusLine( oldCurrent
);
1514 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1516 wxWindow
*parent
= GetParent();
1518 /* we propagate the key event up */
1519 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
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;
1533 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1535 wxWindow
*parent
= GetParent();
1537 /* we send a list_key event up */
1538 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1539 le
.m_code
= event
.KeyCode();
1540 le
.SetEventObject( parent
);
1541 parent
->GetEventHandler()->ProcessEvent( le
);
1543 /* we propagate the char event up */
1544 wxKeyEvent
ke( wxEVT_CHAR
);
1545 ke
.m_shiftDown
= event
.m_shiftDown
;
1546 ke
.m_controlDown
= event
.m_controlDown
;
1547 ke
.m_altDown
= event
.m_altDown
;
1548 ke
.m_metaDown
= event
.m_metaDown
;
1549 ke
.m_keyCode
= event
.m_keyCode
;
1552 ke
.SetEventObject( parent
);
1553 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1555 if (event
.KeyCode() == WXK_TAB
)
1557 wxNavigationKeyEvent nevent
;
1558 nevent
.SetDirection( !event
.ShiftDown() );
1559 nevent
.SetCurrentFocus( m_parent
);
1560 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1563 /* no item -> nothing to do */
1570 switch (event
.KeyCode())
1574 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1575 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1580 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1581 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1586 wxNode
*node
= m_lines
.Last();
1587 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1592 wxNode
*node
= m_lines
.First();
1593 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1599 if (m_mode
& wxLC_REPORT
)
1601 steps
= m_visibleLines
-1;
1606 wxNode
*node
= m_lines
.First();
1607 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1608 steps
= pos
% m_visibleLines
;
1610 wxNode
*node
= m_lines
.Member( m_current
);
1611 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1612 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1618 if (m_mode
& wxLC_REPORT
)
1620 steps
= m_visibleLines
-1;
1624 int pos
= 0; wxNode
*node
= m_lines
.First();
1625 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1626 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1628 wxNode
*node
= m_lines
.Member( m_current
);
1629 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1630 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1635 if (!(m_mode
& wxLC_REPORT
))
1637 wxNode
*node
= m_lines
.Member( m_current
);
1638 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1639 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1645 if (!(m_mode
& wxLC_REPORT
))
1647 wxNode
*node
= m_lines
.Member( m_current
);
1648 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1649 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1655 m_current
->ReverseHilight();
1656 RefreshLine( m_current
);
1661 if (!(m_mode
& wxLC_SINGLE_SEL
))
1663 wxListLineData
*oldCurrent
= m_current
;
1664 m_current
->ReverseHilight();
1665 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1666 if (node
) m_current
= (wxListLineData
*)node
->Data();
1668 RefreshLine( oldCurrent
);
1669 RefreshLine( m_current
);
1670 UnfocusLine( oldCurrent
);
1671 FocusLine( m_current
);
1678 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1679 le
.SetEventObject( GetParent() );
1680 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1681 m_current
->GetItem( 0, le
.m_item
);
1682 GetParent()->GetEventHandler()->ProcessEvent( le
);
1695 extern wxWindow
*g_focusWindow
;
1698 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1701 RefreshLine( m_current
);
1703 if (!GetParent()) return;
1706 g_focusWindow
= GetParent();
1709 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1710 event
.SetEventObject( GetParent() );
1711 GetParent()->GetEventHandler()->ProcessEvent( event
);
1714 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1717 RefreshLine( m_current
);
1720 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1723 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1728 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1730 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1732 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1735 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1737 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1739 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1741 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1743 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1745 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1750 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1752 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1754 m_normal_image_list
->GetSize( index
, width
, height
);
1757 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1759 m_small_image_list
->GetSize( index
, width
, height
);
1762 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1764 m_small_image_list
->GetSize( index
, width
, height
);
1767 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1769 m_small_image_list
->GetSize( index
, width
, height
);
1776 int wxListMainWindow::GetTextLength( wxString
&s
)
1778 wxClientDC
dc( this );
1781 dc
.GetTextExtent( s
, &lw
, &lh
);
1785 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1788 wxNode
*node
= m_lines
.First();
1791 if (line
== (wxListLineData
*)node
->Data()) return i
;
1793 node
= node
->Next();
1798 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1801 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1802 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1805 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1810 m_small_spacing
= spacing
;
1814 m_normal_spacing
= spacing
;
1818 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1820 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1823 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1826 wxNode
*node
= m_columns
.Nth( col
);
1829 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1830 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1831 column
->SetItem( item
);
1833 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1834 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1837 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1839 if (!(m_mode
& wxLC_REPORT
)) return;
1843 wxNode
*node
= (wxNode
*) NULL
;
1845 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1846 if (width
== wxLIST_AUTOSIZE
)
1848 wxClientDC
dc(this);
1849 dc
.SetFont( GetFont() );
1851 node
= m_lines
.First();
1854 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1855 wxNode
*n
= line
->m_items
.Nth( col
);
1858 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1859 int current
= 0, ix
= 0, iy
= 0;
1860 long lx
= 0, ly
= 0;
1861 if (item
->HasImage())
1863 GetImageSize( item
->GetImage(), ix
, iy
);
1866 if (item
->HasText())
1869 item
->GetText( str
);
1870 dc
.GetTextExtent( str
, &lx
, &ly
);
1873 if (current
> max
) max
= current
;
1875 node
= node
->Next();
1880 node
= m_columns
.Nth( col
);
1883 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1884 column
->SetWidth( width
);
1887 node
= m_lines
.First();
1890 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1891 wxNode
*n
= line
->m_items
.Nth( col
);
1894 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1895 item
->SetSize( width
, -1 );
1897 node
= node
->Next();
1900 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1901 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1904 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1906 wxNode
*node
= m_columns
.Nth( col
);
1909 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1910 column
->GetItem( item
);
1922 int wxListMainWindow::GetColumnWidth( int col
)
1924 wxNode
*node
= m_columns
.Nth( col
);
1927 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1928 return column
->GetWidth();
1936 int wxListMainWindow::GetColumnCount()
1938 return m_columns
.Number();
1941 int wxListMainWindow::GetCountPerPage()
1943 return m_visibleLines
;
1946 void wxListMainWindow::SetItem( wxListItem
&item
)
1949 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1952 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1953 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1954 line
->SetItem( item
.m_col
, item
);
1958 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1960 // m_dirty = TRUE; no recalcs needed
1962 wxListLineData
*oldCurrent
= m_current
;
1964 if (stateMask
& wxLIST_STATE_FOCUSED
)
1966 wxNode
*node
= m_lines
.Nth( item
);
1969 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1970 UnfocusLine( m_current
);
1972 FocusLine( m_current
);
1973 RefreshLine( m_current
);
1974 if (oldCurrent
) RefreshLine( oldCurrent
);
1978 if (stateMask
& wxLIST_STATE_SELECTED
)
1980 bool on
= state
& wxLIST_STATE_SELECTED
;
1981 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1983 wxNode
*node
= m_lines
.Nth( item
);
1986 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1987 if (m_mode
& wxLC_SINGLE_SEL
)
1989 UnfocusLine( m_current
);
1991 FocusLine( m_current
);
1992 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1993 RefreshLine( m_current
);
1994 if (oldCurrent
) RefreshLine( oldCurrent
);
1996 bool on
= state
& wxLIST_STATE_SELECTED
;
1997 if (on
!= line
->IsHilighted())
1999 line
->Hilight( on
);
2000 RefreshLine( line
);
2006 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2008 int ret
= wxLIST_STATE_DONTCARE
;
2009 if (stateMask
& wxLIST_STATE_FOCUSED
)
2011 wxNode
*node
= m_lines
.Nth( item
);
2014 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2015 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2018 if (stateMask
& wxLIST_STATE_SELECTED
)
2020 wxNode
*node
= m_lines
.Nth( item
);
2023 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2024 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2030 void wxListMainWindow::GetItem( wxListItem
&item
)
2032 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2035 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2036 line
->GetItem( item
.m_col
, item
);
2047 int wxListMainWindow::GetItemCount()
2049 return m_lines
.Number();
2052 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2054 wxNode
*node
= m_lines
.Nth( index
);
2057 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2058 line
->GetRect( rect
);
2069 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2071 wxNode
*node
= m_lines
.Nth( item
);
2075 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2076 line
->GetRect( rect
);
2088 int wxListMainWindow::GetSelectedItemCount()
2091 wxNode
*node
= m_lines
.First();
2094 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2095 if (line
->IsHilighted()) ret
++;
2096 node
= node
->Next();
2101 void wxListMainWindow::SetMode( long mode
)
2108 if (m_mode
& wxLC_REPORT
)
2110 #if wxUSE_GENERIC_LIST_EXTENSIONS
2124 long wxListMainWindow::GetMode() const
2129 void wxListMainWindow::CalculatePositions()
2131 if (!m_lines
.First()) return;
2133 wxClientDC
dc( this );
2134 dc
.SetFont( GetFont() );
2136 int iconSpacing
= 0;
2137 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2138 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2140 // we take the first line (which also can be an icon or
2141 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2142 // measure the size of the line
2146 int lineSpacing
= 0;
2148 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2149 line
->CalculateSize( &dc
, iconSpacing
);
2151 line
->GetSize( dummy
, lineSpacing
);
2154 int clientWidth
= 0;
2155 int clientHeight
= 0;
2157 if (m_mode
& wxLC_REPORT
)
2161 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2162 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2163 #if wxUSE_GENERIC_LIST_EXTENSIONS
2164 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2166 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2168 GetClientSize( &clientWidth
, &clientHeight
);
2170 wxNode
* node
= m_lines
.First();
2171 int entireWidth
= 0 ;
2174 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2175 line
->CalculateSize( &dc
, iconSpacing
);
2176 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2178 for (int i
= 0; i
< GetColumnCount(); i
++)
2180 line
->SetColumnPosition( i
, col_x
);
2181 col_x
+= GetColumnWidth( i
);
2183 entireWidth
= wxMax( entireWidth
, col_x
) ;
2184 #if wxUSE_GENERIC_LIST_EXTENSIONS
2185 line
->SetPosition( &dc
, x
, y
, col_x
);
2187 y
+= lineSpacing
; // one pixel blank line between items
2188 node
= node
->Next();
2190 m_visibleLines
= clientHeight
/ lineSpacing
;
2191 #if wxUSE_GENERIC_LIST_EXTENSIONS
2192 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2197 // at first we try without any scrollbar. if the items don't
2198 // fit into the window, we recalculate after subtracting an
2199 // approximated 15 pt for the horizontal scrollbar
2201 GetSize( &clientWidth
, &clientHeight
);
2202 clientHeight
-= 4; // sunken frame
2204 int entireWidth
= 0;
2206 for (int tries
= 0; tries
< 2; tries
++)
2209 int x
= 5; // painting is done at x-2
2210 int y
= 5; // painting is done at y-2
2213 int m_currentVisibleLines
= 0;
2214 wxNode
*node
= m_lines
.First();
2217 m_currentVisibleLines
++;
2218 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2219 line
->CalculateSize( &dc
, iconSpacing
);
2220 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2221 line
->GetSize( lineWidth
, lineHeight
);
2222 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2224 if (m_currentVisibleLines
> m_visibleLines
)
2225 m_visibleLines
= m_currentVisibleLines
;
2226 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2228 m_currentVisibleLines
= 0;
2231 entireWidth
+= maxWidth
+6;
2234 node
= node
->Next();
2235 if (!node
) entireWidth
+= maxWidth
;
2236 if ((tries
== 0) && (entireWidth
> clientWidth
))
2238 clientHeight
-= 15; // scrollbar height
2240 m_currentVisibleLines
= 0;
2243 if (!node
) tries
= 1; // everything fits, no second try required
2247 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2248 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2252 void wxListMainWindow::RealizeChanges( void )
2256 wxNode
*node
= m_lines
.First();
2257 if (node
) m_current
= (wxListLineData
*)node
->Data();
2261 FocusLine( m_current
);
2262 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2266 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2269 if (item
> 0) ret
= item
;
2270 if(ret
>= GetItemCount()) return -1;
2271 wxNode
*node
= m_lines
.Nth( ret
);
2274 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2275 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2276 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2277 if (!state
) return ret
;
2279 node
= node
->Next();
2284 void wxListMainWindow::DeleteItem( long index
)
2287 wxNode
*node
= m_lines
.Nth( index
);
2290 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2291 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2293 m_lines
.DeleteNode( node
);
2297 void wxListMainWindow::DeleteColumn( int col
)
2299 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2300 wxT("attempting to delete inexistent column in wxListView") );
2303 wxNode
*node
= m_columns
.Nth( col
);
2304 if (node
) m_columns
.DeleteNode( node
);
2307 void wxListMainWindow::DeleteAllItems( void )
2310 m_current
= (wxListLineData
*) NULL
;
2312 // to make the deletion of all items faster, we don't send the
2313 // notifications in this case: this is compatible with wxMSW and
2314 // documented in DeleteAllItems() description
2316 wxNode
*node
= m_lines
.First();
2319 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2323 node
= node
->Next();
2330 void wxListMainWindow::DeleteEverything( void )
2333 m_current
= (wxListLineData
*) NULL
;
2334 wxNode
*node
= m_lines
.First();
2337 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2339 node
= node
->Next();
2342 m_current
= (wxListLineData
*) NULL
;
2346 void wxListMainWindow::EnsureVisible( long index
)
2348 // We have to call this here because the label in
2349 // question might just have been added and no screen
2350 // update taken place.
2351 if (m_dirty
) wxYield();
2353 wxListLineData
*oldCurrent
= m_current
;
2354 m_current
= (wxListLineData
*) NULL
;
2356 wxNode
*node
= m_lines
.Nth( i
);
2357 if (node
) m_current
= (wxListLineData
*)node
->Data();
2358 if (m_current
) MoveToFocus();
2359 m_current
= oldCurrent
;
2362 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2366 if (pos
< 0) pos
= 0;
2367 wxNode
*node
= m_lines
.Nth( pos
);
2370 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2372 line
->GetText( 0, s
);
2373 if (s
== tmp
) return pos
;
2374 node
= node
->Next();
2380 long wxListMainWindow::FindItem(long start
, long data
)
2383 if (pos
< 0) pos
= 0;
2384 wxNode
*node
= m_lines
.Nth( pos
);
2387 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2389 line
->GetItem( 0, item
);
2390 if (item
.m_data
== data
) return pos
;
2391 node
= node
->Next();
2397 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2399 wxNode
*node
= m_lines
.First();
2403 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2404 long ret
= line
->IsHit( x
, y
);
2410 node
= node
->Next();
2416 void wxListMainWindow::InsertItem( wxListItem
&item
)
2420 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2421 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2422 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2423 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2425 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2427 if (m_mode
& wxLC_REPORT
)
2429 line
->InitItems( GetColumnCount() );
2430 item
.m_width
= GetColumnWidth( 0 )-3;
2434 line
->InitItems( 1 );
2437 line
->SetItem( 0, item
);
2438 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2440 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2441 if (node
) m_lines
.Insert( node
, line
);
2445 m_lines
.Append( line
);
2449 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2452 if (m_mode
& wxLC_REPORT
)
2454 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2455 wxListHeaderData
*column
= new wxListHeaderData( item
);
2456 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2458 wxNode
*node
= m_columns
.Nth( col
);
2460 m_columns
.Insert( node
, column
);
2464 m_columns
.Append( column
);
2469 wxListCtrlCompare list_ctrl_compare_func_2
;
2470 long list_ctrl_compare_data
;
2472 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2474 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2475 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2477 line1
->GetItem( 0, item
);
2478 long data1
= item
.m_data
;
2479 line2
->GetItem( 0, item
);
2480 long data2
= item
.m_data
;
2481 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2484 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2486 list_ctrl_compare_func_2
= fn
;
2487 list_ctrl_compare_data
= data
;
2488 m_lines
.Sort( list_ctrl_compare_func_1
);
2491 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2493 wxScrolledWindow::OnScroll( event
) ;
2494 #if wxUSE_GENERIC_LIST_EXTENSIONS
2496 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2498 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2501 lc
->m_headerWin
->Refresh() ;
2503 lc
->m_headerWin
->MacUpdateImmediately() ;
2510 // -------------------------------------------------------------------------------------
2512 // -------------------------------------------------------------------------------------
2514 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2516 wxListItem::wxListItem()
2525 m_format
= wxLIST_FORMAT_CENTRE
;
2530 // -------------------------------------------------------------------------------------
2532 // -------------------------------------------------------------------------------------
2534 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2536 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2537 wxNotifyEvent( commandType
, id
)
2543 m_cancelled
= FALSE
;
2548 // -------------------------------------------------------------------------------------
2550 // -------------------------------------------------------------------------------------
2552 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2554 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2555 EVT_SIZE (wxListCtrl::OnSize
)
2556 EVT_IDLE (wxListCtrl::OnIdle
)
2559 wxListCtrl::wxListCtrl()
2561 m_imageListNormal
= (wxImageList
*) NULL
;
2562 m_imageListSmall
= (wxImageList
*) NULL
;
2563 m_imageListState
= (wxImageList
*) NULL
;
2564 m_mainWin
= (wxListMainWindow
*) NULL
;
2565 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2568 wxListCtrl::~wxListCtrl()
2572 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2573 const wxPoint
&pos
, const wxSize
&size
,
2574 #if wxUSE_VALIDATORS
2575 long style
, const wxValidator
&validator
,
2577 const wxString
&name
)
2579 m_imageListNormal
= (wxImageList
*) NULL
;
2580 m_imageListSmall
= (wxImageList
*) NULL
;
2581 m_imageListState
= (wxImageList
*) NULL
;
2582 m_mainWin
= (wxListMainWindow
*) NULL
;
2583 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2588 #pragma message disable codcauunr
2589 // VMS reports on this part the warning:
2590 // statement either is unreachable or causes unreachable code
2592 if ((s
& wxLC_REPORT
== 0) &&
2593 (s
& wxLC_LIST
== 0) &&
2594 (s
& wxLC_ICON
== 0))
2599 #pragma message enable codcauunr
2602 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2604 #if wxUSE_VALIDATORS
2605 SetValidator( validator
);
2608 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2610 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2612 if (HasFlag(wxLC_REPORT
))
2613 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2615 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2617 SetBackgroundColour( *wxWHITE
);
2622 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2624 /* handled in OnIdle */
2626 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2629 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2631 long flag
= GetWindowStyle();
2635 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2636 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2637 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2646 if (flag
& style
) flag
-= style
;
2649 SetWindowStyleFlag( flag
);
2652 void wxListCtrl::SetWindowStyleFlag( long flag
)
2656 m_mainWin
->DeleteEverything();
2660 GetClientSize( &width
, &height
);
2662 m_mainWin
->SetMode( flag
);
2664 if (flag
& wxLC_REPORT
)
2666 if (!HasFlag(wxLC_REPORT
))
2670 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2671 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2672 if (HasFlag(wxLC_NO_HEADER
))
2673 m_headerWin
->Show( FALSE
);
2677 if (flag
& wxLC_NO_HEADER
)
2678 m_headerWin
->Show( FALSE
);
2680 m_headerWin
->Show( TRUE
);
2686 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2688 m_headerWin
->Show( FALSE
);
2693 wxWindow::SetWindowStyleFlag( flag
);
2696 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2698 m_mainWin
->GetColumn( col
, item
);
2702 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2704 m_mainWin
->SetColumn( col
, item
);
2708 int wxListCtrl::GetColumnWidth( int col
) const
2710 return m_mainWin
->GetColumnWidth( col
);
2713 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2715 m_mainWin
->SetColumnWidth( col
, width
);
2719 int wxListCtrl::GetCountPerPage() const
2721 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2724 bool wxListCtrl::GetItem( wxListItem
&info
) const
2726 m_mainWin
->GetItem( info
);
2730 bool wxListCtrl::SetItem( wxListItem
&info
)
2732 m_mainWin
->SetItem( info
);
2736 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2739 info
.m_text
= label
;
2740 info
.m_mask
= wxLIST_MASK_TEXT
;
2741 info
.m_itemId
= index
;
2745 info
.m_image
= imageId
;
2746 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2748 m_mainWin
->SetItem(info
);
2752 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2754 return m_mainWin
->GetItemState( item
, stateMask
);
2757 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2759 m_mainWin
->SetItemState( item
, state
, stateMask
);
2763 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2766 info
.m_image
= image
;
2767 info
.m_mask
= wxLIST_MASK_IMAGE
;
2768 info
.m_itemId
= item
;
2769 m_mainWin
->SetItem( info
);
2773 wxString
wxListCtrl::GetItemText( long item
) const
2776 info
.m_itemId
= item
;
2777 m_mainWin
->GetItem( info
);
2781 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2784 info
.m_mask
= wxLIST_MASK_TEXT
;
2785 info
.m_itemId
= item
;
2787 m_mainWin
->SetItem( info
);
2790 long wxListCtrl::GetItemData( long item
) const
2793 info
.m_itemId
= item
;
2794 m_mainWin
->GetItem( info
);
2798 bool wxListCtrl::SetItemData( long item
, long data
)
2801 info
.m_mask
= wxLIST_MASK_DATA
;
2802 info
.m_itemId
= item
;
2804 m_mainWin
->SetItem( info
);
2808 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2810 m_mainWin
->GetItemRect( item
, rect
);
2814 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2816 m_mainWin
->GetItemPosition( item
, pos
);
2820 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2825 int wxListCtrl::GetItemCount() const
2827 return m_mainWin
->GetItemCount();
2830 int wxListCtrl::GetColumnCount() const
2832 return m_mainWin
->GetColumnCount();
2835 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2837 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2840 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2842 return m_mainWin
->GetItemSpacing( isSmall
);
2845 int wxListCtrl::GetSelectedItemCount() const
2847 return m_mainWin
->GetSelectedItemCount();
2851 wxColour wxListCtrl::GetTextColour() const
2855 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2860 long wxListCtrl::GetTopItem() const
2865 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2867 return m_mainWin
->GetNextItem( item
, geom
, state
);
2870 wxImageList
*wxListCtrl::GetImageList(int which
) const
2872 if (which
== wxIMAGE_LIST_NORMAL
)
2874 return m_imageListNormal
;
2876 else if (which
== wxIMAGE_LIST_SMALL
)
2878 return m_imageListSmall
;
2880 else if (which
== wxIMAGE_LIST_STATE
)
2882 return m_imageListState
;
2884 return (wxImageList
*) NULL
;
2887 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2889 m_mainWin
->SetImageList( imageList
, which
);
2892 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2897 bool wxListCtrl::DeleteItem( long item
)
2899 m_mainWin
->DeleteItem( item
);
2903 bool wxListCtrl::DeleteAllItems()
2905 m_mainWin
->DeleteAllItems();
2909 bool wxListCtrl::DeleteAllColumns()
2911 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2917 void wxListCtrl::ClearAll()
2919 m_mainWin
->DeleteEverything();
2922 bool wxListCtrl::DeleteColumn( int col
)
2924 m_mainWin
->DeleteColumn( col
);
2928 void wxListCtrl::Edit( long item
)
2930 m_mainWin
->Edit( item
);
2933 bool wxListCtrl::EnsureVisible( long item
)
2935 m_mainWin
->EnsureVisible( item
);
2939 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2941 return m_mainWin
->FindItem( start
, str
, partial
);
2944 long wxListCtrl::FindItem( long start
, long data
)
2946 return m_mainWin
->FindItem( start
, data
);
2949 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2950 int WXUNUSED(direction
))
2955 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2957 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2960 long wxListCtrl::InsertItem( wxListItem
& info
)
2962 m_mainWin
->InsertItem( info
);
2963 return info
.m_itemId
;
2966 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2969 info
.m_text
= label
;
2970 info
.m_mask
= wxLIST_MASK_TEXT
;
2971 info
.m_itemId
= index
;
2972 return InsertItem( info
);
2975 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2978 info
.m_mask
= wxLIST_MASK_IMAGE
;
2979 info
.m_image
= imageIndex
;
2980 info
.m_itemId
= index
;
2981 return InsertItem( info
);
2984 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2987 info
.m_text
= label
;
2988 info
.m_image
= imageIndex
;
2989 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2990 info
.m_itemId
= index
;
2991 return InsertItem( info
);
2994 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2996 m_mainWin
->InsertColumn( col
, item
);
3000 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3001 int format
, int width
)
3004 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3005 item
.m_text
= heading
;
3008 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3009 item
.m_width
= width
;
3011 item
.m_format
= format
;
3013 return InsertColumn( col
, item
);
3016 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3022 // fn is a function which takes 3 long arguments: item1, item2, data.
3023 // item1 is the long data associated with a first item (NOT the index).
3024 // item2 is the long data associated with a second item (NOT the index).
3025 // data is the same value as passed to SortItems.
3026 // The return value is a negative number if the first item should precede the second
3027 // item, a positive number of the second item should precede the first,
3028 // or zero if the two items are equivalent.
3029 // data is arbitrary data to be passed to the sort function.
3031 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3033 m_mainWin
->SortItems( fn
, data
);
3037 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3039 if (!m_mainWin
->m_dirty
) return;
3043 GetClientSize( &cw
, &ch
);
3050 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3052 m_headerWin
->GetPosition( &x
, &y
);
3053 m_headerWin
->GetSize( &w
, &h
);
3054 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3055 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3057 m_mainWin
->GetPosition( &x
, &y
);
3058 m_mainWin
->GetSize( &w
, &h
);
3059 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3060 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3064 m_mainWin
->GetPosition( &x
, &y
);
3065 m_mainWin
->GetSize( &w
, &h
);
3066 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3067 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3070 m_mainWin
->CalculatePositions();
3071 m_mainWin
->RealizeChanges();
3072 m_mainWin
->m_dirty
= FALSE
;
3073 m_mainWin
->Refresh();
3076 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3078 if ( !wxWindow::SetBackgroundColour( colour
) )
3083 m_mainWin
->SetBackgroundColour( colour
);
3084 m_mainWin
->m_dirty
= TRUE
;
3089 // m_headerWin->SetBackgroundColour( colour );
3095 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3097 if ( !wxWindow::SetForegroundColour( colour
) )
3102 m_mainWin
->SetForegroundColour( colour
);
3103 m_mainWin
->m_dirty
= TRUE
;
3108 m_headerWin
->SetForegroundColour( colour
);
3114 bool wxListCtrl::SetFont( const wxFont
&font
)
3116 if ( !wxWindow::SetFont( font
) )
3121 m_mainWin
->SetFont( font
);
3122 m_mainWin
->m_dirty
= TRUE
;
3127 m_headerWin
->SetFont( font
);