1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
26 #include "wx/dynarray.h"
28 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
29 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
32 // ============================================================================
34 // ============================================================================
36 //-----------------------------------------------------------------------------
37 // wxListItemData (internal)
38 //-----------------------------------------------------------------------------
40 class WXDLLEXPORT wxListItemData
: public wxObject
49 wxListItemAttr
*m_attr
;
53 ~wxListItemData() { delete m_attr
; }
55 wxListItemData( const wxListItem
&info
);
56 void SetItem( const wxListItem
&info
);
57 void SetText( const wxString
&s
);
58 void SetImage( int image
);
59 void SetData( long data
);
60 void SetPosition( int x
, int y
);
61 void SetSize( int width
, int height
);
62 bool HasImage() const;
64 bool IsHit( int x
, int y
) const;
65 void GetText( wxString
&s
);
66 const wxString
& GetText() { return m_text
; }
67 int GetX( void ) const;
68 int GetY( void ) const;
70 int GetHeight() const;
72 void GetItem( wxListItem
&info
) const;
74 wxListItemAttr
*GetAttributes() const { return m_attr
; }
77 DECLARE_DYNAMIC_CLASS(wxListItemData
);
80 //-----------------------------------------------------------------------------
81 // wxListHeaderData (internal)
82 //-----------------------------------------------------------------------------
84 class WXDLLEXPORT wxListHeaderData
: public wxObject
97 wxListHeaderData( const wxListItem
&info
);
98 void SetItem( const wxListItem
&item
);
99 void SetPosition( int x
, int y
);
100 void SetWidth( int w
);
101 void SetFormat( int format
);
102 void SetHeight( int h
);
103 bool HasImage() const;
104 bool HasText() const;
105 bool IsHit( int x
, int y
) const;
106 void GetItem( wxListItem
&item
);
107 void GetText( wxString
&s
);
108 int GetImage() const;
109 int GetWidth() const;
110 int GetFormat() const;
113 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
116 //-----------------------------------------------------------------------------
117 // wxListLineData (internal)
118 //-----------------------------------------------------------------------------
120 class WXDLLEXPORT wxListLineData
: public wxObject
125 wxRect m_bound_label
;
127 wxRect m_bound_hilight
;
130 wxBrush
*m_hilightBrush
;
132 wxListMainWindow
*m_owner
;
134 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
138 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
139 void CalculateSize( wxDC
*dc
, int spacing
);
140 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
141 void SetColumnPosition( int index
, int x
);
142 void GetSize( int &width
, int &height
);
143 void GetExtent( int &x
, int &y
, int &width
, int &height
);
144 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
145 long IsHit( int x
, int y
);
146 void InitItems( int num
);
147 void SetItem( int index
, const wxListItem
&info
);
148 void GetItem( int index
, wxListItem
&info
);
149 void GetText( int index
, wxString
&s
);
150 void SetText( int index
, const wxString s
);
151 int GetImage( int index
);
152 void GetRect( wxRect
&rect
);
153 void Hilight( bool on
);
154 void ReverseHilight();
155 void DrawRubberBand( wxDC
*dc
, bool on
);
156 void Draw( wxDC
*dc
);
157 bool IsInRect( int x
, int y
, const wxRect
&rect
);
159 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
160 void AssignRect( wxRect
&dest
, const wxRect
&source
);
163 void SetAttributes(wxDC
*dc
,
164 const wxListItemAttr
*attr
,
165 const wxColour
& colText
, const wxFont
& font
,
168 DECLARE_DYNAMIC_CLASS(wxListLineData
);
172 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
173 #include "wx/arrimpl.cpp"
174 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
176 //-----------------------------------------------------------------------------
177 // wxListHeaderWindow (internal)
178 //-----------------------------------------------------------------------------
180 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
183 wxListMainWindow
*m_owner
;
184 wxCursor
*m_currentCursor
;
185 wxCursor
*m_resizeCursor
;
188 // column being resized
191 // divider line position in logical (unscrolled) coords
194 // minimal position beyond which the divider line can't be dragged in
199 wxListHeaderWindow();
200 virtual ~wxListHeaderWindow();
202 wxListHeaderWindow( wxWindow
*win
,
204 wxListMainWindow
*owner
,
205 const wxPoint
&pos
= wxDefaultPosition
,
206 const wxSize
&size
= wxDefaultSize
,
208 const wxString
&name
= "wxlistctrlcolumntitles" );
210 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
212 void AdjustDC(wxDC
& dc
);
214 void OnPaint( wxPaintEvent
&event
);
215 void OnMouse( wxMouseEvent
&event
);
216 void OnSetFocus( wxFocusEvent
&event
);
222 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
223 DECLARE_EVENT_TABLE()
226 //-----------------------------------------------------------------------------
227 // wxListRenameTimer (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
233 wxListMainWindow
*m_owner
;
236 wxListRenameTimer( wxListMainWindow
*owner
);
240 //-----------------------------------------------------------------------------
241 // wxListTextCtrl (internal)
242 //-----------------------------------------------------------------------------
244 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
249 wxListMainWindow
*m_owner
;
250 wxString m_startValue
;
254 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
255 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
256 const wxString
&value
= "",
257 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
259 const wxValidator
& validator
= wxDefaultValidator
,
260 const wxString
&name
= "listctrltextctrl" );
261 void OnChar( wxKeyEvent
&event
);
262 void OnKillFocus( wxFocusEvent
&event
);
265 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
266 DECLARE_EVENT_TABLE()
269 //-----------------------------------------------------------------------------
270 // wxListMainWindow (internal)
271 //-----------------------------------------------------------------------------
273 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
277 wxListLineDataArray m_lines
;
279 wxListLineData
*m_current
;
280 wxListLineData
*m_currentEdit
;
282 wxBrush
*m_hilightBrush
;
283 wxColour
*m_hilightColour
;
284 int m_xScroll
,m_yScroll
;
286 wxImageList
*m_small_image_list
;
287 wxImageList
*m_normal_image_list
;
289 int m_normal_spacing
;
293 wxTimer
*m_renameTimer
;
295 wxString m_renameRes
;
300 // for double click logic
301 wxListLineData
*m_lineLastClicked
,
302 *m_lineBeforeLastClicked
;
306 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
307 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
308 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
310 void RefreshLine( wxListLineData
*line
);
311 void OnPaint( wxPaintEvent
&event
);
312 void HilightAll( bool on
);
313 void SendNotify( wxListLineData
*line
, wxEventType command
);
314 void FocusLine( wxListLineData
*line
);
315 void UnfocusLine( wxListLineData
*line
);
316 void SelectLine( wxListLineData
*line
);
317 void DeselectLine( wxListLineData
*line
);
318 void DeleteLine( wxListLineData
*line
);
320 void EditLabel( long item
);
321 void Edit( long item
) { EditLabel(item
); } // deprecated
322 void OnRenameTimer();
323 void OnRenameAccept();
325 void OnMouse( wxMouseEvent
&event
);
327 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
328 void OnChar( wxKeyEvent
&event
);
329 void OnKeyDown( wxKeyEvent
&event
);
330 void OnSetFocus( wxFocusEvent
&event
);
331 void OnKillFocus( wxFocusEvent
&event
);
332 void OnSize( wxSizeEvent
&event
);
333 void OnScroll(wxScrollWinEvent
& event
) ;
335 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
336 void GetImageSize( int index
, int &width
, int &height
);
337 int GetIndexOfLine( const wxListLineData
*line
);
338 int GetTextLength( wxString
&s
); // should be const
340 void SetImageList( wxImageList
*imageList
, int which
);
341 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
342 int GetItemSpacing( bool isSmall
= FALSE
);
343 void SetColumn( int col
, wxListItem
&item
);
344 void SetColumnWidth( int col
, int width
);
345 void GetColumn( int col
, wxListItem
&item
);
346 int GetColumnWidth( int vol
);
347 int GetColumnCount();
348 int GetCountPerPage();
349 void SetItem( wxListItem
&item
);
350 void GetItem( wxListItem
&item
);
351 void SetItemState( long item
, long state
, long stateMask
);
352 int GetItemState( long item
, long stateMask
);
354 void GetItemRect( long index
, wxRect
&rect
);
355 bool GetItemPosition( long item
, wxPoint
& pos
);
356 int GetSelectedItemCount();
357 void SetMode( long mode
);
358 long GetMode() const;
359 void CalculatePositions();
360 void RealizeChanges();
361 long GetNextItem( long item
, int geometry
, int state
);
362 void DeleteItem( long index
);
363 void DeleteAllItems();
364 void DeleteColumn( int col
);
365 void DeleteEverything();
366 void EnsureVisible( long index
);
367 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
368 long FindItem( long start
, long data
);
369 long HitTest( int x
, int y
, int &flags
);
370 void InsertItem( wxListItem
&item
);
371 // void AddItem( wxListItem &item );
372 void InsertColumn( long col
, wxListItem
&item
);
373 // void AddColumn( wxListItem &item );
374 void SortItems( wxListCtrlCompare fn
, long data
);
377 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
378 DECLARE_EVENT_TABLE()
381 // ============================================================================
383 // ============================================================================
385 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
389 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
391 wxListItemData::wxListItemData()
402 wxListItemData::wxListItemData( const wxListItem
&info
)
411 void wxListItemData::SetItem( const wxListItem
&info
)
413 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
414 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
415 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
417 if ( info
.HasAttributes() )
420 *m_attr
= *info
.GetAttributes();
422 m_attr
= new wxListItemAttr(*info
.GetAttributes());
427 m_width
= info
.m_width
;
431 void wxListItemData::SetText( const wxString
&s
)
436 void wxListItemData::SetImage( int image
)
441 void wxListItemData::SetData( long data
)
446 void wxListItemData::SetPosition( int x
, int y
)
452 void wxListItemData::SetSize( int width
, int height
)
454 if (width
!= -1) m_width
= width
;
455 if (height
!= -1) m_height
= height
;
458 bool wxListItemData::HasImage() const
460 return (m_image
>= 0);
463 bool wxListItemData::HasText() const
465 return (!m_text
.IsNull());
468 bool wxListItemData::IsHit( int x
, int y
) const
470 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
473 void wxListItemData::GetText( wxString
&s
)
478 int wxListItemData::GetX() const
483 int wxListItemData::GetY() const
488 int wxListItemData::GetWidth() const
493 int wxListItemData::GetHeight() const
498 int wxListItemData::GetImage() const
503 void wxListItemData::GetItem( wxListItem
&info
) const
505 info
.m_text
= m_text
;
506 info
.m_image
= m_image
;
507 info
.m_data
= m_data
;
511 if ( m_attr
->HasTextColour() )
512 info
.SetTextColour(m_attr
->GetTextColour());
513 if ( m_attr
->HasBackgroundColour() )
514 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
515 if ( m_attr
->HasFont() )
516 info
.SetFont(m_attr
->GetFont());
520 //-----------------------------------------------------------------------------
522 //-----------------------------------------------------------------------------
524 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
526 wxListHeaderData::wxListHeaderData()
537 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
545 void wxListHeaderData::SetItem( const wxListItem
&item
)
547 m_mask
= item
.m_mask
;
548 m_text
= item
.m_text
;
549 m_image
= item
.m_image
;
550 m_format
= item
.m_format
;
551 m_width
= item
.m_width
;
552 if (m_width
< 0) m_width
= 80;
553 if (m_width
< 6) m_width
= 6;
556 void wxListHeaderData::SetPosition( int x
, int y
)
562 void wxListHeaderData::SetHeight( int h
)
567 void wxListHeaderData::SetWidth( int w
)
570 if (m_width
< 0) m_width
= 80;
571 if (m_width
< 6) m_width
= 6;
574 void wxListHeaderData::SetFormat( int format
)
579 bool wxListHeaderData::HasImage() const
581 return (m_image
!= 0);
584 bool wxListHeaderData::HasText() const
586 return (m_text
.Length() > 0);
589 bool wxListHeaderData::IsHit( int x
, int y
) const
591 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
594 void wxListHeaderData::GetItem( wxListItem
&item
)
596 item
.m_mask
= m_mask
;
597 item
.m_text
= m_text
;
598 item
.m_image
= m_image
;
599 item
.m_format
= m_format
;
600 item
.m_width
= m_width
;
603 void wxListHeaderData::GetText( wxString
&s
)
608 int wxListHeaderData::GetImage() const
613 int wxListHeaderData::GetWidth() const
618 int wxListHeaderData::GetFormat() const
623 //-----------------------------------------------------------------------------
625 //-----------------------------------------------------------------------------
627 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
629 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
634 m_hilightBrush
= hilightBrush
;
635 m_items
.DeleteContents( TRUE
);
639 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
646 m_bound_all
.width
= m_spacing
;
647 wxNode
*node
= m_items
.First();
650 wxListItemData
*item
= (wxListItemData
*)node
->Data();
651 wxString s
= item
->GetText();
652 if (s
.IsEmpty()) s
= wxT("H");
654 dc
->GetTextExtent( s
, &lw
, &lh
);
655 if (lh
< 15) lh
= 15;
659 m_bound_all
.height
= m_spacing
+lh
;
660 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
661 m_bound_label
.width
= lw
;
662 m_bound_label
.height
= lh
;
664 if (item
->HasImage())
668 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
669 m_bound_icon
.width
= w
+ 8;
670 m_bound_icon
.height
= h
+ 8;
672 if ( m_bound_icon
.width
> m_bound_all
.width
)
673 m_bound_all
.width
= m_bound_icon
.width
;
674 if ( h
+ lh
> m_bound_all
.height
- 4 )
675 m_bound_all
.height
= h
+ lh
+ 4;
678 if (!item
->HasText())
680 m_bound_hilight
.width
= m_bound_icon
.width
;
681 m_bound_hilight
.height
= m_bound_icon
.height
;
685 m_bound_hilight
.width
= m_bound_label
.width
;
686 m_bound_hilight
.height
= m_bound_label
.height
;
693 wxNode
*node
= m_items
.First();
696 wxListItemData
*item
= (wxListItemData
*)node
->Data();
698 wxString s
= item
->GetText();
699 if (s
.IsEmpty()) s
= wxT("H");
701 dc
->GetTextExtent( s
, &lw
, &lh
);
702 if (lh
< 15) lh
= 15;
705 m_bound_label
.width
= lw
;
706 m_bound_label
.height
= lh
;
708 m_bound_all
.width
= lw
;
709 m_bound_all
.height
= lh
;
711 if (item
->HasImage())
715 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
716 m_bound_icon
.width
= w
;
717 m_bound_icon
.height
= h
;
719 m_bound_all
.width
+= 4 + w
;
720 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
723 m_bound_hilight
.width
= m_bound_all
.width
;
724 m_bound_hilight
.height
= m_bound_all
.height
;
730 m_bound_all
.width
= 0;
731 m_bound_all
.height
= 0;
732 wxNode
*node
= m_items
.First();
735 wxListItemData
*item
= (wxListItemData
*)node
->Data();
736 if (item
->HasImage())
740 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
741 m_bound_icon
.width
= w
;
742 m_bound_icon
.height
= h
;
746 m_bound_icon
.width
= 0;
747 m_bound_icon
.height
= 0;
752 wxListItemData
*item
= (wxListItemData
*)node
->Data();
753 wxString s
= item
->GetText();
754 if (s
.IsEmpty()) s
= wxT("H");
756 dc
->GetTextExtent( s
, &lw
, &lh
);
757 if (lh
< 15) lh
= 15;
761 item
->SetSize( item
->GetWidth(), lh
);
762 m_bound_all
.width
+= lw
;
763 m_bound_all
.height
= lh
;
771 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
772 int x
, int y
, int window_width
)
780 wxNode
*node
= m_items
.First();
783 wxListItemData
*item
= (wxListItemData
*)node
->Data();
784 if (item
->HasImage())
786 m_bound_icon
.x
= m_bound_all
.x
+ 4
787 + (m_spacing
- m_bound_icon
.width
)/2;
788 m_bound_icon
.y
= m_bound_all
.y
+ 4;
792 if (m_bound_all
.width
> m_spacing
)
793 m_bound_label
.x
= m_bound_all
.x
+ 2;
795 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
796 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
797 m_bound_hilight
.x
= m_bound_label
.x
- 2;
798 m_bound_hilight
.y
= m_bound_label
.y
- 2;
802 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
803 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
810 m_bound_hilight
.x
= m_bound_all
.x
;
811 m_bound_hilight
.y
= m_bound_all
.y
;
812 m_bound_label
.y
= m_bound_all
.y
+ 2;
813 wxNode
*node
= m_items
.First();
816 wxListItemData
*item
= (wxListItemData
*)node
->Data();
817 if (item
->HasImage())
819 m_bound_icon
.x
= m_bound_all
.x
+ 2;
820 m_bound_icon
.y
= m_bound_all
.y
+ 2;
821 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
825 m_bound_label
.x
= m_bound_all
.x
+ 2;
833 m_bound_all
.width
= window_width
;
834 AssignRect( m_bound_hilight
, m_bound_all
);
835 m_bound_label
.x
= m_bound_all
.x
+ 2;
836 m_bound_label
.y
= m_bound_all
.y
+ 2;
837 wxNode
*node
= m_items
.First();
840 wxListItemData
*item
= (wxListItemData
*)node
->Data();
841 if (item
->HasImage())
843 m_bound_icon
.x
= m_bound_all
.x
+ 2;
844 m_bound_icon
.y
= m_bound_all
.y
+ 2;
845 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
853 void wxListLineData::SetColumnPosition( int index
, int x
)
855 wxNode
*node
= m_items
.Nth( (size_t)index
);
858 wxListItemData
*item
= (wxListItemData
*)node
->Data();
859 item
->SetPosition( x
, m_bound_all
.y
+1 );
863 void wxListLineData::GetSize( int &width
, int &height
)
865 width
= m_bound_all
.width
;
866 height
= m_bound_all
.height
;
869 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
873 width
= m_bound_all
.width
;
874 height
= m_bound_all
.height
;
877 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
881 width
= m_bound_label
.width
;
882 height
= m_bound_label
.height
;
885 void wxListLineData::GetRect( wxRect
&rect
)
887 AssignRect( rect
, m_bound_all
);
890 long wxListLineData::IsHit( int x
, int y
)
892 wxNode
*node
= m_items
.First();
895 wxListItemData
*item
= (wxListItemData
*)node
->Data();
896 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
897 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
898 // if (!(item->HasImage() || item->HasText())) return 0;
900 // if there is no icon or text = empty
901 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
905 void wxListLineData::InitItems( int num
)
907 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
910 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
912 wxNode
*node
= m_items
.Nth( index
);
915 wxListItemData
*item
= (wxListItemData
*)node
->Data();
916 item
->SetItem( info
);
920 void wxListLineData::GetItem( int index
, wxListItem
&info
)
923 wxNode
*node
= m_items
.Nth( i
);
926 wxListItemData
*item
= (wxListItemData
*)node
->Data();
927 item
->GetItem( info
);
931 void wxListLineData::GetText( int index
, wxString
&s
)
934 wxNode
*node
= m_items
.Nth( i
);
938 wxListItemData
*item
= (wxListItemData
*)node
->Data();
943 void wxListLineData::SetText( int index
, const wxString s
)
946 wxNode
*node
= m_items
.Nth( i
);
949 wxListItemData
*item
= (wxListItemData
*)node
->Data();
954 int wxListLineData::GetImage( int index
)
957 wxNode
*node
= m_items
.Nth( i
);
960 wxListItemData
*item
= (wxListItemData
*)node
->Data();
961 return item
->GetImage();
966 void wxListLineData::SetAttributes(wxDC
*dc
,
967 const wxListItemAttr
*attr
,
968 const wxColour
& colText
,
972 // don't use foregroud colour for drawing highlighted items - this might
973 // make them completely invisible (and there is no way to do bit
974 // arithmetics on wxColour, unfortunately)
975 if ( !hilight
&& attr
&& attr
->HasTextColour() )
977 dc
->SetTextForeground(attr
->GetTextColour());
981 dc
->SetTextForeground(colText
);
984 if ( attr
&& attr
->HasFont() )
986 dc
->SetFont(attr
->GetFont());
994 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
998 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
999 wxCoord dev_w
= m_bound_all
.width
;
1000 wxCoord dev_h
= m_bound_all
.height
;
1002 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1005 wxWindow
*listctrl
= m_owner
->GetParent();
1007 // default foreground colour
1011 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1015 colText
= listctrl
->GetForegroundColour();
1019 wxFont font
= listctrl
->GetFont();
1021 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1022 // using SetAttributes() inside the loop), it will be trivial to
1023 // customize the subitems (in report mode) too.
1024 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1025 wxListItemAttr
*attr
= item
->GetAttributes();
1026 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1028 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1029 if ( paintBG
|| hasBgCol
)
1033 dc
->SetBrush( * m_hilightBrush
);
1038 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1040 dc
->SetBrush( * wxWHITE_BRUSH
);
1043 dc
->SetPen( * wxTRANSPARENT_PEN
);
1044 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1045 m_bound_hilight
.width
, m_bound_hilight
.height
);
1048 if (m_mode
== wxLC_REPORT
)
1050 wxNode
*node
= m_items
.First();
1053 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1054 int x
= item
->GetX();
1055 if (item
->HasImage())
1058 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1059 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1060 x
+= item
->GetX() + 5;
1062 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1063 if (item
->HasText())
1065 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1067 dc
->DestroyClippingRegion();
1068 node
= node
->Next();
1073 wxNode
*node
= m_items
.First();
1076 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1077 if (item
->HasImage())
1079 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1081 if (item
->HasText())
1083 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1089 void wxListLineData::Hilight( bool on
)
1091 if (on
== m_hilighted
) return;
1094 m_owner
->SelectLine( this );
1096 m_owner
->DeselectLine( this );
1099 void wxListLineData::ReverseHilight( void )
1101 m_hilighted
= !m_hilighted
;
1103 m_owner
->SelectLine( this );
1105 m_owner
->DeselectLine( this );
1108 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1112 dc
->SetPen( * wxBLACK_PEN
);
1113 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1114 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1115 m_bound_hilight
.width
, m_bound_hilight
.height
);
1119 void wxListLineData::Draw( wxDC
*dc
)
1121 DoDraw( dc
, m_hilighted
, m_hilighted
);
1124 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1126 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1127 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1130 bool wxListLineData::IsHilighted( void )
1135 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1140 dest
.height
= height
;
1143 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1147 dest
.width
= source
.width
;
1148 dest
.height
= source
.height
;
1151 //-----------------------------------------------------------------------------
1152 // wxListHeaderWindow
1153 //-----------------------------------------------------------------------------
1155 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1157 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1158 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1159 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1160 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1163 wxListHeaderWindow::wxListHeaderWindow( void )
1165 m_owner
= (wxListMainWindow
*) NULL
;
1166 m_currentCursor
= (wxCursor
*) NULL
;
1167 m_resizeCursor
= (wxCursor
*) NULL
;
1168 m_isDragging
= FALSE
;
1171 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1172 const wxPoint
&pos
, const wxSize
&size
,
1173 long style
, const wxString
&name
) :
1174 wxWindow( win
, id
, pos
, size
, style
, name
)
1177 // m_currentCursor = wxSTANDARD_CURSOR;
1178 m_currentCursor
= (wxCursor
*) NULL
;
1179 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1180 m_isDragging
= FALSE
;
1183 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1186 wxListHeaderWindow::~wxListHeaderWindow( void )
1188 delete m_resizeCursor
;
1191 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1193 const int m_corner
= 1;
1195 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1197 dc
->SetPen( *wxBLACK_PEN
);
1198 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1199 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1201 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1204 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1205 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1207 dc
->SetPen( *wxWHITE_PEN
);
1208 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1209 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1210 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1211 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1214 // shift the DC origin to match the position of the main window horz
1215 // scrollbar: this allows us to always use logical coords
1216 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1218 #if wxUSE_GENERIC_LIST_EXTENSIONS
1220 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1223 m_owner
->GetViewStart( &x
, NULL
);
1225 // account for the horz scrollbar offset
1226 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1227 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1230 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1232 wxPaintDC
dc( this );
1238 dc
.SetFont( GetFont() );
1240 // width and height of the entire header window
1242 GetClientSize( &w
, &h
);
1243 #if wxUSE_GENERIC_LIST_EXTENSIONS
1244 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1245 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1247 dc
.SetBackgroundMode(wxTRANSPARENT
);
1249 // do *not* use the listctrl colour for headers - one day we will have a
1250 // function to set it separately
1251 //dc.SetTextForeground( *wxBLACK );
1252 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1254 int x
= 1; // left of the header rect
1255 const int y
= 1; // top
1256 int numColumns
= m_owner
->GetColumnCount();
1258 for (int i
= 0; i
< numColumns
; i
++)
1260 m_owner
->GetColumn( i
, item
);
1261 int wCol
= item
.m_width
;
1262 int cw
= wCol
- 2; // the width of the rect to draw
1264 int xEnd
= x
+ wCol
;
1266 // VZ: no, draw it normally - this is better now as we allow resizing
1267 // of the last column as well
1269 // let the last column occupy all available space
1270 if ( i
== numColumns
- 1 )
1274 dc
.SetPen( *wxWHITE_PEN
);
1276 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1277 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1278 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1279 dc
.DestroyClippingRegion();
1288 void wxListHeaderWindow::DrawCurrent()
1290 int x1
= m_currentX
;
1292 ClientToScreen( &x1
, &y1
);
1294 int x2
= m_currentX
-1;
1296 m_owner
->GetClientSize( NULL
, &y2
);
1297 m_owner
->ClientToScreen( &x2
, &y2
);
1300 dc
.SetLogicalFunction( wxINVERT
);
1301 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1302 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1306 dc
.DrawLine( x1
, y1
, x2
, y2
);
1308 dc
.SetLogicalFunction( wxCOPY
);
1310 dc
.SetPen( wxNullPen
);
1311 dc
.SetBrush( wxNullBrush
);
1314 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1316 // we want to work with logical coords
1317 #if wxUSE_GENERIC_LIST_EXTENSIONS
1319 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1320 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1321 int x
= event
.GetX();
1322 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1323 int y
= event
.GetY();
1327 // we don't draw the line beyond our window, but we allow dragging it
1330 GetClientSize( &w
, NULL
);
1331 #if wxUSE_GENERIC_LIST_EXTENSIONS
1332 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1333 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1336 // erase the line if it was drawn
1337 if ( m_currentX
< w
)
1340 if (event
.ButtonUp())
1343 m_isDragging
= FALSE
;
1345 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1352 m_currentX
= m_minX
+ 7;
1354 // draw in the new location
1355 if ( m_currentX
< w
)
1359 else // not dragging
1362 bool hit_border
= FALSE
;
1364 // end of the current column
1367 // find the column where this event occured
1368 int countCol
= m_owner
->GetColumnCount();
1369 for (int j
= 0; j
< countCol
; j
++)
1371 xpos
+= m_owner
->GetColumnWidth( j
);
1374 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1376 // near the column border
1383 // inside the column
1390 if (event
.LeftDown())
1394 m_isDragging
= TRUE
;
1401 wxWindow
*parent
= GetParent();
1402 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1403 le
.SetEventObject( parent
);
1404 le
.m_col
= m_column
;
1405 parent
->GetEventHandler()->ProcessEvent( le
);
1408 else if (event
.Moving())
1413 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1414 m_currentCursor
= m_resizeCursor
;
1418 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1419 m_currentCursor
= wxSTANDARD_CURSOR
;
1423 SetCursor(*m_currentCursor
);
1428 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1430 m_owner
->SetFocus();
1433 //-----------------------------------------------------------------------------
1434 // wxListRenameTimer (internal)
1435 //-----------------------------------------------------------------------------
1437 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1442 void wxListRenameTimer::Notify()
1444 m_owner
->OnRenameTimer();
1447 //-----------------------------------------------------------------------------
1448 // wxListTextCtrl (internal)
1449 //-----------------------------------------------------------------------------
1451 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1453 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1454 EVT_CHAR (wxListTextCtrl::OnChar
)
1455 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1458 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1459 const wxWindowID id
,
1462 wxListMainWindow
*owner
,
1463 const wxString
&value
,
1467 const wxValidator
& validator
,
1468 const wxString
&name
)
1469 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1474 (*m_accept
) = FALSE
;
1476 m_startValue
= value
;
1479 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1481 if (event
.m_keyCode
== WXK_RETURN
)
1484 (*m_res
) = GetValue();
1486 if (!wxPendingDelete
.Member(this))
1487 wxPendingDelete
.Append(this);
1489 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1490 m_owner
->OnRenameAccept();
1494 if (event
.m_keyCode
== WXK_ESCAPE
)
1496 (*m_accept
) = FALSE
;
1499 if (!wxPendingDelete
.Member(this))
1500 wxPendingDelete
.Append(this);
1508 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1510 if (!wxPendingDelete
.Member(this))
1511 wxPendingDelete
.Append(this);
1513 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1514 m_owner
->OnRenameAccept();
1517 //-----------------------------------------------------------------------------
1519 //-----------------------------------------------------------------------------
1521 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1523 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1524 EVT_PAINT (wxListMainWindow::OnPaint
)
1525 EVT_SIZE (wxListMainWindow::OnSize
)
1526 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1527 EVT_CHAR (wxListMainWindow::OnChar
)
1528 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1529 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1530 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1531 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1534 wxListMainWindow::wxListMainWindow()
1537 m_columns
.DeleteContents( TRUE
);
1538 m_current
= (wxListLineData
*) NULL
;
1540 m_hilightBrush
= (wxBrush
*) NULL
;
1544 m_small_image_list
= (wxImageList
*) NULL
;
1545 m_normal_image_list
= (wxImageList
*) NULL
;
1546 m_small_spacing
= 30;
1547 m_normal_spacing
= 40;
1550 m_lastOnSame
= FALSE
;
1551 m_renameTimer
= new wxListRenameTimer( this );
1552 m_isCreated
= FALSE
;
1556 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1559 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1560 const wxPoint
&pos
, const wxSize
&size
,
1561 long style
, const wxString
&name
) :
1562 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1565 m_columns
.DeleteContents( TRUE
);
1566 m_current
= (wxListLineData
*) NULL
;
1569 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1570 m_small_image_list
= (wxImageList
*) NULL
;
1571 m_normal_image_list
= (wxImageList
*) NULL
;
1572 m_small_spacing
= 30;
1573 m_normal_spacing
= 40;
1576 m_isCreated
= FALSE
;
1580 if (m_mode
& wxLC_REPORT
)
1582 #if wxUSE_GENERIC_LIST_EXTENSIONS
1594 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1597 m_lastOnSame
= FALSE
;
1598 m_renameTimer
= new wxListRenameTimer( this );
1599 m_renameAccept
= FALSE
;
1601 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1604 wxListMainWindow::~wxListMainWindow()
1608 if (m_hilightBrush
) delete m_hilightBrush
;
1610 delete m_renameTimer
;
1613 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1615 if (m_dirty
) return;
1623 line
->GetExtent( x
, y
, w
, h
);
1624 CalcScrolledPosition( x
, y
, &x
, &y
);
1625 wxRect
rect( x
, y
, w
, h
);
1626 Refresh( TRUE
, &rect
);
1629 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1631 // Note: a wxPaintDC must be constructed even if no drawing is
1632 // done (a Windows requirement).
1633 wxPaintDC
dc( this );
1636 if (m_dirty
) return;
1638 if (m_lines
.GetCount() == 0) return;
1642 dc
.SetFont( GetFont() );
1644 if (m_mode
& wxLC_REPORT
)
1646 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1648 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1650 wxSize clientSize
= GetClientSize();
1653 int lineSpacing
= 0;
1654 wxListLineData
*line
= &m_lines
[0];
1656 line
->GetSize( dummy
, lineSpacing
);
1659 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1661 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1662 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1664 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1666 m_lines
[i
].Draw( &dc
);
1667 // Draw horizontal rule if required
1668 if (GetWindowStyle() & wxLC_HRULES
)
1669 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1672 // Draw last horizontal rule
1673 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1674 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1676 // Draw vertical rules if required
1677 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1680 wxRect firstItemRect
;
1681 wxRect lastItemRect
;
1682 GetItemRect(0, firstItemRect
);
1683 GetItemRect(GetItemCount() - 1, lastItemRect
);
1684 int x
= firstItemRect
.GetX();
1685 for (col
= 0; col
< GetColumnCount(); col
++)
1687 int colWidth
= GetColumnWidth(col
);
1689 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1695 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1696 m_lines
[i
].Draw( &dc
);
1699 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1704 void wxListMainWindow::HilightAll( bool on
)
1706 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1708 wxListLineData
*line
= &m_lines
[i
];
1709 if (line
->IsHilighted() != on
)
1711 line
->Hilight( on
);
1712 RefreshLine( line
);
1717 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1719 wxListEvent
le( command
, GetParent()->GetId() );
1720 le
.SetEventObject( GetParent() );
1721 le
.m_itemIndex
= GetIndexOfLine( line
);
1722 line
->GetItem( 0, le
.m_item
);
1723 GetParent()->GetEventHandler()->ProcessEvent( le
);
1724 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1727 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1729 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1732 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1734 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1737 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1739 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1742 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1744 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1747 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1749 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1754 void wxListMainWindow::EditLabel( long item
)
1756 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1757 wxT("wrong index in wxListCtrl::Edit()") );
1759 m_currentEdit
= &m_lines
[(size_t)item
];
1761 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1762 le
.SetEventObject( GetParent() );
1763 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1764 m_currentEdit
->GetItem( 0, le
.m_item
);
1765 GetParent()->GetEventHandler()->ProcessEvent( le
);
1767 if (!le
.IsAllowed())
1770 // We have to call this here because the label in
1771 // question might just have been added and no screen
1772 // update taken place.
1773 if (m_dirty
) wxYield();
1776 m_currentEdit
->GetText( 0, s
);
1781 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1783 wxClientDC
dc(this);
1785 x
= dc
.LogicalToDeviceX( x
);
1786 y
= dc
.LogicalToDeviceY( y
);
1788 wxListTextCtrl
*text
= new wxListTextCtrl(
1789 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1793 void wxListMainWindow::OnRenameTimer()
1795 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1797 Edit( m_lines
.Index( *m_current
) );
1800 void wxListMainWindow::OnRenameAccept()
1802 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1803 le
.SetEventObject( GetParent() );
1804 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1805 m_currentEdit
->GetItem( 0, le
.m_item
);
1806 le
.m_item
.m_text
= m_renameRes
;
1807 GetParent()->GetEventHandler()->ProcessEvent( le
);
1809 if (!le
.IsAllowed()) return;
1812 info
.m_mask
= wxLIST_MASK_TEXT
;
1813 info
.m_itemId
= le
.m_itemIndex
;
1814 info
.m_text
= m_renameRes
;
1815 info
.SetTextColour(le
.m_item
.GetTextColour());
1819 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1821 event
.SetEventObject( GetParent() );
1822 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1824 if (!m_current
) return;
1825 if (m_dirty
) return;
1826 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1828 int x
= event
.GetX();
1829 int y
= event
.GetY();
1830 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1832 /* Did we actually hit an item ? */
1834 wxListLineData
*line
= (wxListLineData
*) NULL
;
1835 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1838 hitResult
= line
->IsHit( x
, y
);
1839 if (hitResult
) break;
1840 line
= (wxListLineData
*) NULL
;
1843 if (event
.Dragging())
1845 if (m_dragCount
== 0)
1846 m_dragStart
= wxPoint(x
,y
);
1850 if (m_dragCount
!= 3) return;
1852 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1853 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1855 wxListEvent
le( command
, GetParent()->GetId() );
1856 le
.SetEventObject( GetParent() );
1857 le
.m_pointDrag
= m_dragStart
;
1858 GetParent()->GetEventHandler()->ProcessEvent( le
);
1869 bool forceClick
= FALSE
;
1870 if (event
.ButtonDClick())
1872 m_renameTimer
->Stop();
1873 m_lastOnSame
= FALSE
;
1875 if ( line
== m_lineBeforeLastClicked
)
1879 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1885 // the first click was on another item, so don't interpret this as
1886 // a double click, but as a simple click instead
1891 if (event
.LeftUp() && m_lastOnSame
)
1894 if ((line
== m_current
) &&
1895 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1896 (m_mode
& wxLC_EDIT_LABELS
) )
1898 m_renameTimer
->Start( 100, TRUE
);
1900 m_lastOnSame
= FALSE
;
1904 if (event
.RightDown())
1906 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1910 if (event
.MiddleDown())
1912 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1916 if ( event
.LeftDown() || forceClick
)
1918 m_lineBeforeLastClicked
= m_lineLastClicked
;
1919 m_lineLastClicked
= line
;
1922 wxListLineData
*oldCurrent
= m_current
;
1923 if (m_mode
& wxLC_SINGLE_SEL
)
1926 HilightAll( FALSE
);
1927 m_current
->ReverseHilight();
1928 RefreshLine( m_current
);
1932 if (event
.ControlDown())
1935 m_current
->ReverseHilight();
1936 RefreshLine( m_current
);
1938 else if (event
.ShiftDown())
1944 int numOfCurrent
= -1;
1945 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1947 wxListLineData
*test_line
= &m_lines
[j
];
1949 if (test_line
== oldCurrent
) break;
1954 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1956 wxListLineData
*test_line
= &m_lines
[j
];
1958 if (test_line
== line
) break;
1961 if (numOfLine
< numOfCurrent
)
1964 numOfLine
= numOfCurrent
;
1968 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1970 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
1971 test_line
->Hilight(TRUE
);
1972 RefreshLine( test_line
);
1978 HilightAll( FALSE
);
1979 m_current
->ReverseHilight();
1980 RefreshLine( m_current
);
1983 if (m_current
!= oldCurrent
)
1985 RefreshLine( oldCurrent
);
1986 UnfocusLine( oldCurrent
);
1987 FocusLine( m_current
);
1990 // forceClick is only set if the previous click was on another item
1991 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
1997 void wxListMainWindow::MoveToFocus()
1999 if (!m_current
) return;
2005 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2009 GetClientSize( &client_w
, &client_h
);
2011 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2012 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2014 if (m_mode
& wxLC_REPORT
)
2016 if (item_y
-5 < view_y
)
2017 Scroll( -1, (item_y
-5)/m_yScroll
);
2018 if (item_y
+item_h
+5 > view_y
+client_h
)
2019 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2023 if (item_x
-view_x
< 5)
2024 Scroll( (item_x
-5)/m_xScroll
, -1 );
2025 if (item_x
+item_w
-5 > view_x
+client_w
)
2026 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2030 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2032 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2033 wxListLineData
*oldCurrent
= m_current
;
2034 m_current
= newCurrent
;
2035 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2036 RefreshLine( m_current
);
2037 RefreshLine( oldCurrent
);
2038 FocusLine( m_current
);
2039 UnfocusLine( oldCurrent
);
2043 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2045 wxWindow
*parent
= GetParent();
2047 /* we propagate the key event up */
2048 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2049 ke
.m_shiftDown
= event
.m_shiftDown
;
2050 ke
.m_controlDown
= event
.m_controlDown
;
2051 ke
.m_altDown
= event
.m_altDown
;
2052 ke
.m_metaDown
= event
.m_metaDown
;
2053 ke
.m_keyCode
= event
.m_keyCode
;
2056 ke
.SetEventObject( parent
);
2057 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2062 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2064 wxWindow
*parent
= GetParent();
2066 /* we send a list_key event up */
2069 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2070 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2071 m_current
->GetItem( 0, le
.m_item
);
2072 le
.m_code
= (int)event
.KeyCode();
2073 le
.SetEventObject( parent
);
2074 parent
->GetEventHandler()->ProcessEvent( le
);
2077 /* we propagate the char event up */
2078 wxKeyEvent
ke( wxEVT_CHAR
);
2079 ke
.m_shiftDown
= event
.m_shiftDown
;
2080 ke
.m_controlDown
= event
.m_controlDown
;
2081 ke
.m_altDown
= event
.m_altDown
;
2082 ke
.m_metaDown
= event
.m_metaDown
;
2083 ke
.m_keyCode
= event
.m_keyCode
;
2086 ke
.SetEventObject( parent
);
2087 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2089 if (event
.KeyCode() == WXK_TAB
)
2091 wxNavigationKeyEvent nevent
;
2092 nevent
.SetWindowChange( event
.ControlDown() );
2093 nevent
.SetDirection( !event
.ShiftDown() );
2094 nevent
.SetEventObject( GetParent()->GetParent() );
2095 nevent
.SetCurrentFocus( m_parent
);
2096 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2099 /* no item -> nothing to do */
2106 switch (event
.KeyCode())
2110 int index
= m_lines
.Index(*m_current
);
2111 if (index
!= wxNOT_FOUND
&& index
> 0)
2112 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2117 int index
= m_lines
.Index(*m_current
);
2118 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2119 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2124 if (!m_lines
.IsEmpty())
2125 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2130 if (!m_lines
.IsEmpty())
2131 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2137 int index
= m_lines
.Index(*m_current
);
2138 if (m_mode
& wxLC_REPORT
)
2140 steps
= m_visibleLines
-1;
2144 steps
= index
% m_visibleLines
;
2146 if (index
!= wxNOT_FOUND
)
2149 if (index
< 0) index
= 0;
2150 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2157 int index
= m_lines
.Index(*m_current
);
2158 if (m_mode
& wxLC_REPORT
)
2160 steps
= m_visibleLines
-1;
2164 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2167 if (index
!= wxNOT_FOUND
)
2170 if ((size_t)index
>= m_lines
.GetCount())
2171 index
= m_lines
.GetCount()-1;
2172 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2178 if (!(m_mode
& wxLC_REPORT
))
2180 int index
= m_lines
.Index(*m_current
);
2181 if (index
!= wxNOT_FOUND
)
2183 index
-= m_visibleLines
;
2184 if (index
< 0) index
= 0;
2185 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2192 if (!(m_mode
& wxLC_REPORT
))
2194 int index
= m_lines
.Index(*m_current
);
2195 if (index
!= wxNOT_FOUND
)
2197 index
+= m_visibleLines
;
2198 if ((size_t)index
>= m_lines
.GetCount())
2199 index
= m_lines
.GetCount()-1;
2200 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2207 if (m_mode
& wxLC_SINGLE_SEL
)
2209 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2210 le
.SetEventObject( GetParent() );
2211 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2212 m_current
->GetItem( 0, le
.m_item
);
2213 GetParent()->GetEventHandler()->ProcessEvent( le
);
2217 m_current
->ReverseHilight();
2218 RefreshLine( m_current
);
2224 if (!(m_mode
& wxLC_SINGLE_SEL
))
2226 wxListLineData
*oldCurrent
= m_current
;
2227 m_current
->ReverseHilight();
2228 int index
= m_lines
.Index( *m_current
) + 1;
2229 if ( (size_t)index
< m_lines
.GetCount() )
2230 m_current
= &m_lines
[index
];
2231 RefreshLine( oldCurrent
);
2232 RefreshLine( m_current
);
2233 UnfocusLine( oldCurrent
);
2234 FocusLine( m_current
);
2242 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2243 le
.SetEventObject( GetParent() );
2244 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2245 m_current
->GetItem( 0, le
.m_item
);
2246 GetParent()->GetEventHandler()->ProcessEvent( le
);
2259 extern wxWindow
*g_focusWindow
;
2262 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2265 RefreshLine( m_current
);
2267 if (!GetParent()) return;
2270 g_focusWindow
= GetParent();
2273 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2274 event
.SetEventObject( GetParent() );
2275 GetParent()->GetEventHandler()->ProcessEvent( event
);
2278 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2281 RefreshLine( m_current
);
2284 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2287 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2293 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2295 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2297 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2300 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2302 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2304 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2306 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2308 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2310 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2315 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2317 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2319 m_normal_image_list
->GetSize( index
, width
, height
);
2322 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2324 m_small_image_list
->GetSize( index
, width
, height
);
2327 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2329 m_small_image_list
->GetSize( index
, width
, height
);
2332 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2334 m_small_image_list
->GetSize( index
, width
, height
);
2341 int wxListMainWindow::GetTextLength( wxString
&s
)
2343 wxClientDC
dc( this );
2346 dc
.GetTextExtent( s
, &lw
, &lh
);
2350 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2352 int i
= m_lines
.Index(*line
);
2353 if (i
== wxNOT_FOUND
) return -1;
2357 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2361 // calc the spacing from the icon size
2364 if ((imageList
) && (imageList
->GetImageCount()) )
2366 imageList
->GetSize(0, width
, height
);
2369 if (which
== wxIMAGE_LIST_NORMAL
)
2371 m_normal_image_list
= imageList
;
2372 m_normal_spacing
= width
+ 8;
2375 if (which
== wxIMAGE_LIST_SMALL
)
2377 m_small_image_list
= imageList
;
2378 m_small_spacing
= width
+ 14;
2382 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2387 m_small_spacing
= spacing
;
2391 m_normal_spacing
= spacing
;
2395 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2397 return isSmall
? m_small_spacing
: m_normal_spacing
;
2400 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2403 wxNode
*node
= m_columns
.Nth( col
);
2406 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2407 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2408 column
->SetItem( item
);
2411 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2413 headerWin
->m_dirty
= TRUE
;
2416 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2418 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2419 _T("SetColumnWidth() can only be called in report mode.") );
2423 wxNode
*node
= (wxNode
*) NULL
;
2425 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2427 // TODO do use the header
2430 else if (width
== wxLIST_AUTOSIZE
)
2432 wxClientDC
dc(this);
2433 dc
.SetFont( GetFont() );
2436 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2438 wxListLineData
*line
= &m_lines
[i
];
2439 wxNode
*n
= line
->m_items
.Nth( col
);
2442 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2443 int current
= 0, ix
= 0, iy
= 0;
2444 wxCoord lx
= 0, ly
= 0;
2445 if (item
->HasImage())
2447 GetImageSize( item
->GetImage(), ix
, iy
);
2450 if (item
->HasText())
2453 item
->GetText( str
);
2454 dc
.GetTextExtent( str
, &lx
, &ly
);
2457 if (current
> max
) max
= current
;
2463 node
= m_columns
.Nth( col
);
2466 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2467 column
->SetWidth( width
);
2470 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2472 wxListLineData
*line
= &m_lines
[i
];
2473 wxNode
*n
= line
->m_items
.Nth( col
);
2476 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2477 item
->SetSize( width
, -1 );
2481 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2483 headerWin
->m_dirty
= TRUE
;
2486 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2488 wxNode
*node
= m_columns
.Nth( col
);
2491 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2492 column
->GetItem( item
);
2504 int wxListMainWindow::GetColumnWidth( int col
)
2506 wxNode
*node
= m_columns
.Nth( col
);
2509 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2510 return column
->GetWidth();
2518 int wxListMainWindow::GetColumnCount()
2520 return m_columns
.Number();
2523 int wxListMainWindow::GetCountPerPage()
2525 return m_visibleLines
;
2528 void wxListMainWindow::SetItem( wxListItem
&item
)
2531 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2533 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2534 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2535 line
->SetItem( item
.m_col
, item
);
2539 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2541 // m_dirty = TRUE; no recalcs needed
2543 wxListLineData
*oldCurrent
= m_current
;
2545 if (stateMask
& wxLIST_STATE_FOCUSED
)
2547 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2549 wxListLineData
*line
= &m_lines
[(size_t)item
];
2550 UnfocusLine( m_current
);
2552 FocusLine( m_current
);
2553 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2554 RefreshLine( m_current
);
2555 if (oldCurrent
) RefreshLine( oldCurrent
);
2559 if (stateMask
& wxLIST_STATE_SELECTED
)
2561 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2562 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2564 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2566 wxListLineData
*line
= &m_lines
[(size_t)item
];
2567 if (m_mode
& wxLC_SINGLE_SEL
)
2569 UnfocusLine( m_current
);
2571 FocusLine( m_current
);
2572 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2573 RefreshLine( m_current
);
2574 if (oldCurrent
) RefreshLine( oldCurrent
);
2576 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2577 if (on
!= line
->IsHilighted())
2579 line
->Hilight( on
);
2580 RefreshLine( line
);
2586 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2588 int ret
= wxLIST_STATE_DONTCARE
;
2589 if (stateMask
& wxLIST_STATE_FOCUSED
)
2591 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2593 wxListLineData
*line
= &m_lines
[(size_t)item
];
2594 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2597 if (stateMask
& wxLIST_STATE_SELECTED
)
2599 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2601 wxListLineData
*line
= &m_lines
[(size_t)item
];
2602 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2608 void wxListMainWindow::GetItem( wxListItem
&item
)
2610 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2612 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2613 line
->GetItem( item
.m_col
, item
);
2624 int wxListMainWindow::GetItemCount()
2626 return m_lines
.GetCount();
2629 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2631 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2633 m_lines
[(size_t)index
].GetRect( rect
);
2644 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2646 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2649 m_lines
[(size_t)item
].GetRect( rect
);
2661 int wxListMainWindow::GetSelectedItemCount()
2664 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2666 if (m_lines
[i
].IsHilighted()) ret
++;
2671 void wxListMainWindow::SetMode( long mode
)
2678 if (m_mode
& wxLC_REPORT
)
2680 #if wxUSE_GENERIC_LIST_EXTENSIONS
2694 long wxListMainWindow::GetMode() const
2699 void wxListMainWindow::CalculatePositions()
2701 if (m_lines
.IsEmpty()) return;
2703 wxClientDC
dc( this );
2704 dc
.SetFont( GetFont() );
2706 int iconSpacing
= 0;
2707 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2708 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2710 // we take the first line (which also can be an icon or
2711 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2712 // measure the size of the line
2716 int lineSpacing
= 0;
2718 wxListLineData
*line
= &m_lines
[0];
2719 line
->CalculateSize( &dc
, iconSpacing
);
2721 line
->GetSize( dummy
, lineSpacing
);
2724 int clientWidth
= 0;
2725 int clientHeight
= 0;
2727 if (m_mode
& wxLC_REPORT
)
2731 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2732 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2733 #if wxUSE_GENERIC_LIST_EXTENSIONS
2734 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2736 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2738 GetClientSize( &clientWidth
, &clientHeight
);
2740 int entireWidth
= 0 ;
2741 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2743 wxListLineData
*line
= &m_lines
[j
];
2744 line
->CalculateSize( &dc
, iconSpacing
);
2745 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2747 for (int i
= 0; i
< GetColumnCount(); i
++)
2749 line
->SetColumnPosition( i
, col_x
);
2750 col_x
+= GetColumnWidth( i
);
2752 entireWidth
= wxMax( entireWidth
, col_x
) ;
2753 #if wxUSE_GENERIC_LIST_EXTENSIONS
2754 line
->SetPosition( &dc
, x
, y
, col_x
);
2756 y
+= lineSpacing
; // one pixel blank line between items
2758 m_visibleLines
= clientHeight
/ lineSpacing
;
2759 #if wxUSE_GENERIC_LIST_EXTENSIONS
2760 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2765 // at first we try without any scrollbar. if the items don't
2766 // fit into the window, we recalculate after subtracting an
2767 // approximated 15 pt for the horizontal scrollbar
2769 GetSize( &clientWidth
, &clientHeight
);
2770 clientHeight
-= 4; // sunken frame
2772 int entireWidth
= 0;
2774 for (int tries
= 0; tries
< 2; tries
++)
2781 int m_currentVisibleLines
= 0;
2782 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2784 m_currentVisibleLines
++;
2785 wxListLineData
*line
= &m_lines
[i
];
2786 line
->CalculateSize( &dc
, iconSpacing
);
2787 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2788 line
->GetSize( lineWidth
, lineHeight
);
2789 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2791 if (m_currentVisibleLines
> m_visibleLines
)
2792 m_visibleLines
= m_currentVisibleLines
;
2793 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2795 m_currentVisibleLines
= 0;
2798 entireWidth
+= maxWidth
+6;
2801 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2802 if ((tries
== 0) && (entireWidth
> clientWidth
))
2804 clientHeight
-= 15; // scrollbar height
2806 m_currentVisibleLines
= 0;
2809 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2813 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2814 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2818 void wxListMainWindow::RealizeChanges()
2822 if (!m_lines
.IsEmpty())
2823 m_current
= &m_lines
[0];
2827 FocusLine( m_current
);
2828 // TODO: MSW doesn't automatically hilight the
2830 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2834 long wxListMainWindow::GetNextItem( long item
,
2835 int WXUNUSED(geometry
),
2839 max
= GetItemCount();
2840 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2841 _T("invalid listctrl index in GetNextItem()") );
2843 // notice that we start with the next item (or the first one if item == -1)
2844 // and this is intentional to allow writing a simple loop to iterate over
2845 // all selected items
2849 // this is not an error because the index was ok initially, just no
2854 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2856 wxListLineData
*line
= &m_lines
[i
];
2857 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2859 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2869 void wxListMainWindow::DeleteItem( long index
)
2872 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2874 wxListLineData
*line
= &m_lines
[(size_t)index
];
2875 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2877 m_lines
.RemoveAt( (size_t)index
);
2881 void wxListMainWindow::DeleteColumn( int col
)
2883 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2884 wxT("attempting to delete inexistent column in wxListView") );
2887 wxNode
*node
= m_columns
.Nth( col
);
2888 if (node
) m_columns
.DeleteNode( node
);
2891 void wxListMainWindow::DeleteAllItems()
2894 m_current
= (wxListLineData
*) NULL
;
2896 // to make the deletion of all items faster, we don't send the
2897 // notifications in this case: this is compatible with wxMSW and
2898 // documented in DeleteAllItems() description
2900 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2901 event
.SetEventObject( GetParent() );
2902 GetParent()->GetEventHandler()->ProcessEvent( event
);
2907 void wxListMainWindow::DeleteEverything()
2914 void wxListMainWindow::EnsureVisible( long index
)
2916 // We have to call this here because the label in
2917 // question might just have been added and no screen
2918 // update taken place.
2919 if (m_dirty
) wxYield();
2921 wxListLineData
*oldCurrent
= m_current
;
2922 m_current
= (wxListLineData
*) NULL
;
2923 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2924 m_current
= &m_lines
[(size_t)index
];
2925 if (m_current
) MoveToFocus();
2926 m_current
= oldCurrent
;
2929 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2933 if (pos
< 0) pos
= 0;
2934 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2936 wxListLineData
*line
= &m_lines
[i
];
2938 line
->GetText( 0, s
);
2939 if (s
== tmp
) return pos
;
2945 long wxListMainWindow::FindItem(long start
, long data
)
2948 if (pos
< 0) pos
= 0;
2949 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2951 wxListLineData
*line
= &m_lines
[i
];
2953 line
->GetItem( 0, item
);
2954 if (item
.m_data
== data
) return pos
;
2960 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2962 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2965 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2967 wxListLineData
*line
= &m_lines
[i
];
2968 long ret
= line
->IsHit( x
, y
);
2969 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
2979 void wxListMainWindow::InsertItem( wxListItem
&item
)
2983 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2984 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2985 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2986 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2988 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2990 if (m_mode
& wxLC_REPORT
)
2992 line
->InitItems( GetColumnCount() );
2993 item
.m_width
= GetColumnWidth( 0 )-3;
2997 line
->InitItems( 1 );
3000 line
->SetItem( 0, item
);
3001 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3003 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3007 m_lines
.Add( line
);
3008 item
.m_itemId
= m_lines
.GetCount();
3012 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3015 if (m_mode
& wxLC_REPORT
)
3017 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3018 wxListHeaderData
*column
= new wxListHeaderData( item
);
3019 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3021 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3023 m_columns
.Insert( node
, column
);
3027 m_columns
.Append( column
);
3032 wxListCtrlCompare list_ctrl_compare_func_2
;
3033 long list_ctrl_compare_data
;
3035 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3037 wxListLineData
*line1
= *arg1
;
3038 wxListLineData
*line2
= *arg2
;
3040 line1
->GetItem( 0, item
);
3041 long data1
= item
.m_data
;
3042 line2
->GetItem( 0, item
);
3043 long data2
= item
.m_data
;
3044 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3047 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3049 list_ctrl_compare_func_2
= fn
;
3050 list_ctrl_compare_data
= data
;
3051 m_lines
.Sort( list_ctrl_compare_func_1
);
3055 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3057 wxScrolledWindow::OnScroll( event
) ;
3058 #if wxUSE_GENERIC_LIST_EXTENSIONS
3060 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3062 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3065 lc
->m_headerWin
->Refresh() ;
3067 lc
->m_headerWin
->MacUpdateImmediately() ;
3074 // -------------------------------------------------------------------------------------
3076 // -------------------------------------------------------------------------------------
3078 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3080 wxListItem::wxListItem()
3089 m_format
= wxLIST_FORMAT_CENTRE
;
3095 void wxListItem::Clear()
3104 m_format
= wxLIST_FORMAT_CENTRE
;
3106 m_text
= wxEmptyString
;
3108 if (m_attr
) delete m_attr
;
3112 void wxListItem::ClearAttributes()
3114 if (m_attr
) delete m_attr
;
3118 // -------------------------------------------------------------------------------------
3120 // -------------------------------------------------------------------------------------
3122 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3124 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3125 wxNotifyEvent( commandType
, id
)
3131 m_cancelled
= FALSE
;
3136 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3138 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3140 wxNotifyEvent::CopyObject(object_dest
);
3142 obj
->m_code
= m_code
;
3143 obj
->m_itemIndex
= m_itemIndex
;
3144 obj
->m_oldItemIndex
= m_oldItemIndex
;
3146 obj
->m_cancelled
= m_cancelled
;
3147 obj
->m_pointDrag
= m_pointDrag
;
3148 obj
->m_item
.m_mask
= m_item
.m_mask
;
3149 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3150 obj
->m_item
.m_col
= m_item
.m_col
;
3151 obj
->m_item
.m_state
= m_item
.m_state
;
3152 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3153 obj
->m_item
.m_text
= m_item
.m_text
;
3154 obj
->m_item
.m_image
= m_item
.m_image
;
3155 obj
->m_item
.m_data
= m_item
.m_data
;
3156 obj
->m_item
.m_format
= m_item
.m_format
;
3157 obj
->m_item
.m_width
= m_item
.m_width
;
3159 if ( m_item
.HasAttributes() )
3161 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3165 // -------------------------------------------------------------------------------------
3167 // -------------------------------------------------------------------------------------
3169 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3171 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3172 EVT_SIZE (wxListCtrl::OnSize
)
3173 EVT_IDLE (wxListCtrl::OnIdle
)
3176 wxListCtrl::wxListCtrl()
3178 m_imageListNormal
= (wxImageList
*) NULL
;
3179 m_imageListSmall
= (wxImageList
*) NULL
;
3180 m_imageListState
= (wxImageList
*) NULL
;
3181 m_mainWin
= (wxListMainWindow
*) NULL
;
3182 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3185 wxListCtrl::~wxListCtrl()
3189 bool wxListCtrl::Create(wxWindow
*parent
,
3194 const wxValidator
&validator
,
3195 const wxString
&name
)
3197 m_imageListNormal
= (wxImageList
*) NULL
;
3198 m_imageListSmall
= (wxImageList
*) NULL
;
3199 m_imageListState
= (wxImageList
*) NULL
;
3200 m_mainWin
= (wxListMainWindow
*) NULL
;
3201 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3203 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3205 style
= style
| wxLC_LIST
;
3208 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3211 if (style
& wxSUNKEN_BORDER
)
3212 style
-= wxSUNKEN_BORDER
;
3214 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3216 if (HasFlag(wxLC_REPORT
))
3218 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3219 if (HasFlag(wxLC_NO_HEADER
))
3220 m_headerWin
->Show( FALSE
);
3224 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3230 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3232 /* handled in OnIdle */
3234 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3237 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3239 long flag
= GetWindowStyle();
3243 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3244 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3245 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3254 if (flag
& style
) flag
-= style
;
3257 SetWindowStyleFlag( flag
);
3260 void wxListCtrl::SetWindowStyleFlag( long flag
)
3264 m_mainWin
->DeleteEverything();
3268 GetClientSize( &width
, &height
);
3270 m_mainWin
->SetMode( flag
);
3272 if (flag
& wxLC_REPORT
)
3274 if (!HasFlag(wxLC_REPORT
))
3278 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3279 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3280 if (HasFlag(wxLC_NO_HEADER
))
3281 m_headerWin
->Show( FALSE
);
3285 if (flag
& wxLC_NO_HEADER
)
3286 m_headerWin
->Show( FALSE
);
3288 m_headerWin
->Show( TRUE
);
3294 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3296 m_headerWin
->Show( FALSE
);
3301 wxWindow::SetWindowStyleFlag( flag
);
3304 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3306 m_mainWin
->GetColumn( col
, item
);
3310 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3312 m_mainWin
->SetColumn( col
, item
);
3316 int wxListCtrl::GetColumnWidth( int col
) const
3318 return m_mainWin
->GetColumnWidth( col
);
3321 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3323 m_mainWin
->SetColumnWidth( col
, width
);
3327 int wxListCtrl::GetCountPerPage() const
3329 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3332 bool wxListCtrl::GetItem( wxListItem
&info
) const
3334 m_mainWin
->GetItem( info
);
3338 bool wxListCtrl::SetItem( wxListItem
&info
)
3340 m_mainWin
->SetItem( info
);
3344 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3347 info
.m_text
= label
;
3348 info
.m_mask
= wxLIST_MASK_TEXT
;
3349 info
.m_itemId
= index
;
3353 info
.m_image
= imageId
;
3354 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3356 m_mainWin
->SetItem(info
);
3360 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3362 return m_mainWin
->GetItemState( item
, stateMask
);
3365 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3367 m_mainWin
->SetItemState( item
, state
, stateMask
);
3371 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3374 info
.m_image
= image
;
3375 info
.m_mask
= wxLIST_MASK_IMAGE
;
3376 info
.m_itemId
= item
;
3377 m_mainWin
->SetItem( info
);
3381 wxString
wxListCtrl::GetItemText( long item
) const
3384 info
.m_itemId
= item
;
3385 m_mainWin
->GetItem( info
);
3389 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3392 info
.m_mask
= wxLIST_MASK_TEXT
;
3393 info
.m_itemId
= item
;
3395 m_mainWin
->SetItem( info
);
3398 long wxListCtrl::GetItemData( long item
) const
3401 info
.m_itemId
= item
;
3402 m_mainWin
->GetItem( info
);
3406 bool wxListCtrl::SetItemData( long item
, long data
)
3409 info
.m_mask
= wxLIST_MASK_DATA
;
3410 info
.m_itemId
= item
;
3412 m_mainWin
->SetItem( info
);
3416 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3418 m_mainWin
->GetItemRect( item
, rect
);
3422 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3424 m_mainWin
->GetItemPosition( item
, pos
);
3428 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3433 int wxListCtrl::GetItemCount() const
3435 return m_mainWin
->GetItemCount();
3438 int wxListCtrl::GetColumnCount() const
3440 return m_mainWin
->GetColumnCount();
3443 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3445 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3448 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3450 return m_mainWin
->GetItemSpacing( isSmall
);
3453 int wxListCtrl::GetSelectedItemCount() const
3455 return m_mainWin
->GetSelectedItemCount();
3458 wxColour
wxListCtrl::GetTextColour() const
3460 return GetForegroundColour();
3463 void wxListCtrl::SetTextColour(const wxColour
& col
)
3465 SetForegroundColour(col
);
3468 long wxListCtrl::GetTopItem() const
3473 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3475 return m_mainWin
->GetNextItem( item
, geom
, state
);
3478 wxImageList
*wxListCtrl::GetImageList(int which
) const
3480 if (which
== wxIMAGE_LIST_NORMAL
)
3482 return m_imageListNormal
;
3484 else if (which
== wxIMAGE_LIST_SMALL
)
3486 return m_imageListSmall
;
3488 else if (which
== wxIMAGE_LIST_STATE
)
3490 return m_imageListState
;
3492 return (wxImageList
*) NULL
;
3495 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3497 m_mainWin
->SetImageList( imageList
, which
);
3500 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3505 bool wxListCtrl::DeleteItem( long item
)
3507 m_mainWin
->DeleteItem( item
);
3511 bool wxListCtrl::DeleteAllItems()
3513 m_mainWin
->DeleteAllItems();
3517 bool wxListCtrl::DeleteAllColumns()
3519 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3525 void wxListCtrl::ClearAll()
3527 m_mainWin
->DeleteEverything();
3530 bool wxListCtrl::DeleteColumn( int col
)
3532 m_mainWin
->DeleteColumn( col
);
3536 void wxListCtrl::Edit( long item
)
3538 m_mainWin
->Edit( item
);
3541 bool wxListCtrl::EnsureVisible( long item
)
3543 m_mainWin
->EnsureVisible( item
);
3547 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3549 return m_mainWin
->FindItem( start
, str
, partial
);
3552 long wxListCtrl::FindItem( long start
, long data
)
3554 return m_mainWin
->FindItem( start
, data
);
3557 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3558 int WXUNUSED(direction
))
3563 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3565 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3568 long wxListCtrl::InsertItem( wxListItem
& info
)
3570 m_mainWin
->InsertItem( info
);
3571 return info
.m_itemId
;
3574 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3577 info
.m_text
= label
;
3578 info
.m_mask
= wxLIST_MASK_TEXT
;
3579 info
.m_itemId
= index
;
3580 return InsertItem( info
);
3583 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3586 info
.m_mask
= wxLIST_MASK_IMAGE
;
3587 info
.m_image
= imageIndex
;
3588 info
.m_itemId
= index
;
3589 return InsertItem( info
);
3592 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3595 info
.m_text
= label
;
3596 info
.m_image
= imageIndex
;
3597 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3598 info
.m_itemId
= index
;
3599 return InsertItem( info
);
3602 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3604 wxASSERT( m_headerWin
);
3605 m_mainWin
->InsertColumn( col
, item
);
3606 m_headerWin
->Refresh();
3611 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3612 int format
, int width
)
3615 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3616 item
.m_text
= heading
;
3619 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3620 item
.m_width
= width
;
3622 item
.m_format
= format
;
3624 return InsertColumn( col
, item
);
3627 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3633 // fn is a function which takes 3 long arguments: item1, item2, data.
3634 // item1 is the long data associated with a first item (NOT the index).
3635 // item2 is the long data associated with a second item (NOT the index).
3636 // data is the same value as passed to SortItems.
3637 // The return value is a negative number if the first item should precede the second
3638 // item, a positive number of the second item should precede the first,
3639 // or zero if the two items are equivalent.
3640 // data is arbitrary data to be passed to the sort function.
3642 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3644 m_mainWin
->SortItems( fn
, data
);
3648 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3650 if (!m_mainWin
->m_dirty
) return;
3654 GetClientSize( &cw
, &ch
);
3661 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3663 m_headerWin
->GetPosition( &x
, &y
);
3664 m_headerWin
->GetSize( &w
, &h
);
3665 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3666 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3668 m_mainWin
->GetPosition( &x
, &y
);
3669 m_mainWin
->GetSize( &w
, &h
);
3670 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3671 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3675 m_mainWin
->GetPosition( &x
, &y
);
3676 m_mainWin
->GetSize( &w
, &h
);
3677 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3678 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3681 m_mainWin
->CalculatePositions();
3682 m_mainWin
->RealizeChanges();
3683 m_mainWin
->m_dirty
= FALSE
;
3684 m_mainWin
->Refresh();
3686 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3688 m_headerWin
->m_dirty
= FALSE
;
3689 m_headerWin
->Refresh();
3693 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3697 m_mainWin
->SetBackgroundColour( colour
);
3698 m_mainWin
->m_dirty
= TRUE
;
3704 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3706 if ( !wxWindow::SetForegroundColour( colour
) )
3711 m_mainWin
->SetForegroundColour( colour
);
3712 m_mainWin
->m_dirty
= TRUE
;
3717 m_headerWin
->SetForegroundColour( colour
);
3723 bool wxListCtrl::SetFont( const wxFont
&font
)
3725 if ( !wxWindow::SetFont( font
) )
3730 m_mainWin
->SetFont( font
);
3731 m_mainWin
->m_dirty
= TRUE
;
3736 m_headerWin
->SetFont( font
);
3742 #if wxUSE_DRAG_AND_DROP
3744 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3746 m_mainWin
->SetDropTarget( dropTarget
);
3749 wxDropTarget
*wxListCtrl::GetDropTarget() const
3751 return m_mainWin
->GetDropTarget();
3754 #endif // wxUSE_DRAG_AND_DROP
3756 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3758 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3761 wxColour
wxListCtrl::GetBackgroundColour() const
3763 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3766 wxColour
wxListCtrl::GetForegroundColour() const
3768 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3771 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3773 return m_mainWin
->PopupMenu( menu
, x
, y
);
3776 void wxListCtrl::SetFocus()
3778 /* The test in window.cpp fails as we are a composite
3779 window, so it checks against "this", but not m_mainWin. */
3780 if ( FindFocus() != this )
3781 m_mainWin
->SetFocus();