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"
30 #include "wx/gtk/win_gtk.h"
33 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
34 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
37 // ============================================================================
39 // ============================================================================
41 //-----------------------------------------------------------------------------
42 // wxListItemData (internal)
43 //-----------------------------------------------------------------------------
45 class WXDLLEXPORT wxListItemData
: public wxObject
54 wxListItemAttr
*m_attr
;
58 ~wxListItemData() { delete m_attr
; }
60 wxListItemData( const wxListItem
&info
);
61 void SetItem( const wxListItem
&info
);
62 void SetText( const wxString
&s
);
63 void SetImage( int image
);
64 void SetData( long data
);
65 void SetPosition( int x
, int y
);
66 void SetSize( int width
, int height
);
67 bool HasImage() const;
69 bool IsHit( int x
, int y
) const;
70 void GetText( wxString
&s
);
71 const wxString
& GetText() { return m_text
; }
72 int GetX( void ) const;
73 int GetY( void ) const;
75 int GetHeight() const;
77 void GetItem( wxListItem
&info
) const;
79 wxListItemAttr
*GetAttributes() const { return m_attr
; }
82 DECLARE_DYNAMIC_CLASS(wxListItemData
);
85 //-----------------------------------------------------------------------------
86 // wxListHeaderData (internal)
87 //-----------------------------------------------------------------------------
89 class WXDLLEXPORT wxListHeaderData
: public wxObject
102 wxListHeaderData( const wxListItem
&info
);
103 void SetItem( const wxListItem
&item
);
104 void SetPosition( int x
, int y
);
105 void SetWidth( int w
);
106 void SetFormat( int format
);
107 void SetHeight( int h
);
108 bool HasImage() const;
109 bool HasText() const;
110 bool IsHit( int x
, int y
) const;
111 void GetItem( wxListItem
&item
);
112 void GetText( wxString
&s
);
113 int GetImage() const;
114 int GetWidth() const;
115 int GetFormat() const;
118 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
121 //-----------------------------------------------------------------------------
122 // wxListLineData (internal)
123 //-----------------------------------------------------------------------------
125 class WXDLLEXPORT wxListLineData
: public wxObject
130 wxRect m_bound_label
;
132 wxRect m_bound_hilight
;
135 wxBrush
*m_hilightBrush
;
137 wxListMainWindow
*m_owner
;
139 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
143 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
144 void CalculateSize( wxDC
*dc
, int spacing
);
145 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
146 void SetColumnPosition( int index
, int x
);
147 void GetSize( int &width
, int &height
);
148 void GetExtent( int &x
, int &y
, int &width
, int &height
);
149 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
150 long IsHit( int x
, int y
);
151 void InitItems( int num
);
152 void SetItem( int index
, const wxListItem
&info
);
153 void GetItem( int index
, wxListItem
&info
);
154 void GetText( int index
, wxString
&s
);
155 void SetText( int index
, const wxString s
);
156 int GetImage( int index
);
157 void GetRect( wxRect
&rect
);
158 void Hilight( bool on
);
159 void ReverseHilight();
160 void DrawRubberBand( wxDC
*dc
, bool on
);
161 void Draw( wxDC
*dc
);
162 bool IsInRect( int x
, int y
, const wxRect
&rect
);
164 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
165 void AssignRect( wxRect
&dest
, const wxRect
&source
);
168 void SetAttributes(wxDC
*dc
,
169 const wxListItemAttr
*attr
,
170 const wxColour
& colText
, const wxFont
& font
,
173 DECLARE_DYNAMIC_CLASS(wxListLineData
);
177 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
178 #include "wx/arrimpl.cpp"
179 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
181 //-----------------------------------------------------------------------------
182 // wxListHeaderWindow (internal)
183 //-----------------------------------------------------------------------------
185 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
188 wxListMainWindow
*m_owner
;
189 wxCursor
*m_currentCursor
;
190 wxCursor
*m_resizeCursor
;
193 // column being resized
196 // divider line position in logical (unscrolled) coords
199 // minimal position beyond which the divider line can't be dragged in
204 wxListHeaderWindow();
205 virtual ~wxListHeaderWindow();
207 wxListHeaderWindow( wxWindow
*win
,
209 wxListMainWindow
*owner
,
210 const wxPoint
&pos
= wxDefaultPosition
,
211 const wxSize
&size
= wxDefaultSize
,
213 const wxString
&name
= "wxlistctrlcolumntitles" );
215 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
217 void AdjustDC(wxDC
& dc
);
219 void OnPaint( wxPaintEvent
&event
);
220 void OnMouse( wxMouseEvent
&event
);
221 void OnSetFocus( wxFocusEvent
&event
);
227 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
228 DECLARE_EVENT_TABLE()
231 //-----------------------------------------------------------------------------
232 // wxListRenameTimer (internal)
233 //-----------------------------------------------------------------------------
235 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
238 wxListMainWindow
*m_owner
;
241 wxListRenameTimer( wxListMainWindow
*owner
);
245 //-----------------------------------------------------------------------------
246 // wxListTextCtrl (internal)
247 //-----------------------------------------------------------------------------
249 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
254 wxListMainWindow
*m_owner
;
255 wxString m_startValue
;
259 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
260 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
261 const wxString
&value
= "",
262 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
264 const wxValidator
& validator
= wxDefaultValidator
,
265 const wxString
&name
= "listctrltextctrl" );
266 void OnChar( wxKeyEvent
&event
);
267 void OnKeyUp( wxKeyEvent
&event
);
268 void OnKillFocus( wxFocusEvent
&event
);
271 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
272 DECLARE_EVENT_TABLE()
275 //-----------------------------------------------------------------------------
276 // wxListMainWindow (internal)
277 //-----------------------------------------------------------------------------
279 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
283 wxListLineDataArray m_lines
;
285 wxListLineData
*m_current
;
286 wxListLineData
*m_currentEdit
;
288 wxBrush
*m_hilightBrush
;
289 wxColour
*m_hilightColour
;
290 int m_xScroll
,m_yScroll
;
292 wxImageList
*m_small_image_list
;
293 wxImageList
*m_normal_image_list
;
295 int m_normal_spacing
;
299 wxTimer
*m_renameTimer
;
301 wxString m_renameRes
;
306 // for double click logic
307 wxListLineData
*m_lineLastClicked
,
308 *m_lineBeforeLastClicked
;
312 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
313 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
314 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
316 void RefreshLine( wxListLineData
*line
);
317 void OnPaint( wxPaintEvent
&event
);
318 void HilightAll( bool on
);
319 void SendNotify( wxListLineData
*line
,
321 wxPoint point
= wxDefaultPosition
);
322 void FocusLine( wxListLineData
*line
);
323 void UnfocusLine( wxListLineData
*line
);
324 void SelectLine( wxListLineData
*line
);
325 void DeselectLine( wxListLineData
*line
);
326 void DeleteLine( wxListLineData
*line
);
328 void EditLabel( long item
);
329 void Edit( long item
) { EditLabel(item
); } // deprecated
330 void OnRenameTimer();
331 void OnRenameAccept();
333 void OnMouse( wxMouseEvent
&event
);
335 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
336 void OnChar( wxKeyEvent
&event
);
337 void OnKeyDown( wxKeyEvent
&event
);
338 void OnSetFocus( wxFocusEvent
&event
);
339 void OnKillFocus( wxFocusEvent
&event
);
340 void OnSize( wxSizeEvent
&event
);
341 void OnScroll(wxScrollWinEvent
& event
) ;
343 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
344 void GetImageSize( int index
, int &width
, int &height
);
345 int GetIndexOfLine( const wxListLineData
*line
);
346 int GetTextLength( wxString
&s
); // should be const
348 void SetImageList( wxImageList
*imageList
, int which
);
349 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
350 int GetItemSpacing( bool isSmall
= FALSE
);
351 void SetColumn( int col
, wxListItem
&item
);
352 void SetColumnWidth( int col
, int width
);
353 void GetColumn( int col
, wxListItem
&item
);
354 int GetColumnWidth( int vol
);
355 int GetColumnCount();
356 int GetCountPerPage();
357 void SetItem( wxListItem
&item
);
358 void GetItem( wxListItem
&item
);
359 void SetItemState( long item
, long state
, long stateMask
);
360 int GetItemState( long item
, long stateMask
);
362 void GetItemRect( long index
, wxRect
&rect
);
363 bool GetItemPosition( long item
, wxPoint
& pos
);
364 int GetSelectedItemCount();
365 void SetMode( long mode
);
366 long GetMode() const;
367 void CalculatePositions();
368 void RealizeChanges();
369 long GetNextItem( long item
, int geometry
, int state
);
370 void DeleteItem( long index
);
371 void DeleteAllItems();
372 void DeleteColumn( int col
);
373 void DeleteEverything();
374 void EnsureVisible( long index
);
375 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
376 long FindItem( long start
, long data
);
377 long HitTest( int x
, int y
, int &flags
);
378 void InsertItem( wxListItem
&item
);
379 // void AddItem( wxListItem &item );
380 void InsertColumn( long col
, wxListItem
&item
);
381 // void AddColumn( wxListItem &item );
382 void SortItems( wxListCtrlCompare fn
, long data
);
385 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
386 DECLARE_EVENT_TABLE()
389 // ============================================================================
391 // ============================================================================
393 //-----------------------------------------------------------------------------
395 //-----------------------------------------------------------------------------
397 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
399 wxListItemData::wxListItemData()
410 wxListItemData::wxListItemData( const wxListItem
&info
)
419 void wxListItemData::SetItem( const wxListItem
&info
)
421 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
422 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
423 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
425 if ( info
.HasAttributes() )
428 *m_attr
= *info
.GetAttributes();
430 m_attr
= new wxListItemAttr(*info
.GetAttributes());
435 m_width
= info
.m_width
;
439 void wxListItemData::SetText( const wxString
&s
)
444 void wxListItemData::SetImage( int image
)
449 void wxListItemData::SetData( long data
)
454 void wxListItemData::SetPosition( int x
, int y
)
460 void wxListItemData::SetSize( int width
, int height
)
462 if (width
!= -1) m_width
= width
;
463 if (height
!= -1) m_height
= height
;
466 bool wxListItemData::HasImage() const
468 return (m_image
>= 0);
471 bool wxListItemData::HasText() const
473 return (!m_text
.IsNull());
476 bool wxListItemData::IsHit( int x
, int y
) const
478 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
481 void wxListItemData::GetText( wxString
&s
)
486 int wxListItemData::GetX() const
491 int wxListItemData::GetY() const
496 int wxListItemData::GetWidth() const
501 int wxListItemData::GetHeight() const
506 int wxListItemData::GetImage() const
511 void wxListItemData::GetItem( wxListItem
&info
) const
513 info
.m_text
= m_text
;
514 info
.m_image
= m_image
;
515 info
.m_data
= m_data
;
519 if ( m_attr
->HasTextColour() )
520 info
.SetTextColour(m_attr
->GetTextColour());
521 if ( m_attr
->HasBackgroundColour() )
522 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
523 if ( m_attr
->HasFont() )
524 info
.SetFont(m_attr
->GetFont());
528 //-----------------------------------------------------------------------------
530 //-----------------------------------------------------------------------------
532 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
534 wxListHeaderData::wxListHeaderData()
545 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
553 void wxListHeaderData::SetItem( const wxListItem
&item
)
555 m_mask
= item
.m_mask
;
556 m_text
= item
.m_text
;
557 m_image
= item
.m_image
;
558 m_format
= item
.m_format
;
559 m_width
= item
.m_width
;
560 if (m_width
< 0) m_width
= 80;
561 if (m_width
< 6) m_width
= 6;
564 void wxListHeaderData::SetPosition( int x
, int y
)
570 void wxListHeaderData::SetHeight( int h
)
575 void wxListHeaderData::SetWidth( int w
)
578 if (m_width
< 0) m_width
= 80;
579 if (m_width
< 6) m_width
= 6;
582 void wxListHeaderData::SetFormat( int format
)
587 bool wxListHeaderData::HasImage() const
589 return (m_image
!= 0);
592 bool wxListHeaderData::HasText() const
594 return (m_text
.Length() > 0);
597 bool wxListHeaderData::IsHit( int x
, int y
) const
599 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
602 void wxListHeaderData::GetItem( wxListItem
&item
)
604 item
.m_mask
= m_mask
;
605 item
.m_text
= m_text
;
606 item
.m_image
= m_image
;
607 item
.m_format
= m_format
;
608 item
.m_width
= m_width
;
611 void wxListHeaderData::GetText( wxString
&s
)
616 int wxListHeaderData::GetImage() const
621 int wxListHeaderData::GetWidth() const
626 int wxListHeaderData::GetFormat() const
631 //-----------------------------------------------------------------------------
633 //-----------------------------------------------------------------------------
635 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
637 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
642 m_hilightBrush
= hilightBrush
;
643 m_items
.DeleteContents( TRUE
);
647 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
654 m_bound_all
.width
= m_spacing
;
655 wxNode
*node
= m_items
.First();
658 wxListItemData
*item
= (wxListItemData
*)node
->Data();
659 wxString s
= item
->GetText();
660 if (s
.IsEmpty()) s
= wxT("H");
662 dc
->GetTextExtent( s
, &lw
, &lh
);
663 if (lh
< 15) lh
= 15;
667 m_bound_all
.height
= m_spacing
+lh
;
668 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
669 m_bound_label
.width
= lw
;
670 m_bound_label
.height
= lh
;
672 if (item
->HasImage())
676 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
677 m_bound_icon
.width
= w
+ 8;
678 m_bound_icon
.height
= h
+ 8;
680 if ( m_bound_icon
.width
> m_bound_all
.width
)
681 m_bound_all
.width
= m_bound_icon
.width
;
682 if ( h
+ lh
> m_bound_all
.height
- 4 )
683 m_bound_all
.height
= h
+ lh
+ 4;
686 if (!item
->HasText())
688 m_bound_hilight
.width
= m_bound_icon
.width
;
689 m_bound_hilight
.height
= m_bound_icon
.height
;
693 m_bound_hilight
.width
= m_bound_label
.width
;
694 m_bound_hilight
.height
= m_bound_label
.height
;
701 wxNode
*node
= m_items
.First();
704 wxListItemData
*item
= (wxListItemData
*)node
->Data();
706 wxString s
= item
->GetText();
707 if (s
.IsEmpty()) s
= wxT("H");
709 dc
->GetTextExtent( s
, &lw
, &lh
);
710 if (lh
< 15) lh
= 15;
713 m_bound_label
.width
= lw
;
714 m_bound_label
.height
= lh
;
716 m_bound_all
.width
= lw
;
717 m_bound_all
.height
= lh
;
719 if (item
->HasImage())
723 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
724 m_bound_icon
.width
= w
;
725 m_bound_icon
.height
= h
;
727 m_bound_all
.width
+= 4 + w
;
728 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
731 m_bound_hilight
.width
= m_bound_all
.width
;
732 m_bound_hilight
.height
= m_bound_all
.height
;
738 m_bound_all
.width
= 0;
739 m_bound_all
.height
= 0;
740 wxNode
*node
= m_items
.First();
743 wxListItemData
*item
= (wxListItemData
*)node
->Data();
744 if (item
->HasImage())
748 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
749 m_bound_icon
.width
= w
;
750 m_bound_icon
.height
= h
;
754 m_bound_icon
.width
= 0;
755 m_bound_icon
.height
= 0;
760 wxListItemData
*item
= (wxListItemData
*)node
->Data();
761 wxString s
= item
->GetText();
762 if (s
.IsEmpty()) s
= wxT("H");
764 dc
->GetTextExtent( s
, &lw
, &lh
);
765 if (lh
< 15) lh
= 15;
769 item
->SetSize( item
->GetWidth(), lh
);
770 m_bound_all
.width
+= lw
;
771 m_bound_all
.height
= lh
;
774 m_bound_label
.width
= m_bound_all
.width
;
775 m_bound_label
.height
= m_bound_all
.height
;
781 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
782 int x
, int y
, int window_width
)
790 wxNode
*node
= m_items
.First();
793 wxListItemData
*item
= (wxListItemData
*)node
->Data();
794 if (item
->HasImage())
796 m_bound_icon
.x
= m_bound_all
.x
+ 4
797 + (m_spacing
- m_bound_icon
.width
)/2;
798 m_bound_icon
.y
= m_bound_all
.y
+ 4;
802 if (m_bound_all
.width
> m_spacing
)
803 m_bound_label
.x
= m_bound_all
.x
+ 2;
805 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
806 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
807 m_bound_hilight
.x
= m_bound_label
.x
- 2;
808 m_bound_hilight
.y
= m_bound_label
.y
- 2;
812 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
813 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
820 m_bound_hilight
.x
= m_bound_all
.x
;
821 m_bound_hilight
.y
= m_bound_all
.y
;
822 m_bound_label
.y
= m_bound_all
.y
+ 2;
823 wxNode
*node
= m_items
.First();
826 wxListItemData
*item
= (wxListItemData
*)node
->Data();
827 if (item
->HasImage())
829 m_bound_icon
.x
= m_bound_all
.x
+ 2;
830 m_bound_icon
.y
= m_bound_all
.y
+ 2;
831 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
835 m_bound_label
.x
= m_bound_all
.x
+ 2;
843 m_bound_all
.width
= window_width
;
844 AssignRect( m_bound_hilight
, m_bound_all
);
845 m_bound_label
.x
= m_bound_all
.x
+ 2;
846 m_bound_label
.y
= m_bound_all
.y
+ 2;
847 wxNode
*node
= m_items
.First();
850 wxListItemData
*item
= (wxListItemData
*)node
->Data();
851 if (item
->HasImage())
853 m_bound_icon
.x
= m_bound_all
.x
+ 2;
854 m_bound_icon
.y
= m_bound_all
.y
+ 2;
855 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
863 void wxListLineData::SetColumnPosition( int index
, int x
)
865 wxNode
*node
= m_items
.Nth( (size_t)index
);
868 wxListItemData
*item
= (wxListItemData
*)node
->Data();
869 item
->SetPosition( x
, m_bound_all
.y
+1 );
873 void wxListLineData::GetSize( int &width
, int &height
)
875 width
= m_bound_all
.width
;
876 height
= m_bound_all
.height
;
879 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
883 width
= m_bound_all
.width
;
884 height
= m_bound_all
.height
;
887 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
891 width
= m_bound_label
.width
;
892 height
= m_bound_label
.height
;
895 void wxListLineData::GetRect( wxRect
&rect
)
897 AssignRect( rect
, m_bound_all
);
900 long wxListLineData::IsHit( int x
, int y
)
902 wxNode
*node
= m_items
.First();
905 wxListItemData
*item
= (wxListItemData
*)node
->Data();
906 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
907 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
908 // if (!(item->HasImage() || item->HasText())) return 0;
910 // if there is no icon or text = empty
911 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
915 void wxListLineData::InitItems( int num
)
917 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
920 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
922 wxNode
*node
= m_items
.Nth( index
);
925 wxListItemData
*item
= (wxListItemData
*)node
->Data();
926 item
->SetItem( info
);
930 void wxListLineData::GetItem( int index
, wxListItem
&info
)
933 wxNode
*node
= m_items
.Nth( i
);
936 wxListItemData
*item
= (wxListItemData
*)node
->Data();
937 item
->GetItem( info
);
941 void wxListLineData::GetText( int index
, wxString
&s
)
944 wxNode
*node
= m_items
.Nth( i
);
948 wxListItemData
*item
= (wxListItemData
*)node
->Data();
953 void wxListLineData::SetText( int index
, const wxString s
)
956 wxNode
*node
= m_items
.Nth( i
);
959 wxListItemData
*item
= (wxListItemData
*)node
->Data();
964 int wxListLineData::GetImage( int index
)
967 wxNode
*node
= m_items
.Nth( i
);
970 wxListItemData
*item
= (wxListItemData
*)node
->Data();
971 return item
->GetImage();
976 void wxListLineData::SetAttributes(wxDC
*dc
,
977 const wxListItemAttr
*attr
,
978 const wxColour
& colText
,
982 // don't use foregroud colour for drawing highlighted items - this might
983 // make them completely invisible (and there is no way to do bit
984 // arithmetics on wxColour, unfortunately)
985 if ( !hilight
&& attr
&& attr
->HasTextColour() )
987 dc
->SetTextForeground(attr
->GetTextColour());
991 dc
->SetTextForeground(colText
);
994 if ( attr
&& attr
->HasFont() )
996 dc
->SetFont(attr
->GetFont());
1004 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1008 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1009 wxCoord dev_w
= m_bound_all
.width
;
1010 wxCoord dev_h
= m_bound_all
.height
;
1012 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1015 wxWindow
*listctrl
= m_owner
->GetParent();
1017 // default foreground colour
1021 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1025 colText
= listctrl
->GetForegroundColour();
1029 wxFont font
= listctrl
->GetFont();
1031 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1032 // using SetAttributes() inside the loop), it will be trivial to
1033 // customize the subitems (in report mode) too.
1034 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1035 wxListItemAttr
*attr
= item
->GetAttributes();
1036 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1038 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1039 if ( paintBG
|| hasBgCol
)
1043 dc
->SetBrush( * m_hilightBrush
);
1048 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1050 dc
->SetBrush( * wxWHITE_BRUSH
);
1053 dc
->SetPen( * wxTRANSPARENT_PEN
);
1054 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1055 m_bound_hilight
.width
, m_bound_hilight
.height
);
1058 if (m_mode
== wxLC_REPORT
)
1060 wxNode
*node
= m_items
.First();
1063 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1064 int x
= item
->GetX();
1065 if (item
->HasImage())
1068 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1069 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1070 x
+= item
->GetX() + 5;
1072 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1073 if (item
->HasText())
1075 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1077 dc
->DestroyClippingRegion();
1078 node
= node
->Next();
1083 wxNode
*node
= m_items
.First();
1086 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1087 if (item
->HasImage())
1089 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1091 if (item
->HasText())
1093 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1099 void wxListLineData::Hilight( bool on
)
1101 if (on
== m_hilighted
) return;
1104 m_owner
->SelectLine( this );
1106 m_owner
->DeselectLine( this );
1109 void wxListLineData::ReverseHilight( void )
1111 m_hilighted
= !m_hilighted
;
1113 m_owner
->SelectLine( this );
1115 m_owner
->DeselectLine( this );
1118 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1122 dc
->SetPen( * wxBLACK_PEN
);
1123 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1124 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1125 m_bound_hilight
.width
, m_bound_hilight
.height
);
1129 void wxListLineData::Draw( wxDC
*dc
)
1131 DoDraw( dc
, m_hilighted
, m_hilighted
);
1134 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1136 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1137 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1140 bool wxListLineData::IsHilighted( void )
1145 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1150 dest
.height
= height
;
1153 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1157 dest
.width
= source
.width
;
1158 dest
.height
= source
.height
;
1161 //-----------------------------------------------------------------------------
1162 // wxListHeaderWindow
1163 //-----------------------------------------------------------------------------
1165 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1167 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1168 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1169 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1170 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1173 wxListHeaderWindow::wxListHeaderWindow( void )
1175 m_owner
= (wxListMainWindow
*) NULL
;
1176 m_currentCursor
= (wxCursor
*) NULL
;
1177 m_resizeCursor
= (wxCursor
*) NULL
;
1178 m_isDragging
= FALSE
;
1181 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1182 const wxPoint
&pos
, const wxSize
&size
,
1183 long style
, const wxString
&name
) :
1184 wxWindow( win
, id
, pos
, size
, style
, name
)
1187 // m_currentCursor = wxSTANDARD_CURSOR;
1188 m_currentCursor
= (wxCursor
*) NULL
;
1189 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1190 m_isDragging
= FALSE
;
1193 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1196 wxListHeaderWindow::~wxListHeaderWindow( void )
1198 delete m_resizeCursor
;
1201 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1204 GtkStateType state
= GTK_STATE_NORMAL
;
1205 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1207 x
= dc
->XLOG2DEV( x
);
1209 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1210 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1212 const int m_corner
= 1;
1214 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1216 dc
->SetPen( *wxBLACK_PEN
);
1217 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1218 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1220 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1223 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1224 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1226 dc
->SetPen( *wxWHITE_PEN
);
1227 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1228 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1229 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1230 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1234 // shift the DC origin to match the position of the main window horz
1235 // scrollbar: this allows us to always use logical coords
1236 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1238 #if wxUSE_GENERIC_LIST_EXTENSIONS
1240 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1243 m_owner
->GetViewStart( &x
, NULL
);
1245 // account for the horz scrollbar offset
1246 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1247 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1250 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1253 wxClientDC
dc( this );
1255 wxPaintDC
dc( this );
1263 dc
.SetFont( GetFont() );
1265 // width and height of the entire header window
1267 GetClientSize( &w
, &h
);
1268 #if wxUSE_GENERIC_LIST_EXTENSIONS
1269 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1270 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1272 dc
.SetBackgroundMode(wxTRANSPARENT
);
1274 // do *not* use the listctrl colour for headers - one day we will have a
1275 // function to set it separately
1276 //dc.SetTextForeground( *wxBLACK );
1277 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1279 int x
= 1; // left of the header rect
1280 const int y
= 1; // top
1281 int numColumns
= m_owner
->GetColumnCount();
1283 for (int i
= 0; i
< numColumns
; i
++)
1285 m_owner
->GetColumn( i
, item
);
1286 int wCol
= item
.m_width
;
1287 int cw
= wCol
- 2; // the width of the rect to draw
1289 int xEnd
= x
+ wCol
;
1291 // VZ: no, draw it normally - this is better now as we allow resizing
1292 // of the last column as well
1294 // let the last column occupy all available space
1295 if ( i
== numColumns
- 1 )
1299 dc
.SetPen( *wxWHITE_PEN
);
1301 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1302 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1303 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1304 dc
.DestroyClippingRegion();
1313 void wxListHeaderWindow::DrawCurrent()
1315 int x1
= m_currentX
;
1317 ClientToScreen( &x1
, &y1
);
1319 int x2
= m_currentX
-1;
1321 m_owner
->GetClientSize( NULL
, &y2
);
1322 m_owner
->ClientToScreen( &x2
, &y2
);
1325 dc
.SetLogicalFunction( wxINVERT
);
1326 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1327 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1331 dc
.DrawLine( x1
, y1
, x2
, y2
);
1333 dc
.SetLogicalFunction( wxCOPY
);
1335 dc
.SetPen( wxNullPen
);
1336 dc
.SetBrush( wxNullBrush
);
1339 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1341 // we want to work with logical coords
1342 #if wxUSE_GENERIC_LIST_EXTENSIONS
1344 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1345 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1346 int x
= event
.GetX();
1347 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1348 int y
= event
.GetY();
1352 // we don't draw the line beyond our window, but we allow dragging it
1355 GetClientSize( &w
, NULL
);
1356 #if wxUSE_GENERIC_LIST_EXTENSIONS
1357 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1358 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1361 // erase the line if it was drawn
1362 if ( m_currentX
< w
)
1365 if (event
.ButtonUp())
1368 m_isDragging
= FALSE
;
1370 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1377 m_currentX
= m_minX
+ 7;
1379 // draw in the new location
1380 if ( m_currentX
< w
)
1384 else // not dragging
1387 bool hit_border
= FALSE
;
1389 // end of the current column
1392 // find the column where this event occured
1393 int countCol
= m_owner
->GetColumnCount();
1394 for (int j
= 0; j
< countCol
; j
++)
1396 xpos
+= m_owner
->GetColumnWidth( j
);
1399 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1401 // near the column border
1408 // inside the column
1415 if (event
.LeftDown())
1419 m_isDragging
= TRUE
;
1426 wxWindow
*parent
= GetParent();
1427 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1428 le
.SetEventObject( parent
);
1429 le
.m_col
= m_column
;
1430 parent
->GetEventHandler()->ProcessEvent( le
);
1433 else if (event
.Moving())
1438 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1439 m_currentCursor
= m_resizeCursor
;
1443 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1444 m_currentCursor
= wxSTANDARD_CURSOR
;
1448 SetCursor(*m_currentCursor
);
1453 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1455 m_owner
->SetFocus();
1458 //-----------------------------------------------------------------------------
1459 // wxListRenameTimer (internal)
1460 //-----------------------------------------------------------------------------
1462 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1467 void wxListRenameTimer::Notify()
1469 m_owner
->OnRenameTimer();
1472 //-----------------------------------------------------------------------------
1473 // wxListTextCtrl (internal)
1474 //-----------------------------------------------------------------------------
1476 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1478 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1479 EVT_CHAR (wxListTextCtrl::OnChar
)
1480 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1481 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1484 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1485 const wxWindowID id
,
1488 wxListMainWindow
*owner
,
1489 const wxString
&value
,
1493 const wxValidator
& validator
,
1494 const wxString
&name
)
1495 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1500 (*m_accept
) = FALSE
;
1502 m_startValue
= value
;
1505 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1507 if (event
.m_keyCode
== WXK_RETURN
)
1510 (*m_res
) = GetValue();
1512 if (!wxPendingDelete
.Member(this))
1513 wxPendingDelete
.Append(this);
1515 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1516 m_owner
->OnRenameAccept();
1520 if (event
.m_keyCode
== WXK_ESCAPE
)
1522 (*m_accept
) = FALSE
;
1525 if (!wxPendingDelete
.Member(this))
1526 wxPendingDelete
.Append(this);
1534 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1536 // auto-grow the textctrl:
1537 wxSize parentSize
= m_owner
->GetSize();
1538 wxPoint myPos
= GetPosition();
1539 wxSize mySize
= GetSize();
1541 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1542 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1543 if (mySize
.x
> sx
) sx
= mySize
.x
;
1549 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1551 if (!wxPendingDelete
.Member(this))
1552 wxPendingDelete
.Append(this);
1554 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1555 m_owner
->OnRenameAccept();
1558 //-----------------------------------------------------------------------------
1560 //-----------------------------------------------------------------------------
1562 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1564 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1565 EVT_PAINT (wxListMainWindow::OnPaint
)
1566 EVT_SIZE (wxListMainWindow::OnSize
)
1567 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1568 EVT_CHAR (wxListMainWindow::OnChar
)
1569 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1570 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1571 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1572 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1575 wxListMainWindow::wxListMainWindow()
1578 m_columns
.DeleteContents( TRUE
);
1579 m_current
= (wxListLineData
*) NULL
;
1581 m_hilightBrush
= (wxBrush
*) NULL
;
1585 m_small_image_list
= (wxImageList
*) NULL
;
1586 m_normal_image_list
= (wxImageList
*) NULL
;
1587 m_small_spacing
= 30;
1588 m_normal_spacing
= 40;
1591 m_lastOnSame
= FALSE
;
1592 m_renameTimer
= new wxListRenameTimer( this );
1593 m_isCreated
= FALSE
;
1597 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1600 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1601 const wxPoint
&pos
, const wxSize
&size
,
1602 long style
, const wxString
&name
) :
1603 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1606 m_columns
.DeleteContents( TRUE
);
1607 m_current
= (wxListLineData
*) NULL
;
1610 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1611 m_small_image_list
= (wxImageList
*) NULL
;
1612 m_normal_image_list
= (wxImageList
*) NULL
;
1613 m_small_spacing
= 30;
1614 m_normal_spacing
= 40;
1617 m_isCreated
= FALSE
;
1621 if (m_mode
& wxLC_REPORT
)
1623 #if wxUSE_GENERIC_LIST_EXTENSIONS
1635 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1638 m_lastOnSame
= FALSE
;
1639 m_renameTimer
= new wxListRenameTimer( this );
1640 m_renameAccept
= FALSE
;
1642 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1645 wxListMainWindow::~wxListMainWindow()
1649 if (m_hilightBrush
) delete m_hilightBrush
;
1651 delete m_renameTimer
;
1654 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1656 if (m_dirty
) return;
1664 line
->GetExtent( x
, y
, w
, h
);
1665 CalcScrolledPosition( x
, y
, &x
, &y
);
1666 wxRect
rect( x
, y
, w
, h
);
1667 Refresh( TRUE
, &rect
);
1670 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1672 // Note: a wxPaintDC must be constructed even if no drawing is
1673 // done (a Windows requirement).
1674 wxPaintDC
dc( this );
1677 if (m_dirty
) return;
1679 if (m_lines
.GetCount() == 0) return;
1683 dc
.SetFont( GetFont() );
1685 if (m_mode
& wxLC_REPORT
)
1687 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1689 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1691 wxSize clientSize
= GetClientSize();
1693 int lineSpacing
= 0;
1694 wxListLineData
*line
= &m_lines
[0];
1696 line
->GetSize( dummy
, lineSpacing
);
1699 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1701 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1702 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1704 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1706 m_lines
[i
].Draw( &dc
);
1707 // Draw horizontal rule if required
1708 if (GetWindowStyle() & wxLC_HRULES
)
1709 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1712 // Draw last horizontal rule
1713 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1714 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1716 // Draw vertical rules if required
1717 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1720 wxRect firstItemRect
;
1721 wxRect lastItemRect
;
1722 GetItemRect(0, firstItemRect
);
1723 GetItemRect(GetItemCount() - 1, lastItemRect
);
1724 int x
= firstItemRect
.GetX();
1725 for (col
= 0; col
< GetColumnCount(); col
++)
1727 int colWidth
= GetColumnWidth(col
);
1729 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1735 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1736 m_lines
[i
].Draw( &dc
);
1739 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1744 void wxListMainWindow::HilightAll( bool on
)
1746 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1748 wxListLineData
*line
= &m_lines
[i
];
1749 if (line
->IsHilighted() != on
)
1751 line
->Hilight( on
);
1752 RefreshLine( line
);
1757 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1758 wxEventType command
,
1761 wxListEvent
le( command
, GetParent()->GetId() );
1762 le
.SetEventObject( GetParent() );
1763 le
.m_itemIndex
= GetIndexOfLine( line
);
1765 // set only for events which have position
1766 if ( point
!= wxDefaultPosition
)
1767 le
.m_pointDrag
= point
;
1769 line
->GetItem( 0, le
.m_item
);
1770 GetParent()->GetEventHandler()->ProcessEvent( le
);
1771 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1774 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1776 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1779 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1781 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1784 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1786 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1789 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1791 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1794 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1796 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1801 void wxListMainWindow::EditLabel( long item
)
1803 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1804 wxT("wrong index in wxListCtrl::Edit()") );
1806 m_currentEdit
= &m_lines
[(size_t)item
];
1808 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1809 le
.SetEventObject( GetParent() );
1810 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1811 m_currentEdit
->GetItem( 0, le
.m_item
);
1812 GetParent()->GetEventHandler()->ProcessEvent( le
);
1814 if (!le
.IsAllowed())
1817 // We have to call this here because the label in
1818 // question might just have been added and no screen
1819 // update taken place.
1820 if (m_dirty
) wxYield();
1823 m_currentEdit
->GetText( 0, s
);
1828 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1830 wxClientDC
dc(this);
1832 x
= dc
.LogicalToDeviceX( x
);
1833 y
= dc
.LogicalToDeviceY( y
);
1835 wxListTextCtrl
*text
= new wxListTextCtrl(
1836 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1840 void wxListMainWindow::OnRenameTimer()
1842 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1844 Edit( m_lines
.Index( *m_current
) );
1847 void wxListMainWindow::OnRenameAccept()
1849 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1850 le
.SetEventObject( GetParent() );
1851 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1852 m_currentEdit
->GetItem( 0, le
.m_item
);
1853 le
.m_item
.m_text
= m_renameRes
;
1854 GetParent()->GetEventHandler()->ProcessEvent( le
);
1856 if (!le
.IsAllowed()) return;
1859 info
.m_mask
= wxLIST_MASK_TEXT
;
1860 info
.m_itemId
= le
.m_itemIndex
;
1861 info
.m_text
= m_renameRes
;
1862 info
.SetTextColour(le
.m_item
.GetTextColour());
1866 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1868 event
.SetEventObject( GetParent() );
1869 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1871 if (!m_current
) return;
1872 if (m_dirty
) return;
1873 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1875 int x
= event
.GetX();
1876 int y
= event
.GetY();
1877 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1879 /* Did we actually hit an item ? */
1881 wxListLineData
*line
= (wxListLineData
*) NULL
;
1882 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1885 hitResult
= line
->IsHit( x
, y
);
1886 if (hitResult
) break;
1887 line
= (wxListLineData
*) NULL
;
1890 if (event
.Dragging())
1892 if (m_dragCount
== 0)
1893 m_dragStart
= wxPoint(x
,y
);
1897 if (m_dragCount
!= 3) return;
1899 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1900 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1902 wxListEvent
le( command
, GetParent()->GetId() );
1903 le
.SetEventObject( GetParent() );
1904 le
.m_pointDrag
= m_dragStart
;
1905 GetParent()->GetEventHandler()->ProcessEvent( le
);
1916 bool forceClick
= FALSE
;
1917 if (event
.ButtonDClick())
1919 m_renameTimer
->Stop();
1920 m_lastOnSame
= FALSE
;
1922 if ( line
== m_lineBeforeLastClicked
)
1926 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1932 // the first click was on another item, so don't interpret this as
1933 // a double click, but as a simple click instead
1938 if (event
.LeftUp() && m_lastOnSame
)
1941 if ((line
== m_current
) &&
1942 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1943 (m_mode
& wxLC_EDIT_LABELS
) )
1945 m_renameTimer
->Start( 100, TRUE
);
1947 m_lastOnSame
= FALSE
;
1951 if (event
.RightDown())
1953 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
1954 event
.GetPosition() );
1958 if (event
.MiddleDown())
1960 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1964 if ( event
.LeftDown() || forceClick
)
1966 m_lineBeforeLastClicked
= m_lineLastClicked
;
1967 m_lineLastClicked
= line
;
1970 wxListLineData
*oldCurrent
= m_current
;
1971 if (m_mode
& wxLC_SINGLE_SEL
)
1974 HilightAll( FALSE
);
1975 m_current
->ReverseHilight();
1976 RefreshLine( m_current
);
1980 if (event
.ControlDown())
1983 m_current
->ReverseHilight();
1984 RefreshLine( m_current
);
1986 else if (event
.ShiftDown())
1992 int numOfCurrent
= -1;
1993 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1995 wxListLineData
*test_line
= &m_lines
[j
];
1997 if (test_line
== oldCurrent
) break;
2002 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2004 wxListLineData
*test_line
= &m_lines
[j
];
2006 if (test_line
== line
) break;
2009 if (numOfLine
< numOfCurrent
)
2012 numOfLine
= numOfCurrent
;
2016 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2018 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2019 test_line
->Hilight(TRUE
);
2020 RefreshLine( test_line
);
2026 HilightAll( FALSE
);
2027 m_current
->ReverseHilight();
2028 RefreshLine( m_current
);
2031 if (m_current
!= oldCurrent
)
2033 RefreshLine( oldCurrent
);
2034 UnfocusLine( oldCurrent
);
2035 FocusLine( m_current
);
2038 // forceClick is only set if the previous click was on another item
2039 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2045 void wxListMainWindow::MoveToFocus()
2047 if (!m_current
) return;
2053 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2057 GetClientSize( &client_w
, &client_h
);
2059 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2060 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2062 if (m_mode
& wxLC_REPORT
)
2064 if (item_y
< view_y
)
2065 Scroll( -1, (item_y
)/m_yScroll
);
2066 if (item_y
+item_h
+5 > view_y
+client_h
)
2067 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2071 if (item_x
-view_x
< 5)
2072 Scroll( (item_x
-5)/m_xScroll
, -1 );
2073 if (item_x
+item_w
-5 > view_x
+client_w
)
2074 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2078 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2080 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2081 wxListLineData
*oldCurrent
= m_current
;
2082 m_current
= newCurrent
;
2083 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2084 RefreshLine( m_current
);
2085 RefreshLine( oldCurrent
);
2086 FocusLine( m_current
);
2087 UnfocusLine( oldCurrent
);
2091 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2093 wxWindow
*parent
= GetParent();
2095 /* we propagate the key event up */
2096 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2097 ke
.m_shiftDown
= event
.m_shiftDown
;
2098 ke
.m_controlDown
= event
.m_controlDown
;
2099 ke
.m_altDown
= event
.m_altDown
;
2100 ke
.m_metaDown
= event
.m_metaDown
;
2101 ke
.m_keyCode
= event
.m_keyCode
;
2104 ke
.SetEventObject( parent
);
2105 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2110 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2112 wxWindow
*parent
= GetParent();
2114 /* we send a list_key event up */
2117 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2118 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2119 m_current
->GetItem( 0, le
.m_item
);
2120 le
.m_code
= (int)event
.KeyCode();
2121 le
.SetEventObject( parent
);
2122 parent
->GetEventHandler()->ProcessEvent( le
);
2125 /* we propagate the char event up */
2126 wxKeyEvent
ke( wxEVT_CHAR
);
2127 ke
.m_shiftDown
= event
.m_shiftDown
;
2128 ke
.m_controlDown
= event
.m_controlDown
;
2129 ke
.m_altDown
= event
.m_altDown
;
2130 ke
.m_metaDown
= event
.m_metaDown
;
2131 ke
.m_keyCode
= event
.m_keyCode
;
2134 ke
.SetEventObject( parent
);
2135 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2137 if (event
.KeyCode() == WXK_TAB
)
2139 wxNavigationKeyEvent nevent
;
2140 nevent
.SetWindowChange( event
.ControlDown() );
2141 nevent
.SetDirection( !event
.ShiftDown() );
2142 nevent
.SetEventObject( GetParent()->GetParent() );
2143 nevent
.SetCurrentFocus( m_parent
);
2144 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2147 /* no item -> nothing to do */
2154 switch (event
.KeyCode())
2158 int index
= m_lines
.Index(*m_current
);
2159 if (index
!= wxNOT_FOUND
&& index
> 0)
2160 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2165 int index
= m_lines
.Index(*m_current
);
2166 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2167 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2172 if (!m_lines
.IsEmpty())
2173 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2178 if (!m_lines
.IsEmpty())
2179 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2185 int index
= m_lines
.Index(*m_current
);
2186 if (m_mode
& wxLC_REPORT
)
2188 steps
= m_visibleLines
-1;
2192 steps
= index
% m_visibleLines
;
2194 if (index
!= wxNOT_FOUND
)
2197 if (index
< 0) index
= 0;
2198 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2205 int index
= m_lines
.Index(*m_current
);
2206 if (m_mode
& wxLC_REPORT
)
2208 steps
= m_visibleLines
-1;
2212 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2215 if (index
!= wxNOT_FOUND
)
2218 if ((size_t)index
>= m_lines
.GetCount())
2219 index
= m_lines
.GetCount()-1;
2220 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2226 if (!(m_mode
& wxLC_REPORT
))
2228 int index
= m_lines
.Index(*m_current
);
2229 if (index
!= wxNOT_FOUND
)
2231 index
-= m_visibleLines
;
2232 if (index
< 0) index
= 0;
2233 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2240 if (!(m_mode
& wxLC_REPORT
))
2242 int index
= m_lines
.Index(*m_current
);
2243 if (index
!= wxNOT_FOUND
)
2245 index
+= m_visibleLines
;
2246 if ((size_t)index
>= m_lines
.GetCount())
2247 index
= m_lines
.GetCount()-1;
2248 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2255 if (m_mode
& wxLC_SINGLE_SEL
)
2257 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2258 le
.SetEventObject( GetParent() );
2259 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2260 m_current
->GetItem( 0, le
.m_item
);
2261 GetParent()->GetEventHandler()->ProcessEvent( le
);
2265 m_current
->ReverseHilight();
2266 RefreshLine( m_current
);
2272 if (!(m_mode
& wxLC_SINGLE_SEL
))
2274 wxListLineData
*oldCurrent
= m_current
;
2275 m_current
->ReverseHilight();
2276 int index
= m_lines
.Index( *m_current
) + 1;
2277 if ( (size_t)index
< m_lines
.GetCount() )
2278 m_current
= &m_lines
[index
];
2279 RefreshLine( oldCurrent
);
2280 RefreshLine( m_current
);
2281 UnfocusLine( oldCurrent
);
2282 FocusLine( m_current
);
2290 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2291 le
.SetEventObject( GetParent() );
2292 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2293 m_current
->GetItem( 0, le
.m_item
);
2294 GetParent()->GetEventHandler()->ProcessEvent( le
);
2307 extern wxWindow
*g_focusWindow
;
2310 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2313 RefreshLine( m_current
);
2315 if (!GetParent()) return;
2318 g_focusWindow
= GetParent();
2321 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2322 event
.SetEventObject( GetParent() );
2323 GetParent()->GetEventHandler()->ProcessEvent( event
);
2326 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2329 RefreshLine( m_current
);
2332 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2335 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2341 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2343 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2345 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2348 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2350 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2352 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2354 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2356 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2358 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2363 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2365 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2367 m_normal_image_list
->GetSize( index
, width
, height
);
2370 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2372 m_small_image_list
->GetSize( index
, width
, height
);
2375 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2377 m_small_image_list
->GetSize( index
, width
, height
);
2380 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2382 m_small_image_list
->GetSize( index
, width
, height
);
2389 int wxListMainWindow::GetTextLength( wxString
&s
)
2391 wxClientDC
dc( this );
2394 dc
.GetTextExtent( s
, &lw
, &lh
);
2398 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2400 int i
= m_lines
.Index(*line
);
2401 if (i
== wxNOT_FOUND
) return -1;
2405 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2409 // calc the spacing from the icon size
2412 if ((imageList
) && (imageList
->GetImageCount()) )
2414 imageList
->GetSize(0, width
, height
);
2417 if (which
== wxIMAGE_LIST_NORMAL
)
2419 m_normal_image_list
= imageList
;
2420 m_normal_spacing
= width
+ 8;
2423 if (which
== wxIMAGE_LIST_SMALL
)
2425 m_small_image_list
= imageList
;
2426 m_small_spacing
= width
+ 14;
2430 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2435 m_small_spacing
= spacing
;
2439 m_normal_spacing
= spacing
;
2443 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2445 return isSmall
? m_small_spacing
: m_normal_spacing
;
2448 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2451 wxNode
*node
= m_columns
.Nth( col
);
2454 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2455 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2456 column
->SetItem( item
);
2459 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2461 headerWin
->m_dirty
= TRUE
;
2464 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2466 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2467 _T("SetColumnWidth() can only be called in report mode.") );
2471 wxNode
*node
= (wxNode
*) NULL
;
2473 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2475 // TODO do use the header
2478 else if (width
== wxLIST_AUTOSIZE
)
2480 wxClientDC
dc(this);
2481 dc
.SetFont( GetFont() );
2484 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2486 wxListLineData
*line
= &m_lines
[i
];
2487 wxNode
*n
= line
->m_items
.Nth( col
);
2490 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2491 int current
= 0, ix
= 0, iy
= 0;
2492 wxCoord lx
= 0, ly
= 0;
2493 if (item
->HasImage())
2495 GetImageSize( item
->GetImage(), ix
, iy
);
2498 if (item
->HasText())
2501 item
->GetText( str
);
2502 dc
.GetTextExtent( str
, &lx
, &ly
);
2505 if (current
> max
) max
= current
;
2511 node
= m_columns
.Nth( col
);
2514 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2515 column
->SetWidth( width
);
2518 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2520 wxListLineData
*line
= &m_lines
[i
];
2521 wxNode
*n
= line
->m_items
.Nth( col
);
2524 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2525 item
->SetSize( width
, -1 );
2529 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2531 headerWin
->m_dirty
= TRUE
;
2534 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2536 wxNode
*node
= m_columns
.Nth( col
);
2539 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2540 column
->GetItem( item
);
2552 int wxListMainWindow::GetColumnWidth( int col
)
2554 wxNode
*node
= m_columns
.Nth( col
);
2557 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2558 return column
->GetWidth();
2566 int wxListMainWindow::GetColumnCount()
2568 return m_columns
.Number();
2571 int wxListMainWindow::GetCountPerPage()
2573 return m_visibleLines
;
2576 void wxListMainWindow::SetItem( wxListItem
&item
)
2579 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2581 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2582 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2583 line
->SetItem( item
.m_col
, item
);
2587 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2589 // m_dirty = TRUE; no recalcs needed
2591 wxListLineData
*oldCurrent
= m_current
;
2593 if (stateMask
& wxLIST_STATE_FOCUSED
)
2595 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2597 wxListLineData
*line
= &m_lines
[(size_t)item
];
2598 UnfocusLine( m_current
);
2600 FocusLine( m_current
);
2601 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2602 RefreshLine( m_current
);
2603 if (oldCurrent
) RefreshLine( oldCurrent
);
2607 if (stateMask
& wxLIST_STATE_SELECTED
)
2609 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2610 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2612 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2614 wxListLineData
*line
= &m_lines
[(size_t)item
];
2615 if (m_mode
& wxLC_SINGLE_SEL
)
2617 UnfocusLine( m_current
);
2619 FocusLine( m_current
);
2620 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2621 RefreshLine( m_current
);
2622 if (oldCurrent
) RefreshLine( oldCurrent
);
2624 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2625 if (on
!= line
->IsHilighted())
2627 line
->Hilight( on
);
2628 RefreshLine( line
);
2634 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2636 int ret
= wxLIST_STATE_DONTCARE
;
2637 if (stateMask
& wxLIST_STATE_FOCUSED
)
2639 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2641 wxListLineData
*line
= &m_lines
[(size_t)item
];
2642 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2645 if (stateMask
& wxLIST_STATE_SELECTED
)
2647 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2649 wxListLineData
*line
= &m_lines
[(size_t)item
];
2650 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2656 void wxListMainWindow::GetItem( wxListItem
&item
)
2658 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2660 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2661 line
->GetItem( item
.m_col
, item
);
2672 int wxListMainWindow::GetItemCount()
2674 return m_lines
.GetCount();
2677 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2679 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2681 m_lines
[(size_t)index
].GetRect( rect
);
2682 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2693 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2696 this->GetItemRect(item
,rect
);
2697 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2701 int wxListMainWindow::GetSelectedItemCount()
2704 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2706 if (m_lines
[i
].IsHilighted()) ret
++;
2711 void wxListMainWindow::SetMode( long mode
)
2718 if (m_mode
& wxLC_REPORT
)
2720 #if wxUSE_GENERIC_LIST_EXTENSIONS
2734 long wxListMainWindow::GetMode() const
2739 void wxListMainWindow::CalculatePositions()
2741 if (m_lines
.IsEmpty()) return;
2743 wxClientDC
dc( this );
2744 dc
.SetFont( GetFont() );
2746 int iconSpacing
= 0;
2747 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2748 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2750 // we take the first line (which also can be an icon or
2751 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2752 // measure the size of the line
2756 int lineSpacing
= 0;
2758 wxListLineData
*line
= &m_lines
[0];
2759 line
->CalculateSize( &dc
, iconSpacing
);
2761 line
->GetSize( dummy
, lineSpacing
);
2764 int clientWidth
= 0;
2765 int clientHeight
= 0;
2767 if (m_mode
& wxLC_REPORT
)
2769 // scroll one line per step
2770 m_yScroll
= lineSpacing
;
2774 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2775 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2776 #if wxUSE_GENERIC_LIST_EXTENSIONS
2777 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2779 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2781 GetClientSize( &clientWidth
, &clientHeight
);
2783 int entireWidth
= 0 ;
2784 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2786 wxListLineData
*line
= &m_lines
[j
];
2787 line
->CalculateSize( &dc
, iconSpacing
);
2788 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2790 for (int i
= 0; i
< GetColumnCount(); i
++)
2792 line
->SetColumnPosition( i
, col_x
);
2793 col_x
+= GetColumnWidth( i
);
2795 entireWidth
= wxMax( entireWidth
, col_x
) ;
2796 #if wxUSE_GENERIC_LIST_EXTENSIONS
2797 line
->SetPosition( &dc
, x
, y
, col_x
);
2799 y
+= lineSpacing
; // one pixel blank line between items
2801 m_visibleLines
= clientHeight
/ lineSpacing
;
2802 #if wxUSE_GENERIC_LIST_EXTENSIONS
2803 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2808 // at first we try without any scrollbar. if the items don't
2809 // fit into the window, we recalculate after subtracting an
2810 // approximated 15 pt for the horizontal scrollbar
2812 GetSize( &clientWidth
, &clientHeight
);
2813 clientHeight
-= 4; // sunken frame
2815 int entireWidth
= 0;
2817 for (int tries
= 0; tries
< 2; tries
++)
2824 int m_currentVisibleLines
= 0;
2825 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2827 m_currentVisibleLines
++;
2828 wxListLineData
*line
= &m_lines
[i
];
2829 line
->CalculateSize( &dc
, iconSpacing
);
2830 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2831 line
->GetSize( lineWidth
, lineHeight
);
2832 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2834 if (m_currentVisibleLines
> m_visibleLines
)
2835 m_visibleLines
= m_currentVisibleLines
;
2836 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2838 m_currentVisibleLines
= 0;
2841 entireWidth
+= maxWidth
+6;
2844 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2845 if ((tries
== 0) && (entireWidth
> clientWidth
))
2847 clientHeight
-= 15; // scrollbar height
2849 m_currentVisibleLines
= 0;
2852 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2856 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2857 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2861 void wxListMainWindow::RealizeChanges()
2865 if (!m_lines
.IsEmpty())
2866 m_current
= &m_lines
[0];
2870 FocusLine( m_current
);
2871 // TODO: MSW doesn't automatically hilight the
2873 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2877 long wxListMainWindow::GetNextItem( long item
,
2878 int WXUNUSED(geometry
),
2882 max
= GetItemCount();
2883 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2884 _T("invalid listctrl index in GetNextItem()") );
2886 // notice that we start with the next item (or the first one if item == -1)
2887 // and this is intentional to allow writing a simple loop to iterate over
2888 // all selected items
2892 // this is not an error because the index was ok initially, just no
2897 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2899 wxListLineData
*line
= &m_lines
[i
];
2900 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2902 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2912 void wxListMainWindow::DeleteItem( long index
)
2915 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2917 wxListLineData
*line
= &m_lines
[(size_t)index
];
2918 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2920 m_lines
.RemoveAt( (size_t)index
);
2924 void wxListMainWindow::DeleteColumn( int col
)
2926 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2927 wxT("attempting to delete inexistent column in wxListView") );
2930 wxNode
*node
= m_columns
.Nth( col
);
2931 if (node
) m_columns
.DeleteNode( node
);
2934 void wxListMainWindow::DeleteAllItems()
2937 m_current
= (wxListLineData
*) NULL
;
2939 // to make the deletion of all items faster, we don't send the
2940 // notifications in this case: this is compatible with wxMSW and
2941 // documented in DeleteAllItems() description
2943 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2944 event
.SetEventObject( GetParent() );
2945 GetParent()->GetEventHandler()->ProcessEvent( event
);
2950 void wxListMainWindow::DeleteEverything()
2957 void wxListMainWindow::EnsureVisible( long index
)
2959 // We have to call this here because the label in
2960 // question might just have been added and no screen
2961 // update taken place.
2962 if (m_dirty
) wxYield();
2964 wxListLineData
*oldCurrent
= m_current
;
2965 m_current
= (wxListLineData
*) NULL
;
2966 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2967 m_current
= &m_lines
[(size_t)index
];
2968 if (m_current
) MoveToFocus();
2969 m_current
= oldCurrent
;
2972 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2976 if (pos
< 0) pos
= 0;
2977 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2979 wxListLineData
*line
= &m_lines
[i
];
2981 line
->GetText( 0, s
);
2982 if (s
== tmp
) return pos
;
2988 long wxListMainWindow::FindItem(long start
, long data
)
2991 if (pos
< 0) pos
= 0;
2992 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2994 wxListLineData
*line
= &m_lines
[i
];
2996 line
->GetItem( 0, item
);
2997 if (item
.m_data
== data
) return pos
;
3003 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3005 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3008 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3010 wxListLineData
*line
= &m_lines
[i
];
3011 long ret
= line
->IsHit( x
, y
);
3012 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3022 void wxListMainWindow::InsertItem( wxListItem
&item
)
3026 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3027 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3028 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3029 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3031 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3033 if (m_mode
& wxLC_REPORT
)
3035 line
->InitItems( GetColumnCount() );
3036 item
.m_width
= GetColumnWidth( 0 )-3;
3040 line
->InitItems( 1 );
3043 line
->SetItem( 0, item
);
3044 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3046 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3050 m_lines
.Add( line
);
3051 item
.m_itemId
= m_lines
.GetCount()-1;
3055 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3058 if (m_mode
& wxLC_REPORT
)
3060 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3061 wxListHeaderData
*column
= new wxListHeaderData( item
);
3062 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3064 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3066 m_columns
.Insert( node
, column
);
3070 m_columns
.Append( column
);
3075 wxListCtrlCompare list_ctrl_compare_func_2
;
3076 long list_ctrl_compare_data
;
3078 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3080 wxListLineData
*line1
= *arg1
;
3081 wxListLineData
*line2
= *arg2
;
3083 line1
->GetItem( 0, item
);
3084 long data1
= item
.m_data
;
3085 line2
->GetItem( 0, item
);
3086 long data2
= item
.m_data
;
3087 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3090 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3092 list_ctrl_compare_func_2
= fn
;
3093 list_ctrl_compare_data
= data
;
3094 m_lines
.Sort( list_ctrl_compare_func_1
);
3098 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3100 wxScrolledWindow::OnScroll( event
) ;
3101 #if wxUSE_GENERIC_LIST_EXTENSIONS
3103 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3105 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3108 lc
->m_headerWin
->Refresh() ;
3110 lc
->m_headerWin
->MacUpdateImmediately() ;
3117 // -------------------------------------------------------------------------------------
3119 // -------------------------------------------------------------------------------------
3121 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3123 wxListItem::wxListItem()
3132 m_format
= wxLIST_FORMAT_CENTRE
;
3138 void wxListItem::Clear()
3147 m_format
= wxLIST_FORMAT_CENTRE
;
3149 m_text
= wxEmptyString
;
3151 if (m_attr
) delete m_attr
;
3155 void wxListItem::ClearAttributes()
3157 if (m_attr
) delete m_attr
;
3161 // -------------------------------------------------------------------------------------
3163 // -------------------------------------------------------------------------------------
3165 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3167 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3168 wxNotifyEvent( commandType
, id
)
3174 m_cancelled
= FALSE
;
3179 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3181 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3183 wxNotifyEvent::CopyObject(object_dest
);
3185 obj
->m_code
= m_code
;
3186 obj
->m_itemIndex
= m_itemIndex
;
3187 obj
->m_oldItemIndex
= m_oldItemIndex
;
3189 obj
->m_cancelled
= m_cancelled
;
3190 obj
->m_pointDrag
= m_pointDrag
;
3191 obj
->m_item
.m_mask
= m_item
.m_mask
;
3192 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3193 obj
->m_item
.m_col
= m_item
.m_col
;
3194 obj
->m_item
.m_state
= m_item
.m_state
;
3195 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3196 obj
->m_item
.m_text
= m_item
.m_text
;
3197 obj
->m_item
.m_image
= m_item
.m_image
;
3198 obj
->m_item
.m_data
= m_item
.m_data
;
3199 obj
->m_item
.m_format
= m_item
.m_format
;
3200 obj
->m_item
.m_width
= m_item
.m_width
;
3202 if ( m_item
.HasAttributes() )
3204 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3208 // -------------------------------------------------------------------------------------
3210 // -------------------------------------------------------------------------------------
3212 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3214 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3215 EVT_SIZE (wxListCtrl::OnSize
)
3216 EVT_IDLE (wxListCtrl::OnIdle
)
3219 wxListCtrl::wxListCtrl()
3221 m_imageListNormal
= (wxImageList
*) NULL
;
3222 m_imageListSmall
= (wxImageList
*) NULL
;
3223 m_imageListState
= (wxImageList
*) NULL
;
3224 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3225 m_mainWin
= (wxListMainWindow
*) NULL
;
3226 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3229 wxListCtrl::~wxListCtrl()
3231 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3232 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3233 if (m_ownsImageListState
) delete m_imageListState
;
3236 bool wxListCtrl::Create(wxWindow
*parent
,
3241 const wxValidator
&validator
,
3242 const wxString
&name
)
3244 m_imageListNormal
= (wxImageList
*) NULL
;
3245 m_imageListSmall
= (wxImageList
*) NULL
;
3246 m_imageListState
= (wxImageList
*) NULL
;
3247 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3248 m_mainWin
= (wxListMainWindow
*) NULL
;
3249 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3251 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3253 style
= style
| wxLC_LIST
;
3256 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3259 if (style
& wxSUNKEN_BORDER
)
3260 style
-= wxSUNKEN_BORDER
;
3262 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3264 if (HasFlag(wxLC_REPORT
))
3266 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3267 if (HasFlag(wxLC_NO_HEADER
))
3268 m_headerWin
->Show( FALSE
);
3272 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3278 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3280 /* handled in OnIdle */
3282 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3285 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3287 long flag
= GetWindowStyle();
3291 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3292 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3293 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3302 if (flag
& style
) flag
-= style
;
3305 SetWindowStyleFlag( flag
);
3308 void wxListCtrl::SetWindowStyleFlag( long flag
)
3312 m_mainWin
->DeleteEverything();
3316 GetClientSize( &width
, &height
);
3318 m_mainWin
->SetMode( flag
);
3320 if (flag
& wxLC_REPORT
)
3322 if (!HasFlag(wxLC_REPORT
))
3326 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3327 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3328 if (HasFlag(wxLC_NO_HEADER
))
3329 m_headerWin
->Show( FALSE
);
3333 if (flag
& wxLC_NO_HEADER
)
3334 m_headerWin
->Show( FALSE
);
3336 m_headerWin
->Show( TRUE
);
3342 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3344 m_headerWin
->Show( FALSE
);
3349 wxWindow::SetWindowStyleFlag( flag
);
3352 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3354 m_mainWin
->GetColumn( col
, item
);
3358 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3360 m_mainWin
->SetColumn( col
, item
);
3364 int wxListCtrl::GetColumnWidth( int col
) const
3366 return m_mainWin
->GetColumnWidth( col
);
3369 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3371 m_mainWin
->SetColumnWidth( col
, width
);
3375 int wxListCtrl::GetCountPerPage() const
3377 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3380 bool wxListCtrl::GetItem( wxListItem
&info
) const
3382 m_mainWin
->GetItem( info
);
3386 bool wxListCtrl::SetItem( wxListItem
&info
)
3388 m_mainWin
->SetItem( info
);
3392 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3395 info
.m_text
= label
;
3396 info
.m_mask
= wxLIST_MASK_TEXT
;
3397 info
.m_itemId
= index
;
3401 info
.m_image
= imageId
;
3402 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3404 m_mainWin
->SetItem(info
);
3408 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3410 return m_mainWin
->GetItemState( item
, stateMask
);
3413 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3415 m_mainWin
->SetItemState( item
, state
, stateMask
);
3419 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3422 info
.m_image
= image
;
3423 info
.m_mask
= wxLIST_MASK_IMAGE
;
3424 info
.m_itemId
= item
;
3425 m_mainWin
->SetItem( info
);
3429 wxString
wxListCtrl::GetItemText( long item
) const
3432 info
.m_itemId
= item
;
3433 m_mainWin
->GetItem( info
);
3437 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3440 info
.m_mask
= wxLIST_MASK_TEXT
;
3441 info
.m_itemId
= item
;
3443 m_mainWin
->SetItem( info
);
3446 long wxListCtrl::GetItemData( long item
) const
3449 info
.m_itemId
= item
;
3450 m_mainWin
->GetItem( info
);
3454 bool wxListCtrl::SetItemData( long item
, long data
)
3457 info
.m_mask
= wxLIST_MASK_DATA
;
3458 info
.m_itemId
= item
;
3460 m_mainWin
->SetItem( info
);
3464 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3466 m_mainWin
->GetItemRect( item
, rect
);
3470 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3472 m_mainWin
->GetItemPosition( item
, pos
);
3476 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3481 int wxListCtrl::GetItemCount() const
3483 return m_mainWin
->GetItemCount();
3486 int wxListCtrl::GetColumnCount() const
3488 return m_mainWin
->GetColumnCount();
3491 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3493 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3496 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3498 return m_mainWin
->GetItemSpacing( isSmall
);
3501 int wxListCtrl::GetSelectedItemCount() const
3503 return m_mainWin
->GetSelectedItemCount();
3506 wxColour
wxListCtrl::GetTextColour() const
3508 return GetForegroundColour();
3511 void wxListCtrl::SetTextColour(const wxColour
& col
)
3513 SetForegroundColour(col
);
3516 long wxListCtrl::GetTopItem() const
3521 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3523 return m_mainWin
->GetNextItem( item
, geom
, state
);
3526 wxImageList
*wxListCtrl::GetImageList(int which
) const
3528 if (which
== wxIMAGE_LIST_NORMAL
)
3530 return m_imageListNormal
;
3532 else if (which
== wxIMAGE_LIST_SMALL
)
3534 return m_imageListSmall
;
3536 else if (which
== wxIMAGE_LIST_STATE
)
3538 return m_imageListState
;
3540 return (wxImageList
*) NULL
;
3543 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3545 if ( which
== wxIMAGE_LIST_NORMAL
)
3547 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3548 m_imageListNormal
= imageList
;
3549 m_ownsImageListNormal
= FALSE
;
3551 else if ( which
== wxIMAGE_LIST_SMALL
)
3553 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3554 m_imageListSmall
= imageList
;
3555 m_ownsImageListSmall
= FALSE
;
3557 else if ( which
== wxIMAGE_LIST_STATE
)
3559 if (m_ownsImageListState
) delete m_imageListState
;
3560 m_imageListState
= imageList
;
3561 m_ownsImageListState
= FALSE
;
3564 m_mainWin
->SetImageList( imageList
, which
);
3567 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3569 SetImageList(imageList
, which
);
3570 if ( which
== wxIMAGE_LIST_NORMAL
)
3571 m_ownsImageListNormal
= TRUE
;
3572 else if ( which
== wxIMAGE_LIST_SMALL
)
3573 m_ownsImageListSmall
= TRUE
;
3574 else if ( which
== wxIMAGE_LIST_STATE
)
3575 m_ownsImageListState
= TRUE
;
3578 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3583 bool wxListCtrl::DeleteItem( long item
)
3585 m_mainWin
->DeleteItem( item
);
3589 bool wxListCtrl::DeleteAllItems()
3591 m_mainWin
->DeleteAllItems();
3595 bool wxListCtrl::DeleteAllColumns()
3597 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3603 void wxListCtrl::ClearAll()
3605 m_mainWin
->DeleteEverything();
3608 bool wxListCtrl::DeleteColumn( int col
)
3610 m_mainWin
->DeleteColumn( col
);
3614 void wxListCtrl::Edit( long item
)
3616 m_mainWin
->Edit( item
);
3619 bool wxListCtrl::EnsureVisible( long item
)
3621 m_mainWin
->EnsureVisible( item
);
3625 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3627 return m_mainWin
->FindItem( start
, str
, partial
);
3630 long wxListCtrl::FindItem( long start
, long data
)
3632 return m_mainWin
->FindItem( start
, data
);
3635 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3636 int WXUNUSED(direction
))
3641 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3643 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3646 long wxListCtrl::InsertItem( wxListItem
& info
)
3648 m_mainWin
->InsertItem( info
);
3649 return info
.m_itemId
;
3652 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3655 info
.m_text
= label
;
3656 info
.m_mask
= wxLIST_MASK_TEXT
;
3657 info
.m_itemId
= index
;
3658 return InsertItem( info
);
3661 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3664 info
.m_mask
= wxLIST_MASK_IMAGE
;
3665 info
.m_image
= imageIndex
;
3666 info
.m_itemId
= index
;
3667 return InsertItem( info
);
3670 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3673 info
.m_text
= label
;
3674 info
.m_image
= imageIndex
;
3675 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3676 info
.m_itemId
= index
;
3677 return InsertItem( info
);
3680 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3682 wxASSERT( m_headerWin
);
3683 m_mainWin
->InsertColumn( col
, item
);
3684 m_headerWin
->Refresh();
3689 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3690 int format
, int width
)
3693 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3694 item
.m_text
= heading
;
3697 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3698 item
.m_width
= width
;
3700 item
.m_format
= format
;
3702 return InsertColumn( col
, item
);
3705 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3711 // fn is a function which takes 3 long arguments: item1, item2, data.
3712 // item1 is the long data associated with a first item (NOT the index).
3713 // item2 is the long data associated with a second item (NOT the index).
3714 // data is the same value as passed to SortItems.
3715 // The return value is a negative number if the first item should precede the second
3716 // item, a positive number of the second item should precede the first,
3717 // or zero if the two items are equivalent.
3718 // data is arbitrary data to be passed to the sort function.
3720 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3722 m_mainWin
->SortItems( fn
, data
);
3726 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3728 if (!m_mainWin
->m_dirty
) return;
3732 GetClientSize( &cw
, &ch
);
3739 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3741 m_headerWin
->GetPosition( &x
, &y
);
3742 m_headerWin
->GetSize( &w
, &h
);
3743 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3744 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3746 m_mainWin
->GetPosition( &x
, &y
);
3747 m_mainWin
->GetSize( &w
, &h
);
3748 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3749 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3753 m_mainWin
->GetPosition( &x
, &y
);
3754 m_mainWin
->GetSize( &w
, &h
);
3755 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3756 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3759 m_mainWin
->CalculatePositions();
3760 m_mainWin
->RealizeChanges();
3761 m_mainWin
->m_dirty
= FALSE
;
3762 m_mainWin
->Refresh();
3764 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3766 m_headerWin
->m_dirty
= FALSE
;
3767 m_headerWin
->Refresh();
3771 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3775 m_mainWin
->SetBackgroundColour( colour
);
3776 m_mainWin
->m_dirty
= TRUE
;
3782 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3784 if ( !wxWindow::SetForegroundColour( colour
) )
3789 m_mainWin
->SetForegroundColour( colour
);
3790 m_mainWin
->m_dirty
= TRUE
;
3795 m_headerWin
->SetForegroundColour( colour
);
3801 bool wxListCtrl::SetFont( const wxFont
&font
)
3803 if ( !wxWindow::SetFont( font
) )
3808 m_mainWin
->SetFont( font
);
3809 m_mainWin
->m_dirty
= TRUE
;
3814 m_headerWin
->SetFont( font
);
3820 #if wxUSE_DRAG_AND_DROP
3822 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3824 m_mainWin
->SetDropTarget( dropTarget
);
3827 wxDropTarget
*wxListCtrl::GetDropTarget() const
3829 return m_mainWin
->GetDropTarget();
3832 #endif // wxUSE_DRAG_AND_DROP
3834 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3836 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3839 wxColour
wxListCtrl::GetBackgroundColour() const
3841 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3844 wxColour
wxListCtrl::GetForegroundColour() const
3846 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3849 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3851 return m_mainWin
->PopupMenu( menu
, x
, y
);
3854 void wxListCtrl::SetFocus()
3856 /* The test in window.cpp fails as we are a composite
3857 window, so it checks against "this", but not m_mainWin. */
3858 if ( FindFocus() != this )
3859 m_mainWin
->SetFocus();