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( const int image
)
64 void wxListItemData::SetData( const long data
)
69 void wxListItemData::SetPosition( const int x
, const int y
)
75 void wxListItemData::SetSize( int const width
, const 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( const int x
, const 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( const int x
, const int y
)
185 void wxListHeaderData::SetHeight( const int h
)
190 void wxListHeaderData::SetWidth( const int w
)
193 if (m_width
< 0) m_width
= 80;
194 if (m_width
< 6) m_width
= 6;
197 void wxListHeaderData::SetFormat( const 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
, const int mode
, wxBrush
*hilightBrush
)
257 m_hilightBrush
= hilightBrush
;
258 m_items
.DeleteContents( TRUE
);
262 void wxListLineData::CalculateSize( wxPaintDC
*dc
, const 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
, const int x
, const int y
, const 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( const int index
, const 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( const int x
, const 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( const int num
)
451 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
454 void wxListLineData::SetItem( const 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( const int index
, wxString
&s
)
478 wxNode
*node
= m_items
.Nth( i
);
482 wxListItemData
*item
= (wxListItemData
*)node
->Data();
487 void wxListLineData::SetText( const int index
, const wxString s
)
490 wxNode
*node
= m_items
.Nth( i
);
493 wxListItemData
*item
= (wxListItemData
*)node
->Data();
498 int wxListLineData::GetImage( const 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
, const bool hilight
, const 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( const 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
, const 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( const int x
, const 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
, const int x
, const int y
, const int width
, const 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
, const wxWindowID id
, wxListMainWindow
*owner
,
656 const wxPoint
&pos
, const wxSize
&size
,
657 const 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 );
809 m_isDragging
= FALSE
;
812 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, const wxWindowID id
,
813 const wxPoint
&pos
, const wxSize
&size
,
814 const 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
;
831 m_isDragging
= FALSE
;
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( const 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
, long 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_current
) return;
1036 if (m_dirty
) return;
1037 // wxDragCanvas::OnEvent( event );
1039 wxClientDC
dc(this);
1041 long x
= dc
.DeviceToLogicalX( (long)event
.GetX() );
1042 long y
= dc
.DeviceToLogicalY( (long)event
.GetY() );
1045 wxNode
*node
= m_lines
.First();
1046 wxListLineData
*line
= NULL
;
1049 line
= (wxListLineData
*)node
->Data();
1050 hitResult
= line
->IsHit( x
, y
);
1051 if (hitResult
) break;
1053 node
= node
->Next();
1056 if (!event
.Dragging()) m_isDragging
= FALSE
;
1058 if (event
.Dragging() && (!m_isDragging
))
1060 m_isDragging
= TRUE
;
1061 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_DRAG
, m_parent
->GetId() );
1062 le
.SetEventObject( this );
1071 if (event
.ButtonDClick())
1074 m_lastOnSame
= FALSE
;
1075 m_renameTimer
->Stop();
1076 ActivateLine( line
);
1080 if (event
.LeftUp() && m_lastOnSame
)
1083 if ((line
== m_current
) &&
1084 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) /* &&
1085 (m_mode & wxLC_ICON) */ )
1087 m_renameTimer
->Start( 330, TRUE
);
1089 m_lastOnSame
= FALSE
;
1093 if (event
.LeftDown())
1096 wxListLineData
*oldCurrent
= m_current
;
1098 if (!event
.ShiftDown() || (m_mode
& wxLC_SINGLE_SEL
)) HilightAll( FALSE
);
1099 m_current
->ReverseHilight();
1100 RefreshLine( m_current
);
1101 if (m_current
!= oldCurrent
)
1103 UnfocusLine( oldCurrent
);
1104 FocusLine( m_current
);
1105 RefreshLine( oldCurrent
);
1107 m_lastOnSame
= (m_current
== oldCurrent
);
1113 void wxListMainWindow::MoveToFocus( void )
1115 if (!m_current
) return;
1121 m_current->GetExtent( x, y, w, h );
1124 GetClientSize( &w_p, &h_p );
1125 if (m_mode & wxLC_REPORT)
1127 if (GetScrollPos( wxHORIZONTAL ) != 0) SetScrollPos( wxHORIZONTAL, 0);
1128 int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
1129 if ((y > y_s) && (y+h < y_s+h_p)) return;
1130 if (y-y_s < 5) SetScrollPos( wxVERTICAL, (y-5)/m_yScroll );
1131 if (y+h+5 > y_s+h_p) SetScrollPos( wxVERTICAL, (y+h-h_p+h+5)/m_yScroll );
1135 if (GetScrollPos( wxVERTICAL ) != 0) SetScrollPos( wxVERTICAL, 0);
1136 int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL );
1137 if ((x > x_s) && (x+w < x_s+w_p)) return;
1138 if (x-x_s < 5) SetScrollPos( wxHORIZONTAL, (x-5)/m_xScroll );
1139 if (x+w > x_s+w_p) SetScrollPos( wxHORIZONTAL, (x+w-w_p+5)/m_xScroll );
1144 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1146 UnfocusLine( m_current
);
1147 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1148 wxListLineData
*oldCurrent
= m_current
;
1149 m_current
= newCurrent
;
1151 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1152 FocusLine( m_current
);
1153 RefreshLine( m_current
);
1154 RefreshLine( oldCurrent
);
1157 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1160 if (event.KeyCode() == WXK_TAB)
1162 if (event.ShiftDown())
1169 if (!m_current
) return;
1170 switch (event
.KeyCode())
1174 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1175 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1180 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1181 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1186 wxNode
*node
= m_lines
.Last();
1187 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1192 wxNode
*node
= m_lines
.First();
1193 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1199 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1203 wxNode
*node
= m_lines
.First();
1204 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); };
1205 steps
= pos
% m_visibleLines
;
1207 wxNode
*node
= m_lines
.Member( m_current
);
1208 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
1209 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1215 if (m_mode
& wxLC_REPORT
) { steps
= m_visibleLines
-1; }
1218 int pos
= 0; wxNode
*node
= m_lines
.First();
1219 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); };
1220 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
1222 wxNode
*node
= m_lines
.Member( m_current
);
1223 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
1224 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1229 if (!(m_mode
& wxLC_REPORT
))
1231 wxNode
*node
= m_lines
.Member( m_current
);
1232 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
1233 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1239 if (!(m_mode
& wxLC_REPORT
))
1241 wxNode
*node
= m_lines
.Member( m_current
);
1242 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
1243 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
1249 if (!(m_mode
& wxLC_SINGLE_SEL
))
1251 wxListLineData
*oldCurrent
= m_current
;
1252 UnfocusLine( m_current
);
1253 m_current
->ReverseHilight();
1254 wxNode
*node
= m_lines
.Member( m_current
)->Next();
1255 if (node
) m_current
= (wxListLineData
*)node
->Data();
1257 FocusLine( m_current
);
1258 RefreshLine( m_current
);
1259 RefreshLine( oldCurrent
);
1266 ActivateLine( m_current
);
1278 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1281 RefreshLine( m_current
);
1283 if (!m_parent
) return;
1285 wxFocusEvent
event( wxEVT_SET_FOCUS
, m_parent
->GetId() );
1286 event
.SetEventObject( m_parent
);
1287 m_parent
->ProcessEvent( event
);
1290 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1293 RefreshLine( m_current
);
1296 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1299 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
1301 CalculatePositions();
1302 printf( "OnSize::Refresh.\n" );
1308 wxFont
*wxListMainWindow::GetMyFont( void )
1313 void wxListMainWindow::DrawImage( int index
, wxPaintDC
*dc
, int x
, int y
)
1315 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1317 m_normal_image_list
->Draw( index
, *dc
, x
, y
);
1320 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1322 m_small_image_list
->Draw( index
, *dc
, x
, y
);
1326 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
1328 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
1330 m_normal_image_list
->GetSize( index
, width
, height
);
1333 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
1335 m_small_image_list
->GetSize( index
, width
, height
);
1342 int wxListMainWindow::GetTextLength( wxString
&s
)
1344 wxPaintDC
dc( this );
1347 dc
.GetTextExtent( s
, &lw
, &lh
);
1351 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
1354 wxNode
*node
= m_lines
.First();
1357 if (line
== (wxListLineData
*)node
->Data()) return i
;
1359 node
= node
->Next();
1364 void wxListMainWindow::SetImageList( wxImageList
*imageList
, const int which
)
1367 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
1368 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
1371 void wxListMainWindow::SetItemSpacing( const int spacing
, const bool isSmall
)
1376 m_small_spacing
= spacing
;
1380 m_normal_spacing
= spacing
;
1384 int wxListMainWindow::GetItemSpacing( const bool isSmall
)
1386 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
1389 void wxListMainWindow::SetColumn( const int col
, wxListItem
&item
)
1392 wxNode
*node
= m_columns
.Nth( col
);
1395 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
1396 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1397 column
->SetItem( item
);
1401 void wxListMainWindow::SetColumnWidth( const int col
, const int width
)
1404 wxNode
*node
= m_columns
.Nth( col
);
1407 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1408 column
->SetWidth( width
);
1412 void wxListMainWindow::GetColumn( const int col
, wxListItem
&item
)
1414 wxNode
*node
= m_columns
.Nth( col
);
1417 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1418 column
->GetItem( item
);
1430 int wxListMainWindow::GetColumnWidth( const int col
)
1432 wxNode
*node
= m_columns
.Nth( col
);
1435 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
1436 return column
->GetWidth();
1442 int wxListMainWindow::GetColumnCount( void )
1444 return m_columns
.Number();
1447 int wxListMainWindow::GetCountPerPage( void )
1449 return m_visibleLines
;
1452 void wxListMainWindow::SetItem( wxListItem
&item
)
1455 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1458 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1459 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
1460 line
->SetItem( item
.m_col
, item
);
1464 void wxListMainWindow::SetItemState( const long item
, const long state
, const long stateMask
)
1466 // m_dirty = TRUE; no recalcs needed
1467 wxListLineData
*oldCurrent
= m_current
;
1468 if (stateMask
& wxLIST_STATE_FOCUSED
)
1470 wxNode
*node
= m_lines
.Nth( item
);
1473 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1474 UnfocusLine( m_current
);
1476 FocusLine( m_current
);
1477 RefreshLine( m_current
);
1478 RefreshLine( oldCurrent
);
1481 if (stateMask
& wxLIST_STATE_SELECTED
)
1483 wxNode
*node
= m_lines
.Nth( item
);
1486 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1487 bool on
= state
& wxLIST_STATE_SELECTED
;
1488 line
->Hilight( on
);
1489 RefreshLine( m_current
);
1490 RefreshLine( oldCurrent
);
1495 int wxListMainWindow::GetItemState( const long item
, const long stateMask
)
1497 int ret
= wxLIST_STATE_DONTCARE
;
1498 if (stateMask
& wxLIST_STATE_FOCUSED
)
1500 wxNode
*node
= m_lines
.Nth( item
);
1503 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1504 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
1507 if (stateMask
& wxLIST_STATE_SELECTED
)
1509 wxNode
*node
= m_lines
.Nth( item
);
1512 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1513 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
1519 void wxListMainWindow::GetItem( wxListItem
&item
)
1521 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1524 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1525 line
->GetItem( item
.m_col
, item
);
1536 int wxListMainWindow::GetItemCount( void )
1538 return m_lines
.Number();
1541 void wxListMainWindow::GetItemRect( const long index
, wxRectangle
&rect
)
1543 wxNode
*node
= m_lines
.Nth( index
);
1546 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1547 line
->GetRect( rect
);
1558 int wxListMainWindow::GetSelectedItemCount( void )
1561 wxNode
*node
= m_lines
.First();
1564 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1565 if (line
->IsHilighted()) ret
++;
1566 node
= node
->Next();
1571 void wxListMainWindow::SetMode( const long mode
)
1578 if (m_mode
& wxLC_REPORT
)
1590 long wxListMainWindow::GetMode( void ) const
1595 void wxListMainWindow::CalculatePositions( void )
1597 wxPaintDC
dc( this );
1598 dc
.SetFont( wxSystemSettings::GetSystemFont( wxSYS_SYSTEM_FONT
) );
1600 int iconSpacing
= 0;
1601 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
1602 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
1603 wxNode
*node
= m_lines
.First();
1606 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1607 line
->CalculateSize( &dc
, iconSpacing
);
1608 node
= node
->Next();
1613 int lineSpacing
= 0;
1615 node
= m_lines
.First();
1618 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1620 line
->GetSize( dummy
, lineSpacing
);
1626 lineSpacing
= 6 + (int)dc
.GetCharHeight();
1629 int clientWidth
= 0;
1630 int clientHeight
= 0;
1632 if (m_mode
& wxLC_REPORT
)
1636 int entireHeight
= m_lines
.Number() * lineSpacing
+ 10;
1637 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+10) / m_yScroll
, 0, 0, TRUE
);
1638 GetClientSize( &clientWidth
, &clientHeight
);
1639 node
= m_lines
.First();
1642 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1643 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1645 for (int i
= 0; i
< GetColumnCount(); i
++)
1647 line
->SetColumnPosition( i
, col_x
);
1648 col_x
+= GetColumnWidth( i
);
1651 node
= node
->Next();
1656 // At first, we try without any scrollbar
1657 GetSize( &clientWidth
, &clientHeight
);
1659 int entireWidth
= 0;
1661 for (int tries
= 0; tries
< 2; tries
++)
1667 node
= m_lines
.First();
1670 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1671 line
->SetPosition( &dc
, x
, y
, clientWidth
);
1672 line
->GetSize( lineWidth
, lineHeight
);
1673 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
1675 if (y
+lineHeight
> clientHeight
-4)
1679 entireWidth
+= maxWidth
+13;
1682 node
= node
->Next();
1683 if (!node
) entireWidth
+= maxWidth
;
1684 if ((tries
== 0) && (entireWidth
> clientWidth
))
1686 clientHeight
-= 14; // scrollbar height
1689 if (!node
) tries
= 1;
1692 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, 0, 0, TRUE
);
1694 m_visibleLines
= (clientHeight
-4) / (lineSpacing
);
1697 void wxListMainWindow::RealizeChanges( void )
1701 wxNode
*node
= m_lines
.First();
1702 if (node
) m_current
= (wxListLineData
*)node
->Data();
1706 FocusLine( m_current
);
1707 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
1711 long wxListMainWindow::GetNextItem( const long item
, int WXUNUSED(geometry
), int state
)
1714 if (item
> 0) ret
= item
;
1715 wxNode
*node
= m_lines
.Nth( ret
);
1718 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1719 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
)) return ret
;
1720 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted())) return ret
;
1721 if (!state
) return ret
;
1723 node
= node
->Next();
1728 void wxListMainWindow::DeleteItem( const long index
)
1731 wxNode
*node
= m_lines
.Nth( index
);
1734 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1736 m_lines
.DeleteNode( node
);
1740 void wxListMainWindow::DeleteColumn( const int col
)
1743 wxNode
*node
= m_columns
.Nth( col
);
1744 if (node
) m_columns
.DeleteNode( node
);
1747 void wxListMainWindow::DeleteAllItems( void )
1750 wxNode
*node
= m_lines
.First();
1753 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1755 node
= node
->Next();
1761 void wxListMainWindow::DeleteEverything( void )
1764 wxNode
*node
= m_lines
.First();
1767 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1769 node
= node
->Next();
1776 void wxListMainWindow::EnsureVisible( const long index
)
1778 wxListLineData
*oldCurrent
= m_current
;
1781 wxNode
*node
= m_lines
.Nth( i
);
1782 if (node
) m_current
= (wxListLineData
*)node
->Data();
1783 if (m_current
) MoveToFocus();
1784 m_current
= oldCurrent
;
1787 long wxListMainWindow::FindItem(const long start
, const wxString
& str
, const bool WXUNUSED(partial
) )
1791 if (pos
< 0) pos
= 0;
1792 wxNode
*node
= m_lines
.Nth( pos
);
1795 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1797 line
->GetText( 0, s
);
1798 if (s
== tmp
) return pos
;
1799 node
= node
->Next();
1805 long wxListMainWindow::FindItem(const long start
, const long data
)
1808 if (pos
< 0) pos
= 0;
1809 wxNode
*node
= m_lines
.Nth( pos
);
1812 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1814 line
->GetItem( 0, item
);
1815 if (item
.m_data
== data
) return pos
;
1816 node
= node
->Next();
1822 long wxListMainWindow::HitTest( const int x
, const int y
, int &flags
)
1824 wxNode
*node
= m_lines
.First();
1828 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1829 long ret
= line
->IsHit( x
, y
);
1835 node
= node
->Next();
1841 void wxListMainWindow::InsertItem( wxListItem
&item
)
1845 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
1846 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
1847 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
1848 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
1849 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
1850 if (m_mode
& wxLC_REPORT
)
1852 line
->InitItems( GetColumnCount() );
1853 item
.m_width
= GetColumnWidth( 0 )-3;
1856 line
->InitItems( 1 );
1857 line
->SetItem( 0, item
);
1858 wxNode
*node
= m_lines
.Nth( item
.m_itemId
);
1860 m_lines
.Insert( node
, line
);
1862 m_lines
.Append( line
);
1865 void wxListMainWindow::InsertColumn( const long col
, wxListItem
&item
)
1868 if (m_mode
& wxLC_REPORT
)
1870 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
1871 wxListHeaderData
*column
= new wxListHeaderData( item
);
1872 wxNode
*node
= m_columns
.Nth( col
);
1874 m_columns
.Insert( node
, column
);
1876 m_columns
.Append( column
);
1880 wxListCtrlCompare list_ctrl_compare_func_2
;
1881 long list_ctrl_compare_data
;
1883 int list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
1885 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
1886 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
1888 line1
->GetItem( 0, item
);
1889 long data1
= item
.m_data
;
1890 line2
->GetItem( 0, item
);
1891 long data2
= item
.m_data
;
1892 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
1895 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
1897 list_ctrl_compare_func_2
= fn
;
1898 list_ctrl_compare_data
= data
;
1899 m_lines
.Sort( list_ctrl_compare_func_1
);
1902 bool wxListMainWindow::OnListNotify( wxListEvent
&event
)
1904 if (m_parent
) m_parent
->ProcessEvent( event
);
1908 // -------------------------------------------------------------------------------------
1910 // -------------------------------------------------------------------------------------
1912 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
1914 wxListItem::wxListItem(void)
1923 m_format
= wxLIST_FORMAT_CENTRE
;
1928 // -------------------------------------------------------------------------------------
1930 // -------------------------------------------------------------------------------------
1932 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxCommandEvent
)
1934 wxListEvent::wxListEvent( WXTYPE commandType
, int id
):
1935 wxCommandEvent( commandType
, id
)
1940 m_cancelled
= FALSE
;
1943 // -------------------------------------------------------------------------------------
1945 // -------------------------------------------------------------------------------------
1947 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
1949 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
1950 EVT_SIZE (wxListCtrl::OnSize
)
1953 wxListCtrl::wxListCtrl(void)
1955 m_imageListNormal
= NULL
;
1956 m_imageListSmall
= NULL
;
1957 m_imageListState
= NULL
;
1960 wxListCtrl::wxListCtrl( wxWindow
*parent
, const wxWindowID id
,
1961 const wxPoint
&pos
, const wxSize
&size
,
1962 const long style
, const wxString
&name
)
1965 Create( parent
, id
, pos
, size
, style
, name
);
1968 wxListCtrl::~wxListCtrl(void)
1972 bool wxListCtrl::Create( wxWindow
*parent
, const wxWindowID id
,
1973 const wxPoint
&pos
, const wxSize
&size
,
1974 const long style
, const wxString
&name
)
1976 m_imageListNormal
= NULL
;
1977 m_imageListSmall
= NULL
;
1978 m_imageListState
= NULL
;
1982 if ((s
& wxLC_REPORT
== 0) &&
1983 (s
& wxLC_LIST
== 0) &&
1984 (s
& wxLC_ICON
== 0))
1987 bool ret
= wxControl::Create( parent
, id
, pos
, size
, s
, name
);
1989 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, s
);
1991 if (GetWindowStyleFlag() & wxLC_REPORT
)
1992 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23) );
1999 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2003 wxWindow::OnSize( event );
2007 GetClientSize( &cw, &ch );
2009 if (GetWindowStyleFlag() & wxLC_REPORT)
2011 m_headerWin->SetSize( 0, 0, cw, 23 );
2012 m_mainWin->SetSize( 0, 24, cw, ch-24 );
2016 m_mainWin->SetSize( 0, 0, cw, ch );
2021 void wxListCtrl::SetSingleStyle( const long style
, const bool add
)
2023 long flag
= GetWindowStyleFlag();
2027 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
2028 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
2029 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
2038 if (flag
& style
) flag
-= style
;
2041 SetWindowStyleFlag( flag
);
2044 void wxListCtrl::SetWindowStyleFlag( const long flag
)
2046 m_mainWin
->DeleteEverything();
2050 GetClientSize( &width
, &height
);
2052 m_mainWin
->SetMode( flag
);
2054 if (flag
& wxLC_REPORT
)
2056 if (!(GetWindowStyleFlag() & wxLC_REPORT
))
2058 // m_mainWin->SetSize( 0, 24, width, height-24 );
2061 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(width
,23) );
2065 // m_headerWin->SetSize( 0, 0, width, 23 );
2066 m_headerWin
->Show( TRUE
);
2072 if (GetWindowStyleFlag() & wxLC_REPORT
)
2074 // m_mainWin->SetSize( 0, 0, width, height );
2075 m_headerWin
->Show( FALSE
);
2079 wxWindow::SetWindowStyleFlag( flag
);
2082 void wxListCtrl::RealizeChanges( void )
2084 m_mainWin
->m_dirty
= TRUE
;
2088 GetClientSize( &cw
, &ch
);
2095 if (GetWindowStyleFlag() & wxLC_REPORT
)
2097 m_headerWin
->GetPosition( &x
, &y
);
2098 m_headerWin
->GetSize( &w
, &h
);
2099 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
2100 m_headerWin
->SetSize( 0, 0, cw
, 23 );
2102 m_mainWin
->GetPosition( &x
, &y
);
2103 m_mainWin
->GetSize( &w
, &h
);
2104 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
2105 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
2109 m_mainWin
->GetPosition( &x
, &y
);
2110 m_mainWin
->GetSize( &w
, &h
);
2111 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
2112 m_mainWin
->SetSize( 0, 0, cw
, ch
);
2115 m_mainWin
->CalculatePositions();
2116 m_mainWin
->RealizeChanges();
2117 m_mainWin
->m_dirty
= FALSE
;
2118 m_mainWin
->Refresh();
2121 void wxListCtrl::SetBackgroundColour(const wxColour
& col
)
2123 // This is from Julian. You know.
2124 // Not in wxWin 1.xx ???
2125 wxWindow::SetBackgroundColour( (wxColour
&)col
);
2128 bool wxListCtrl::GetColumn(const int col
, wxListItem
&item
)
2130 m_mainWin
->GetColumn( col
, item
);
2134 bool wxListCtrl::SetColumn( const int col
, wxListItem
& item
)
2136 m_mainWin
->SetColumn( col
, item
);
2140 int wxListCtrl::GetColumnWidth( const int col
)
2142 return m_mainWin
->GetColumnWidth( col
);
2145 bool wxListCtrl::SetColumnWidth( const int col
, const int width
)
2147 m_mainWin
->SetColumnWidth( col
, width
);
2151 int wxListCtrl::GetCountPerPage(void)
2153 return m_mainWin
->GetCountPerPage(); // different from Windows ?
2157 wxText& wxListCtrl::GetEditControl(void) const
2162 bool wxListCtrl::GetItem( wxListItem
&info
)
2164 m_mainWin
->GetItem( info
);
2168 bool wxListCtrl::SetItem( wxListItem
&info
)
2170 m_mainWin
->SetItem( info
);
2174 long wxListCtrl::SetItem( const long index
, const int col
, const wxString
& label
, const int imageId
)
2177 info
.m_text
= label
;
2178 info
.m_mask
= wxLIST_MASK_TEXT
;
2179 info
.m_itemId
= index
;
2183 info
.m_image
= imageId
;
2184 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2187 m_mainWin
->SetItem(info
);
2191 int wxListCtrl::GetItemState( const long item
, const long stateMask
)
2193 return m_mainWin
->GetItemState( item
, stateMask
);
2196 bool wxListCtrl::SetItemState( const long item
, const long state
, const long stateMask
)
2198 m_mainWin
->SetItemState( item
, state
, stateMask
);
2202 bool wxListCtrl::SetItemImage( const long item
, const int image
, const int WXUNUSED(selImage
) )
2205 info
.m_image
= image
;
2206 info
.m_mask
= wxLIST_MASK_IMAGE
;
2207 info
.m_itemId
= item
;
2208 m_mainWin
->SetItem( info
);
2212 wxString
wxListCtrl::GetItemText( const long item
)
2215 info
.m_itemId
= item
;
2216 m_mainWin
->GetItem( info
);
2220 void wxListCtrl::SetItemText( const long item
, const wxString
&str
)
2223 info
.m_mask
= wxLIST_MASK_TEXT
;
2224 info
.m_itemId
= item
;
2226 m_mainWin
->SetItem( info
);
2229 long wxListCtrl::GetItemData( const long item
)
2232 info
.m_itemId
= item
;
2233 m_mainWin
->GetItem( info
);
2237 bool wxListCtrl::SetItemData( const long item
, long data
)
2240 info
.m_mask
= wxLIST_MASK_DATA
;
2241 info
.m_itemId
= item
;
2243 m_mainWin
->SetItem( info
);
2247 bool wxListCtrl::GetItemRect( const long item
, wxRectangle
&rect
, const int WXUNUSED(code
) )
2249 m_mainWin
->GetItemRect( item
, rect
);
2253 bool wxListCtrl::GetItemPosition( const long WXUNUSED(item
), wxPoint
& WXUNUSED(pos
) ) const
2258 bool wxListCtrl::SetItemPosition( const long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
2263 int wxListCtrl::GetItemCount(void)
2265 return m_mainWin
->GetItemCount();
2268 int wxListCtrl::GetItemSpacing( bool isSmall
)
2270 return m_mainWin
->GetItemSpacing( isSmall
);
2273 int wxListCtrl::GetSelectedItemCount(void)
2275 return m_mainWin
->GetSelectedItemCount();
2279 wxColour wxListCtrl::GetTextColour(void) const
2283 void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
2288 long wxListCtrl::GetTopItem(void)
2293 long wxListCtrl::GetNextItem( const long item
, int geom
, int state
)
2295 return m_mainWin
->GetNextItem( item
, geom
, state
);
2298 wxImageList
*wxListCtrl::GetImageList(const int which
)
2300 if (which
== wxIMAGE_LIST_NORMAL
)
2302 return m_imageListNormal
;
2304 else if (which
== wxIMAGE_LIST_SMALL
)
2306 return m_imageListSmall
;
2308 else if (which
== wxIMAGE_LIST_STATE
)
2310 return m_imageListState
;
2315 void wxListCtrl::SetImageList( wxImageList
*imageList
, const int which
)
2317 m_mainWin
->SetImageList( imageList
, which
);
2320 bool wxListCtrl::Arrange( const int WXUNUSED(flag
) )
2325 bool wxListCtrl::DeleteItem( const long item
)
2327 m_mainWin
->DeleteItem( item
);
2331 bool wxListCtrl::DeleteAllItems(void)
2333 m_mainWin
->DeleteAllItems();
2337 bool wxListCtrl::DeleteColumn( const int col
)
2339 m_mainWin
->DeleteColumn( col
);
2344 wxText& wxListCtrl::Edit( const long WXUNUSED(item ) )
2349 bool wxListCtrl::EnsureVisible( const long item
)
2351 m_mainWin
->EnsureVisible( item
);
2355 long wxListCtrl::FindItem( const long start
, const wxString
& str
, const bool partial
)
2357 return m_mainWin
->FindItem( start
, str
, partial
);
2360 long wxListCtrl::FindItem( const long start
, const long data
)
2362 return m_mainWin
->FindItem( start
, data
);
2365 long wxListCtrl::FindItem( const long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
2366 const int WXUNUSED(direction
))
2371 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
2373 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
2376 long wxListCtrl::InsertItem( wxListItem
& info
)
2378 m_mainWin
->InsertItem( info
);
2382 long wxListCtrl::InsertItem( const long index
, const wxString
&label
)
2385 info
.m_text
= label
;
2386 info
.m_mask
= wxLIST_MASK_TEXT
;
2387 info
.m_itemId
= index
;
2388 return InsertItem( info
);
2391 long wxListCtrl::InsertItem( const long index
, const int imageIndex
)
2394 info
.m_mask
= wxLIST_MASK_IMAGE
;
2395 info
.m_image
= imageIndex
;
2396 info
.m_itemId
= index
;
2397 return InsertItem( info
);
2400 long wxListCtrl::InsertItem( const long index
, const wxString
&label
, const int imageIndex
)
2403 info
.m_text
= label
;
2404 info
.m_image
= imageIndex
;
2405 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
2406 info
.m_itemId
= index
;
2407 return InsertItem( info
);
2410 long wxListCtrl::InsertColumn( const long col
, wxListItem
&item
)
2412 m_mainWin
->InsertColumn( col
, item
);
2416 long wxListCtrl::InsertColumn( const long col
, const wxString
&heading
,
2417 const int format
, const int width
)
2420 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
2421 item
.m_text
= heading
;
2424 item
.m_mask
|= wxLIST_MASK_WIDTH
;
2425 item
.m_width
= width
;
2428 item
.m_format
= format
;
2430 return InsertColumn( col
, item
);
2433 bool wxListCtrl::ScrollList( const int WXUNUSED(dx
), const int WXUNUSED(dy
) )
2439 // fn is a function which takes 3 long arguments: item1, item2, data.
2440 // item1 is the long data associated with a first item (NOT the index).
2441 // item2 is the long data associated with a second item (NOT the index).
2442 // data is the same value as passed to SortItems.
2443 // The return value is a negative number if the first item should precede the second
2444 // item, a positive number of the second item should precede the first,
2445 // or zero if the two items are equivalent.
2446 // data is arbitrary data to be passed to the sort function.
2448 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
2450 m_mainWin
->SortItems( fn
, data
);