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
)
56 void wxListItemData::SetItem( const wxListItem
&info
)
58 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
59 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
60 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
62 if ( info
.HasAttributes() )
65 *m_attr
= *info
.GetAttributes();
67 m_attr
= new wxListItemAttr(*info
.GetAttributes());
72 m_width
= info
.m_width
;
76 void wxListItemData::SetText( const wxString
&s
)
81 void wxListItemData::SetImage( int image
)
86 void wxListItemData::SetData( long data
)
91 void wxListItemData::SetPosition( int x
, int y
)
97 void wxListItemData::SetSize( int width
, int height
)
99 if (width
!= -1) m_width
= width
;
100 if (height
!= -1) m_height
= height
;
103 bool wxListItemData::HasImage() const
105 return (m_image
>= 0);
108 bool wxListItemData::HasText() const
110 return (!m_text
.IsNull());
113 bool wxListItemData::IsHit( int x
, int y
) const
115 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
118 void wxListItemData::GetText( wxString
&s
)
123 int wxListItemData::GetX() const
128 int wxListItemData::GetY() const
133 int wxListItemData::GetWidth() const
138 int wxListItemData::GetHeight() const
143 int wxListItemData::GetImage() const
148 void wxListItemData::GetItem( wxListItem
&info
) const
150 info
.m_text
= m_text
;
151 info
.m_image
= m_image
;
152 info
.m_data
= m_data
;
156 if ( m_attr
->HasTextColour() )
157 info
.SetTextColour(m_attr
->GetTextColour());
158 if ( m_attr
->HasBackgroundColour() )
159 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
160 if ( m_attr
->HasFont() )
161 info
.SetFont(m_attr
->GetFont());
165 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
169 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
171 wxListHeaderData::wxListHeaderData()
182 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
190 void wxListHeaderData::SetItem( const wxListItem
&item
)
192 m_mask
= item
.m_mask
;
193 m_text
= item
.m_text
;
194 m_image
= item
.m_image
;
195 m_format
= item
.m_format
;
196 m_width
= item
.m_width
;
197 if (m_width
< 0) m_width
= 80;
198 if (m_width
< 6) m_width
= 6;
201 void wxListHeaderData::SetPosition( int x
, int y
)
207 void wxListHeaderData::SetHeight( int h
)
212 void wxListHeaderData::SetWidth( int w
)
215 if (m_width
< 0) m_width
= 80;
216 if (m_width
< 6) m_width
= 6;
219 void wxListHeaderData::SetFormat( int format
)
224 bool wxListHeaderData::HasImage() const
226 return (m_image
!= 0);
229 bool wxListHeaderData::HasText() const
231 return (m_text
.Length() > 0);
234 bool wxListHeaderData::IsHit( int x
, int y
) const
236 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
239 void wxListHeaderData::GetItem( wxListItem
&item
)
241 item
.m_mask
= m_mask
;
242 item
.m_text
= m_text
;
243 item
.m_image
= m_image
;
244 item
.m_format
= m_format
;
245 item
.m_width
= m_width
;
248 void wxListHeaderData::GetText( wxString
&s
)
253 int wxListHeaderData::GetImage() const
258 int wxListHeaderData::GetWidth() const
263 int wxListHeaderData::GetFormat() const
268 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
272 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
274 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
279 m_hilightBrush
= hilightBrush
;
280 m_items
.DeleteContents( TRUE
);
284 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
291 m_bound_all
.width
= m_spacing
;
292 m_bound_all
.height
= m_spacing
+13;
293 wxNode
*node
= m_items
.First();
296 wxListItemData
*item
= (wxListItemData
*)node
->Data();
297 wxString s
= item
->GetText();
299 dc
->GetTextExtent( s
, &lw
, &lh
);
300 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
306 wxNode
*node
= m_items
.First();
309 wxListItemData
*item
= (wxListItemData
*)node
->Data();
310 wxString s
= item
->GetText();
312 dc
->GetTextExtent( s
, &lw
, &lh
);
313 m_bound_all
.width
= lw
;
314 m_bound_all
.height
= lh
;
315 if (item
->HasImage())
319 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
320 m_bound_all
.width
+= 4 + w
;
321 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
328 m_bound_all
.width
= 0;
329 m_bound_all
.height
= 0;
330 wxNode
*node
= m_items
.First();
333 wxListItemData
*item
= (wxListItemData
*)node
->Data();
336 if (s
.IsNull()) s
= "H";
338 dc
->GetTextExtent( s
, &lw
, &lh
);
339 item
->SetSize( item
->GetWidth(), lh
);
340 m_bound_all
.width
+= lw
;
341 m_bound_all
.height
= lh
;
349 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
357 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
358 AssignRect( m_bound_label
, 0, 0, 0, 0 );
359 AssignRect( m_bound_hilight
, m_bound_all
);
360 wxNode
*node
= m_items
.First();
363 wxListItemData
*item
= (wxListItemData
*)node
->Data();
364 if (item
->HasImage())
366 wxListItemData
*item
= (wxListItemData
*)node
->Data();
369 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
370 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
371 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
372 m_bound_icon
.width
= w
;
373 m_bound_icon
.height
= h
;
374 if (!item
->HasText())
376 AssignRect( m_bound_hilight
, m_bound_icon
);
377 m_bound_hilight
.x
-= 5;
378 m_bound_hilight
.y
-= 5;
379 m_bound_hilight
.width
+= 9;
380 m_bound_hilight
.height
+= 9;
388 dc
->GetTextExtent( s
, &lw
, &lh
);
389 if (m_bound_all
.width
> m_spacing
)
390 m_bound_label
.x
= m_bound_all
.x
;
392 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
393 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
394 m_bound_label
.width
= lw
;
395 m_bound_label
.height
= lh
;
396 AssignRect( m_bound_hilight
, m_bound_label
);
397 m_bound_hilight
.x
-= 2;
398 m_bound_hilight
.y
-= 2;
399 m_bound_hilight
.width
+= 4;
400 m_bound_hilight
.height
+= 4;
407 AssignRect( m_bound_label
, m_bound_all
);
410 m_bound_all
.width
+= 4;
411 m_bound_all
.height
+= 3;
412 AssignRect( m_bound_hilight
, m_bound_all
);
413 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
414 wxNode
*node
= m_items
.First();
417 wxListItemData
*item
= (wxListItemData
*)node
->Data();
418 if (item
->HasImage())
420 m_bound_icon
.x
= m_bound_all
.x
+ 2;
421 m_bound_icon
.y
= m_bound_all
.y
+ 2;
424 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
425 m_bound_icon
.width
= w
;
426 m_bound_icon
.height
= h
;
427 m_bound_label
.x
+= 4 + w
;
428 m_bound_label
.width
-= 4 + w
;
436 dc
->GetTextExtent( "H", &lw
, &lh
);
439 m_bound_all
.height
= lh
+3;
440 m_bound_all
.width
= window_width
;
441 AssignRect( m_bound_hilight
, m_bound_all
);
442 AssignRect( m_bound_label
, m_bound_all
);
443 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
444 wxNode
*node
= m_items
.First();
447 wxListItemData
*item
= (wxListItemData
*)node
->Data();
450 if (s
.IsEmpty()) s
= wxT("H");
452 dc
->GetTextExtent( s
, &lw
, &lh
);
453 m_bound_label
.width
= lw
;
454 m_bound_label
.height
= lh
;
455 if (item
->HasImage())
457 m_bound_icon
.x
= m_bound_all
.x
+ 2;
458 m_bound_icon
.y
= m_bound_all
.y
+ 2;
461 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
462 m_bound_icon
.width
= w
;
463 m_bound_icon
.height
= h
;
464 m_bound_label
.x
+= 4 + w
;
472 void wxListLineData::SetColumnPosition( int index
, int x
)
475 wxNode
*node
= m_items
.Nth( i
);
478 wxListItemData
*item
= (wxListItemData
*)node
->Data();
479 item
->SetPosition( x
, m_bound_all
.y
+1 );
483 void wxListLineData::GetSize( int &width
, int &height
)
485 width
= m_bound_all
.width
;
486 height
= m_bound_all
.height
;
489 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
493 width
= m_bound_all
.width
;
494 height
= m_bound_all
.height
;
497 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
501 width
= m_bound_label
.width
;
502 height
= m_bound_label
.height
;
505 void wxListLineData::GetRect( wxRect
&rect
)
507 AssignRect( rect
, m_bound_all
);
510 long wxListLineData::IsHit( int x
, int y
)
512 wxNode
*node
= m_items
.First();
515 wxListItemData
*item
= (wxListItemData
*)node
->Data();
516 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
517 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
518 // if (!(item->HasImage() || item->HasText())) return 0;
520 // if there is no icon or text = empty
521 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
525 void wxListLineData::InitItems( int num
)
527 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
530 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
532 wxNode
*node
= m_items
.Nth( index
);
535 wxListItemData
*item
= (wxListItemData
*)node
->Data();
536 item
->SetItem( info
);
540 void wxListLineData::GetItem( int index
, wxListItem
&info
)
543 wxNode
*node
= m_items
.Nth( i
);
546 wxListItemData
*item
= (wxListItemData
*)node
->Data();
547 item
->GetItem( info
);
551 void wxListLineData::GetText( int index
, wxString
&s
)
554 wxNode
*node
= m_items
.Nth( i
);
558 wxListItemData
*item
= (wxListItemData
*)node
->Data();
563 void wxListLineData::SetText( int index
, const wxString s
)
566 wxNode
*node
= m_items
.Nth( i
);
569 wxListItemData
*item
= (wxListItemData
*)node
->Data();
574 int wxListLineData::GetImage( int index
)
577 wxNode
*node
= m_items
.Nth( i
);
580 wxListItemData
*item
= (wxListItemData
*)node
->Data();
581 return item
->GetImage();
586 void wxListLineData::SetAttributes(wxDC
*dc
,
587 const wxListItemAttr
*attr
,
588 const wxColour
& colText
,
591 if ( attr
&& attr
->HasTextColour() )
593 dc
->SetTextForeground(attr
->GetTextColour());
597 dc
->SetTextForeground(colText
);
600 if ( attr
&& attr
->HasFont() )
602 dc
->SetFont(attr
->GetFont());
610 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
612 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
613 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
614 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
615 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
617 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
622 wxWindow
*listctrl
= m_owner
->GetParent();
624 // default foreground colour
628 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
632 colText
= listctrl
->GetForegroundColour();
636 wxFont font
= listctrl
->GetFont();
638 // VZ: currently we set the colours/fonts only once, but like this (i.e.
639 // using SetAttributes() inside the loop), it will be trivial to
640 // customize the subitems (in report mode) too.
641 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
642 wxListItemAttr
*attr
= item
->GetAttributes();
643 SetAttributes(dc
, attr
, colText
, font
);
645 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
646 if ( paintBG
|| hasBgCol
)
650 dc
->SetBrush( * m_hilightBrush
);
655 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
657 dc
->SetBrush( * wxWHITE_BRUSH
);
660 dc
->SetPen( * wxTRANSPARENT_PEN
);
661 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
662 m_bound_hilight
.width
, m_bound_hilight
.height
);
665 if (m_mode
== wxLC_REPORT
)
667 wxNode
*node
= m_items
.First();
670 wxListItemData
*item
= (wxListItemData
*)node
->Data();
671 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
672 int x
= item
->GetX();
673 if (item
->HasImage())
676 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
677 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
678 x
+= item
->GetX() + 5;
682 dc
->DrawText( item
->GetText(), x
, item
->GetY() );
684 dc
->DestroyClippingRegion();
690 wxNode
*node
= m_items
.First();
693 wxListItemData
*item
= (wxListItemData
*)node
->Data();
694 if (item
->HasImage())
696 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
700 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
706 void wxListLineData::Hilight( bool on
)
708 if (on
== m_hilighted
) return;
710 m_owner
->SelectLine( this );
712 m_owner
->DeselectLine( this );
716 void wxListLineData::ReverseHilight( void )
718 m_hilighted
= !m_hilighted
;
720 m_owner
->SelectLine( this );
722 m_owner
->DeselectLine( this );
725 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
729 dc
->SetPen( * wxBLACK_PEN
);
730 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
731 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
732 m_bound_hilight
.width
, m_bound_hilight
.height
);
736 void wxListLineData::Draw( wxDC
*dc
)
738 DoDraw( dc
, m_hilighted
, m_hilighted
);
741 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
743 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
744 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
747 bool wxListLineData::IsHilighted( void )
752 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
757 dest
.height
= height
;
760 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
764 dest
.width
= source
.width
;
765 dest
.height
= source
.height
;
768 //-----------------------------------------------------------------------------
769 // wxListHeaderWindow
770 //-----------------------------------------------------------------------------
772 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
774 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
775 EVT_PAINT (wxListHeaderWindow::OnPaint
)
776 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
777 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
780 wxListHeaderWindow::wxListHeaderWindow( void )
782 m_owner
= (wxListMainWindow
*) NULL
;
783 m_currentCursor
= (wxCursor
*) NULL
;
784 m_resizeCursor
= (wxCursor
*) NULL
;
785 m_isDragging
= FALSE
;
788 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
789 const wxPoint
&pos
, const wxSize
&size
,
790 long style
, const wxString
&name
) :
791 wxWindow( win
, id
, pos
, size
, style
, name
)
794 // m_currentCursor = wxSTANDARD_CURSOR;
795 m_currentCursor
= (wxCursor
*) NULL
;
796 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
797 m_isDragging
= FALSE
;
798 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
801 wxListHeaderWindow::~wxListHeaderWindow( void )
803 delete m_resizeCursor
;
806 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
808 const int m_corner
= 1;
810 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
812 dc
->SetPen( *wxBLACK_PEN
);
813 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
814 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
816 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
819 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
820 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
822 dc
->SetPen( *wxWHITE_PEN
);
823 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
824 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
825 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
826 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
829 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
831 wxPaintDC
dc( this );
833 #if wxUSE_GENERIC_LIST_EXTENSIONS
834 if ( m_owner
->GetMode() & wxLC_REPORT
)
839 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
840 m_owner
->ViewStart( &x
, &y
) ;
841 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
846 dc
.SetFont( GetFont() );
852 GetClientSize( &w
, &h
);
854 dc
.SetBackgroundMode(wxTRANSPARENT
);
855 dc
.SetTextForeground( *wxBLACK
);
856 if (m_foregroundColour
.Ok()) dc
.SetTextForeground( m_foregroundColour
);
860 int numColumns
= m_owner
->GetColumnCount();
862 for (int i
= 0; i
< numColumns
; i
++)
864 m_owner
->GetColumn( i
, item
);
865 int cw
= item
.m_width
-2;
866 #if wxUSE_GENERIC_LIST_EXTENSIONS
867 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
868 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
870 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
872 dc
.SetPen( *wxWHITE_PEN
);
874 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
875 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
876 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
877 dc
.DestroyClippingRegion();
879 #if wxUSE_GENERIC_LIST_EXTENSIONS
880 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
888 void wxListHeaderWindow::DrawCurrent()
892 int x2
= m_currentX
-1;
895 m_owner
->GetClientSize( &dummy
, &y2
);
896 ClientToScreen( &x1
, &y1
);
897 m_owner
->ClientToScreen( &x2
, &y2
);
900 dc
.SetLogicalFunction( wxINVERT
);
901 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
902 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
904 dc
.DrawLine( x1
, y1
, x2
, y2
);
906 dc
.SetLogicalFunction( wxCOPY
);
908 dc
.SetPen( wxNullPen
);
909 dc
.SetBrush( wxNullBrush
);
912 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
914 int x
= event
.GetX();
915 int y
= event
.GetY();
919 if (event
.ButtonUp())
922 m_isDragging
= FALSE
;
923 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
929 GetClientSize( &size_x
, & dummy
);
933 m_currentX
= m_minX
+7;
934 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
941 bool hit_border
= FALSE
;
943 for (int j
= 0; j
< m_owner
->GetColumnCount()-1; j
++)
945 xpos
+= m_owner
->GetColumnWidth( j
);
947 if ((abs(x
-xpos
) < 3) && (y
< 22))
959 if (event
.LeftDown())
971 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
972 le
.SetEventObject( GetParent() );
974 GetParent()->GetEventHandler()->ProcessEvent( le
);
983 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
984 m_currentCursor
= m_resizeCursor
;
988 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
989 m_currentCursor
= wxSTANDARD_CURSOR
;
994 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
999 //-----------------------------------------------------------------------------
1000 // wxListRenameTimer (internal)
1001 //-----------------------------------------------------------------------------
1003 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1008 void wxListRenameTimer::Notify()
1010 m_owner
->OnRenameTimer();
1013 //-----------------------------------------------------------------------------
1014 // wxListTextCtrl (internal)
1015 //-----------------------------------------------------------------------------
1017 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1019 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1020 EVT_CHAR (wxListTextCtrl::OnChar
)
1021 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1024 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
1025 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
1026 const wxString
&value
, const wxPoint
&pos
, const wxSize
&size
,
1027 #if wxUSE_VALIDATORS
1028 int style
, const wxValidator
& validator
, const wxString
&name
) :
1030 wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1035 (*m_accept
) = FALSE
;
1037 m_startValue
= value
;
1040 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1042 if (event
.m_keyCode
== WXK_RETURN
)
1045 (*m_res
) = GetValue();
1046 m_owner
->SetFocus();
1049 if (event
.m_keyCode
== WXK_ESCAPE
)
1051 (*m_accept
) = FALSE
;
1053 m_owner
->SetFocus();
1059 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1061 if (wxPendingDelete
.Member(this)) return;
1063 wxPendingDelete
.Append(this);
1065 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1066 m_owner
->OnRenameAccept();
1069 //-----------------------------------------------------------------------------
1071 //-----------------------------------------------------------------------------
1073 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1075 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1076 EVT_PAINT (wxListMainWindow::OnPaint
)
1077 EVT_SIZE (wxListMainWindow::OnSize
)
1078 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1079 EVT_CHAR (wxListMainWindow::OnChar
)
1080 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1081 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1082 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1083 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1086 wxListMainWindow::wxListMainWindow()
1089 m_lines
.DeleteContents( TRUE
);
1090 m_columns
.DeleteContents( TRUE
);
1091 m_current
= (wxListLineData
*) NULL
;
1093 m_hilightBrush
= (wxBrush
*) NULL
;
1097 m_small_image_list
= (wxImageList
*) NULL
;
1098 m_normal_image_list
= (wxImageList
*) NULL
;
1099 m_small_spacing
= 30;
1100 m_normal_spacing
= 40;
1103 m_lastOnSame
= FALSE
;
1104 m_renameTimer
= new wxListRenameTimer( this );
1105 m_isCreated
= FALSE
;
1109 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1110 const wxPoint
&pos
, const wxSize
&size
,
1111 long style
, const wxString
&name
) :
1112 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1115 m_lines
.DeleteContents( TRUE
);
1116 m_columns
.DeleteContents( TRUE
);
1117 m_current
= (wxListLineData
*) NULL
;
1120 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1121 m_small_image_list
= (wxImageList
*) NULL
;
1122 m_normal_image_list
= (wxImageList
*) NULL
;
1123 m_small_spacing
= 30;
1124 m_normal_spacing
= 40;
1127 m_isCreated
= FALSE
;
1131 if (m_mode
& wxLC_REPORT
)
1133 #if wxUSE_GENERIC_LIST_EXTENSIONS
1145 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1148 m_lastOnSame
= FALSE
;
1149 m_renameTimer
= new wxListRenameTimer( this );
1150 m_renameAccept
= FALSE
;
1152 SetBackgroundColour( *wxWHITE
);
1155 wxListMainWindow::~wxListMainWindow()
1157 if (m_hilightBrush
) delete m_hilightBrush
;
1159 delete m_renameTimer
;
1162 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1170 wxClientDC
dc(this);
1172 line
->GetExtent( x
, y
, w
, h
);
1174 dc
.LogicalToDeviceX(x
-3),
1175 dc
.LogicalToDeviceY(y
-3),
1176 dc
.LogicalToDeviceXRel(w
+6),
1177 dc
.LogicalToDeviceXRel(h
+6) );
1178 Refresh( TRUE
, &rect
);
1182 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1184 // Note: a wxPaintDC must be constructed even if no drawing is
1185 // done (a Windows requirement).
1186 wxPaintDC
dc( this );
1189 if (m_dirty
) return;
1191 if (m_lines
.GetCount() == 0) return;
1195 dc
.SetFont( GetFont() );
1197 if (m_mode
& wxLC_REPORT
)
1199 int lineSpacing
= 0;
1200 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1202 line
->GetSize( dummy
, lineSpacing
);
1205 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1207 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1208 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1212 line
= (wxListLineData
*)node
->Data();
1214 node
= node
->Next();
1219 wxNode
*node
= m_lines
.First();
1222 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1224 node
= node
->Next();
1228 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1233 void wxListMainWindow::HilightAll( bool on
)
1235 wxNode
*node
= m_lines
.First();
1238 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1239 if (line
->IsHilighted() != on
)
1241 line
->Hilight( on
);
1242 RefreshLine( line
);
1244 node
= node
->Next();
1248 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1250 wxListEvent
le( command
, GetParent()->GetId() );
1251 le
.SetEventObject( GetParent() );
1252 le
.m_itemIndex
= GetIndexOfLine( line
);
1253 line
->GetItem( 0, le
.m_item
);
1254 // GetParent()->GetEventHandler()->ProcessEvent( le );
1255 GetParent()->GetEventHandler()->AddPendingEvent( le
);
1258 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1260 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1263 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1265 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1268 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1270 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1273 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1275 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1278 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1280 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1285 void wxListMainWindow::EditLabel( long item
)
1287 wxNode
*node
= m_lines
.Nth( item
);
1288 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1290 m_currentEdit
= (wxListLineData
*) node
->Data();
1292 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1293 le
.SetEventObject( GetParent() );
1294 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1295 m_currentEdit
->GetItem( 0, le
.m_item
);
1296 GetParent()->GetEventHandler()->ProcessEvent( le
);
1298 if (!le
.IsAllowed())
1301 // We have to call this here because the label in
1302 // question might just have been added and no screen
1303 // update taken place.
1304 if (m_dirty
) wxYield();
1307 m_currentEdit
->GetText( 0, s
);
1312 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1314 wxClientDC
dc(this);
1316 x
= dc
.LogicalToDeviceX( x
);
1317 y
= dc
.LogicalToDeviceY( y
);
1319 wxListTextCtrl
*text
= new wxListTextCtrl(
1320 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1324 void wxListMainWindow::OnRenameTimer()
1326 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1328 Edit( m_lines
.IndexOf( m_current
) );
1331 void wxListMainWindow::OnRenameAccept()
1333 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1334 le
.SetEventObject( GetParent() );
1335 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1336 m_currentEdit
->GetItem( 0, le
.m_item
);
1337 le
.m_item
.m_text
= m_renameRes
;
1338 GetParent()->GetEventHandler()->ProcessEvent( le
);
1340 if (!le
.IsAllowed()) return;
1343 info
.m_mask
= wxLIST_MASK_TEXT
;
1344 info
.m_itemId
= le
.m_itemIndex
;
1345 info
.m_text
= m_renameRes
;
1346 info
.SetTextColour(le
.m_item
.GetTextColour());
1350 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1352 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1354 if (!m_current
) return;
1355 if (m_dirty
) return;
1356 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1358 wxClientDC
dc(this);
1360 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1361 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1363 /* Did we actually hit an item ? */
1365 wxNode
*node
= m_lines
.First();
1366 wxListLineData
*line
= (wxListLineData
*) NULL
;
1369 line
= (wxListLineData
*)node
->Data();
1370 hitResult
= line
->IsHit( x
, y
);
1371 if (hitResult
) break;
1372 line
= (wxListLineData
*) NULL
;
1373 node
= node
->Next();
1376 if (event
.Dragging())
1378 if (m_dragCount
== 0)
1379 m_dragStart
= wxPoint(x
,y
);
1383 if (m_dragCount
!= 3) return;
1385 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1386 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1388 wxListEvent
le( command
, GetParent()->GetId() );
1389 le
.SetEventObject( GetParent() );
1390 le
.m_pointDrag
= m_dragStart
;
1391 GetParent()->GetEventHandler()->ProcessEvent( le
);
1402 if (event
.ButtonDClick())
1405 m_lastOnSame
= FALSE
;
1406 m_renameTimer
->Stop();
1408 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1413 if (event
.LeftUp() && m_lastOnSame
)
1416 if ((line
== m_current
) &&
1417 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1418 (m_mode
& wxLC_EDIT_LABELS
) )
1420 m_renameTimer
->Start( 100, TRUE
);
1422 m_lastOnSame
= FALSE
;
1426 if (event
.RightDown())
1428 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1432 if (event
.MiddleDown())
1434 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1438 if (event
.LeftDown())
1441 wxListLineData
*oldCurrent
= m_current
;
1442 if (m_mode
& wxLC_SINGLE_SEL
)
1445 HilightAll( FALSE
);
1446 m_current
->ReverseHilight();
1447 RefreshLine( m_current
);
1451 if (event
.ShiftDown())
1454 m_current
->ReverseHilight();
1455 RefreshLine( m_current
);
1457 else if (event
.ControlDown())
1461 int numOfCurrent
= -1;
1462 node
= m_lines
.First();
1465 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1467 if (test_line
== oldCurrent
) break;
1468 node
= node
->Next();
1472 node
= m_lines
.First();
1475 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1477 if (test_line
== line
) break;
1478 node
= node
->Next();
1481 if (numOfLine
< numOfCurrent
)
1484 numOfLine
= numOfCurrent
;
1488 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1489 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1491 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1492 test_line
->Hilight(TRUE
);
1493 RefreshLine( test_line
);
1494 node
= node
->Next();
1500 HilightAll( FALSE
);
1501 m_current
->ReverseHilight();
1502 RefreshLine( m_current
);
1505 if (m_current
!= oldCurrent
)
1507 RefreshLine( oldCurrent
);
1508 UnfocusLine( oldCurrent
);
1509 FocusLine( m_current
);
1511 m_lastOnSame
= (m_current
== oldCurrent
);
1516 void wxListMainWindow::MoveToFocus()
1518 if (!m_current
) return;
1524 m_current
->GetExtent( x
, y
, w
, h
);
1528 GetClientSize( &w_p
, &h_p
);
1530 if (m_mode
& wxLC_REPORT
)
1532 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1533 if ((y
> y_s
) && (y
+h
< y_s
+h_p
)) return;
1534 if (y
-y_s
< 5) { Scroll( -1, (y
-5-h_p
/2)/m_yScroll
); }
1535 if (y
+h
+5 > y_s
+h_p
) { Scroll( -1, (y
+h
-h_p
/2+h
+15)/m_yScroll
); }
1539 int x_s
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1540 if ((x
> x_s
) && (x
+w
< x_s
+w_p
)) return;
1541 if (x
-x_s
< 5) { Scroll( (x
-5)/m_xScroll
, -1 ); }
1542 if (x
+w
-5 > x_s
+w_p
) { Scroll( (x
+w
-w_p
+15)/m_xScroll
, -1 ); }
1546 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1548 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1549 wxListLineData
*oldCurrent
= m_current
;
1550 m_current
= newCurrent
;
1552 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1553 RefreshLine( m_current
);
1554 RefreshLine( oldCurrent
);
1555 FocusLine( m_current
);
1556 UnfocusLine( oldCurrent
);
1559 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1561 wxWindow
*parent
= GetParent();
1563 /* we propagate the key event up */
1564 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1565 ke
.m_shiftDown
= event
.m_shiftDown
;
1566 ke
.m_controlDown
= event
.m_controlDown
;
1567 ke
.m_altDown
= event
.m_altDown
;
1568 ke
.m_metaDown
= event
.m_metaDown
;
1569 ke
.m_keyCode
= event
.m_keyCode
;
1572 ke
.SetEventObject( parent
);
1573 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1578 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1580 wxWindow
*parent
= GetParent();
1582 /* we send a list_key event up */
1583 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1584 le
.m_code
= event
.KeyCode();
1585 le
.SetEventObject( parent
);
1586 parent
->GetEventHandler()->ProcessEvent( le
);
1588 /* we propagate the char event up */
1589 wxKeyEvent
ke( wxEVT_CHAR
);
1590 ke
.m_shiftDown
= event
.m_shiftDown
;
1591 ke
.m_controlDown
= event
.m_controlDown
;
1592 ke
.m_altDown
= event
.m_altDown
;
1593 ke
.m_metaDown
= event
.m_metaDown
;
1594 ke
.m_keyCode
= event
.m_keyCode
;
1597 ke
.SetEventObject( parent
);
1598 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1600 if (event
.KeyCode() == WXK_TAB
)
1602 wxNavigationKeyEvent nevent
;
1603 nevent
.SetDirection( !event
.ShiftDown() );
1604 nevent
.SetCurrentFocus( m_parent
);
1605 if (m_parent
->GetEventHandler()->ProcessEvent( nevent
)) return;
1608 /* no item -> nothing to do */
1615 switch (event
.KeyCode())
1619 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1620 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1625 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1626 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1631 wxNode
*node
= m_lines
.Last();
1632 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1637 wxNode
*node
= m_lines
.First();
1638 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1644 if (m_mode
& wxLC_REPORT
)
1646 steps
= m_visibleLines
-1;
1651 wxNode
*node
= m_lines
.First();
1652 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1653 steps
= pos
% m_visibleLines
;
1655 wxNode
*node
= m_lines
.Member( m_current
);
1656 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1657 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1663 if (m_mode
& wxLC_REPORT
)
1665 steps
= m_visibleLines
-1;
1669 int pos
= 0; wxNode
*node
= m_lines
.First();
1670 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
1671 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1673 wxNode
*node
= m_lines
.Member( m_current
);
1674 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1675 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1680 if (!(m_mode
& wxLC_REPORT
))
1682 wxNode
*node
= m_lines
.Member( m_current
);
1683 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1684 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1690 if (!(m_mode
& wxLC_REPORT
))
1692 wxNode
*node
= m_lines
.Member( m_current
);
1693 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1694 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1700 m_current
->ReverseHilight();
1701 RefreshLine( m_current
);
1706 if (!(m_mode
& wxLC_SINGLE_SEL
))
1708 wxListLineData
*oldCurrent
= m_current
;
1709 m_current
->ReverseHilight();
1710 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1711 if (node
) m_current
= (wxListLineData
*)node
->Data();
1713 RefreshLine( oldCurrent
);
1714 RefreshLine( m_current
);
1715 UnfocusLine( oldCurrent
);
1716 FocusLine( m_current
);
1723 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
1724 le
.SetEventObject( GetParent() );
1725 le
.m_itemIndex
= GetIndexOfLine( m_current
);
1726 m_current
->GetItem( 0, le
.m_item
);
1727 GetParent()->GetEventHandler()->ProcessEvent( le
);
1740 extern wxWindow
*g_focusWindow
;
1743 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1746 RefreshLine( m_current
);
1748 if (!GetParent()) return;
1751 g_focusWindow
= GetParent();
1754 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
1755 event
.SetEventObject( GetParent() );
1756 GetParent()->GetEventHandler()->ProcessEvent( event
);
1759 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1762 RefreshLine( m_current
);
1765 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1768 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1773 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
1775 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1777 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1780 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1782 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1784 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1786 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1788 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1790 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1795 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1797 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1799 m_normal_image_list
->GetSize( index
, width
, height
);
1802 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1804 m_small_image_list
->GetSize( index
, width
, height
);
1807 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
1809 m_small_image_list
->GetSize( index
, width
, height
);
1812 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
1814 m_small_image_list
->GetSize( index
, width
, height
);
1821 int wxListMainWindow::GetTextLength( wxString
&s
)
1823 wxClientDC
dc( this );
1826 dc
.GetTextExtent( s
, &lw
, &lh
);
1830 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1833 wxNode
*node
= m_lines
.First();
1836 if (line
== (wxListLineData
*)node
->Data()) return i
;
1838 node
= node
->Next();
1843 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1846 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1847 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1850 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1855 m_small_spacing
= spacing
;
1859 m_normal_spacing
= spacing
;
1863 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1865 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1868 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1871 wxNode
*node
= m_columns
.Nth( col
);
1874 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1875 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1876 column
->SetItem( item
);
1878 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1879 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1882 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1884 if (!(m_mode
& wxLC_REPORT
)) return;
1888 wxNode
*node
= (wxNode
*) NULL
;
1890 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
1891 if (width
== wxLIST_AUTOSIZE
)
1893 wxClientDC
dc(this);
1894 dc
.SetFont( GetFont() );
1896 node
= m_lines
.First();
1899 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1900 wxNode
*n
= line
->m_items
.Nth( col
);
1903 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1904 int current
= 0, ix
= 0, iy
= 0;
1905 long lx
= 0, ly
= 0;
1906 if (item
->HasImage())
1908 GetImageSize( item
->GetImage(), ix
, iy
);
1911 if (item
->HasText())
1914 item
->GetText( str
);
1915 dc
.GetTextExtent( str
, &lx
, &ly
);
1918 if (current
> max
) max
= current
;
1920 node
= node
->Next();
1925 node
= m_columns
.Nth( col
);
1928 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1929 column
->SetWidth( width
);
1932 node
= m_lines
.First();
1935 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1936 wxNode
*n
= line
->m_items
.Nth( col
);
1939 wxListItemData
*item
= (wxListItemData
*)n
->Data();
1940 item
->SetSize( width
, -1 );
1942 node
= node
->Next();
1945 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
1946 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
1949 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1951 wxNode
*node
= m_columns
.Nth( col
);
1954 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1955 column
->GetItem( item
);
1967 int wxListMainWindow::GetColumnWidth( int col
)
1969 wxNode
*node
= m_columns
.Nth( col
);
1972 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1973 return column
->GetWidth();
1981 int wxListMainWindow::GetColumnCount()
1983 return m_columns
.Number();
1986 int wxListMainWindow::GetCountPerPage()
1988 return m_visibleLines
;
1991 void wxListMainWindow::SetItem( wxListItem
&item
)
1994 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1997 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1998 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1999 line
->SetItem( item
.m_col
, item
);
2003 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2005 // m_dirty = TRUE; no recalcs needed
2007 wxListLineData
*oldCurrent
= m_current
;
2009 if (stateMask
& wxLIST_STATE_FOCUSED
)
2011 wxNode
*node
= m_lines
.Nth( item
);
2014 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2015 UnfocusLine( m_current
);
2017 FocusLine( m_current
);
2018 RefreshLine( m_current
);
2019 if (oldCurrent
) RefreshLine( oldCurrent
);
2023 if (stateMask
& wxLIST_STATE_SELECTED
)
2025 bool on
= state
& wxLIST_STATE_SELECTED
;
2026 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2028 wxNode
*node
= m_lines
.Nth( item
);
2031 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2032 if (m_mode
& wxLC_SINGLE_SEL
)
2034 UnfocusLine( m_current
);
2036 FocusLine( m_current
);
2037 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2038 RefreshLine( m_current
);
2039 if (oldCurrent
) RefreshLine( oldCurrent
);
2041 bool on
= state
& wxLIST_STATE_SELECTED
;
2042 if (on
!= line
->IsHilighted())
2044 line
->Hilight( on
);
2045 RefreshLine( line
);
2051 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2053 int ret
= wxLIST_STATE_DONTCARE
;
2054 if (stateMask
& wxLIST_STATE_FOCUSED
)
2056 wxNode
*node
= m_lines
.Nth( item
);
2059 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2060 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2063 if (stateMask
& wxLIST_STATE_SELECTED
)
2065 wxNode
*node
= m_lines
.Nth( item
);
2068 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2069 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2075 void wxListMainWindow::GetItem( wxListItem
&item
)
2077 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2080 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2081 line
->GetItem( item
.m_col
, item
);
2092 int wxListMainWindow::GetItemCount()
2094 return m_lines
.Number();
2097 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2099 wxNode
*node
= m_lines
.Nth( index
);
2102 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2103 line
->GetRect( rect
);
2114 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2116 wxNode
*node
= m_lines
.Nth( item
);
2120 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2121 line
->GetRect( rect
);
2133 int wxListMainWindow::GetSelectedItemCount()
2136 wxNode
*node
= m_lines
.First();
2139 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2140 if (line
->IsHilighted()) ret
++;
2141 node
= node
->Next();
2146 void wxListMainWindow::SetMode( long mode
)
2153 if (m_mode
& wxLC_REPORT
)
2155 #if wxUSE_GENERIC_LIST_EXTENSIONS
2169 long wxListMainWindow::GetMode() const
2174 void wxListMainWindow::CalculatePositions()
2176 if (!m_lines
.First()) return;
2178 wxClientDC
dc( this );
2179 dc
.SetFont( GetFont() );
2181 int iconSpacing
= 0;
2182 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2183 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2185 // we take the first line (which also can be an icon or
2186 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2187 // measure the size of the line
2191 int lineSpacing
= 0;
2193 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2194 line
->CalculateSize( &dc
, iconSpacing
);
2196 line
->GetSize( dummy
, lineSpacing
);
2199 int clientWidth
= 0;
2200 int clientHeight
= 0;
2202 if (m_mode
& wxLC_REPORT
)
2206 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2207 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2208 #if wxUSE_GENERIC_LIST_EXTENSIONS
2209 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2211 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2213 GetClientSize( &clientWidth
, &clientHeight
);
2215 wxNode
* node
= m_lines
.First();
2216 int entireWidth
= 0 ;
2219 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2220 line
->CalculateSize( &dc
, iconSpacing
);
2221 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2223 for (int i
= 0; i
< GetColumnCount(); i
++)
2225 line
->SetColumnPosition( i
, col_x
);
2226 col_x
+= GetColumnWidth( i
);
2228 entireWidth
= wxMax( entireWidth
, col_x
) ;
2229 #if wxUSE_GENERIC_LIST_EXTENSIONS
2230 line
->SetPosition( &dc
, x
, y
, col_x
);
2232 y
+= lineSpacing
; // one pixel blank line between items
2233 node
= node
->Next();
2235 m_visibleLines
= clientHeight
/ lineSpacing
;
2236 #if wxUSE_GENERIC_LIST_EXTENSIONS
2237 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2242 // at first we try without any scrollbar. if the items don't
2243 // fit into the window, we recalculate after subtracting an
2244 // approximated 15 pt for the horizontal scrollbar
2246 GetSize( &clientWidth
, &clientHeight
);
2247 clientHeight
-= 4; // sunken frame
2249 int entireWidth
= 0;
2251 for (int tries
= 0; tries
< 2; tries
++)
2254 int x
= 5; // painting is done at x-2
2255 int y
= 5; // painting is done at y-2
2258 int m_currentVisibleLines
= 0;
2259 wxNode
*node
= m_lines
.First();
2262 m_currentVisibleLines
++;
2263 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2264 line
->CalculateSize( &dc
, iconSpacing
);
2265 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2266 line
->GetSize( lineWidth
, lineHeight
);
2267 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2269 if (m_currentVisibleLines
> m_visibleLines
)
2270 m_visibleLines
= m_currentVisibleLines
;
2271 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2273 m_currentVisibleLines
= 0;
2276 entireWidth
+= maxWidth
+6;
2279 node
= node
->Next();
2280 if (!node
) entireWidth
+= maxWidth
;
2281 if ((tries
== 0) && (entireWidth
> clientWidth
))
2283 clientHeight
-= 15; // scrollbar height
2285 m_currentVisibleLines
= 0;
2288 if (!node
) tries
= 1; // everything fits, no second try required
2292 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2293 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2297 void wxListMainWindow::RealizeChanges( void )
2301 wxNode
*node
= m_lines
.First();
2302 if (node
) m_current
= (wxListLineData
*)node
->Data();
2306 FocusLine( m_current
);
2307 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2311 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
2314 if (item
> 0) ret
= item
;
2315 if(ret
>= GetItemCount()) return -1;
2316 wxNode
*node
= m_lines
.Nth( ret
);
2319 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2320 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
2321 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
2322 if (!state
) return ret
;
2324 node
= node
->Next();
2329 void wxListMainWindow::DeleteItem( long index
)
2332 wxNode
*node
= m_lines
.Nth( index
);
2335 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2336 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2338 m_lines
.DeleteNode( node
);
2342 void wxListMainWindow::DeleteColumn( int col
)
2344 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2345 wxT("attempting to delete inexistent column in wxListView") );
2348 wxNode
*node
= m_columns
.Nth( col
);
2349 if (node
) m_columns
.DeleteNode( node
);
2352 void wxListMainWindow::DeleteAllItems( void )
2355 m_current
= (wxListLineData
*) NULL
;
2357 // to make the deletion of all items faster, we don't send the
2358 // notifications in this case: this is compatible with wxMSW and
2359 // documented in DeleteAllItems() description
2361 wxNode
*node
= m_lines
.First();
2364 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2368 node
= node
->Next();
2375 void wxListMainWindow::DeleteEverything( void )
2378 m_current
= (wxListLineData
*) NULL
;
2379 wxNode
*node
= m_lines
.First();
2382 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2384 node
= node
->Next();
2387 m_current
= (wxListLineData
*) NULL
;
2391 void wxListMainWindow::EnsureVisible( long index
)
2393 // We have to call this here because the label in
2394 // question might just have been added and no screen
2395 // update taken place.
2396 if (m_dirty
) wxYield();
2398 wxListLineData
*oldCurrent
= m_current
;
2399 m_current
= (wxListLineData
*) NULL
;
2401 wxNode
*node
= m_lines
.Nth( i
);
2402 if (node
) m_current
= (wxListLineData
*)node
->Data();
2403 if (m_current
) MoveToFocus();
2404 m_current
= oldCurrent
;
2407 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2411 if (pos
< 0) pos
= 0;
2412 wxNode
*node
= m_lines
.Nth( pos
);
2415 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2417 line
->GetText( 0, s
);
2418 if (s
== tmp
) return pos
;
2419 node
= node
->Next();
2425 long wxListMainWindow::FindItem(long start
, long data
)
2428 if (pos
< 0) pos
= 0;
2429 wxNode
*node
= m_lines
.Nth( pos
);
2432 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2434 line
->GetItem( 0, item
);
2435 if (item
.m_data
== data
) return pos
;
2436 node
= node
->Next();
2442 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2444 wxNode
*node
= m_lines
.First();
2448 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2449 long ret
= line
->IsHit( x
, y
);
2455 node
= node
->Next();
2461 void wxListMainWindow::InsertItem( wxListItem
&item
)
2465 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2466 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2467 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2468 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2470 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2472 if (m_mode
& wxLC_REPORT
)
2474 line
->InitItems( GetColumnCount() );
2475 item
.m_width
= GetColumnWidth( 0 )-3;
2479 line
->InitItems( 1 );
2482 line
->SetItem( 0, item
);
2483 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2485 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
2486 if (node
) m_lines
.Insert( node
, line
);
2490 m_lines
.Append( line
);
2494 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2497 if (m_mode
& wxLC_REPORT
)
2499 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2500 wxListHeaderData
*column
= new wxListHeaderData( item
);
2501 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2503 wxNode
*node
= m_columns
.Nth( col
);
2505 m_columns
.Insert( node
, column
);
2509 m_columns
.Append( column
);
2514 wxListCtrlCompare list_ctrl_compare_func_2
;
2515 long list_ctrl_compare_data
;
2517 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2519 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2520 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2522 line1
->GetItem( 0, item
);
2523 long data1
= item
.m_data
;
2524 line2
->GetItem( 0, item
);
2525 long data2
= item
.m_data
;
2526 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2529 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2531 list_ctrl_compare_func_2
= fn
;
2532 list_ctrl_compare_data
= data
;
2533 m_lines
.Sort( list_ctrl_compare_func_1
);
2536 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2538 wxScrolledWindow::OnScroll( event
) ;
2539 #if wxUSE_GENERIC_LIST_EXTENSIONS
2541 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2543 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2546 lc
->m_headerWin
->Refresh() ;
2548 lc
->m_headerWin
->MacUpdateImmediately() ;
2555 // -------------------------------------------------------------------------------------
2557 // -------------------------------------------------------------------------------------
2559 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2561 wxListItem::wxListItem()
2570 m_format
= wxLIST_FORMAT_CENTRE
;
2576 // -------------------------------------------------------------------------------------
2578 // -------------------------------------------------------------------------------------
2580 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2582 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2583 wxNotifyEvent( commandType
, id
)
2589 m_cancelled
= FALSE
;
2594 void wxListEvent::CopyObject(wxObject
& object_dest
) const
2596 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
2598 wxNotifyEvent::CopyObject(object_dest
);
2600 obj
->m_code
= m_code
;
2601 obj
->m_itemIndex
= m_itemIndex
;
2602 obj
->m_oldItemIndex
= m_oldItemIndex
;
2604 obj
->m_cancelled
= m_cancelled
;
2605 obj
->m_pointDrag
= m_pointDrag
;
2606 obj
->m_item
.m_mask
= m_item
.m_mask
;
2607 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
2608 obj
->m_item
.m_col
= m_item
.m_col
;
2609 obj
->m_item
.m_state
= m_item
.m_state
;
2610 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
2611 obj
->m_item
.m_text
= m_item
.m_text
;
2612 obj
->m_item
.m_image
= m_item
.m_image
;
2613 obj
->m_item
.m_data
= m_item
.m_data
;
2614 obj
->m_item
.m_format
= m_item
.m_format
;
2615 obj
->m_item
.m_width
= m_item
.m_width
;
2617 if ( m_item
.HasAttributes() )
2619 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
2623 // -------------------------------------------------------------------------------------
2625 // -------------------------------------------------------------------------------------
2627 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2629 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2630 EVT_SIZE (wxListCtrl::OnSize
)
2631 EVT_IDLE (wxListCtrl::OnIdle
)
2634 wxListCtrl::wxListCtrl()
2636 m_imageListNormal
= (wxImageList
*) NULL
;
2637 m_imageListSmall
= (wxImageList
*) NULL
;
2638 m_imageListState
= (wxImageList
*) NULL
;
2639 m_mainWin
= (wxListMainWindow
*) NULL
;
2640 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2643 wxListCtrl::~wxListCtrl()
2647 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2648 const wxPoint
&pos
, const wxSize
&size
,
2649 #if wxUSE_VALIDATORS
2650 long style
, const wxValidator
&validator
,
2652 const wxString
&name
)
2654 m_imageListNormal
= (wxImageList
*) NULL
;
2655 m_imageListSmall
= (wxImageList
*) NULL
;
2656 m_imageListState
= (wxImageList
*) NULL
;
2657 m_mainWin
= (wxListMainWindow
*) NULL
;
2658 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2663 #pragma message disable codcauunr
2664 // VMS reports on this part the warning:
2665 // statement either is unreachable or causes unreachable code
2667 if ((s
& wxLC_REPORT
== 0) &&
2668 (s
& wxLC_LIST
== 0) &&
2669 (s
& wxLC_ICON
== 0))
2674 #pragma message enable codcauunr
2677 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2679 #if wxUSE_VALIDATORS
2680 SetValidator( validator
);
2683 if (s
& wxSUNKEN_BORDER
) s
-= wxSUNKEN_BORDER
;
2685 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2687 if (HasFlag(wxLC_REPORT
))
2688 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
2690 m_headerWin
= (wxListHeaderWindow
*) NULL
;
2692 SetBackgroundColour( *wxWHITE
);
2697 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2699 /* handled in OnIdle */
2701 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2704 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2706 long flag
= GetWindowStyle();
2710 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2711 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2712 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2721 if (flag
& style
) flag
-= style
;
2724 SetWindowStyleFlag( flag
);
2727 void wxListCtrl::SetWindowStyleFlag( long flag
)
2731 m_mainWin
->DeleteEverything();
2735 GetClientSize( &width
, &height
);
2737 m_mainWin
->SetMode( flag
);
2739 if (flag
& wxLC_REPORT
)
2741 if (!HasFlag(wxLC_REPORT
))
2745 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
2746 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
2747 if (HasFlag(wxLC_NO_HEADER
))
2748 m_headerWin
->Show( FALSE
);
2752 if (flag
& wxLC_NO_HEADER
)
2753 m_headerWin
->Show( FALSE
);
2755 m_headerWin
->Show( TRUE
);
2761 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
2763 m_headerWin
->Show( FALSE
);
2768 wxWindow::SetWindowStyleFlag( flag
);
2771 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
2773 m_mainWin
->GetColumn( col
, item
);
2777 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2779 m_mainWin
->SetColumn( col
, item
);
2783 int wxListCtrl::GetColumnWidth( int col
) const
2785 return m_mainWin
->GetColumnWidth( col
);
2788 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2790 m_mainWin
->SetColumnWidth( col
, width
);
2794 int wxListCtrl::GetCountPerPage() const
2796 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2799 bool wxListCtrl::GetItem( wxListItem
&info
) const
2801 m_mainWin
->GetItem( info
);
2805 bool wxListCtrl::SetItem( wxListItem
&info
)
2807 m_mainWin
->SetItem( info
);
2811 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2814 info
.m_text
= label
;
2815 info
.m_mask
= wxLIST_MASK_TEXT
;
2816 info
.m_itemId
= index
;
2820 info
.m_image
= imageId
;
2821 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2823 m_mainWin
->SetItem(info
);
2827 int wxListCtrl::GetItemState( long item
, long stateMask
) const
2829 return m_mainWin
->GetItemState( item
, stateMask
);
2832 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2834 m_mainWin
->SetItemState( item
, state
, stateMask
);
2838 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2841 info
.m_image
= image
;
2842 info
.m_mask
= wxLIST_MASK_IMAGE
;
2843 info
.m_itemId
= item
;
2844 m_mainWin
->SetItem( info
);
2848 wxString
wxListCtrl::GetItemText( long item
) const
2851 info
.m_itemId
= item
;
2852 m_mainWin
->GetItem( info
);
2856 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2859 info
.m_mask
= wxLIST_MASK_TEXT
;
2860 info
.m_itemId
= item
;
2862 m_mainWin
->SetItem( info
);
2865 long wxListCtrl::GetItemData( long item
) const
2868 info
.m_itemId
= item
;
2869 m_mainWin
->GetItem( info
);
2873 bool wxListCtrl::SetItemData( long item
, long data
)
2876 info
.m_mask
= wxLIST_MASK_DATA
;
2877 info
.m_itemId
= item
;
2879 m_mainWin
->SetItem( info
);
2883 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
2885 m_mainWin
->GetItemRect( item
, rect
);
2889 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
2891 m_mainWin
->GetItemPosition( item
, pos
);
2895 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2900 int wxListCtrl::GetItemCount() const
2902 return m_mainWin
->GetItemCount();
2905 int wxListCtrl::GetColumnCount() const
2907 return m_mainWin
->GetColumnCount();
2910 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2912 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2915 int wxListCtrl::GetItemSpacing( bool isSmall
) const
2917 return m_mainWin
->GetItemSpacing( isSmall
);
2920 int wxListCtrl::GetSelectedItemCount() const
2922 return m_mainWin
->GetSelectedItemCount();
2925 wxColour
wxListCtrl::GetTextColour() const
2927 return GetForegroundColour();
2930 void wxListCtrl::SetTextColour(const wxColour
& col
)
2932 SetForegroundColour(col
);
2935 long wxListCtrl::GetTopItem() const
2940 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2942 return m_mainWin
->GetNextItem( item
, geom
, state
);
2945 wxImageList
*wxListCtrl::GetImageList(int which
) const
2947 if (which
== wxIMAGE_LIST_NORMAL
)
2949 return m_imageListNormal
;
2951 else if (which
== wxIMAGE_LIST_SMALL
)
2953 return m_imageListSmall
;
2955 else if (which
== wxIMAGE_LIST_STATE
)
2957 return m_imageListState
;
2959 return (wxImageList
*) NULL
;
2962 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2964 m_mainWin
->SetImageList( imageList
, which
);
2967 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2972 bool wxListCtrl::DeleteItem( long item
)
2974 m_mainWin
->DeleteItem( item
);
2978 bool wxListCtrl::DeleteAllItems()
2980 m_mainWin
->DeleteAllItems();
2984 bool wxListCtrl::DeleteAllColumns()
2986 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
2992 void wxListCtrl::ClearAll()
2994 m_mainWin
->DeleteEverything();
2997 bool wxListCtrl::DeleteColumn( int col
)
2999 m_mainWin
->DeleteColumn( col
);
3003 void wxListCtrl::Edit( long item
)
3005 m_mainWin
->Edit( item
);
3008 bool wxListCtrl::EnsureVisible( long item
)
3010 m_mainWin
->EnsureVisible( item
);
3014 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3016 return m_mainWin
->FindItem( start
, str
, partial
);
3019 long wxListCtrl::FindItem( long start
, long data
)
3021 return m_mainWin
->FindItem( start
, data
);
3024 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3025 int WXUNUSED(direction
))
3030 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3032 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3035 long wxListCtrl::InsertItem( wxListItem
& info
)
3037 m_mainWin
->InsertItem( info
);
3038 return info
.m_itemId
;
3041 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3044 info
.m_text
= label
;
3045 info
.m_mask
= wxLIST_MASK_TEXT
;
3046 info
.m_itemId
= index
;
3047 return InsertItem( info
);
3050 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3053 info
.m_mask
= wxLIST_MASK_IMAGE
;
3054 info
.m_image
= imageIndex
;
3055 info
.m_itemId
= index
;
3056 return InsertItem( info
);
3059 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3062 info
.m_text
= label
;
3063 info
.m_image
= imageIndex
;
3064 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3065 info
.m_itemId
= index
;
3066 return InsertItem( info
);
3069 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3071 m_mainWin
->InsertColumn( col
, item
);
3075 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3076 int format
, int width
)
3079 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3080 item
.m_text
= heading
;
3083 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3084 item
.m_width
= width
;
3086 item
.m_format
= format
;
3088 return InsertColumn( col
, item
);
3091 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3097 // fn is a function which takes 3 long arguments: item1, item2, data.
3098 // item1 is the long data associated with a first item (NOT the index).
3099 // item2 is the long data associated with a second item (NOT the index).
3100 // data is the same value as passed to SortItems.
3101 // The return value is a negative number if the first item should precede the second
3102 // item, a positive number of the second item should precede the first,
3103 // or zero if the two items are equivalent.
3104 // data is arbitrary data to be passed to the sort function.
3106 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3108 m_mainWin
->SortItems( fn
, data
);
3112 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3114 if (!m_mainWin
->m_dirty
) return;
3118 GetClientSize( &cw
, &ch
);
3125 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3127 m_headerWin
->GetPosition( &x
, &y
);
3128 m_headerWin
->GetSize( &w
, &h
);
3129 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3130 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3132 m_mainWin
->GetPosition( &x
, &y
);
3133 m_mainWin
->GetSize( &w
, &h
);
3134 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3135 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3139 m_mainWin
->GetPosition( &x
, &y
);
3140 m_mainWin
->GetSize( &w
, &h
);
3141 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3142 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3145 m_mainWin
->CalculatePositions();
3146 m_mainWin
->RealizeChanges();
3147 m_mainWin
->m_dirty
= FALSE
;
3148 m_mainWin
->Refresh();
3151 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3153 if ( !wxWindow::SetBackgroundColour( colour
) )
3158 m_mainWin
->SetBackgroundColour( colour
);
3159 m_mainWin
->m_dirty
= TRUE
;
3164 // m_headerWin->SetBackgroundColour( colour );
3170 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3172 if ( !wxWindow::SetForegroundColour( colour
) )
3177 m_mainWin
->SetForegroundColour( colour
);
3178 m_mainWin
->m_dirty
= TRUE
;
3183 m_headerWin
->SetForegroundColour( colour
);
3189 bool wxListCtrl::SetFont( const wxFont
&font
)
3191 if ( !wxWindow::SetFont( font
) )
3196 m_mainWin
->SetFont( font
);
3197 m_mainWin
->m_dirty
= TRUE
;
3202 m_headerWin
->SetFont( font
);