1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "listctrl.h"
15 #include "wx/listctrl.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
23 wxListItemData::wxListItemData(void)
34 wxListItemData::wxListItemData( const wxListItem
&info
)
38 m_colour
= info
.m_colour
;
42 void wxListItemData::SetItem( const wxListItem
&info
)
44 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
45 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
46 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
47 m_colour
= info
.m_colour
;
50 m_width
= info
.m_width
;
54 void wxListItemData::SetText( const wxString
&s
)
59 void wxListItemData::SetImage( int image
)
64 void wxListItemData::SetData( long data
)
69 void wxListItemData::SetPosition( int x
, int y
)
75 void wxListItemData::SetSize( int const width
, int height
)
81 void wxListItemData::SetColour( wxColour
*col
)
86 bool wxListItemData::HasImage(void) const
88 return (m_image
>= 0);
91 bool wxListItemData::HasText(void) const
93 return (!m_text
.IsNull());
96 bool wxListItemData::IsHit( int x
, int y
) const
98 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
101 void wxListItemData::GetText( wxString
&s
)
106 int wxListItemData::GetX( void ) const
111 int wxListItemData::GetY( void ) const
116 int wxListItemData::GetWidth(void) const
121 int wxListItemData::GetHeight(void) const
126 int wxListItemData::GetImage(void) const
131 void wxListItemData::GetItem( wxListItem
&info
)
133 info
.m_text
= m_text
;
134 info
.m_image
= m_image
;
135 info
.m_data
= m_data
;
138 wxColour
*wxListItemData::GetColour(void)
143 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
147 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
149 wxListHeaderData::wxListHeaderData(void)
160 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
168 void wxListHeaderData::SetItem( const wxListItem
&item
)
170 m_mask
= item
.m_mask
;
171 m_text
= item
.m_text
;
172 m_image
= item
.m_image
;
173 m_format
= item
.m_format
;
174 m_width
= item
.m_width
;
175 if (m_width
< 0) m_width
= 80;
176 if (m_width
< 6) m_width
= 6;
179 void wxListHeaderData::SetPosition( int x
, int y
)
185 void wxListHeaderData::SetHeight( int h
)
190 void wxListHeaderData::SetWidth( int w
)
193 if (m_width
< 0) m_width
= 80;
194 if (m_width
< 6) m_width
= 6;
197 void wxListHeaderData::SetFormat( int format
)
202 bool wxListHeaderData::HasImage(void) const
204 return (m_image
!= 0);
207 bool wxListHeaderData::HasText(void) const
209 return (m_text
.Length() > 0);
212 bool wxListHeaderData::IsHit( int x
, int y
) const
214 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
217 void wxListHeaderData::GetItem( wxListItem
&item
)
219 item
.m_mask
= m_mask
;
220 item
.m_text
= m_text
;
221 item
.m_image
= m_image
;
222 item
.m_format
= m_format
;
223 item
.m_width
= m_width
;
226 void wxListHeaderData::GetText( wxString
&s
)
231 int wxListHeaderData::GetImage(void) const
236 int wxListHeaderData::GetWidth(void) const
241 int wxListHeaderData::GetFormat(void) const
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
250 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
252 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
257 m_hilightBrush
= hilightBrush
;
258 m_items
.DeleteContents( TRUE
);
262 void wxListLineData::CalculateSize( wxPaintDC
*dc
, int spacing
)
269 m_bound_all
.width
= m_spacing
;
270 m_bound_all
.height
= m_spacing
+13;
271 wxNode
*node
= m_items
.First();
274 wxListItemData
*item
= (wxListItemData
*)node
->Data();
278 dc
->GetTextExtent( s
, &lw
, &lh
);
279 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
285 wxNode
*node
= m_items
.First();
288 wxListItemData
*item
= (wxListItemData
*)node
->Data();
292 dc
->GetTextExtent( s
, &lw
, &lh
);
293 m_bound_all
.width
= lw
;
294 m_bound_all
.height
= lh
;
300 m_bound_all
.width
= 0;
301 m_bound_all
.height
= 0;
302 wxNode
*node
= m_items
.First();
305 wxListItemData
*item
= (wxListItemData
*)node
->Data();
308 if (s
.IsNull()) s
= "H";
310 dc
->GetTextExtent( s
, &lw
, &lh
);
311 item
->SetSize( item
->GetWidth(), lh
);
312 m_bound_all
.width
+= lw
;
313 m_bound_all
.height
= lh
;
321 void wxListLineData::SetPosition( wxPaintDC
*dc
, int x
, int y
, int window_width
)
329 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
330 AssignRect( m_bound_label
, 0, 0, 0, 0 );
331 AssignRect( m_bound_hilight
, m_bound_all
);
332 wxNode
*node
= m_items
.First();
335 wxListItemData
*item
= (wxListItemData
*)node
->Data();
336 if (item
->HasImage())
338 wxListItemData
*item
= (wxListItemData
*)node
->Data();
341 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
342 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
343 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
344 m_bound_icon
.width
= w
;
345 m_bound_icon
.height
= h
;
346 if (!item
->HasText())
348 AssignRect( m_bound_hilight
, m_bound_icon
);
349 m_bound_hilight
.x
-= 3;
350 m_bound_hilight
.y
-= 3;
351 m_bound_hilight
.width
+= 7;
352 m_bound_hilight
.height
+= 7;
360 dc
->GetTextExtent( s
, &lw
, &lh
);
361 if (m_bound_all
.width
> m_spacing
)
362 m_bound_label
.x
= m_bound_all
.x
;
364 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
365 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
366 m_bound_label
.width
= lw
;
367 m_bound_label
.height
= lh
;
368 AssignRect( m_bound_hilight
, m_bound_label
);
375 AssignRect( m_bound_label
, m_bound_all
);
376 AssignRect( m_bound_hilight
, m_bound_all
);
377 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
383 dc
->GetTextExtent( "H", &lw
, &lh
);
384 m_bound_all
.height
= lh
;
385 m_bound_all
.width
= window_width
;
386 AssignRect( m_bound_label
, m_bound_all
);
387 AssignRect( m_bound_hilight
, m_bound_all
);
388 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
389 m_bound_hilight
.width
= window_width
-10;
390 m_bound_label
.width
= window_width
-10;
396 void wxListLineData::SetColumnPosition( int index
, int x
)
399 wxNode
*node
= m_items
.Nth( i
);
402 wxListItemData
*item
= (wxListItemData
*)node
->Data();
403 item
->SetPosition( x
, m_bound_all
.y
);
407 void wxListLineData::GetSize( int &width
, int &height
)
409 width
= m_bound_all
.width
;
410 height
= m_bound_all
.height
;
413 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
417 width
= m_bound_all
.width
;
418 height
= m_bound_all
.height
;
421 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
425 width
= m_bound_label
.width
;
426 height
= m_bound_label
.height
;
429 void wxListLineData::GetRect( wxRectangle
&rect
)
431 AssignRect( rect
, m_bound_all
);
434 long wxListLineData::IsHit( int x
, int y
)
436 wxNode
*node
= m_items
.First();
439 wxListItemData
*item
= (wxListItemData
*)node
->Data();
440 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
441 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
442 // if (!(item->HasImage() || item->HasText())) return 0;
444 // if there is no icon or text = empty
445 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
449 void wxListLineData::InitItems( int num
)
451 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
454 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
456 wxNode
*node
= m_items
.Nth( index
);
459 wxListItemData
*item
= (wxListItemData
*)node
->Data();
460 item
->SetItem( info
);
464 void wxListLineData::GetItem( int const index
, wxListItem
&info
)
467 wxNode
*node
= m_items
.Nth( i
);
470 wxListItemData
*item
= (wxListItemData
*)node
->Data();
471 item
->GetItem( info
);
475 void wxListLineData::GetText( int index
, wxString
&s
)
478 wxNode
*node
= m_items
.Nth( i
);
482 wxListItemData
*item
= (wxListItemData
*)node
->Data();
487 void wxListLineData::SetText( int index
, const wxString s
)
490 wxNode
*node
= m_items
.Nth( i
);
493 wxListItemData
*item
= (wxListItemData
*)node
->Data();
498 int wxListLineData::GetImage( int index
)
501 wxNode
*node
= m_items
.Nth( i
);
504 wxListItemData
*item
= (wxListItemData
*)node
->Data();
505 return item
->GetImage();
510 void wxListLineData::DoDraw( wxPaintDC
*dc
, bool hilight
, bool paintBG
)
512 long dev_x
= dc
->LogicalToDeviceX( m_bound_all
.x
-2 );
513 long dev_y
= dc
->LogicalToDeviceY( m_bound_all
.y
-2 );
514 long dev_w
= dc
->LogicalToDeviceXRel( m_bound_all
.width
+4 );
515 long dev_h
= dc
->LogicalToDeviceYRel( m_bound_all
.height
+4 );
516 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
) ) return;
522 dc
->SetBrush( m_hilightBrush
);
523 dc
->SetPen( wxTRANSPARENT_PEN
);
527 dc
->SetBrush( wxWHITE_BRUSH
);
528 dc
->SetPen( wxTRANSPARENT_PEN
);
530 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
531 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
533 if (m_mode
== wxLC_REPORT
)
536 wxNode
*node
= m_items
.First();
539 wxListItemData
*info
= (wxListItemData
*)node
->Data();
540 dc
->SetClippingRegion( info
->GetX(), info
->GetY(), info
->GetWidth(), info
->GetHeight() );
543 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
545 dc
->SetTextForeground( info
->GetColour() );
546 dc
->DrawText( s
, info
->GetX()+2, info
->GetY() );
547 dc
->DestroyClippingRegion();
553 wxNode
*node
= m_items
.First();
556 wxListItemData
*item
= (wxListItemData
*)node
->Data();
557 if (item
->HasImage())
559 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
566 dc
->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
) );
568 dc
->SetTextForeground( item
->GetColour() );
569 dc
->DrawText( s
, m_bound_label
.x
, m_bound_label
.y
);
575 void wxListLineData::Hilight( bool on
)
577 if (on
== m_hilighted
) return;
579 m_owner
->SelectLine( this );
581 m_owner
->DeselectLine( this );
585 void wxListLineData::ReverseHilight( void )
587 m_hilighted
= !m_hilighted
;
589 m_owner
->SelectLine( this );
591 m_owner
->DeselectLine( this );
594 void wxListLineData::DrawRubberBand( wxPaintDC
*dc
, bool on
)
598 dc
->SetPen( wxBLACK_PEN
);
599 dc
->SetBrush( wxTRANSPARENT_BRUSH
);
600 dc
->DrawRectangle( m_bound_hilight
.x
-2, m_bound_hilight
.y
-2,
601 m_bound_hilight
.width
+4, m_bound_hilight
.height
+4 );
605 void wxListLineData::Draw( wxPaintDC
*dc
)
607 DoDraw( dc
, m_hilighted
, m_hilighted
);
610 bool wxListLineData::IsInRect( int x
, int y
, const wxRectangle
&rect
)
612 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) && (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
615 bool wxListLineData::IsHilighted( void )
620 void wxListLineData::AssignRect( wxRectangle
&dest
, int x
, int y
, int width
, int height
)
625 dest
.height
= height
;
628 void wxListLineData::AssignRect( wxRectangle
&dest
, const wxRectangle
&source
)
632 dest
.width
= source
.width
;
633 dest
.height
= source
.height
;
636 //-----------------------------------------------------------------------------
637 // wxListHeaderWindow
638 //-----------------------------------------------------------------------------
640 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
642 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
643 EVT_PAINT (wxListHeaderWindow::OnPaint
)
644 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
645 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
648 wxListHeaderWindow::wxListHeaderWindow( void )
651 m_currentCursor
= NULL
;
652 m_resizeCursor
= NULL
;
655 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
656 const wxPoint
&pos
, const wxSize
&size
,
657 long style
, const wxString
&name
) :
658 wxWindow( win
, id
, pos
, size
, style
, name
)
661 // m_currentCursor = wxSTANDARD_CURSOR;
662 m_currentCursor
= NULL
;
663 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
666 void wxListHeaderWindow::DoDrawRect( wxPaintDC
*dc
, int x
, int y
, int w
, int h
)
670 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
672 dc
->SetPen( *wxBLACK_PEN
);
673 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
674 dc
->DrawRectangle( x
, y
+h
, w
, 1 ); // bottom (outer)
676 dc
->SetPen( *wxMEDIUM_GREY_PEN
);
677 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
678 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
680 dc
->SetPen( *wxWHITE_PEN
);
681 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
682 // dc->DrawRectangle( x, y+1, w-m_corner, 1 ); // top (inner)
683 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
684 // dc->DrawRectangle( x+1, y, 1, h-1 ); // left (inner)
687 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
689 wxPaintDC
dc( this );
694 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
700 GetClientSize( &w
, &h
);
702 dc
.SetTextForeground( *wxBLACK
);
706 int numColumns
= m_owner
->GetColumnCount();
708 for (int i
= 0; i
< numColumns
; i
++)
710 m_owner
->GetColumn( i
, item
);
711 int cw
= item
.m_width
-2;
712 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5)) cw
= w
-x
-1;
713 dc
.SetPen( *wxWHITE_PEN
);
715 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
716 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
717 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
718 dc
.DestroyClippingRegion();
725 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
729 event
.Position( &fx
, &fy
);
736 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
738 xpos
+= m_owner
->GetColumnWidth( j
);
739 if ((abs(x
-xpos
) < 2) && (y
< 14)) { hit
= TRUE
; break; }
743 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( m_resizeCursor
);
744 m_currentCursor
= m_resizeCursor
;
748 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( wxSTANDARD_CURSOR
);
749 m_currentCursor
= wxSTANDARD_CURSOR
;
754 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
759 //-----------------------------------------------------------------------------
760 // wxListRenameTimer (internal)
761 //-----------------------------------------------------------------------------
763 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
768 void wxListRenameTimer::Notify()
770 m_owner
->OnRenameTimer();
773 //-----------------------------------------------------------------------------
775 //-----------------------------------------------------------------------------
777 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
779 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
780 EVT_PAINT (wxListMainWindow::OnPaint
)
781 EVT_SIZE (wxListMainWindow::OnSize
)
782 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
783 EVT_CHAR (wxListMainWindow::OnChar
)
784 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
785 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
788 wxListMainWindow::wxListMainWindow( void )
791 m_lines
.DeleteContents( TRUE
);
792 m_columns
.DeleteContents( TRUE
);
795 m_hilightBrush
= NULL
;
800 m_small_image_list
= NULL
;
801 m_normal_image_list
= NULL
;
802 m_small_spacing
= 30;
803 m_normal_spacing
= 40;
806 m_lastOnSame
= FALSE
;
807 // m_renameTimer = new wxRenameTimer( this );
812 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
813 const wxPoint
&pos
, const wxSize
&size
,
814 long style
, const wxString
&name
) :
815 wxScrolledWindow( parent
, id
, pos
, size
, style
, name
)
818 m_lines
.DeleteContents( TRUE
);
819 m_columns
.DeleteContents( TRUE
);
823 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
824 m_small_image_list
= NULL
;
825 m_normal_image_list
= NULL
;
826 m_small_spacing
= 30;
827 m_normal_spacing
= 40;
828 // AllowDoubleClick( TRUE );
829 m_myFont
= wxNORMAL_FONT
;
836 if (m_mode
& wxLC_REPORT
)
846 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
849 m_lastOnSame
= FALSE
;
850 m_renameTimer
= new wxListRenameTimer( this );
851 m_renameAccept
= FALSE
;
852 // m_text = new wxRawListTextCtrl( GetParent(), "", &m_renameAccept, &m_renameRes, this, 10, 10, 40, 10 );
853 // m_text->Show( FALSE );
855 SetBackgroundColour( *wxWHITE
);
858 char *accepted_drop_types[] = { "text/plain" };
859 gtk_widget_dnd_drag_set( m_wxwindow, TRUE, accepted_drop_types, 1 );
863 wxListMainWindow::~wxListMainWindow( void )
865 // if (m_hilightColour) delete m_hilightColour;
866 // if (m_hilightBrush) delete m_hilightBrush;
867 // if (m_myFont) delete m_myFont;
868 delete m_renameTimer
;
872 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
882 line
->GetExtent( x
, y
, w
, h
);
884 dc
.LogicalToDeviceX(x
-3),
885 dc
.LogicalToDeviceY(y
-3),
886 dc
.LogicalToDeviceXRel(w
+6),
887 dc
.LogicalToDeviceXRel(h
+6) );
888 Refresh( TRUE
, &rect
);
892 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
896 wxPaintDC
dc( this );
901 // dc.SetFont( *m_myFont );
902 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
904 wxNode
*node
= m_lines
.First();
907 wxListLineData
*line
= (wxListLineData
*)node
->Data();
911 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
916 void wxListMainWindow::HilightAll( bool on
)
918 wxNode
*node
= m_lines
.First();
921 wxListLineData
*line
= (wxListLineData
*)node
->Data();
922 if (line
->IsHilighted() != on
)
931 void wxListMainWindow::ActivateLine( wxListLineData
*line
)
933 if (!m_parent
) return;
934 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, m_parent
->GetId() );
935 le
.SetEventObject( m_parent
);
937 le
.m_itemIndex
= GetIndexOfLine( line
);
939 line
->GetItem( 0, le
.m_item
);
943 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
945 if (!m_parent
) return;
946 wxListEvent
le( command
, m_parent
->GetId() );
947 le
.SetEventObject( m_parent
);
949 le
.m_itemIndex
= GetIndexOfLine( line
);
951 line
->GetItem( 0, le
.m_item
);
955 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
957 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
960 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
962 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
965 void wxListMainWindow::SelectLine( wxListLineData
*line
)
967 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
970 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
972 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
975 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
977 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
980 void wxListMainWindow::RenameLine( wxListLineData
*line
, const wxString
&newName
)
982 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
);
984 le
.m_itemIndex
= GetIndexOfLine( line
);
986 line
->GetItem( 0, le
.m_item
);
987 le
.m_item
.m_text
= newName
;
991 void wxListMainWindow::OnRenameTimer()
995 m_current
->GetText( 0, s
);
1000 m_current
->GetLabelExtent( x
, y
, w
, h
);
1003 GetPosition( &dx
, &dy
);
1007 wxRawListTextCtrl *text = new wxRawListTextCtrl(
1008 GetParent(), s, &m_renameAccept, &m_renameRes, this, x+2, y+2, w+8, h+8 );
1012 m_text->SetSize( x+3, y+3, w+6, h+6 );
1013 m_text->SetValue( s );
1014 m_text->Show( TRUE );
1018 char *res = wxGetTextFromUser( _("Enter new name:"), "", s );
1023 RenameLine( m_current, s );
1028 void wxListMainWindow::OnRenameAccept()
1030 RenameLine( m_current
, m_renameRes
);
1033 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1035 if (m_parent
->ProcessEvent( event
)) return;
1037 if (!m_current
) return;
1038 if (m_dirty
) return;
1040 wxClientDC
dc(this);
1042 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1043 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1046 wxNode
*node
= m_lines
.First();
1047 wxListLineData
*line
= NULL
;
1050 line
= (wxListLineData
*)node
->Data();
1051 hitResult
= line
->IsHit( x
, y
);
1052 if (hitResult
) break;
1054 node
= node
->Next();
1057 if (!event
.Dragging())
1062 if (event
.Dragging() && (m_dragCount
> 3))
1065 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, m_parent
->GetId() );
1066 le
.SetEventObject( this );
1075 if (event
.ButtonDClick())
1078 m_lastOnSame
= FALSE
;
1079 m_renameTimer
->Stop();
1080 ActivateLine( line
);
1084 if (event
.LeftUp() && m_lastOnSame
)
1087 if ((line
== m_current
) &&
1088 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) /* &&
1089 (m_mode & wxLC_ICON) */ )
1091 m_renameTimer
->Start( 330, TRUE
);
1093 m_lastOnSame
= FALSE
;
1097 if (event
.LeftDown())
1100 wxListLineData
*oldCurrent
= m_current
;
1101 if (m_mode
& wxLC_SINGLE_SEL
)
1104 HilightAll( FALSE
);
1105 m_current
->ReverseHilight();
1106 RefreshLine( m_current
);
1110 if (event
.ShiftDown())
1113 m_current
->ReverseHilight();
1114 RefreshLine( m_current
);
1116 else if (event
.ControlDown())
1119 int numOfCurrent
= -1;
1120 node
= m_lines
.First();
1123 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1125 if (test_line
== oldCurrent
) break;
1126 node
= node
->Next();
1129 node
= m_lines
.First();
1132 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1134 if (test_line
== line
) break;
1135 node
= node
->Next();
1138 if (numOfLine
< numOfCurrent
)
1139 { int i
= numOfLine
; numOfLine
= numOfCurrent
; numOfCurrent
= i
; }
1140 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1141 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1143 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1144 test_line
->Hilight(TRUE
);
1145 RefreshLine( test_line
);
1146 node
= node
->Next();
1152 HilightAll( FALSE
);
1153 m_current
->ReverseHilight();
1154 RefreshLine( m_current
);
1157 if (m_current
!= oldCurrent
)
1159 RefreshLine( oldCurrent
);
1160 UnfocusLine( oldCurrent
);
1161 FocusLine( m_current
);
1163 m_lastOnSame
= (m_current
== oldCurrent
);
1169 void wxListMainWindow::MoveToFocus( void )
1171 if (!m_current
) return;
1177 m_current->GetExtent( x, y, w, h );
1180 GetClientSize( &w_p, &h_p );
1181 if (m_mode & wxLC_REPORT)
1183 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1184 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1185 if ((y > y_s) && (y+h < y_s+h_p)) return;
1186 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1187 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1191 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1192 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1193 if ((x > x_s) && (x+w < x_s+w_p)) return;
1194 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1195 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1200 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1202 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1203 wxListLineData
*oldCurrent
= m_current
;
1204 m_current
= newCurrent
;
1206 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1207 RefreshLine( m_current
);
1208 RefreshLine( oldCurrent
);
1209 FocusLine( m_current
);
1210 UnfocusLine( oldCurrent
);
1213 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1216 if (event.KeyCode() == WXK_TAB)
1218 if (event.ShiftDown())
1225 if (!m_current
) return;
1226 switch (event
.KeyCode())
1230 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1231 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1236 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1237 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1242 wxNode
*node
= m_lines
.Last();
1243 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1248 wxNode
*node
= m_lines
.First();
1249 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1255 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1259 wxNode
*node
= m_lines
.First();
1260 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); };
1261 steps
= pos
% m_visibleLines
;
1263 wxNode
*node
= m_lines
.Member( m_current
);
1264 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1265 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1271 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1274 int pos
= 0; wxNode
*node
= m_lines
.First();
1275 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); };
1276 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1278 wxNode
*node
= m_lines
.Member( m_current
);
1279 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1280 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1285 if (!(m_mode
& wxLC_REPORT
))
1287 wxNode
*node
= m_lines
.Member( m_current
);
1288 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1289 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1295 if (!(m_mode
& wxLC_REPORT
))
1297 wxNode
*node
= m_lines
.Member( m_current
);
1298 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1299 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1305 m_current
->ReverseHilight();
1306 RefreshLine( m_current
);
1311 if (!(m_mode
& wxLC_SINGLE_SEL
))
1313 wxListLineData
*oldCurrent
= m_current
;
1314 m_current
->ReverseHilight();
1315 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1316 if (node
) m_current
= (wxListLineData
*)node
->Data();
1318 RefreshLine( oldCurrent
);
1319 RefreshLine( m_current
);
1320 UnfocusLine( oldCurrent
);
1321 FocusLine( m_current
);
1328 ActivateLine( m_current
);
1340 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1343 RefreshLine( m_current
);
1345 if (!m_parent
) return;
1347 wxFocusEvent
event( wxEVT_SET_FOCUS
, m_parent
->GetId() );
1348 event
.SetEventObject( m_parent
);
1349 m_parent
->ProcessEvent( event
);
1352 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1355 RefreshLine( m_current
);
1358 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1361 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1363 CalculatePositions();
1364 printf( "OnSize::Refresh.\n" );
1370 wxFont
*wxListMainWindow::GetMyFont( void )
1375 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1377 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1379 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1382 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1384 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
1388 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1390 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1392 m_normal_image_list
->GetSize( index
, width
, height
);
1395 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1397 m_small_image_list
->GetSize( index
, width
, height
);
1404 int wxListMainWindow::GetTextLength( wxString
&s
)
1406 wxPaintDC
dc( this );
1409 dc
.GetTextExtent( s
, &lw
, &lh
);
1413 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1416 wxNode
*node
= m_lines
.First();
1419 if (line
== (wxListLineData
*)node
->Data()) return i
;
1421 node
= node
->Next();
1426 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
1429 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1430 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1433 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
1438 m_small_spacing
= spacing
;
1442 m_normal_spacing
= spacing
;
1446 int wxListMainWindow::GetItemSpacing( bool isSmall
)
1448 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1451 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
1454 wxNode
*node
= m_columns
.Nth( col
);
1457 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1458 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1459 column
->SetItem( item
);
1463 void wxListMainWindow::SetColumnWidth( int col
, int width
)
1466 wxNode
*node
= m_columns
.Nth( col
);
1469 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1470 column
->SetWidth( width
);
1474 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
1476 wxNode
*node
= m_columns
.Nth( col
);
1479 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1480 column
->GetItem( item
);
1492 int wxListMainWindow::GetColumnWidth( int col
)
1494 wxNode
*node
= m_columns
.Nth( col
);
1497 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1498 return column
->GetWidth();
1504 int wxListMainWindow::GetColumnCount( void )
1506 return m_columns
.Number();
1509 int wxListMainWindow::GetCountPerPage( void )
1511 return m_visibleLines
;
1514 void wxListMainWindow::SetItem( wxListItem
&item
)
1517 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1520 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1521 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1522 line
->SetItem( item
.m_col
, item
);
1526 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
1528 // m_dirty = TRUE; no recalcs needed
1529 wxListLineData
*oldCurrent
= m_current
;
1530 if (stateMask
& wxLIST_STATE_FOCUSED
)
1532 wxNode
*node
= m_lines
.Nth( item
);
1535 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1536 UnfocusLine( m_current
);
1538 FocusLine( m_current
);
1539 RefreshLine( m_current
);
1540 RefreshLine( oldCurrent
);
1543 if (stateMask
& wxLIST_STATE_SELECTED
)
1545 wxNode
*node
= m_lines
.Nth( item
);
1548 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1549 bool on
= state
& wxLIST_STATE_SELECTED
;
1550 line
->Hilight( on
);
1551 RefreshLine( m_current
);
1552 RefreshLine( oldCurrent
);
1557 int wxListMainWindow::GetItemState( long item
, long stateMask
)
1559 int ret
= wxLIST_STATE_DONTCARE
;
1560 if (stateMask
& wxLIST_STATE_FOCUSED
)
1562 wxNode
*node
= m_lines
.Nth( item
);
1565 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1566 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1569 if (stateMask
& wxLIST_STATE_SELECTED
)
1571 wxNode
*node
= m_lines
.Nth( item
);
1574 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1575 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1581 void wxListMainWindow::GetItem( wxListItem
&item
)
1583 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1586 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1587 line
->GetItem( item
.m_col
, item
);
1598 int wxListMainWindow::GetItemCount( void )
1600 return m_lines
.Number();
1603 void wxListMainWindow::GetItemRect( long index
, wxRectangle
&rect
)
1605 wxNode
*node
= m_lines
.Nth( index
);
1608 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1609 line
->GetRect( rect
);
1620 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
1622 wxNode
*node
= m_lines
.Nth( item
);
1626 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1627 line
->GetRect( rect
);
1639 int wxListMainWindow::GetSelectedItemCount( void )
1642 wxNode
*node
= m_lines
.First();
1645 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1646 if (line
->IsHilighted()) ret
++;
1647 node
= node
->Next();
1652 void wxListMainWindow::SetMode( long mode
)
1659 if (m_mode
& wxLC_REPORT
)
1671 long wxListMainWindow::GetMode( void ) const
1676 void wxListMainWindow::CalculatePositions( void )
1678 wxPaintDC
dc( this );
1679 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1681 int iconSpacing
= 0;
1682 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1683 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1684 wxNode
*node
= m_lines
.First();
1687 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1688 line
->CalculateSize( &dc
, iconSpacing
);
1689 node
= node
->Next();
1694 int lineSpacing
= 0;
1696 node
= m_lines
.First();
1699 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1701 line
->GetSize( dummy
, lineSpacing
);
1707 lineSpacing
= 6 + (int)dc
.GetCharHeight();
1710 int clientWidth
= 0;
1711 int clientHeight
= 0;
1713 if (m_mode
& wxLC_REPORT
)
1717 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1718 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1719 GetClientSize( &clientWidth
, &clientHeight
);
1720 node
= m_lines
.First();
1723 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1724 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1726 for (int i
= 0; i
< GetColumnCount(); i
++)
1728 line
->SetColumnPosition( i
, col_x
);
1729 col_x
+= GetColumnWidth( i
);
1732 node
= node
->Next();
1737 // At first, we try without any scrollbar
1738 GetSize( &clientWidth
, &clientHeight
);
1740 int entireWidth
= 0;
1742 for (int tries
= 0; tries
< 2; tries
++)
1748 node
= m_lines
.First();
1751 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1752 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1753 line
->GetSize( lineWidth
, lineHeight
);
1754 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1756 if (y
+lineHeight
> clientHeight
-4)
1760 entireWidth
+= maxWidth
+13;
1763 node
= node
->Next();
1764 if (!node
) entireWidth
+= maxWidth
;
1765 if ((tries
== 0) && (entireWidth
> clientWidth
))
1767 clientHeight
-= 14; // scrollbar height
1770 if (!node
) tries
= 1;
1773 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1775 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1778 void wxListMainWindow::RealizeChanges( void )
1782 wxNode
*node
= m_lines
.First();
1783 if (node
) m_current
= (wxListLineData
*)node
->Data();
1787 FocusLine( m_current
);
1788 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1792 long wxListMainWindow::GetNextItem( long item
, int WXUNUSED(geometry
), int state
)
1795 if (item
> 0) ret
= item
;
1796 wxNode
*node
= m_lines
.Nth( ret
);
1799 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1800 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1801 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1802 if (!state
) return ret
;
1804 node
= node
->Next();
1809 void wxListMainWindow::DeleteItem( long index
)
1812 wxNode
*node
= m_lines
.Nth( index
);
1815 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1816 if (m_current
== line
) m_current
= NULL
;
1818 m_lines
.DeleteNode( node
);
1822 void wxListMainWindow::DeleteColumn( int col
)
1825 wxNode
*node
= m_columns
.Nth( col
);
1826 if (node
) m_columns
.DeleteNode( node
);
1829 void wxListMainWindow::DeleteAllItems( void )
1833 wxNode
*node
= m_lines
.First();
1836 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1838 node
= node
->Next();
1843 void wxListMainWindow::DeleteEverything( void )
1847 wxNode
*node
= m_lines
.First();
1850 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1852 node
= node
->Next();
1859 void wxListMainWindow::EnsureVisible( long index
)
1861 wxListLineData
*oldCurrent
= m_current
;
1864 wxNode
*node
= m_lines
.Nth( i
);
1865 if (node
) m_current
= (wxListLineData
*)node
->Data();
1866 if (m_current
) MoveToFocus();
1867 m_current
= oldCurrent
;
1870 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
1874 if (pos
< 0) pos
= 0;
1875 wxNode
*node
= m_lines
.Nth( pos
);
1878 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1880 line
->GetText( 0, s
);
1881 if (s
== tmp
) return pos
;
1882 node
= node
->Next();
1888 long wxListMainWindow::FindItem(long start
, long data
)
1891 if (pos
< 0) pos
= 0;
1892 wxNode
*node
= m_lines
.Nth( pos
);
1895 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1897 line
->GetItem( 0, item
);
1898 if (item
.m_data
== data
) return pos
;
1899 node
= node
->Next();
1905 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
1907 wxNode
*node
= m_lines
.First();
1911 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1912 long ret
= line
->IsHit( x
, y
);
1918 node
= node
->Next();
1924 void wxListMainWindow::InsertItem( wxListItem
&item
)
1928 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
1929 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
1930 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
1931 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
1932 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
1933 if (m_mode
& wxLC_REPORT
)
1935 line
->InitItems( GetColumnCount() );
1936 item
.m_width
= GetColumnWidth( 0 )-3;
1939 line
->InitItems( 1 );
1940 line
->SetItem( 0, item
);
1941 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1943 m_lines
.Insert( node
, line
);
1945 m_lines
.Append( line
);
1948 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
1951 if (m_mode
& wxLC_REPORT
)
1953 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
1954 wxListHeaderData
*column
= new wxListHeaderData( item
);
1955 wxNode
*node
= m_columns
.Nth( col
);
1957 m_columns
.Insert( node
, column
);
1959 m_columns
.Append( column
);
1963 wxListCtrlCompare list_ctrl_compare_func_2
;
1964 long list_ctrl_compare_data
;
1966 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
1968 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
1969 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
1971 line1
->GetItem( 0, item
);
1972 long data1
= item
.m_data
;
1973 line2
->GetItem( 0, item
);
1974 long data2
= item
.m_data
;
1975 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
1978 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
1980 list_ctrl_compare_func_2
= fn
;
1981 list_ctrl_compare_data
= data
;
1982 m_lines
.Sort( list_ctrl_compare_func_1
);
1985 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
1987 if (m_parent
) m_parent
->ProcessEvent( event
);
1991 // -------------------------------------------------------------------------------------
1993 // -------------------------------------------------------------------------------------
1995 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
1997 wxListItem::wxListItem(void)
2006 m_format
= wxLIST_FORMAT_CENTRE
;
2011 // -------------------------------------------------------------------------------------
2013 // -------------------------------------------------------------------------------------
2015 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
2017 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2018 wxCommandEvent( commandType
, id
)
2023 m_cancelled
= FALSE
;
2026 // -------------------------------------------------------------------------------------
2028 // -------------------------------------------------------------------------------------
2030 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
2032 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
2033 EVT_SIZE (wxListCtrl::OnSize
)
2034 EVT_IDLE (wxListCtrl::OnIdle
)
2037 wxListCtrl::wxListCtrl(void)
2039 m_imageListNormal
= NULL
;
2040 m_imageListSmall
= NULL
;
2041 m_imageListState
= NULL
;
2044 wxListCtrl::wxListCtrl( wxWindow
*parent
, wxWindowID id
,
2045 const wxPoint
&pos
, const wxSize
&size
,
2046 long style
, const wxString
&name
)
2049 Create( parent
, id
, pos
, size
, style
, name
);
2052 wxListCtrl::~wxListCtrl(void)
2056 bool wxListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2057 const wxPoint
&pos
, const wxSize
&size
,
2058 long style
, const wxString
&name
)
2060 m_imageListNormal
= NULL
;
2061 m_imageListSmall
= NULL
;
2062 m_imageListState
= NULL
;
2066 if ((s
& wxLC_REPORT
== 0) &&
2067 (s
& wxLC_LIST
== 0) &&
2068 (s
& wxLC_ICON
== 0))
2071 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
2073 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
2075 if (GetWindowStyleFlag() & wxLC_REPORT
)
2076 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
2083 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2085 // handled in OnIdle
2087 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
2090 void wxListCtrl::SetSingleStyle( long style
, bool add
)
2092 long flag
= GetWindowStyleFlag();
2096 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2097 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2098 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2107 if (flag
& style
) flag
-= style
;
2110 SetWindowStyleFlag( flag
);
2113 void wxListCtrl::SetWindowStyleFlag( long flag
)
2115 m_mainWin
->DeleteEverything();
2119 GetClientSize( &width
, &height
);
2121 m_mainWin
->SetMode( flag
);
2123 if (flag
& wxLC_REPORT
)
2125 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2127 // m_mainWin->SetSize( 0, 24, width, height-24 );
2130 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2134 // m_headerWin->SetSize( 0, 0, width, 23 );
2135 m_headerWin
->Show( TRUE
);
2141 if (GetWindowStyleFlag() & wxLC_REPORT
)
2143 // m_mainWin->SetSize( 0, 0, width, height );
2144 m_headerWin
->Show( FALSE
);
2148 wxWindow::SetWindowStyleFlag( flag
);
2151 void wxListCtrl::SetBackgroundColour(const wxColour
& col
)
2153 // This is from Julian. You know.
2154 // Not in wxWin 1.xx ???
2155 wxWindow::SetBackgroundColour( (wxColour
&)col
);
2158 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
)
2160 m_mainWin
->GetColumn( col
, item
);
2164 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
2166 m_mainWin
->SetColumn( col
, item
);
2170 int wxListCtrl::GetColumnWidth( int col
)
2172 return m_mainWin
->GetColumnWidth( col
);
2175 bool wxListCtrl::SetColumnWidth( int col
, int width
)
2177 m_mainWin
->SetColumnWidth( col
, width
);
2181 int wxListCtrl::GetCountPerPage(void)
2183 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2187 wxText& wxListCtrl::GetEditControl(void) const
2192 bool wxListCtrl::GetItem( wxListItem
&info
)
2194 m_mainWin
->GetItem( info
);
2198 bool wxListCtrl::SetItem( wxListItem
&info
)
2200 m_mainWin
->SetItem( info
);
2204 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
2207 info
.m_text
= label
;
2208 info
.m_mask
= wxLIST_MASK_TEXT
;
2209 info
.m_itemId
= index
;
2213 info
.m_image
= imageId
;
2214 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2217 m_mainWin
->SetItem(info
);
2221 int wxListCtrl::GetItemState( long item
, long stateMask
)
2223 return m_mainWin
->GetItemState( item
, stateMask
);
2226 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
2228 m_mainWin
->SetItemState( item
, state
, stateMask
);
2232 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
2235 info
.m_image
= image
;
2236 info
.m_mask
= wxLIST_MASK_IMAGE
;
2237 info
.m_itemId
= item
;
2238 m_mainWin
->SetItem( info
);
2242 wxString
wxListCtrl::GetItemText( long item
)
2245 info
.m_itemId
= item
;
2246 m_mainWin
->GetItem( info
);
2250 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
2253 info
.m_mask
= wxLIST_MASK_TEXT
;
2254 info
.m_itemId
= item
;
2256 m_mainWin
->SetItem( info
);
2259 long wxListCtrl::GetItemData( long item
)
2262 info
.m_itemId
= item
;
2263 m_mainWin
->GetItem( info
);
2267 bool wxListCtrl::SetItemData( long item
, long data
)
2270 info
.m_mask
= wxLIST_MASK_DATA
;
2271 info
.m_itemId
= item
;
2273 m_mainWin
->SetItem( info
);
2277 bool wxListCtrl::GetItemRect( long item
, wxRectangle
&rect
, int WXUNUSED(code
) )
2279 m_mainWin
->GetItemRect( item
, rect
);
2283 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
)
2285 m_mainWin
->GetItemPosition( item
, pos
);
2289 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2294 int wxListCtrl::GetItemCount(void)
2296 return m_mainWin
->GetItemCount();
2299 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
2301 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
2304 int wxListCtrl::GetItemSpacing( bool isSmall
)
2306 return m_mainWin
->GetItemSpacing( isSmall
);
2309 int wxListCtrl::GetSelectedItemCount(void)
2311 return m_mainWin
->GetSelectedItemCount();
2315 wxColour wxListCtrl::GetTextColour(void) const
2319 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2324 long wxListCtrl::GetTopItem(void)
2329 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
2331 return m_mainWin
->GetNextItem( item
, geom
, state
);
2334 wxImageList
*wxListCtrl::GetImageList(int which
)
2336 if (which
== wxIMAGE_LIST_NORMAL
)
2338 return m_imageListNormal
;
2340 else if (which
== wxIMAGE_LIST_SMALL
)
2342 return m_imageListSmall
;
2344 else if (which
== wxIMAGE_LIST_STATE
)
2346 return m_imageListState
;
2351 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
2353 m_mainWin
->SetImageList( imageList
, which
);
2356 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
2361 bool wxListCtrl::DeleteItem( long item
)
2363 m_mainWin
->DeleteItem( item
);
2367 bool wxListCtrl::DeleteAllItems(void)
2369 m_mainWin
->DeleteAllItems();
2373 bool wxListCtrl::DeleteColumn( int col
)
2375 m_mainWin
->DeleteColumn( col
);
2380 wxText& wxListCtrl::Edit( long WXUNUSED(item ) )
2385 bool wxListCtrl::EnsureVisible( long item
)
2387 m_mainWin
->EnsureVisible( item
);
2391 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
2393 return m_mainWin
->FindItem( start
, str
, partial
);
2396 long wxListCtrl::FindItem( long start
, long data
)
2398 return m_mainWin
->FindItem( start
, data
);
2401 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2402 int WXUNUSED(direction
))
2407 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2409 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2412 long wxListCtrl::InsertItem( wxListItem
& info
)
2414 m_mainWin
->InsertItem( info
);
2418 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
2421 info
.m_text
= label
;
2422 info
.m_mask
= wxLIST_MASK_TEXT
;
2423 info
.m_itemId
= index
;
2424 return InsertItem( info
);
2427 long wxListCtrl::InsertItem( long index
, int imageIndex
)
2430 info
.m_mask
= wxLIST_MASK_IMAGE
;
2431 info
.m_image
= imageIndex
;
2432 info
.m_itemId
= index
;
2433 return InsertItem( info
);
2436 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
2439 info
.m_text
= label
;
2440 info
.m_image
= imageIndex
;
2441 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2442 info
.m_itemId
= index
;
2443 return InsertItem( info
);
2446 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
2448 m_mainWin
->InsertColumn( col
, item
);
2452 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
2453 int format
, int width
)
2456 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2457 item
.m_text
= heading
;
2460 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2461 item
.m_width
= width
;
2464 item
.m_format
= format
;
2466 return InsertColumn( col
, item
);
2469 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
2475 // fn is a function which takes 3 long arguments: item1, item2, data.
2476 // item1 is the long data associated with a first item (NOT the index).
2477 // item2 is the long data associated with a second item (NOT the index).
2478 // data is the same value as passed to SortItems.
2479 // The return value is a negative number if the first item should precede the second
2480 // item, a positive number of the second item should precede the first,
2481 // or zero if the two items are equivalent.
2482 // data is arbitrary data to be passed to the sort function.
2484 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2486 m_mainWin
->SortItems( fn
, data
);
2490 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
2492 if (!m_mainWin
->m_dirty
) return;
2496 GetClientSize( &cw
, &ch
);
2503 if (GetWindowStyleFlag() & wxLC_REPORT
)
2505 m_headerWin
->GetPosition( &x
, &y
);
2506 m_headerWin
->GetSize( &w
, &h
);
2507 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2508 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2510 m_mainWin
->GetPosition( &x
, &y
);
2511 m_mainWin
->GetSize( &w
, &h
);
2512 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2513 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2517 m_mainWin
->GetPosition( &x
, &y
);
2518 m_mainWin
->GetSize( &w
, &h
);
2519 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2520 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2523 m_mainWin
->CalculatePositions();
2524 m_mainWin
->RealizeChanges();
2525 m_mainWin
->m_dirty
= FALSE
;
2526 m_mainWin
->Refresh();