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
= (wxColour
*)&info
.GetTextColour();
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
= (wxColour
*)&info
.GetTextColour();
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
.SetTextColour(*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 wxColour
*colour
= (wxColour
*) NULL
;
613 wxNode
*node
= m_items
.First();
616 wxListItemData
*item
= (wxListItemData
*)node
->Data();
617 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
618 int x
= item
->GetX();
619 if (item
->HasImage())
622 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
623 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
624 x
+= item
->GetX() + 5;
627 colour
= item
->GetColour();
632 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
634 dc
->SetTextForeground( *colour
);
635 dc
->DrawText( s
, x
, item
->GetY() );
637 dc
->DestroyClippingRegion();
643 wxNode
*node
= m_items
.First();
646 wxListItemData
*item
= (wxListItemData
*)node
->Data();
647 if (item
->HasImage())
649 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
656 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
658 dc
->SetTextForeground( * item
->GetColour() );
659 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
665 void wxListLineData::Hilight( bool on
)
667 if (on
== m_hilighted
) return;
669 m_owner
->SelectLine( this );
671 m_owner
->DeselectLine( this );
675 void wxListLineData::ReverseHilight( void )
677 m_hilighted
= !m_hilighted
;
679 m_owner
->SelectLine( this );
681 m_owner
->DeselectLine( this );
684 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
688 dc
->SetPen( * wxBLACK_PEN
);
689 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
690 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
691 m_bound_hilight
.width
, m_bound_hilight
.height
);
695 void wxListLineData::Draw( wxDC
*dc
)
697 DoDraw( dc
, m_hilighted
, m_hilighted
);
700 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
702 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
703 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
706 bool wxListLineData::IsHilighted( void )
711 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
716 dest
.height
= height
;
719 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
723 dest
.width
= source
.width
;
724 dest
.height
= source
.height
;
727 //-----------------------------------------------------------------------------
728 // wxListHeaderWindow
729 //-----------------------------------------------------------------------------
731 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
733 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
734 EVT_PAINT (wxListHeaderWindow::OnPaint
)
735 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
736 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
739 wxListHeaderWindow::wxListHeaderWindow( void )
741 m_owner
= (wxListMainWindow
*) NULL
;
742 m_currentCursor
= (wxCursor
*) NULL
;
743 m_resizeCursor
= (wxCursor
*) NULL
;
744 m_isDragging
= FALSE
;
747 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
748 const wxPoint
&pos
, const wxSize
&size
,
749 long style
, const wxString
&name
) :
750 wxWindow( win
, id
, pos
, size
, style
, name
)
753 // m_currentCursor = wxSTANDARD_CURSOR;
754 m_currentCursor
= (wxCursor
*) NULL
;
755 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
756 m_isDragging
= FALSE
;
757 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
760 wxListHeaderWindow::~wxListHeaderWindow( void )
762 delete m_resizeCursor
;
765 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
767 const int m_corner
= 1;
769 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
771 dc
->SetPen( *wxBLACK_PEN
);
772 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
773 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
775 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
778 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
779 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
781 dc
->SetPen( *wxWHITE_PEN
);
782 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
783 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
784 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
785 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
788 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
790 wxPaintDC
dc( this );
792 #if wxUSE_GENERIC_LIST_EXTENSIONS
793 if ( m_owner
->GetMode() & wxLC_REPORT
)
798 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
799 m_owner
->ViewStart( &x
, &y
) ;
800 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
805 dc
.SetFont( GetFont() );
811 GetClientSize( &w
, &h
);
813 dc
.SetBackgroundMode(wxTRANSPARENT
);
814 dc
.SetTextForeground( *wxBLACK
);
815 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
819 int numColumns
= m_owner
->GetColumnCount();
821 for (int i
= 0; i
< numColumns
; i
++)
823 m_owner
->GetColumn( i
, item
);
824 int cw
= item
.m_width
-2;
825 #if wxUSE_GENERIC_LIST_EXTENSIONS
826 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
827 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
829 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
831 dc
.SetPen( *wxWHITE_PEN
);
833 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
834 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
835 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
836 dc
.DestroyClippingRegion();
838 #if wxUSE_GENERIC_LIST_EXTENSIONS
839 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
847 void wxListHeaderWindow::DrawCurrent()
851 int x2
= m_currentX
-1;
854 m_owner
->GetClientSize( &dummy
, &y2
);
855 ClientToScreen( &x1
, &y1
);
856 m_owner
->ClientToScreen( &x2
, &y2
);
859 dc
.SetLogicalFunction( wxINVERT
);
860 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
861 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
863 dc
.DrawLine( x1
, y1
, x2
, y2
);
865 dc
.SetLogicalFunction( wxCOPY
);
867 dc
.SetPen( wxNullPen
);
868 dc
.SetBrush( wxNullBrush
);
871 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
873 int x
= event
.GetX();
874 int y
= event
.GetY();
878 if (event
.ButtonUp())
881 m_isDragging
= FALSE
;
882 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
888 GetClientSize( &size_x
, & dummy
);
892 m_currentX
= m_minX
+7;
893 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
900 bool hit_border
= FALSE
;
902 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
904 xpos
+= m_owner
->GetColumnWidth( j
);
906 if ((abs(x
-xpos
) < 3) && (y
< 22))
918 if (event
.LeftDown())
930 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
931 le
.SetEventObject( GetParent() );
933 GetParent()->GetEventHandler()->ProcessEvent( le
);
942 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
943 m_currentCursor
= m_resizeCursor
;
947 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
948 m_currentCursor
= wxSTANDARD_CURSOR
;
953 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
958 //-----------------------------------------------------------------------------
959 // wxListRenameTimer (internal)
960 //-----------------------------------------------------------------------------
962 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
967 void wxListRenameTimer::Notify()
969 m_owner
->OnRenameTimer();
972 //-----------------------------------------------------------------------------
973 // wxListTextCtrl (internal)
974 //-----------------------------------------------------------------------------
976 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
978 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
979 EVT_CHAR (wxListTextCtrl::OnChar
)
980 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
983 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
984 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
985 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
987 int style
, const wxValidator
& validator
, const wxString
&name
) :
989 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
996 m_startValue
= value
;
999 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1001 if (event
.m_keyCode
== WXK_RETURN
)
1004 (*m_res
) = GetValue();
1005 m_owner
->SetFocus();
1008 if (event
.m_keyCode
== WXK_ESCAPE
)
1010 (*m_accept
) = FALSE
;
1012 m_owner
->SetFocus();
1018 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1020 if (wxPendingDelete
.Member(this)) return;
1022 wxPendingDelete
.Append(this);
1024 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1025 m_owner
->OnRenameAccept();
1028 //-----------------------------------------------------------------------------
1030 //-----------------------------------------------------------------------------
1032 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1034 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1035 EVT_PAINT (wxListMainWindow::OnPaint
)
1036 EVT_SIZE (wxListMainWindow::OnSize
)
1037 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1038 EVT_CHAR (wxListMainWindow::OnChar
)
1039 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1040 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1041 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1042 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1045 wxListMainWindow::wxListMainWindow()
1048 m_lines
.DeleteContents( TRUE
);
1049 m_columns
.DeleteContents( TRUE
);
1050 m_current
= (wxListLineData
*) NULL
;
1052 m_hilightBrush
= (wxBrush
*) NULL
;
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_lastOnSame
= FALSE
;
1063 m_renameTimer
= new wxListRenameTimer( this );
1064 m_isCreated
= FALSE
;
1068 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1069 const wxPoint
&pos
, const wxSize
&size
,
1070 long style
, const wxString
&name
) :
1071 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1074 m_lines
.DeleteContents( TRUE
);
1075 m_columns
.DeleteContents( TRUE
);
1076 m_current
= (wxListLineData
*) NULL
;
1079 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1080 m_small_image_list
= (wxImageList
*) NULL
;
1081 m_normal_image_list
= (wxImageList
*) NULL
;
1082 m_small_spacing
= 30;
1083 m_normal_spacing
= 40;
1086 m_isCreated
= FALSE
;
1090 if (m_mode
& wxLC_REPORT
)
1092 #if wxUSE_GENERIC_LIST_EXTENSIONS
1104 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1107 m_lastOnSame
= FALSE
;
1108 m_renameTimer
= new wxListRenameTimer( this );
1109 m_renameAccept
= FALSE
;
1111 SetBackgroundColour( *wxWHITE
);
1114 wxListMainWindow::~wxListMainWindow()
1116 if (m_hilightBrush
) delete m_hilightBrush
;
1118 delete m_renameTimer
;
1121 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1129 wxClientDC
dc(this);
1131 line
->GetExtent( x
, y
, w
, h
);
1133 dc
.LogicalToDeviceX(x
-3),
1134 dc
.LogicalToDeviceY(y
-3),
1135 dc
.LogicalToDeviceXRel(w
+6),
1136 dc
.LogicalToDeviceXRel(h
+6) );
1137 Refresh( TRUE
, &rect
);
1141 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1143 // Note: a wxPaintDC must be constructed even if no drawing is
1144 // done (a Windows requirement).
1145 wxPaintDC
dc( this );
1148 if (m_dirty
) return;
1150 if (m_lines
.GetCount() == 0) return;
1154 dc
.SetFont( GetFont() );
1156 if (m_mode
& wxLC_REPORT
)
1158 int lineSpacing
= 0;
1159 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1161 line
->GetSize( dummy
, lineSpacing
);
1164 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1166 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1167 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1171 line
= (wxListLineData
*)node
->Data();
1173 node
= node
->Next();
1178 wxNode
*node
= m_lines
.First();
1181 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1183 node
= node
->Next();
1187 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1192 void wxListMainWindow::HilightAll( bool on
)
1194 wxNode
*node
= m_lines
.First();
1197 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1198 if (line
->IsHilighted() != on
)
1200 line
->Hilight( on
);
1201 RefreshLine( line
);
1203 node
= node
->Next();
1207 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1209 wxListEvent
le( command
, GetParent()->GetId() );
1210 le
.SetEventObject( GetParent() );
1211 le
.m_itemIndex
= GetIndexOfLine( line
);
1212 line
->GetItem( 0, le
.m_item
);
1213 // GetParent()->GetEventHandler()->ProcessEvent( le );
1214 GetParent()->GetEventHandler()->AddPendingEvent( le
);
1217 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1219 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1222 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1224 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1227 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1229 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1232 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1234 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1237 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1239 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1244 void wxListMainWindow::EditLabel( long item
)
1246 wxNode
*node
= m_lines
.Nth( item
);
1247 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1249 m_currentEdit
= (wxListLineData
*) node
->Data();
1251 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1252 le
.SetEventObject( GetParent() );
1253 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1254 m_currentEdit
->GetItem( 0, le
.m_item
);
1255 GetParent()->GetEventHandler()->ProcessEvent( le
);
1257 if (!le
.IsAllowed())
1260 // We have to call this here because the label in
1261 // question might just have been added and no screen
1262 // update taken place.
1263 if (m_dirty
) wxYield();
1266 m_currentEdit
->GetText( 0, s
);
1271 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1273 wxClientDC
dc(this);
1275 x
= dc
.LogicalToDeviceX( x
);
1276 y
= dc
.LogicalToDeviceY( y
);
1278 wxListTextCtrl
*text
= new wxListTextCtrl(
1279 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1283 void wxListMainWindow::OnRenameTimer()
1285 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1287 Edit( m_lines
.IndexOf( m_current
) );
1290 void wxListMainWindow::OnRenameAccept()
1292 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1293 le
.SetEventObject( GetParent() );
1294 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1295 m_currentEdit
->GetItem( 0, le
.m_item
);
1296 le
.m_item
.m_text
= m_renameRes
;
1297 GetParent()->GetEventHandler()->ProcessEvent( le
);
1299 if (!le
.IsAllowed()) return;
1302 info
.m_mask
= wxLIST_MASK_TEXT
;
1303 info
.m_itemId
= le
.m_itemIndex
;
1304 info
.m_text
= m_renameRes
;
1305 info
.SetTextColour(le
.m_item
.GetTextColour());
1309 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1311 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1313 if (!m_current
) return;
1314 if (m_dirty
) return;
1315 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1317 wxClientDC
dc(this);
1319 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1320 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1322 /* Did we actually hit an item ? */
1324 wxNode
*node
= m_lines
.First();
1325 wxListLineData
*line
= (wxListLineData
*) NULL
;
1328 line
= (wxListLineData
*)node
->Data();
1329 hitResult
= line
->IsHit( x
, y
);
1330 if (hitResult
) break;
1331 line
= (wxListLineData
*) NULL
;
1332 node
= node
->Next();
1335 if (event
.Dragging())
1337 if (m_dragCount
== 0)
1338 m_dragStart
= wxPoint(x
,y
);
1342 if (m_dragCount
!= 3) return;
1344 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1345 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1347 wxListEvent
le( command
, GetParent()->GetId() );
1348 le
.SetEventObject( GetParent() );
1349 le
.m_pointDrag
= m_dragStart
;
1350 GetParent()->GetEventHandler()->ProcessEvent( le
);
1361 if (event
.ButtonDClick())
1364 m_lastOnSame
= FALSE
;
1365 m_renameTimer
->Stop();
1367 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1372 if (event
.LeftUp() && m_lastOnSame
)
1375 if ((line
== m_current
) &&
1376 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1377 (m_mode
& wxLC_EDIT_LABELS
) )
1379 m_renameTimer
->Start( 100, TRUE
);
1381 m_lastOnSame
= FALSE
;
1385 if (event
.RightDown())
1387 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1391 if (event
.MiddleDown())
1393 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1397 if (event
.LeftDown())
1400 wxListLineData
*oldCurrent
= m_current
;
1401 if (m_mode
& wxLC_SINGLE_SEL
)
1404 HilightAll( FALSE
);
1405 m_current
->ReverseHilight();
1406 RefreshLine( m_current
);
1410 if (event
.ShiftDown())
1413 m_current
->ReverseHilight();
1414 RefreshLine( m_current
);
1416 else if (event
.ControlDown())
1420 int numOfCurrent
= -1;
1421 node
= m_lines
.First();
1424 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1426 if (test_line
== oldCurrent
) break;
1427 node
= node
->Next();
1431 node
= m_lines
.First();
1434 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1436 if (test_line
== line
) break;
1437 node
= node
->Next();
1440 if (numOfLine
< numOfCurrent
)
1443 numOfLine
= numOfCurrent
;
1447 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1448 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1450 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1451 test_line
->Hilight(TRUE
);
1452 RefreshLine( test_line
);
1453 node
= node
->Next();
1459 HilightAll( FALSE
);
1460 m_current
->ReverseHilight();
1461 RefreshLine( m_current
);
1464 if (m_current
!= oldCurrent
)
1466 RefreshLine( oldCurrent
);
1467 UnfocusLine( oldCurrent
);
1468 FocusLine( m_current
);
1470 m_lastOnSame
= (m_current
== oldCurrent
);
1475 void wxListMainWindow::MoveToFocus()
1477 if (!m_current
) return;
1483 m_current
->GetExtent( x
, y
, w
, h
);
1487 GetClientSize( &w_p
, &h_p
);
1489 if (m_mode
& wxLC_REPORT
)
1491 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1492 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1493 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1494 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1498 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1499 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1500 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1501 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1505 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1507 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1508 wxListLineData
*oldCurrent
= m_current
;
1509 m_current
= newCurrent
;
1511 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1512 RefreshLine( m_current
);
1513 RefreshLine( oldCurrent
);
1514 FocusLine( m_current
);
1515 UnfocusLine( oldCurrent
);
1518 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1520 wxWindow
*parent
= GetParent();
1522 /* we propagate the key event up */
1523 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1524 ke
.m_shiftDown
= event
.m_shiftDown
;
1525 ke
.m_controlDown
= event
.m_controlDown
;
1526 ke
.m_altDown
= event
.m_altDown
;
1527 ke
.m_metaDown
= event
.m_metaDown
;
1528 ke
.m_keyCode
= event
.m_keyCode
;
1531 ke
.SetEventObject( parent
);
1532 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1537 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1539 wxWindow
*parent
= GetParent();
1541 /* we send a list_key event up */
1542 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1543 le
.m_code
= event
.KeyCode();
1544 le
.SetEventObject( parent
);
1545 parent
->GetEventHandler()->ProcessEvent( le
);
1547 /* we propagate the char event up */
1548 wxKeyEvent
ke( wxEVT_CHAR
);
1549 ke
.m_shiftDown
= event
.m_shiftDown
;
1550 ke
.m_controlDown
= event
.m_controlDown
;
1551 ke
.m_altDown
= event
.m_altDown
;
1552 ke
.m_metaDown
= event
.m_metaDown
;
1553 ke
.m_keyCode
= event
.m_keyCode
;
1556 ke
.SetEventObject( parent
);
1557 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1559 if (event
.KeyCode() == WXK_TAB
)
1561 wxNavigationKeyEvent nevent
;
1562 nevent
.SetDirection( !event
.ShiftDown() );
1563 nevent
.SetCurrentFocus( m_parent
);
1564 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1567 /* no item -> nothing to do */
1574 switch (event
.KeyCode())
1578 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1579 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1584 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1585 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1590 wxNode
*node
= m_lines
.Last();
1591 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1596 wxNode
*node
= m_lines
.First();
1597 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1603 if (m_mode
& wxLC_REPORT
)
1605 steps
= m_visibleLines
-1;
1610 wxNode
*node
= m_lines
.First();
1611 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1612 steps
= pos
% m_visibleLines
;
1614 wxNode
*node
= m_lines
.Member( m_current
);
1615 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1616 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1622 if (m_mode
& wxLC_REPORT
)
1624 steps
= m_visibleLines
-1;
1628 int pos
= 0; wxNode
*node
= m_lines
.First();
1629 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1630 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1632 wxNode
*node
= m_lines
.Member( m_current
);
1633 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1634 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1639 if (!(m_mode
& wxLC_REPORT
))
1641 wxNode
*node
= m_lines
.Member( m_current
);
1642 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1643 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1649 if (!(m_mode
& wxLC_REPORT
))
1651 wxNode
*node
= m_lines
.Member( m_current
);
1652 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1653 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1659 m_current
->ReverseHilight();
1660 RefreshLine( m_current
);
1665 if (!(m_mode
& wxLC_SINGLE_SEL
))
1667 wxListLineData
*oldCurrent
= m_current
;
1668 m_current
->ReverseHilight();
1669 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1670 if (node
) m_current
= (wxListLineData
*)node
->Data();
1672 RefreshLine( oldCurrent
);
1673 RefreshLine( m_current
);
1674 UnfocusLine( oldCurrent
);
1675 FocusLine( m_current
);
1682 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1683 le
.SetEventObject( GetParent() );
1684 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1685 m_current
->GetItem( 0, le
.m_item
);
1686 GetParent()->GetEventHandler()->ProcessEvent( le
);
1699 extern wxWindow
*g_focusWindow
;
1702 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1705 RefreshLine( m_current
);
1707 if (!GetParent()) return;
1710 g_focusWindow
= GetParent();
1713 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1714 event
.SetEventObject( GetParent() );
1715 GetParent()->GetEventHandler()->ProcessEvent( event
);
1718 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1721 RefreshLine( m_current
);
1724 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1727 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1732 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1734 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1736 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1739 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1741 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1743 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1745 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1747 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1749 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1754 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1756 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1758 m_normal_image_list
->GetSize( index
, width
, height
);
1761 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1763 m_small_image_list
->GetSize( index
, width
, height
);
1766 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1768 m_small_image_list
->GetSize( index
, width
, height
);
1771 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1773 m_small_image_list
->GetSize( index
, width
, height
);
1780 int wxListMainWindow::GetTextLength( wxString
&s
)
1782 wxClientDC
dc( this );
1785 dc
.GetTextExtent( s
, &lw
, &lh
);
1789 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1792 wxNode
*node
= m_lines
.First();
1795 if (line
== (wxListLineData
*)node
->Data()) return i
;
1797 node
= node
->Next();
1802 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1805 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1806 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1809 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1814 m_small_spacing
= spacing
;
1818 m_normal_spacing
= spacing
;
1822 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1824 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1827 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1830 wxNode
*node
= m_columns
.Nth( col
);
1833 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1834 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1835 column
->SetItem( item
);
1837 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1838 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1841 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1843 if (!(m_mode
& wxLC_REPORT
)) return;
1847 wxNode
*node
= (wxNode
*) NULL
;
1849 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1850 if (width
== wxLIST_AUTOSIZE
)
1852 wxClientDC
dc(this);
1853 dc
.SetFont( GetFont() );
1855 node
= m_lines
.First();
1858 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1859 wxNode
*n
= line
->m_items
.Nth( col
);
1862 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1863 int current
= 0, ix
= 0, iy
= 0;
1864 long lx
= 0, ly
= 0;
1865 if (item
->HasImage())
1867 GetImageSize( item
->GetImage(), ix
, iy
);
1870 if (item
->HasText())
1873 item
->GetText( str
);
1874 dc
.GetTextExtent( str
, &lx
, &ly
);
1877 if (current
> max
) max
= current
;
1879 node
= node
->Next();
1884 node
= m_columns
.Nth( col
);
1887 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1888 column
->SetWidth( width
);
1891 node
= m_lines
.First();
1894 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1895 wxNode
*n
= line
->m_items
.Nth( col
);
1898 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1899 item
->SetSize( width
, -1 );
1901 node
= node
->Next();
1904 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1905 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1908 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1910 wxNode
*node
= m_columns
.Nth( col
);
1913 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1914 column
->GetItem( item
);
1926 int wxListMainWindow::GetColumnWidth( int col
)
1928 wxNode
*node
= m_columns
.Nth( col
);
1931 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1932 return column
->GetWidth();
1940 int wxListMainWindow::GetColumnCount()
1942 return m_columns
.Number();
1945 int wxListMainWindow::GetCountPerPage()
1947 return m_visibleLines
;
1950 void wxListMainWindow::SetItem( wxListItem
&item
)
1953 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1956 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1957 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1958 line
->SetItem( item
.m_col
, item
);
1962 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1964 // m_dirty = TRUE; no recalcs needed
1966 wxListLineData
*oldCurrent
= m_current
;
1968 if (stateMask
& wxLIST_STATE_FOCUSED
)
1970 wxNode
*node
= m_lines
.Nth( item
);
1973 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1974 UnfocusLine( m_current
);
1976 FocusLine( m_current
);
1977 RefreshLine( m_current
);
1978 if (oldCurrent
) RefreshLine( oldCurrent
);
1982 if (stateMask
& wxLIST_STATE_SELECTED
)
1984 bool on
= state
& wxLIST_STATE_SELECTED
;
1985 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
1987 wxNode
*node
= m_lines
.Nth( item
);
1990 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1991 if (m_mode
& wxLC_SINGLE_SEL
)
1993 UnfocusLine( m_current
);
1995 FocusLine( m_current
);
1996 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
1997 RefreshLine( m_current
);
1998 if (oldCurrent
) RefreshLine( oldCurrent
);
2000 bool on
= state
& wxLIST_STATE_SELECTED
;
2001 if (on
!= line
->IsHilighted())
2003 line
->Hilight( on
);
2004 RefreshLine( line
);
2010 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2012 int ret
= wxLIST_STATE_DONTCARE
;
2013 if (stateMask
& wxLIST_STATE_FOCUSED
)
2015 wxNode
*node
= m_lines
.Nth( item
);
2018 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2019 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2022 if (stateMask
& wxLIST_STATE_SELECTED
)
2024 wxNode
*node
= m_lines
.Nth( item
);
2027 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2028 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2034 void wxListMainWindow::GetItem( wxListItem
&item
)
2036 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2039 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2040 line
->GetItem( item
.m_col
, item
);
2051 int wxListMainWindow::GetItemCount()
2053 return m_lines
.Number();
2056 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2058 wxNode
*node
= m_lines
.Nth( index
);
2061 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2062 line
->GetRect( rect
);
2073 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2075 wxNode
*node
= m_lines
.Nth( item
);
2079 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2080 line
->GetRect( rect
);
2092 int wxListMainWindow::GetSelectedItemCount()
2095 wxNode
*node
= m_lines
.First();
2098 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2099 if (line
->IsHilighted()) ret
++;
2100 node
= node
->Next();
2105 void wxListMainWindow::SetMode( long mode
)
2112 if (m_mode
& wxLC_REPORT
)
2114 #if wxUSE_GENERIC_LIST_EXTENSIONS
2128 long wxListMainWindow::GetMode() const
2133 void wxListMainWindow::CalculatePositions()
2135 if (!m_lines
.First()) return;
2137 wxClientDC
dc( this );
2138 dc
.SetFont( GetFont() );
2140 int iconSpacing
= 0;
2141 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2142 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2144 // we take the first line (which also can be an icon or
2145 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2146 // measure the size of the line
2150 int lineSpacing
= 0;
2152 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2153 line
->CalculateSize( &dc
, iconSpacing
);
2155 line
->GetSize( dummy
, lineSpacing
);
2158 int clientWidth
= 0;
2159 int clientHeight
= 0;
2161 if (m_mode
& wxLC_REPORT
)
2165 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2166 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2167 #if wxUSE_GENERIC_LIST_EXTENSIONS
2168 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2170 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2172 GetClientSize( &clientWidth
, &clientHeight
);
2174 wxNode
* node
= m_lines
.First();
2175 int entireWidth
= 0 ;
2178 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2179 line
->CalculateSize( &dc
, iconSpacing
);
2180 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2182 for (int i
= 0; i
< GetColumnCount(); i
++)
2184 line
->SetColumnPosition( i
, col_x
);
2185 col_x
+= GetColumnWidth( i
);
2187 entireWidth
= wxMax( entireWidth
, col_x
) ;
2188 #if wxUSE_GENERIC_LIST_EXTENSIONS
2189 line
->SetPosition( &dc
, x
, y
, col_x
);
2191 y
+= lineSpacing
; // one pixel blank line between items
2192 node
= node
->Next();
2194 m_visibleLines
= clientHeight
/ lineSpacing
;
2195 #if wxUSE_GENERIC_LIST_EXTENSIONS
2196 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2201 // at first we try without any scrollbar. if the items don't
2202 // fit into the window, we recalculate after subtracting an
2203 // approximated 15 pt for the horizontal scrollbar
2205 GetSize( &clientWidth
, &clientHeight
);
2206 clientHeight
-= 4; // sunken frame
2208 int entireWidth
= 0;
2210 for (int tries
= 0; tries
< 2; tries
++)
2213 int x
= 5; // painting is done at x-2
2214 int y
= 5; // painting is done at y-2
2217 int m_currentVisibleLines
= 0;
2218 wxNode
*node
= m_lines
.First();
2221 m_currentVisibleLines
++;
2222 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2223 line
->CalculateSize( &dc
, iconSpacing
);
2224 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2225 line
->GetSize( lineWidth
, lineHeight
);
2226 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2228 if (m_currentVisibleLines
> m_visibleLines
)
2229 m_visibleLines
= m_currentVisibleLines
;
2230 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2232 m_currentVisibleLines
= 0;
2235 entireWidth
+= maxWidth
+6;
2238 node
= node
->Next();
2239 if (!node
) entireWidth
+= maxWidth
;
2240 if ((tries
== 0) && (entireWidth
> clientWidth
))
2242 clientHeight
-= 15; // scrollbar height
2244 m_currentVisibleLines
= 0;
2247 if (!node
) tries
= 1; // everything fits, no second try required
2251 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2252 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2256 void wxListMainWindow::RealizeChanges( void )
2260 wxNode
*node
= m_lines
.First();
2261 if (node
) m_current
= (wxListLineData
*)node
->Data();
2265 FocusLine( m_current
);
2266 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2270 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2273 if (item
> 0) ret
= item
;
2274 if(ret
>= GetItemCount()) return -1;
2275 wxNode
*node
= m_lines
.Nth( ret
);
2278 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2279 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2280 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2281 if (!state
) return ret
;
2283 node
= node
->Next();
2288 void wxListMainWindow::DeleteItem( long index
)
2291 wxNode
*node
= m_lines
.Nth( index
);
2294 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2295 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2297 m_lines
.DeleteNode( node
);
2301 void wxListMainWindow::DeleteColumn( int col
)
2303 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2304 wxT("attempting to delete inexistent column in wxListView") );
2307 wxNode
*node
= m_columns
.Nth( col
);
2308 if (node
) m_columns
.DeleteNode( node
);
2311 void wxListMainWindow::DeleteAllItems( void )
2314 m_current
= (wxListLineData
*) NULL
;
2316 // to make the deletion of all items faster, we don't send the
2317 // notifications in this case: this is compatible with wxMSW and
2318 // documented in DeleteAllItems() description
2320 wxNode
*node
= m_lines
.First();
2323 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2327 node
= node
->Next();
2334 void wxListMainWindow::DeleteEverything( void )
2337 m_current
= (wxListLineData
*) NULL
;
2338 wxNode
*node
= m_lines
.First();
2341 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2343 node
= node
->Next();
2346 m_current
= (wxListLineData
*) NULL
;
2350 void wxListMainWindow::EnsureVisible( long index
)
2352 // We have to call this here because the label in
2353 // question might just have been added and no screen
2354 // update taken place.
2355 if (m_dirty
) wxYield();
2357 wxListLineData
*oldCurrent
= m_current
;
2358 m_current
= (wxListLineData
*) NULL
;
2360 wxNode
*node
= m_lines
.Nth( i
);
2361 if (node
) m_current
= (wxListLineData
*)node
->Data();
2362 if (m_current
) MoveToFocus();
2363 m_current
= oldCurrent
;
2366 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2370 if (pos
< 0) pos
= 0;
2371 wxNode
*node
= m_lines
.Nth( pos
);
2374 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2376 line
->GetText( 0, s
);
2377 if (s
== tmp
) return pos
;
2378 node
= node
->Next();
2384 long wxListMainWindow::FindItem(long start
, long data
)
2387 if (pos
< 0) pos
= 0;
2388 wxNode
*node
= m_lines
.Nth( pos
);
2391 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2393 line
->GetItem( 0, item
);
2394 if (item
.m_data
== data
) return pos
;
2395 node
= node
->Next();
2401 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2403 wxNode
*node
= m_lines
.First();
2407 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2408 long ret
= line
->IsHit( x
, y
);
2414 node
= node
->Next();
2420 void wxListMainWindow::InsertItem( wxListItem
&item
)
2424 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2425 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2426 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2427 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2429 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2431 if (m_mode
& wxLC_REPORT
)
2433 line
->InitItems( GetColumnCount() );
2434 item
.m_width
= GetColumnWidth( 0 )-3;
2438 line
->InitItems( 1 );
2441 line
->SetItem( 0, item
);
2442 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2444 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2445 if (node
) m_lines
.Insert( node
, line
);
2449 m_lines
.Append( line
);
2453 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2456 if (m_mode
& wxLC_REPORT
)
2458 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2459 wxListHeaderData
*column
= new wxListHeaderData( item
);
2460 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2462 wxNode
*node
= m_columns
.Nth( col
);
2464 m_columns
.Insert( node
, column
);
2468 m_columns
.Append( column
);
2473 wxListCtrlCompare list_ctrl_compare_func_2
;
2474 long list_ctrl_compare_data
;
2476 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2478 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2479 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2481 line1
->GetItem( 0, item
);
2482 long data1
= item
.m_data
;
2483 line2
->GetItem( 0, item
);
2484 long data2
= item
.m_data
;
2485 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2488 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2490 list_ctrl_compare_func_2
= fn
;
2491 list_ctrl_compare_data
= data
;
2492 m_lines
.Sort( list_ctrl_compare_func_1
);
2495 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2497 wxScrolledWindow::OnScroll( event
) ;
2498 #if wxUSE_GENERIC_LIST_EXTENSIONS
2500 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2502 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2505 lc
->m_headerWin
->Refresh() ;
2507 lc
->m_headerWin
->MacUpdateImmediately() ;
2514 // -------------------------------------------------------------------------------------
2516 // -------------------------------------------------------------------------------------
2518 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2520 wxListItem::wxListItem()
2529 m_format
= wxLIST_FORMAT_CENTRE
;
2535 // -------------------------------------------------------------------------------------
2537 // -------------------------------------------------------------------------------------
2539 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2541 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2542 wxNotifyEvent( commandType
, id
)
2548 m_cancelled
= FALSE
;
2553 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2555 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2557 wxNotifyEvent::CopyObject(object_dest
);
2559 obj
->m_code
= m_code
;
2560 obj
->m_itemIndex
= m_itemIndex
;
2561 obj
->m_oldItemIndex
= m_oldItemIndex
;
2563 obj
->m_cancelled
= m_cancelled
;
2564 obj
->m_pointDrag
= m_pointDrag
;
2565 obj
->m_item
.m_mask
= m_item
.m_mask
;
2566 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2567 obj
->m_item
.m_col
= m_item
.m_col
;
2568 obj
->m_item
.m_state
= m_item
.m_state
;
2569 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2570 obj
->m_item
.m_text
= m_item
.m_text
;
2571 obj
->m_item
.m_image
= m_item
.m_image
;
2572 obj
->m_item
.m_data
= m_item
.m_data
;
2573 obj
->m_item
.m_format
= m_item
.m_format
;
2574 obj
->m_item
.m_width
= m_item
.m_width
;
2576 if ( m_item
.HasAttributes() )
2578 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2582 // -------------------------------------------------------------------------------------
2584 // -------------------------------------------------------------------------------------
2586 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2588 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2589 EVT_SIZE (wxListCtrl::OnSize
)
2590 EVT_IDLE (wxListCtrl::OnIdle
)
2593 wxListCtrl::wxListCtrl()
2595 m_imageListNormal
= (wxImageList
*) NULL
;
2596 m_imageListSmall
= (wxImageList
*) NULL
;
2597 m_imageListState
= (wxImageList
*) NULL
;
2598 m_mainWin
= (wxListMainWindow
*) NULL
;
2599 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2602 wxListCtrl::~wxListCtrl()
2606 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2607 const wxPoint
&pos
, const wxSize
&size
,
2608 #if wxUSE_VALIDATORS
2609 long style
, const wxValidator
&validator
,
2611 const wxString
&name
)
2613 m_imageListNormal
= (wxImageList
*) NULL
;
2614 m_imageListSmall
= (wxImageList
*) NULL
;
2615 m_imageListState
= (wxImageList
*) NULL
;
2616 m_mainWin
= (wxListMainWindow
*) NULL
;
2617 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2622 #pragma message disable codcauunr
2623 // VMS reports on this part the warning:
2624 // statement either is unreachable or causes unreachable code
2626 if ((s
& wxLC_REPORT
== 0) &&
2627 (s
& wxLC_LIST
== 0) &&
2628 (s
& wxLC_ICON
== 0))
2633 #pragma message enable codcauunr
2636 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2638 #if wxUSE_VALIDATORS
2639 SetValidator( validator
);
2642 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2644 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2646 if (HasFlag(wxLC_REPORT
))
2647 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2649 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2651 SetBackgroundColour( *wxWHITE
);
2656 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2658 /* handled in OnIdle */
2660 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2663 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2665 long flag
= GetWindowStyle();
2669 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2670 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2671 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2680 if (flag
& style
) flag
-= style
;
2683 SetWindowStyleFlag( flag
);
2686 void wxListCtrl::SetWindowStyleFlag( long flag
)
2690 m_mainWin
->DeleteEverything();
2694 GetClientSize( &width
, &height
);
2696 m_mainWin
->SetMode( flag
);
2698 if (flag
& wxLC_REPORT
)
2700 if (!HasFlag(wxLC_REPORT
))
2704 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2705 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2706 if (HasFlag(wxLC_NO_HEADER
))
2707 m_headerWin
->Show( FALSE
);
2711 if (flag
& wxLC_NO_HEADER
)
2712 m_headerWin
->Show( FALSE
);
2714 m_headerWin
->Show( TRUE
);
2720 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2722 m_headerWin
->Show( FALSE
);
2727 wxWindow::SetWindowStyleFlag( flag
);
2730 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2732 m_mainWin
->GetColumn( col
, item
);
2736 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2738 m_mainWin
->SetColumn( col
, item
);
2742 int wxListCtrl::GetColumnWidth( int col
) const
2744 return m_mainWin
->GetColumnWidth( col
);
2747 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2749 m_mainWin
->SetColumnWidth( col
, width
);
2753 int wxListCtrl::GetCountPerPage() const
2755 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2758 bool wxListCtrl::GetItem( wxListItem
&info
) const
2760 m_mainWin
->GetItem( info
);
2764 bool wxListCtrl::SetItem( wxListItem
&info
)
2766 m_mainWin
->SetItem( info
);
2770 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2773 info
.m_text
= label
;
2774 info
.m_mask
= wxLIST_MASK_TEXT
;
2775 info
.m_itemId
= index
;
2779 info
.m_image
= imageId
;
2780 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2782 m_mainWin
->SetItem(info
);
2786 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2788 return m_mainWin
->GetItemState( item
, stateMask
);
2791 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2793 m_mainWin
->SetItemState( item
, state
, stateMask
);
2797 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2800 info
.m_image
= image
;
2801 info
.m_mask
= wxLIST_MASK_IMAGE
;
2802 info
.m_itemId
= item
;
2803 m_mainWin
->SetItem( info
);
2807 wxString
wxListCtrl::GetItemText( long item
) const
2810 info
.m_itemId
= item
;
2811 m_mainWin
->GetItem( info
);
2815 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2818 info
.m_mask
= wxLIST_MASK_TEXT
;
2819 info
.m_itemId
= item
;
2821 m_mainWin
->SetItem( info
);
2824 long wxListCtrl::GetItemData( long item
) const
2827 info
.m_itemId
= item
;
2828 m_mainWin
->GetItem( info
);
2832 bool wxListCtrl::SetItemData( long item
, long data
)
2835 info
.m_mask
= wxLIST_MASK_DATA
;
2836 info
.m_itemId
= item
;
2838 m_mainWin
->SetItem( info
);
2842 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2844 m_mainWin
->GetItemRect( item
, rect
);
2848 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2850 m_mainWin
->GetItemPosition( item
, pos
);
2854 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2859 int wxListCtrl::GetItemCount() const
2861 return m_mainWin
->GetItemCount();
2864 int wxListCtrl::GetColumnCount() const
2866 return m_mainWin
->GetColumnCount();
2869 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2871 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2874 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2876 return m_mainWin
->GetItemSpacing( isSmall
);
2879 int wxListCtrl::GetSelectedItemCount() const
2881 return m_mainWin
->GetSelectedItemCount();
2885 wxColour wxListCtrl::GetTextColour() const
2889 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2894 long wxListCtrl::GetTopItem() const
2899 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2901 return m_mainWin
->GetNextItem( item
, geom
, state
);
2904 wxImageList
*wxListCtrl::GetImageList(int which
) const
2906 if (which
== wxIMAGE_LIST_NORMAL
)
2908 return m_imageListNormal
;
2910 else if (which
== wxIMAGE_LIST_SMALL
)
2912 return m_imageListSmall
;
2914 else if (which
== wxIMAGE_LIST_STATE
)
2916 return m_imageListState
;
2918 return (wxImageList
*) NULL
;
2921 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2923 m_mainWin
->SetImageList( imageList
, which
);
2926 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2931 bool wxListCtrl::DeleteItem( long item
)
2933 m_mainWin
->DeleteItem( item
);
2937 bool wxListCtrl::DeleteAllItems()
2939 m_mainWin
->DeleteAllItems();
2943 bool wxListCtrl::DeleteAllColumns()
2945 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2951 void wxListCtrl::ClearAll()
2953 m_mainWin
->DeleteEverything();
2956 bool wxListCtrl::DeleteColumn( int col
)
2958 m_mainWin
->DeleteColumn( col
);
2962 void wxListCtrl::Edit( long item
)
2964 m_mainWin
->Edit( item
);
2967 bool wxListCtrl::EnsureVisible( long item
)
2969 m_mainWin
->EnsureVisible( item
);
2973 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2975 return m_mainWin
->FindItem( start
, str
, partial
);
2978 long wxListCtrl::FindItem( long start
, long data
)
2980 return m_mainWin
->FindItem( start
, data
);
2983 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2984 int WXUNUSED(direction
))
2989 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2991 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2994 long wxListCtrl::InsertItem( wxListItem
& info
)
2996 m_mainWin
->InsertItem( info
);
2997 return info
.m_itemId
;
3000 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3003 info
.m_text
= label
;
3004 info
.m_mask
= wxLIST_MASK_TEXT
;
3005 info
.m_itemId
= index
;
3006 return InsertItem( info
);
3009 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3012 info
.m_mask
= wxLIST_MASK_IMAGE
;
3013 info
.m_image
= imageIndex
;
3014 info
.m_itemId
= index
;
3015 return InsertItem( info
);
3018 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3021 info
.m_text
= label
;
3022 info
.m_image
= imageIndex
;
3023 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3024 info
.m_itemId
= index
;
3025 return InsertItem( info
);
3028 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3030 m_mainWin
->InsertColumn( col
, item
);
3034 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3035 int format
, int width
)
3038 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3039 item
.m_text
= heading
;
3042 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3043 item
.m_width
= width
;
3045 item
.m_format
= format
;
3047 return InsertColumn( col
, item
);
3050 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3056 // fn is a function which takes 3 long arguments: item1, item2, data.
3057 // item1 is the long data associated with a first item (NOT the index).
3058 // item2 is the long data associated with a second item (NOT the index).
3059 // data is the same value as passed to SortItems.
3060 // The return value is a negative number if the first item should precede the second
3061 // item, a positive number of the second item should precede the first,
3062 // or zero if the two items are equivalent.
3063 // data is arbitrary data to be passed to the sort function.
3065 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3067 m_mainWin
->SortItems( fn
, data
);
3071 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3073 if (!m_mainWin
->m_dirty
) return;
3077 GetClientSize( &cw
, &ch
);
3084 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3086 m_headerWin
->GetPosition( &x
, &y
);
3087 m_headerWin
->GetSize( &w
, &h
);
3088 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3089 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3091 m_mainWin
->GetPosition( &x
, &y
);
3092 m_mainWin
->GetSize( &w
, &h
);
3093 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3094 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3098 m_mainWin
->GetPosition( &x
, &y
);
3099 m_mainWin
->GetSize( &w
, &h
);
3100 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3101 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3104 m_mainWin
->CalculatePositions();
3105 m_mainWin
->RealizeChanges();
3106 m_mainWin
->m_dirty
= FALSE
;
3107 m_mainWin
->Refresh();
3110 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3112 if ( !wxWindow::SetBackgroundColour( colour
) )
3117 m_mainWin
->SetBackgroundColour( colour
);
3118 m_mainWin
->m_dirty
= TRUE
;
3123 // m_headerWin->SetBackgroundColour( colour );
3129 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3131 if ( !wxWindow::SetForegroundColour( colour
) )
3136 m_mainWin
->SetForegroundColour( colour
);
3137 m_mainWin
->m_dirty
= TRUE
;
3142 m_headerWin
->SetForegroundColour( colour
);
3148 bool wxListCtrl::SetFont( const wxFont
&font
)
3150 if ( !wxWindow::SetFont( font
) )
3155 m_mainWin
->SetFont( font
);
3156 m_mainWin
->m_dirty
= TRUE
;
3161 m_headerWin
->SetFont( font
);