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();
1652 int lineSpacing
= 0;
1653 wxListLineData
*line
= &m_lines
[0];
1655 line
->GetSize( dummy
, lineSpacing
);
1658 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1660 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1661 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1663 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1665 m_lines
[i
].Draw( &dc
);
1666 // Draw horizontal rule if required
1667 if (GetWindowStyle() & wxLC_HRULES
)
1668 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1671 // Draw last horizontal rule
1672 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1673 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1675 // Draw vertical rules if required
1676 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1679 wxRect firstItemRect
;
1680 wxRect lastItemRect
;
1681 GetItemRect(0, firstItemRect
);
1682 GetItemRect(GetItemCount() - 1, lastItemRect
);
1683 int x
= firstItemRect
.GetX();
1684 for (col
= 0; col
< GetColumnCount(); col
++)
1686 int colWidth
= GetColumnWidth(col
);
1688 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1694 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1695 m_lines
[i
].Draw( &dc
);
1698 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1703 void wxListMainWindow::HilightAll( bool on
)
1705 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1707 wxListLineData
*line
= &m_lines
[i
];
1708 if (line
->IsHilighted() != on
)
1710 line
->Hilight( on
);
1711 RefreshLine( line
);
1716 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1718 wxListEvent
le( command
, GetParent()->GetId() );
1719 le
.SetEventObject( GetParent() );
1720 le
.m_itemIndex
= GetIndexOfLine( line
);
1721 line
->GetItem( 0, le
.m_item
);
1722 GetParent()->GetEventHandler()->ProcessEvent( le
);
1723 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1726 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1728 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1731 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1733 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1736 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1738 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1741 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1743 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1746 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1748 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1753 void wxListMainWindow::EditLabel( long item
)
1755 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1756 wxT("wrong index in wxListCtrl::Edit()") );
1758 m_currentEdit
= &m_lines
[(size_t)item
];
1760 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1761 le
.SetEventObject( GetParent() );
1762 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1763 m_currentEdit
->GetItem( 0, le
.m_item
);
1764 GetParent()->GetEventHandler()->ProcessEvent( le
);
1766 if (!le
.IsAllowed())
1769 // We have to call this here because the label in
1770 // question might just have been added and no screen
1771 // update taken place.
1772 if (m_dirty
) wxYield();
1775 m_currentEdit
->GetText( 0, s
);
1780 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1782 wxClientDC
dc(this);
1784 x
= dc
.LogicalToDeviceX( x
);
1785 y
= dc
.LogicalToDeviceY( y
);
1787 wxListTextCtrl
*text
= new wxListTextCtrl(
1788 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1792 void wxListMainWindow::OnRenameTimer()
1794 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1796 Edit( m_lines
.Index( *m_current
) );
1799 void wxListMainWindow::OnRenameAccept()
1801 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1802 le
.SetEventObject( GetParent() );
1803 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1804 m_currentEdit
->GetItem( 0, le
.m_item
);
1805 le
.m_item
.m_text
= m_renameRes
;
1806 GetParent()->GetEventHandler()->ProcessEvent( le
);
1808 if (!le
.IsAllowed()) return;
1811 info
.m_mask
= wxLIST_MASK_TEXT
;
1812 info
.m_itemId
= le
.m_itemIndex
;
1813 info
.m_text
= m_renameRes
;
1814 info
.SetTextColour(le
.m_item
.GetTextColour());
1818 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1820 event
.SetEventObject( GetParent() );
1821 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1823 if (!m_current
) return;
1824 if (m_dirty
) return;
1825 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1827 int x
= event
.GetX();
1828 int y
= event
.GetY();
1829 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1831 /* Did we actually hit an item ? */
1833 wxListLineData
*line
= (wxListLineData
*) NULL
;
1834 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1837 hitResult
= line
->IsHit( x
, y
);
1838 if (hitResult
) break;
1839 line
= (wxListLineData
*) NULL
;
1842 if (event
.Dragging())
1844 if (m_dragCount
== 0)
1845 m_dragStart
= wxPoint(x
,y
);
1849 if (m_dragCount
!= 3) return;
1851 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1852 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1854 wxListEvent
le( command
, GetParent()->GetId() );
1855 le
.SetEventObject( GetParent() );
1856 le
.m_pointDrag
= m_dragStart
;
1857 GetParent()->GetEventHandler()->ProcessEvent( le
);
1868 bool forceClick
= FALSE
;
1869 if (event
.ButtonDClick())
1871 m_renameTimer
->Stop();
1872 m_lastOnSame
= FALSE
;
1874 if ( line
== m_lineBeforeLastClicked
)
1878 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1884 // the first click was on another item, so don't interpret this as
1885 // a double click, but as a simple click instead
1890 if (event
.LeftUp() && m_lastOnSame
)
1893 if ((line
== m_current
) &&
1894 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1895 (m_mode
& wxLC_EDIT_LABELS
) )
1897 m_renameTimer
->Start( 100, TRUE
);
1899 m_lastOnSame
= FALSE
;
1903 if (event
.RightDown())
1905 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1909 if (event
.MiddleDown())
1911 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1915 if ( event
.LeftDown() || forceClick
)
1917 m_lineBeforeLastClicked
= m_lineLastClicked
;
1918 m_lineLastClicked
= line
;
1921 wxListLineData
*oldCurrent
= m_current
;
1922 if (m_mode
& wxLC_SINGLE_SEL
)
1925 HilightAll( FALSE
);
1926 m_current
->ReverseHilight();
1927 RefreshLine( m_current
);
1931 if (event
.ControlDown())
1934 m_current
->ReverseHilight();
1935 RefreshLine( m_current
);
1937 else if (event
.ShiftDown())
1943 int numOfCurrent
= -1;
1944 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1946 wxListLineData
*test_line
= &m_lines
[j
];
1948 if (test_line
== oldCurrent
) break;
1953 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1955 wxListLineData
*test_line
= &m_lines
[j
];
1957 if (test_line
== line
) break;
1960 if (numOfLine
< numOfCurrent
)
1963 numOfLine
= numOfCurrent
;
1967 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1969 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
1970 test_line
->Hilight(TRUE
);
1971 RefreshLine( test_line
);
1977 HilightAll( FALSE
);
1978 m_current
->ReverseHilight();
1979 RefreshLine( m_current
);
1982 if (m_current
!= oldCurrent
)
1984 RefreshLine( oldCurrent
);
1985 UnfocusLine( oldCurrent
);
1986 FocusLine( m_current
);
1989 // forceClick is only set if the previous click was on another item
1990 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
1996 void wxListMainWindow::MoveToFocus()
1998 if (!m_current
) return;
2004 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2008 GetClientSize( &client_w
, &client_h
);
2010 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2011 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2013 if (m_mode
& wxLC_REPORT
)
2015 if (item_y
-5 < view_y
)
2016 Scroll( -1, (item_y
-5)/m_yScroll
);
2017 if (item_y
+item_h
+5 > view_y
+client_h
)
2018 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2022 if (item_x
-view_x
< 5)
2023 Scroll( (item_x
-5)/m_xScroll
, -1 );
2024 if (item_x
+item_w
-5 > view_x
+client_w
)
2025 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2029 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2031 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2032 wxListLineData
*oldCurrent
= m_current
;
2033 m_current
= newCurrent
;
2034 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2035 RefreshLine( m_current
);
2036 RefreshLine( oldCurrent
);
2037 FocusLine( m_current
);
2038 UnfocusLine( oldCurrent
);
2042 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2044 wxWindow
*parent
= GetParent();
2046 /* we propagate the key event up */
2047 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2048 ke
.m_shiftDown
= event
.m_shiftDown
;
2049 ke
.m_controlDown
= event
.m_controlDown
;
2050 ke
.m_altDown
= event
.m_altDown
;
2051 ke
.m_metaDown
= event
.m_metaDown
;
2052 ke
.m_keyCode
= event
.m_keyCode
;
2055 ke
.SetEventObject( parent
);
2056 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2061 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2063 wxWindow
*parent
= GetParent();
2065 /* we send a list_key event up */
2068 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2069 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2070 m_current
->GetItem( 0, le
.m_item
);
2071 le
.m_code
= (int)event
.KeyCode();
2072 le
.SetEventObject( parent
);
2073 parent
->GetEventHandler()->ProcessEvent( le
);
2076 /* we propagate the char event up */
2077 wxKeyEvent
ke( wxEVT_CHAR
);
2078 ke
.m_shiftDown
= event
.m_shiftDown
;
2079 ke
.m_controlDown
= event
.m_controlDown
;
2080 ke
.m_altDown
= event
.m_altDown
;
2081 ke
.m_metaDown
= event
.m_metaDown
;
2082 ke
.m_keyCode
= event
.m_keyCode
;
2085 ke
.SetEventObject( parent
);
2086 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2088 if (event
.KeyCode() == WXK_TAB
)
2090 wxNavigationKeyEvent nevent
;
2091 nevent
.SetWindowChange( event
.ControlDown() );
2092 nevent
.SetDirection( !event
.ShiftDown() );
2093 nevent
.SetEventObject( GetParent()->GetParent() );
2094 nevent
.SetCurrentFocus( m_parent
);
2095 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2098 /* no item -> nothing to do */
2105 switch (event
.KeyCode())
2109 int index
= m_lines
.Index(*m_current
);
2110 if (index
!= wxNOT_FOUND
&& index
> 0)
2111 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2116 int index
= m_lines
.Index(*m_current
);
2117 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2118 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2123 if (!m_lines
.IsEmpty())
2124 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2129 if (!m_lines
.IsEmpty())
2130 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2136 int index
= m_lines
.Index(*m_current
);
2137 if (m_mode
& wxLC_REPORT
)
2139 steps
= m_visibleLines
-1;
2143 steps
= index
% m_visibleLines
;
2145 if (index
!= wxNOT_FOUND
)
2148 if (index
< 0) index
= 0;
2149 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2156 int index
= m_lines
.Index(*m_current
);
2157 if (m_mode
& wxLC_REPORT
)
2159 steps
= m_visibleLines
-1;
2163 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2166 if (index
!= wxNOT_FOUND
)
2169 if ((size_t)index
>= m_lines
.GetCount())
2170 index
= m_lines
.GetCount()-1;
2171 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2177 if (!(m_mode
& wxLC_REPORT
))
2179 int index
= m_lines
.Index(*m_current
);
2180 if (index
!= wxNOT_FOUND
)
2182 index
-= m_visibleLines
;
2183 if (index
< 0) index
= 0;
2184 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2191 if (!(m_mode
& wxLC_REPORT
))
2193 int index
= m_lines
.Index(*m_current
);
2194 if (index
!= wxNOT_FOUND
)
2196 index
+= m_visibleLines
;
2197 if ((size_t)index
>= m_lines
.GetCount())
2198 index
= m_lines
.GetCount()-1;
2199 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2206 if (m_mode
& wxLC_SINGLE_SEL
)
2208 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2209 le
.SetEventObject( GetParent() );
2210 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2211 m_current
->GetItem( 0, le
.m_item
);
2212 GetParent()->GetEventHandler()->ProcessEvent( le
);
2216 m_current
->ReverseHilight();
2217 RefreshLine( m_current
);
2223 if (!(m_mode
& wxLC_SINGLE_SEL
))
2225 wxListLineData
*oldCurrent
= m_current
;
2226 m_current
->ReverseHilight();
2227 int index
= m_lines
.Index( *m_current
) + 1;
2228 if ( (size_t)index
< m_lines
.GetCount() )
2229 m_current
= &m_lines
[index
];
2230 RefreshLine( oldCurrent
);
2231 RefreshLine( m_current
);
2232 UnfocusLine( oldCurrent
);
2233 FocusLine( m_current
);
2241 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2242 le
.SetEventObject( GetParent() );
2243 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2244 m_current
->GetItem( 0, le
.m_item
);
2245 GetParent()->GetEventHandler()->ProcessEvent( le
);
2258 extern wxWindow
*g_focusWindow
;
2261 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2264 RefreshLine( m_current
);
2266 if (!GetParent()) return;
2269 g_focusWindow
= GetParent();
2272 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2273 event
.SetEventObject( GetParent() );
2274 GetParent()->GetEventHandler()->ProcessEvent( event
);
2277 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2280 RefreshLine( m_current
);
2283 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2286 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2292 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2294 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2296 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2299 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2301 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2303 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2305 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2307 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2309 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2314 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2316 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2318 m_normal_image_list
->GetSize( index
, width
, height
);
2321 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2323 m_small_image_list
->GetSize( index
, width
, height
);
2326 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2328 m_small_image_list
->GetSize( index
, width
, height
);
2331 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2333 m_small_image_list
->GetSize( index
, width
, height
);
2340 int wxListMainWindow::GetTextLength( wxString
&s
)
2342 wxClientDC
dc( this );
2345 dc
.GetTextExtent( s
, &lw
, &lh
);
2349 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2351 int i
= m_lines
.Index(*line
);
2352 if (i
== wxNOT_FOUND
) return -1;
2356 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2360 // calc the spacing from the icon size
2363 if ((imageList
) && (imageList
->GetImageCount()) )
2365 imageList
->GetSize(0, width
, height
);
2368 if (which
== wxIMAGE_LIST_NORMAL
)
2370 m_normal_image_list
= imageList
;
2371 m_normal_spacing
= width
+ 8;
2374 if (which
== wxIMAGE_LIST_SMALL
)
2376 m_small_image_list
= imageList
;
2377 m_small_spacing
= width
+ 14;
2381 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2386 m_small_spacing
= spacing
;
2390 m_normal_spacing
= spacing
;
2394 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2396 return isSmall
? m_small_spacing
: m_normal_spacing
;
2399 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2402 wxNode
*node
= m_columns
.Nth( col
);
2405 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2406 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2407 column
->SetItem( item
);
2410 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2412 headerWin
->m_dirty
= TRUE
;
2415 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2417 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2418 _T("SetColumnWidth() can only be called in report mode.") );
2422 wxNode
*node
= (wxNode
*) NULL
;
2424 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2426 // TODO do use the header
2429 else if (width
== wxLIST_AUTOSIZE
)
2431 wxClientDC
dc(this);
2432 dc
.SetFont( GetFont() );
2435 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2437 wxListLineData
*line
= &m_lines
[i
];
2438 wxNode
*n
= line
->m_items
.Nth( col
);
2441 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2442 int current
= 0, ix
= 0, iy
= 0;
2443 wxCoord lx
= 0, ly
= 0;
2444 if (item
->HasImage())
2446 GetImageSize( item
->GetImage(), ix
, iy
);
2449 if (item
->HasText())
2452 item
->GetText( str
);
2453 dc
.GetTextExtent( str
, &lx
, &ly
);
2456 if (current
> max
) max
= current
;
2462 node
= m_columns
.Nth( col
);
2465 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2466 column
->SetWidth( width
);
2469 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2471 wxListLineData
*line
= &m_lines
[i
];
2472 wxNode
*n
= line
->m_items
.Nth( col
);
2475 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2476 item
->SetSize( width
, -1 );
2480 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2482 headerWin
->m_dirty
= TRUE
;
2485 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2487 wxNode
*node
= m_columns
.Nth( col
);
2490 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2491 column
->GetItem( item
);
2503 int wxListMainWindow::GetColumnWidth( int col
)
2505 wxNode
*node
= m_columns
.Nth( col
);
2508 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2509 return column
->GetWidth();
2517 int wxListMainWindow::GetColumnCount()
2519 return m_columns
.Number();
2522 int wxListMainWindow::GetCountPerPage()
2524 return m_visibleLines
;
2527 void wxListMainWindow::SetItem( wxListItem
&item
)
2530 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2532 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2533 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2534 line
->SetItem( item
.m_col
, item
);
2538 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2540 // m_dirty = TRUE; no recalcs needed
2542 wxListLineData
*oldCurrent
= m_current
;
2544 if (stateMask
& wxLIST_STATE_FOCUSED
)
2546 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2548 wxListLineData
*line
= &m_lines
[(size_t)item
];
2549 UnfocusLine( m_current
);
2551 FocusLine( m_current
);
2552 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2553 RefreshLine( m_current
);
2554 if (oldCurrent
) RefreshLine( oldCurrent
);
2558 if (stateMask
& wxLIST_STATE_SELECTED
)
2560 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2561 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2563 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2565 wxListLineData
*line
= &m_lines
[(size_t)item
];
2566 if (m_mode
& wxLC_SINGLE_SEL
)
2568 UnfocusLine( m_current
);
2570 FocusLine( m_current
);
2571 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2572 RefreshLine( m_current
);
2573 if (oldCurrent
) RefreshLine( oldCurrent
);
2575 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2576 if (on
!= line
->IsHilighted())
2578 line
->Hilight( on
);
2579 RefreshLine( line
);
2585 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2587 int ret
= wxLIST_STATE_DONTCARE
;
2588 if (stateMask
& wxLIST_STATE_FOCUSED
)
2590 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2592 wxListLineData
*line
= &m_lines
[(size_t)item
];
2593 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2596 if (stateMask
& wxLIST_STATE_SELECTED
)
2598 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2600 wxListLineData
*line
= &m_lines
[(size_t)item
];
2601 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2607 void wxListMainWindow::GetItem( wxListItem
&item
)
2609 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2611 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2612 line
->GetItem( item
.m_col
, item
);
2623 int wxListMainWindow::GetItemCount()
2625 return m_lines
.GetCount();
2628 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2630 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2632 m_lines
[(size_t)index
].GetRect( rect
);
2643 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2645 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2648 m_lines
[(size_t)item
].GetRect( rect
);
2660 int wxListMainWindow::GetSelectedItemCount()
2663 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2665 if (m_lines
[i
].IsHilighted()) ret
++;
2670 void wxListMainWindow::SetMode( long mode
)
2677 if (m_mode
& wxLC_REPORT
)
2679 #if wxUSE_GENERIC_LIST_EXTENSIONS
2693 long wxListMainWindow::GetMode() const
2698 void wxListMainWindow::CalculatePositions()
2700 if (m_lines
.IsEmpty()) return;
2702 wxClientDC
dc( this );
2703 dc
.SetFont( GetFont() );
2705 int iconSpacing
= 0;
2706 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2707 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2709 // we take the first line (which also can be an icon or
2710 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2711 // measure the size of the line
2715 int lineSpacing
= 0;
2717 wxListLineData
*line
= &m_lines
[0];
2718 line
->CalculateSize( &dc
, iconSpacing
);
2720 line
->GetSize( dummy
, lineSpacing
);
2723 int clientWidth
= 0;
2724 int clientHeight
= 0;
2726 if (m_mode
& wxLC_REPORT
)
2730 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2731 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2732 #if wxUSE_GENERIC_LIST_EXTENSIONS
2733 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2735 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2737 GetClientSize( &clientWidth
, &clientHeight
);
2739 int entireWidth
= 0 ;
2740 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2742 wxListLineData
*line
= &m_lines
[j
];
2743 line
->CalculateSize( &dc
, iconSpacing
);
2744 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2746 for (int i
= 0; i
< GetColumnCount(); i
++)
2748 line
->SetColumnPosition( i
, col_x
);
2749 col_x
+= GetColumnWidth( i
);
2751 entireWidth
= wxMax( entireWidth
, col_x
) ;
2752 #if wxUSE_GENERIC_LIST_EXTENSIONS
2753 line
->SetPosition( &dc
, x
, y
, col_x
);
2755 y
+= lineSpacing
; // one pixel blank line between items
2757 m_visibleLines
= clientHeight
/ lineSpacing
;
2758 #if wxUSE_GENERIC_LIST_EXTENSIONS
2759 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2764 // at first we try without any scrollbar. if the items don't
2765 // fit into the window, we recalculate after subtracting an
2766 // approximated 15 pt for the horizontal scrollbar
2768 GetSize( &clientWidth
, &clientHeight
);
2769 clientHeight
-= 4; // sunken frame
2771 int entireWidth
= 0;
2773 for (int tries
= 0; tries
< 2; tries
++)
2780 int m_currentVisibleLines
= 0;
2781 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2783 m_currentVisibleLines
++;
2784 wxListLineData
*line
= &m_lines
[i
];
2785 line
->CalculateSize( &dc
, iconSpacing
);
2786 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2787 line
->GetSize( lineWidth
, lineHeight
);
2788 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2790 if (m_currentVisibleLines
> m_visibleLines
)
2791 m_visibleLines
= m_currentVisibleLines
;
2792 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2794 m_currentVisibleLines
= 0;
2797 entireWidth
+= maxWidth
+6;
2800 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2801 if ((tries
== 0) && (entireWidth
> clientWidth
))
2803 clientHeight
-= 15; // scrollbar height
2805 m_currentVisibleLines
= 0;
2808 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2812 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2813 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2817 void wxListMainWindow::RealizeChanges()
2821 if (!m_lines
.IsEmpty())
2822 m_current
= &m_lines
[0];
2826 FocusLine( m_current
);
2827 // TODO: MSW doesn't automatically hilight the
2829 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2833 long wxListMainWindow::GetNextItem( long item
,
2834 int WXUNUSED(geometry
),
2838 max
= GetItemCount();
2839 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2840 _T("invalid listctrl index in GetNextItem()") );
2842 // notice that we start with the next item (or the first one if item == -1)
2843 // and this is intentional to allow writing a simple loop to iterate over
2844 // all selected items
2848 // this is not an error because the index was ok initially, just no
2853 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2855 wxListLineData
*line
= &m_lines
[i
];
2856 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2858 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2868 void wxListMainWindow::DeleteItem( long index
)
2871 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2873 wxListLineData
*line
= &m_lines
[(size_t)index
];
2874 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2876 m_lines
.RemoveAt( (size_t)index
);
2880 void wxListMainWindow::DeleteColumn( int col
)
2882 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2883 wxT("attempting to delete inexistent column in wxListView") );
2886 wxNode
*node
= m_columns
.Nth( col
);
2887 if (node
) m_columns
.DeleteNode( node
);
2890 void wxListMainWindow::DeleteAllItems()
2893 m_current
= (wxListLineData
*) NULL
;
2895 // to make the deletion of all items faster, we don't send the
2896 // notifications in this case: this is compatible with wxMSW and
2897 // documented in DeleteAllItems() description
2899 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2900 event
.SetEventObject( GetParent() );
2901 GetParent()->GetEventHandler()->ProcessEvent( event
);
2906 void wxListMainWindow::DeleteEverything()
2913 void wxListMainWindow::EnsureVisible( long index
)
2915 // We have to call this here because the label in
2916 // question might just have been added and no screen
2917 // update taken place.
2918 if (m_dirty
) wxYield();
2920 wxListLineData
*oldCurrent
= m_current
;
2921 m_current
= (wxListLineData
*) NULL
;
2922 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2923 m_current
= &m_lines
[(size_t)index
];
2924 if (m_current
) MoveToFocus();
2925 m_current
= oldCurrent
;
2928 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2932 if (pos
< 0) pos
= 0;
2933 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2935 wxListLineData
*line
= &m_lines
[i
];
2937 line
->GetText( 0, s
);
2938 if (s
== tmp
) return pos
;
2944 long wxListMainWindow::FindItem(long start
, long data
)
2947 if (pos
< 0) pos
= 0;
2948 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2950 wxListLineData
*line
= &m_lines
[i
];
2952 line
->GetItem( 0, item
);
2953 if (item
.m_data
== data
) return pos
;
2959 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2961 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2964 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2966 wxListLineData
*line
= &m_lines
[i
];
2967 long ret
= line
->IsHit( x
, y
);
2968 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
2978 void wxListMainWindow::InsertItem( wxListItem
&item
)
2982 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2983 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2984 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2985 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2987 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2989 if (m_mode
& wxLC_REPORT
)
2991 line
->InitItems( GetColumnCount() );
2992 item
.m_width
= GetColumnWidth( 0 )-3;
2996 line
->InitItems( 1 );
2999 line
->SetItem( 0, item
);
3000 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3002 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3006 m_lines
.Add( line
);
3007 item
.m_itemId
= m_lines
.GetCount();
3011 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3014 if (m_mode
& wxLC_REPORT
)
3016 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3017 wxListHeaderData
*column
= new wxListHeaderData( item
);
3018 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3020 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3022 m_columns
.Insert( node
, column
);
3026 m_columns
.Append( column
);
3031 wxListCtrlCompare list_ctrl_compare_func_2
;
3032 long list_ctrl_compare_data
;
3034 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3036 wxListLineData
*line1
= *arg1
;
3037 wxListLineData
*line2
= *arg2
;
3039 line1
->GetItem( 0, item
);
3040 long data1
= item
.m_data
;
3041 line2
->GetItem( 0, item
);
3042 long data2
= item
.m_data
;
3043 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3046 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3048 list_ctrl_compare_func_2
= fn
;
3049 list_ctrl_compare_data
= data
;
3050 m_lines
.Sort( list_ctrl_compare_func_1
);
3054 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3056 wxScrolledWindow::OnScroll( event
) ;
3057 #if wxUSE_GENERIC_LIST_EXTENSIONS
3059 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3061 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3064 lc
->m_headerWin
->Refresh() ;
3066 lc
->m_headerWin
->MacUpdateImmediately() ;
3073 // -------------------------------------------------------------------------------------
3075 // -------------------------------------------------------------------------------------
3077 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3079 wxListItem::wxListItem()
3088 m_format
= wxLIST_FORMAT_CENTRE
;
3094 void wxListItem::Clear()
3103 m_format
= wxLIST_FORMAT_CENTRE
;
3105 m_text
= wxEmptyString
;
3107 if (m_attr
) delete m_attr
;
3111 void wxListItem::ClearAttributes()
3113 if (m_attr
) delete m_attr
;
3117 // -------------------------------------------------------------------------------------
3119 // -------------------------------------------------------------------------------------
3121 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3123 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3124 wxNotifyEvent( commandType
, id
)
3130 m_cancelled
= FALSE
;
3135 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3137 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3139 wxNotifyEvent::CopyObject(object_dest
);
3141 obj
->m_code
= m_code
;
3142 obj
->m_itemIndex
= m_itemIndex
;
3143 obj
->m_oldItemIndex
= m_oldItemIndex
;
3145 obj
->m_cancelled
= m_cancelled
;
3146 obj
->m_pointDrag
= m_pointDrag
;
3147 obj
->m_item
.m_mask
= m_item
.m_mask
;
3148 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3149 obj
->m_item
.m_col
= m_item
.m_col
;
3150 obj
->m_item
.m_state
= m_item
.m_state
;
3151 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3152 obj
->m_item
.m_text
= m_item
.m_text
;
3153 obj
->m_item
.m_image
= m_item
.m_image
;
3154 obj
->m_item
.m_data
= m_item
.m_data
;
3155 obj
->m_item
.m_format
= m_item
.m_format
;
3156 obj
->m_item
.m_width
= m_item
.m_width
;
3158 if ( m_item
.HasAttributes() )
3160 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3164 // -------------------------------------------------------------------------------------
3166 // -------------------------------------------------------------------------------------
3168 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3170 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3171 EVT_SIZE (wxListCtrl::OnSize
)
3172 EVT_IDLE (wxListCtrl::OnIdle
)
3175 wxListCtrl::wxListCtrl()
3177 m_imageListNormal
= (wxImageList
*) NULL
;
3178 m_imageListSmall
= (wxImageList
*) NULL
;
3179 m_imageListState
= (wxImageList
*) NULL
;
3180 m_mainWin
= (wxListMainWindow
*) NULL
;
3181 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3184 wxListCtrl::~wxListCtrl()
3188 bool wxListCtrl::Create(wxWindow
*parent
,
3193 const wxValidator
&validator
,
3194 const wxString
&name
)
3196 m_imageListNormal
= (wxImageList
*) NULL
;
3197 m_imageListSmall
= (wxImageList
*) NULL
;
3198 m_imageListState
= (wxImageList
*) NULL
;
3199 m_mainWin
= (wxListMainWindow
*) NULL
;
3200 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3202 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3204 style
= style
| wxLC_LIST
;
3207 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3210 if (style
& wxSUNKEN_BORDER
)
3211 style
-= wxSUNKEN_BORDER
;
3213 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3215 if (HasFlag(wxLC_REPORT
))
3217 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3218 if (HasFlag(wxLC_NO_HEADER
))
3219 m_headerWin
->Show( FALSE
);
3223 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3229 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3231 /* handled in OnIdle */
3233 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3236 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3238 long flag
= GetWindowStyle();
3242 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3243 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3244 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3253 if (flag
& style
) flag
-= style
;
3256 SetWindowStyleFlag( flag
);
3259 void wxListCtrl::SetWindowStyleFlag( long flag
)
3263 m_mainWin
->DeleteEverything();
3267 GetClientSize( &width
, &height
);
3269 m_mainWin
->SetMode( flag
);
3271 if (flag
& wxLC_REPORT
)
3273 if (!HasFlag(wxLC_REPORT
))
3277 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3278 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3279 if (HasFlag(wxLC_NO_HEADER
))
3280 m_headerWin
->Show( FALSE
);
3284 if (flag
& wxLC_NO_HEADER
)
3285 m_headerWin
->Show( FALSE
);
3287 m_headerWin
->Show( TRUE
);
3293 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3295 m_headerWin
->Show( FALSE
);
3300 wxWindow::SetWindowStyleFlag( flag
);
3303 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3305 m_mainWin
->GetColumn( col
, item
);
3309 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3311 m_mainWin
->SetColumn( col
, item
);
3315 int wxListCtrl::GetColumnWidth( int col
) const
3317 return m_mainWin
->GetColumnWidth( col
);
3320 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3322 m_mainWin
->SetColumnWidth( col
, width
);
3326 int wxListCtrl::GetCountPerPage() const
3328 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3331 bool wxListCtrl::GetItem( wxListItem
&info
) const
3333 m_mainWin
->GetItem( info
);
3337 bool wxListCtrl::SetItem( wxListItem
&info
)
3339 m_mainWin
->SetItem( info
);
3343 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3346 info
.m_text
= label
;
3347 info
.m_mask
= wxLIST_MASK_TEXT
;
3348 info
.m_itemId
= index
;
3352 info
.m_image
= imageId
;
3353 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3355 m_mainWin
->SetItem(info
);
3359 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3361 return m_mainWin
->GetItemState( item
, stateMask
);
3364 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3366 m_mainWin
->SetItemState( item
, state
, stateMask
);
3370 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3373 info
.m_image
= image
;
3374 info
.m_mask
= wxLIST_MASK_IMAGE
;
3375 info
.m_itemId
= item
;
3376 m_mainWin
->SetItem( info
);
3380 wxString
wxListCtrl::GetItemText( long item
) const
3383 info
.m_itemId
= item
;
3384 m_mainWin
->GetItem( info
);
3388 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3391 info
.m_mask
= wxLIST_MASK_TEXT
;
3392 info
.m_itemId
= item
;
3394 m_mainWin
->SetItem( info
);
3397 long wxListCtrl::GetItemData( long item
) const
3400 info
.m_itemId
= item
;
3401 m_mainWin
->GetItem( info
);
3405 bool wxListCtrl::SetItemData( long item
, long data
)
3408 info
.m_mask
= wxLIST_MASK_DATA
;
3409 info
.m_itemId
= item
;
3411 m_mainWin
->SetItem( info
);
3415 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3417 m_mainWin
->GetItemRect( item
, rect
);
3421 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3423 m_mainWin
->GetItemPosition( item
, pos
);
3427 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3432 int wxListCtrl::GetItemCount() const
3434 return m_mainWin
->GetItemCount();
3437 int wxListCtrl::GetColumnCount() const
3439 return m_mainWin
->GetColumnCount();
3442 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3444 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3447 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3449 return m_mainWin
->GetItemSpacing( isSmall
);
3452 int wxListCtrl::GetSelectedItemCount() const
3454 return m_mainWin
->GetSelectedItemCount();
3457 wxColour
wxListCtrl::GetTextColour() const
3459 return GetForegroundColour();
3462 void wxListCtrl::SetTextColour(const wxColour
& col
)
3464 SetForegroundColour(col
);
3467 long wxListCtrl::GetTopItem() const
3472 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3474 return m_mainWin
->GetNextItem( item
, geom
, state
);
3477 wxImageList
*wxListCtrl::GetImageList(int which
) const
3479 if (which
== wxIMAGE_LIST_NORMAL
)
3481 return m_imageListNormal
;
3483 else if (which
== wxIMAGE_LIST_SMALL
)
3485 return m_imageListSmall
;
3487 else if (which
== wxIMAGE_LIST_STATE
)
3489 return m_imageListState
;
3491 return (wxImageList
*) NULL
;
3494 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3496 m_mainWin
->SetImageList( imageList
, which
);
3499 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3504 bool wxListCtrl::DeleteItem( long item
)
3506 m_mainWin
->DeleteItem( item
);
3510 bool wxListCtrl::DeleteAllItems()
3512 m_mainWin
->DeleteAllItems();
3516 bool wxListCtrl::DeleteAllColumns()
3518 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3524 void wxListCtrl::ClearAll()
3526 m_mainWin
->DeleteEverything();
3529 bool wxListCtrl::DeleteColumn( int col
)
3531 m_mainWin
->DeleteColumn( col
);
3535 void wxListCtrl::Edit( long item
)
3537 m_mainWin
->Edit( item
);
3540 bool wxListCtrl::EnsureVisible( long item
)
3542 m_mainWin
->EnsureVisible( item
);
3546 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3548 return m_mainWin
->FindItem( start
, str
, partial
);
3551 long wxListCtrl::FindItem( long start
, long data
)
3553 return m_mainWin
->FindItem( start
, data
);
3556 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3557 int WXUNUSED(direction
))
3562 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3564 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3567 long wxListCtrl::InsertItem( wxListItem
& info
)
3569 m_mainWin
->InsertItem( info
);
3570 return info
.m_itemId
;
3573 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3576 info
.m_text
= label
;
3577 info
.m_mask
= wxLIST_MASK_TEXT
;
3578 info
.m_itemId
= index
;
3579 return InsertItem( info
);
3582 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3585 info
.m_mask
= wxLIST_MASK_IMAGE
;
3586 info
.m_image
= imageIndex
;
3587 info
.m_itemId
= index
;
3588 return InsertItem( info
);
3591 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3594 info
.m_text
= label
;
3595 info
.m_image
= imageIndex
;
3596 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3597 info
.m_itemId
= index
;
3598 return InsertItem( info
);
3601 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3603 wxASSERT( m_headerWin
);
3604 m_mainWin
->InsertColumn( col
, item
);
3605 m_headerWin
->Refresh();
3610 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3611 int format
, int width
)
3614 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3615 item
.m_text
= heading
;
3618 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3619 item
.m_width
= width
;
3621 item
.m_format
= format
;
3623 return InsertColumn( col
, item
);
3626 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3632 // fn is a function which takes 3 long arguments: item1, item2, data.
3633 // item1 is the long data associated with a first item (NOT the index).
3634 // item2 is the long data associated with a second item (NOT the index).
3635 // data is the same value as passed to SortItems.
3636 // The return value is a negative number if the first item should precede the second
3637 // item, a positive number of the second item should precede the first,
3638 // or zero if the two items are equivalent.
3639 // data is arbitrary data to be passed to the sort function.
3641 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3643 m_mainWin
->SortItems( fn
, data
);
3647 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3649 if (!m_mainWin
->m_dirty
) return;
3653 GetClientSize( &cw
, &ch
);
3660 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3662 m_headerWin
->GetPosition( &x
, &y
);
3663 m_headerWin
->GetSize( &w
, &h
);
3664 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3665 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3667 m_mainWin
->GetPosition( &x
, &y
);
3668 m_mainWin
->GetSize( &w
, &h
);
3669 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3670 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3674 m_mainWin
->GetPosition( &x
, &y
);
3675 m_mainWin
->GetSize( &w
, &h
);
3676 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3677 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3680 m_mainWin
->CalculatePositions();
3681 m_mainWin
->RealizeChanges();
3682 m_mainWin
->m_dirty
= FALSE
;
3683 m_mainWin
->Refresh();
3685 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3687 m_headerWin
->m_dirty
= FALSE
;
3688 m_headerWin
->Refresh();
3692 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3696 m_mainWin
->SetBackgroundColour( colour
);
3697 m_mainWin
->m_dirty
= TRUE
;
3703 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3705 if ( !wxWindow::SetForegroundColour( colour
) )
3710 m_mainWin
->SetForegroundColour( colour
);
3711 m_mainWin
->m_dirty
= TRUE
;
3716 m_headerWin
->SetForegroundColour( colour
);
3722 bool wxListCtrl::SetFont( const wxFont
&font
)
3724 if ( !wxWindow::SetFont( font
) )
3729 m_mainWin
->SetFont( font
);
3730 m_mainWin
->m_dirty
= TRUE
;
3735 m_headerWin
->SetFont( font
);
3741 #if wxUSE_DRAG_AND_DROP
3743 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3745 m_mainWin
->SetDropTarget( dropTarget
);
3748 wxDropTarget
*wxListCtrl::GetDropTarget() const
3750 return m_mainWin
->GetDropTarget();
3753 #endif // wxUSE_DRAG_AND_DROP
3755 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3757 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3760 wxColour
wxListCtrl::GetBackgroundColour() const
3762 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3765 wxColour
wxListCtrl::GetForegroundColour() const
3767 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3770 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3772 return m_mainWin
->PopupMenu( menu
, x
, y
);
3775 void wxListCtrl::SetFocus()
3777 /* The test in window.cpp fails as we are a composite
3778 window, so it checks against "this", but not m_mainWin. */
3779 if ( FindFocus() != this )
3780 m_mainWin
->SetFocus();