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
) )
1252 wxPaintDC
dc( this );
1258 dc
.SetFont( GetFont() );
1260 // width and height of the entire header window
1262 GetClientSize( &w
, &h
);
1263 #if wxUSE_GENERIC_LIST_EXTENSIONS
1264 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1265 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1267 dc
.SetBackgroundMode(wxTRANSPARENT
);
1269 // do *not* use the listctrl colour for headers - one day we will have a
1270 // function to set it separately
1271 //dc.SetTextForeground( *wxBLACK );
1272 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1274 int x
= 1; // left of the header rect
1275 const int y
= 1; // top
1276 int numColumns
= m_owner
->GetColumnCount();
1278 for (int i
= 0; i
< numColumns
; i
++)
1280 m_owner
->GetColumn( i
, item
);
1281 int wCol
= item
.m_width
;
1282 int cw
= wCol
- 2; // the width of the rect to draw
1284 int xEnd
= x
+ wCol
;
1286 // VZ: no, draw it normally - this is better now as we allow resizing
1287 // of the last column as well
1289 // let the last column occupy all available space
1290 if ( i
== numColumns
- 1 )
1294 dc
.SetPen( *wxWHITE_PEN
);
1296 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1297 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1298 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1299 dc
.DestroyClippingRegion();
1308 void wxListHeaderWindow::DrawCurrent()
1310 int x1
= m_currentX
;
1312 ClientToScreen( &x1
, &y1
);
1314 int x2
= m_currentX
-1;
1316 m_owner
->GetClientSize( NULL
, &y2
);
1317 m_owner
->ClientToScreen( &x2
, &y2
);
1320 dc
.SetLogicalFunction( wxINVERT
);
1321 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1322 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1326 dc
.DrawLine( x1
, y1
, x2
, y2
);
1328 dc
.SetLogicalFunction( wxCOPY
);
1330 dc
.SetPen( wxNullPen
);
1331 dc
.SetBrush( wxNullBrush
);
1334 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1336 // we want to work with logical coords
1337 #if wxUSE_GENERIC_LIST_EXTENSIONS
1339 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1340 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1341 int x
= event
.GetX();
1342 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1343 int y
= event
.GetY();
1347 // we don't draw the line beyond our window, but we allow dragging it
1350 GetClientSize( &w
, NULL
);
1351 #if wxUSE_GENERIC_LIST_EXTENSIONS
1352 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1353 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1356 // erase the line if it was drawn
1357 if ( m_currentX
< w
)
1360 if (event
.ButtonUp())
1363 m_isDragging
= FALSE
;
1365 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1372 m_currentX
= m_minX
+ 7;
1374 // draw in the new location
1375 if ( m_currentX
< w
)
1379 else // not dragging
1382 bool hit_border
= FALSE
;
1384 // end of the current column
1387 // find the column where this event occured
1388 int countCol
= m_owner
->GetColumnCount();
1389 for (int j
= 0; j
< countCol
; j
++)
1391 xpos
+= m_owner
->GetColumnWidth( j
);
1394 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1396 // near the column border
1403 // inside the column
1410 if (event
.LeftDown())
1414 m_isDragging
= TRUE
;
1421 wxWindow
*parent
= GetParent();
1422 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1423 le
.SetEventObject( parent
);
1424 le
.m_col
= m_column
;
1425 parent
->GetEventHandler()->ProcessEvent( le
);
1428 else if (event
.Moving())
1433 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1434 m_currentCursor
= m_resizeCursor
;
1438 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1439 m_currentCursor
= wxSTANDARD_CURSOR
;
1443 SetCursor(*m_currentCursor
);
1448 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1450 m_owner
->SetFocus();
1453 //-----------------------------------------------------------------------------
1454 // wxListRenameTimer (internal)
1455 //-----------------------------------------------------------------------------
1457 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1462 void wxListRenameTimer::Notify()
1464 m_owner
->OnRenameTimer();
1467 //-----------------------------------------------------------------------------
1468 // wxListTextCtrl (internal)
1469 //-----------------------------------------------------------------------------
1471 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1473 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1474 EVT_CHAR (wxListTextCtrl::OnChar
)
1475 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1476 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1479 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1480 const wxWindowID id
,
1483 wxListMainWindow
*owner
,
1484 const wxString
&value
,
1488 const wxValidator
& validator
,
1489 const wxString
&name
)
1490 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1495 (*m_accept
) = FALSE
;
1497 m_startValue
= value
;
1500 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1502 if (event
.m_keyCode
== WXK_RETURN
)
1505 (*m_res
) = GetValue();
1507 if (!wxPendingDelete
.Member(this))
1508 wxPendingDelete
.Append(this);
1510 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1511 m_owner
->OnRenameAccept();
1515 if (event
.m_keyCode
== WXK_ESCAPE
)
1517 (*m_accept
) = FALSE
;
1520 if (!wxPendingDelete
.Member(this))
1521 wxPendingDelete
.Append(this);
1529 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1531 // auto-grow the textctrl:
1532 wxSize parentSize
= m_owner
->GetSize();
1533 wxPoint myPos
= GetPosition();
1534 wxSize mySize
= GetSize();
1536 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1537 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1538 if (mySize
.x
> sx
) sx
= mySize
.x
;
1544 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1546 if (!wxPendingDelete
.Member(this))
1547 wxPendingDelete
.Append(this);
1549 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1550 m_owner
->OnRenameAccept();
1553 //-----------------------------------------------------------------------------
1555 //-----------------------------------------------------------------------------
1557 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1559 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1560 EVT_PAINT (wxListMainWindow::OnPaint
)
1561 EVT_SIZE (wxListMainWindow::OnSize
)
1562 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1563 EVT_CHAR (wxListMainWindow::OnChar
)
1564 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1565 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1566 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1567 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1570 wxListMainWindow::wxListMainWindow()
1573 m_columns
.DeleteContents( TRUE
);
1574 m_current
= (wxListLineData
*) NULL
;
1576 m_hilightBrush
= (wxBrush
*) NULL
;
1580 m_small_image_list
= (wxImageList
*) NULL
;
1581 m_normal_image_list
= (wxImageList
*) NULL
;
1582 m_small_spacing
= 30;
1583 m_normal_spacing
= 40;
1586 m_lastOnSame
= FALSE
;
1587 m_renameTimer
= new wxListRenameTimer( this );
1588 m_isCreated
= FALSE
;
1592 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1595 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1596 const wxPoint
&pos
, const wxSize
&size
,
1597 long style
, const wxString
&name
) :
1598 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1601 m_columns
.DeleteContents( TRUE
);
1602 m_current
= (wxListLineData
*) NULL
;
1605 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1606 m_small_image_list
= (wxImageList
*) NULL
;
1607 m_normal_image_list
= (wxImageList
*) NULL
;
1608 m_small_spacing
= 30;
1609 m_normal_spacing
= 40;
1612 m_isCreated
= FALSE
;
1616 if (m_mode
& wxLC_REPORT
)
1618 #if wxUSE_GENERIC_LIST_EXTENSIONS
1630 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1633 m_lastOnSame
= FALSE
;
1634 m_renameTimer
= new wxListRenameTimer( this );
1635 m_renameAccept
= FALSE
;
1637 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1640 wxListMainWindow::~wxListMainWindow()
1644 if (m_hilightBrush
) delete m_hilightBrush
;
1646 delete m_renameTimer
;
1649 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1651 if (m_dirty
) return;
1659 line
->GetExtent( x
, y
, w
, h
);
1660 CalcScrolledPosition( x
, y
, &x
, &y
);
1661 wxRect
rect( x
, y
, w
, h
);
1662 Refresh( TRUE
, &rect
);
1665 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1667 // Note: a wxPaintDC must be constructed even if no drawing is
1668 // done (a Windows requirement).
1669 wxPaintDC
dc( this );
1672 if (m_dirty
) return;
1674 if (m_lines
.GetCount() == 0) return;
1678 dc
.SetFont( GetFont() );
1680 if (m_mode
& wxLC_REPORT
)
1682 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1684 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1686 wxSize clientSize
= GetClientSize();
1688 int lineSpacing
= 0;
1689 wxListLineData
*line
= &m_lines
[0];
1691 line
->GetSize( dummy
, lineSpacing
);
1694 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1696 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1697 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1699 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1701 m_lines
[i
].Draw( &dc
);
1702 // Draw horizontal rule if required
1703 if (GetWindowStyle() & wxLC_HRULES
)
1704 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1707 // Draw last horizontal rule
1708 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1709 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1711 // Draw vertical rules if required
1712 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1715 wxRect firstItemRect
;
1716 wxRect lastItemRect
;
1717 GetItemRect(0, firstItemRect
);
1718 GetItemRect(GetItemCount() - 1, lastItemRect
);
1719 int x
= firstItemRect
.GetX();
1720 for (col
= 0; col
< GetColumnCount(); col
++)
1722 int colWidth
= GetColumnWidth(col
);
1724 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1730 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1731 m_lines
[i
].Draw( &dc
);
1734 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1739 void wxListMainWindow::HilightAll( bool on
)
1741 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1743 wxListLineData
*line
= &m_lines
[i
];
1744 if (line
->IsHilighted() != on
)
1746 line
->Hilight( on
);
1747 RefreshLine( line
);
1752 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1753 wxEventType command
,
1756 wxListEvent
le( command
, GetParent()->GetId() );
1757 le
.SetEventObject( GetParent() );
1758 le
.m_itemIndex
= GetIndexOfLine( line
);
1760 // set only for events which have position
1761 if ( point
!= wxDefaultPosition
)
1762 le
.m_pointDrag
= point
;
1764 line
->GetItem( 0, le
.m_item
);
1765 GetParent()->GetEventHandler()->ProcessEvent( le
);
1766 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1769 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1771 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1774 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1776 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1779 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1781 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1784 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1786 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1789 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1791 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1796 void wxListMainWindow::EditLabel( long item
)
1798 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1799 wxT("wrong index in wxListCtrl::Edit()") );
1801 m_currentEdit
= &m_lines
[(size_t)item
];
1803 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1804 le
.SetEventObject( GetParent() );
1805 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1806 m_currentEdit
->GetItem( 0, le
.m_item
);
1807 GetParent()->GetEventHandler()->ProcessEvent( le
);
1809 if (!le
.IsAllowed())
1812 // We have to call this here because the label in
1813 // question might just have been added and no screen
1814 // update taken place.
1815 if (m_dirty
) wxYield();
1818 m_currentEdit
->GetText( 0, s
);
1823 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1825 wxClientDC
dc(this);
1827 x
= dc
.LogicalToDeviceX( x
);
1828 y
= dc
.LogicalToDeviceY( y
);
1830 wxListTextCtrl
*text
= new wxListTextCtrl(
1831 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1835 void wxListMainWindow::OnRenameTimer()
1837 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1839 Edit( m_lines
.Index( *m_current
) );
1842 void wxListMainWindow::OnRenameAccept()
1844 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1845 le
.SetEventObject( GetParent() );
1846 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1847 m_currentEdit
->GetItem( 0, le
.m_item
);
1848 le
.m_item
.m_text
= m_renameRes
;
1849 GetParent()->GetEventHandler()->ProcessEvent( le
);
1851 if (!le
.IsAllowed()) return;
1854 info
.m_mask
= wxLIST_MASK_TEXT
;
1855 info
.m_itemId
= le
.m_itemIndex
;
1856 info
.m_text
= m_renameRes
;
1857 info
.SetTextColour(le
.m_item
.GetTextColour());
1861 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1863 event
.SetEventObject( GetParent() );
1864 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1866 if (!m_current
) return;
1867 if (m_dirty
) return;
1868 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1870 int x
= event
.GetX();
1871 int y
= event
.GetY();
1872 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1874 /* Did we actually hit an item ? */
1876 wxListLineData
*line
= (wxListLineData
*) NULL
;
1877 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1880 hitResult
= line
->IsHit( x
, y
);
1881 if (hitResult
) break;
1882 line
= (wxListLineData
*) NULL
;
1885 if (event
.Dragging())
1887 if (m_dragCount
== 0)
1888 m_dragStart
= wxPoint(x
,y
);
1892 if (m_dragCount
!= 3) return;
1894 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1895 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1897 wxListEvent
le( command
, GetParent()->GetId() );
1898 le
.SetEventObject( GetParent() );
1899 le
.m_pointDrag
= m_dragStart
;
1900 GetParent()->GetEventHandler()->ProcessEvent( le
);
1911 bool forceClick
= FALSE
;
1912 if (event
.ButtonDClick())
1914 m_renameTimer
->Stop();
1915 m_lastOnSame
= FALSE
;
1917 if ( line
== m_lineBeforeLastClicked
)
1921 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1927 // the first click was on another item, so don't interpret this as
1928 // a double click, but as a simple click instead
1933 if (event
.LeftUp() && m_lastOnSame
)
1936 if ((line
== m_current
) &&
1937 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1938 (m_mode
& wxLC_EDIT_LABELS
) )
1940 m_renameTimer
->Start( 100, TRUE
);
1942 m_lastOnSame
= FALSE
;
1946 if (event
.RightDown())
1948 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
1949 event
.GetPosition() );
1953 if (event
.MiddleDown())
1955 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1959 if ( event
.LeftDown() || forceClick
)
1961 m_lineBeforeLastClicked
= m_lineLastClicked
;
1962 m_lineLastClicked
= line
;
1965 wxListLineData
*oldCurrent
= m_current
;
1966 if (m_mode
& wxLC_SINGLE_SEL
)
1969 HilightAll( FALSE
);
1970 m_current
->ReverseHilight();
1971 RefreshLine( m_current
);
1975 if (event
.ControlDown())
1978 m_current
->ReverseHilight();
1979 RefreshLine( m_current
);
1981 else if (event
.ShiftDown())
1987 int numOfCurrent
= -1;
1988 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1990 wxListLineData
*test_line
= &m_lines
[j
];
1992 if (test_line
== oldCurrent
) break;
1997 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1999 wxListLineData
*test_line
= &m_lines
[j
];
2001 if (test_line
== line
) break;
2004 if (numOfLine
< numOfCurrent
)
2007 numOfLine
= numOfCurrent
;
2011 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2013 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2014 test_line
->Hilight(TRUE
);
2015 RefreshLine( test_line
);
2021 HilightAll( FALSE
);
2022 m_current
->ReverseHilight();
2023 RefreshLine( m_current
);
2026 if (m_current
!= oldCurrent
)
2028 RefreshLine( oldCurrent
);
2029 UnfocusLine( oldCurrent
);
2030 FocusLine( m_current
);
2033 // forceClick is only set if the previous click was on another item
2034 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2040 void wxListMainWindow::MoveToFocus()
2042 if (!m_current
) return;
2048 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2052 GetClientSize( &client_w
, &client_h
);
2054 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2055 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2057 if (m_mode
& wxLC_REPORT
)
2059 if (item_y
< view_y
)
2060 Scroll( -1, (item_y
)/m_yScroll
);
2061 if (item_y
+item_h
+5 > view_y
+client_h
)
2062 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2066 if (item_x
-view_x
< 5)
2067 Scroll( (item_x
-5)/m_xScroll
, -1 );
2068 if (item_x
+item_w
-5 > view_x
+client_w
)
2069 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2073 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2075 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2076 wxListLineData
*oldCurrent
= m_current
;
2077 m_current
= newCurrent
;
2078 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2079 RefreshLine( m_current
);
2080 RefreshLine( oldCurrent
);
2081 FocusLine( m_current
);
2082 UnfocusLine( oldCurrent
);
2086 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2088 wxWindow
*parent
= GetParent();
2090 /* we propagate the key event up */
2091 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2092 ke
.m_shiftDown
= event
.m_shiftDown
;
2093 ke
.m_controlDown
= event
.m_controlDown
;
2094 ke
.m_altDown
= event
.m_altDown
;
2095 ke
.m_metaDown
= event
.m_metaDown
;
2096 ke
.m_keyCode
= event
.m_keyCode
;
2099 ke
.SetEventObject( parent
);
2100 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2105 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2107 wxWindow
*parent
= GetParent();
2109 /* we send a list_key event up */
2112 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2113 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2114 m_current
->GetItem( 0, le
.m_item
);
2115 le
.m_code
= (int)event
.KeyCode();
2116 le
.SetEventObject( parent
);
2117 parent
->GetEventHandler()->ProcessEvent( le
);
2120 /* we propagate the char event up */
2121 wxKeyEvent
ke( wxEVT_CHAR
);
2122 ke
.m_shiftDown
= event
.m_shiftDown
;
2123 ke
.m_controlDown
= event
.m_controlDown
;
2124 ke
.m_altDown
= event
.m_altDown
;
2125 ke
.m_metaDown
= event
.m_metaDown
;
2126 ke
.m_keyCode
= event
.m_keyCode
;
2129 ke
.SetEventObject( parent
);
2130 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2132 if (event
.KeyCode() == WXK_TAB
)
2134 wxNavigationKeyEvent nevent
;
2135 nevent
.SetWindowChange( event
.ControlDown() );
2136 nevent
.SetDirection( !event
.ShiftDown() );
2137 nevent
.SetEventObject( GetParent()->GetParent() );
2138 nevent
.SetCurrentFocus( m_parent
);
2139 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2142 /* no item -> nothing to do */
2149 switch (event
.KeyCode())
2153 int index
= m_lines
.Index(*m_current
);
2154 if (index
!= wxNOT_FOUND
&& index
> 0)
2155 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2160 int index
= m_lines
.Index(*m_current
);
2161 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2162 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2167 if (!m_lines
.IsEmpty())
2168 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2173 if (!m_lines
.IsEmpty())
2174 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2180 int index
= m_lines
.Index(*m_current
);
2181 if (m_mode
& wxLC_REPORT
)
2183 steps
= m_visibleLines
-1;
2187 steps
= index
% m_visibleLines
;
2189 if (index
!= wxNOT_FOUND
)
2192 if (index
< 0) index
= 0;
2193 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2200 int index
= m_lines
.Index(*m_current
);
2201 if (m_mode
& wxLC_REPORT
)
2203 steps
= m_visibleLines
-1;
2207 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2210 if (index
!= wxNOT_FOUND
)
2213 if ((size_t)index
>= m_lines
.GetCount())
2214 index
= m_lines
.GetCount()-1;
2215 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2221 if (!(m_mode
& wxLC_REPORT
))
2223 int index
= m_lines
.Index(*m_current
);
2224 if (index
!= wxNOT_FOUND
)
2226 index
-= m_visibleLines
;
2227 if (index
< 0) index
= 0;
2228 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2235 if (!(m_mode
& wxLC_REPORT
))
2237 int index
= m_lines
.Index(*m_current
);
2238 if (index
!= wxNOT_FOUND
)
2240 index
+= m_visibleLines
;
2241 if ((size_t)index
>= m_lines
.GetCount())
2242 index
= m_lines
.GetCount()-1;
2243 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2250 if (m_mode
& wxLC_SINGLE_SEL
)
2252 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2253 le
.SetEventObject( GetParent() );
2254 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2255 m_current
->GetItem( 0, le
.m_item
);
2256 GetParent()->GetEventHandler()->ProcessEvent( le
);
2260 m_current
->ReverseHilight();
2261 RefreshLine( m_current
);
2267 if (!(m_mode
& wxLC_SINGLE_SEL
))
2269 wxListLineData
*oldCurrent
= m_current
;
2270 m_current
->ReverseHilight();
2271 int index
= m_lines
.Index( *m_current
) + 1;
2272 if ( (size_t)index
< m_lines
.GetCount() )
2273 m_current
= &m_lines
[index
];
2274 RefreshLine( oldCurrent
);
2275 RefreshLine( m_current
);
2276 UnfocusLine( oldCurrent
);
2277 FocusLine( m_current
);
2285 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2286 le
.SetEventObject( GetParent() );
2287 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2288 m_current
->GetItem( 0, le
.m_item
);
2289 GetParent()->GetEventHandler()->ProcessEvent( le
);
2302 extern wxWindow
*g_focusWindow
;
2305 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2308 RefreshLine( m_current
);
2310 if (!GetParent()) return;
2313 g_focusWindow
= GetParent();
2316 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2317 event
.SetEventObject( GetParent() );
2318 GetParent()->GetEventHandler()->ProcessEvent( event
);
2321 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2324 RefreshLine( m_current
);
2327 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2330 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2336 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2338 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2340 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2343 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2345 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2347 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2349 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2351 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2353 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2358 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2360 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2362 m_normal_image_list
->GetSize( index
, width
, height
);
2365 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2367 m_small_image_list
->GetSize( index
, width
, height
);
2370 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2372 m_small_image_list
->GetSize( index
, width
, height
);
2375 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2377 m_small_image_list
->GetSize( index
, width
, height
);
2384 int wxListMainWindow::GetTextLength( wxString
&s
)
2386 wxClientDC
dc( this );
2389 dc
.GetTextExtent( s
, &lw
, &lh
);
2393 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2395 int i
= m_lines
.Index(*line
);
2396 if (i
== wxNOT_FOUND
) return -1;
2400 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2404 // calc the spacing from the icon size
2407 if ((imageList
) && (imageList
->GetImageCount()) )
2409 imageList
->GetSize(0, width
, height
);
2412 if (which
== wxIMAGE_LIST_NORMAL
)
2414 m_normal_image_list
= imageList
;
2415 m_normal_spacing
= width
+ 8;
2418 if (which
== wxIMAGE_LIST_SMALL
)
2420 m_small_image_list
= imageList
;
2421 m_small_spacing
= width
+ 14;
2425 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2430 m_small_spacing
= spacing
;
2434 m_normal_spacing
= spacing
;
2438 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2440 return isSmall
? m_small_spacing
: m_normal_spacing
;
2443 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2446 wxNode
*node
= m_columns
.Nth( col
);
2449 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2450 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2451 column
->SetItem( item
);
2454 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2456 headerWin
->m_dirty
= TRUE
;
2459 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2461 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2462 _T("SetColumnWidth() can only be called in report mode.") );
2466 wxNode
*node
= (wxNode
*) NULL
;
2468 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2470 // TODO do use the header
2473 else if (width
== wxLIST_AUTOSIZE
)
2475 wxClientDC
dc(this);
2476 dc
.SetFont( GetFont() );
2479 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2481 wxListLineData
*line
= &m_lines
[i
];
2482 wxNode
*n
= line
->m_items
.Nth( col
);
2485 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2486 int current
= 0, ix
= 0, iy
= 0;
2487 wxCoord lx
= 0, ly
= 0;
2488 if (item
->HasImage())
2490 GetImageSize( item
->GetImage(), ix
, iy
);
2493 if (item
->HasText())
2496 item
->GetText( str
);
2497 dc
.GetTextExtent( str
, &lx
, &ly
);
2500 if (current
> max
) max
= current
;
2506 node
= m_columns
.Nth( col
);
2509 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2510 column
->SetWidth( width
);
2513 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2515 wxListLineData
*line
= &m_lines
[i
];
2516 wxNode
*n
= line
->m_items
.Nth( col
);
2519 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2520 item
->SetSize( width
, -1 );
2524 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2526 headerWin
->m_dirty
= TRUE
;
2529 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2531 wxNode
*node
= m_columns
.Nth( col
);
2534 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2535 column
->GetItem( item
);
2547 int wxListMainWindow::GetColumnWidth( int col
)
2549 wxNode
*node
= m_columns
.Nth( col
);
2552 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2553 return column
->GetWidth();
2561 int wxListMainWindow::GetColumnCount()
2563 return m_columns
.Number();
2566 int wxListMainWindow::GetCountPerPage()
2568 return m_visibleLines
;
2571 void wxListMainWindow::SetItem( wxListItem
&item
)
2574 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2576 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2577 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2578 line
->SetItem( item
.m_col
, item
);
2582 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2584 // m_dirty = TRUE; no recalcs needed
2586 wxListLineData
*oldCurrent
= m_current
;
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 UnfocusLine( m_current
);
2595 FocusLine( m_current
);
2596 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2597 RefreshLine( m_current
);
2598 if (oldCurrent
) RefreshLine( oldCurrent
);
2602 if (stateMask
& wxLIST_STATE_SELECTED
)
2604 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2605 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2607 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2609 wxListLineData
*line
= &m_lines
[(size_t)item
];
2610 if (m_mode
& wxLC_SINGLE_SEL
)
2612 UnfocusLine( m_current
);
2614 FocusLine( m_current
);
2615 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2616 RefreshLine( m_current
);
2617 if (oldCurrent
) RefreshLine( oldCurrent
);
2619 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2620 if (on
!= line
->IsHilighted())
2622 line
->Hilight( on
);
2623 RefreshLine( line
);
2629 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2631 int ret
= wxLIST_STATE_DONTCARE
;
2632 if (stateMask
& wxLIST_STATE_FOCUSED
)
2634 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2636 wxListLineData
*line
= &m_lines
[(size_t)item
];
2637 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2640 if (stateMask
& wxLIST_STATE_SELECTED
)
2642 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2644 wxListLineData
*line
= &m_lines
[(size_t)item
];
2645 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2651 void wxListMainWindow::GetItem( wxListItem
&item
)
2653 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2655 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2656 line
->GetItem( item
.m_col
, item
);
2667 int wxListMainWindow::GetItemCount()
2669 return m_lines
.GetCount();
2672 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2674 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2676 m_lines
[(size_t)index
].GetRect( rect
);
2677 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2688 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2691 this->GetItemRect(item
,rect
);
2692 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2696 int wxListMainWindow::GetSelectedItemCount()
2699 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2701 if (m_lines
[i
].IsHilighted()) ret
++;
2706 void wxListMainWindow::SetMode( long mode
)
2713 if (m_mode
& wxLC_REPORT
)
2715 #if wxUSE_GENERIC_LIST_EXTENSIONS
2729 long wxListMainWindow::GetMode() const
2734 void wxListMainWindow::CalculatePositions()
2736 if (m_lines
.IsEmpty()) return;
2738 wxClientDC
dc( this );
2739 dc
.SetFont( GetFont() );
2741 int iconSpacing
= 0;
2742 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2743 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2745 // we take the first line (which also can be an icon or
2746 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2747 // measure the size of the line
2751 int lineSpacing
= 0;
2753 wxListLineData
*line
= &m_lines
[0];
2754 line
->CalculateSize( &dc
, iconSpacing
);
2756 line
->GetSize( dummy
, lineSpacing
);
2759 int clientWidth
= 0;
2760 int clientHeight
= 0;
2762 if (m_mode
& wxLC_REPORT
)
2764 // scroll one line per step
2765 m_yScroll
= lineSpacing
;
2769 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2770 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2771 #if wxUSE_GENERIC_LIST_EXTENSIONS
2772 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2774 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2776 GetClientSize( &clientWidth
, &clientHeight
);
2778 int entireWidth
= 0 ;
2779 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2781 wxListLineData
*line
= &m_lines
[j
];
2782 line
->CalculateSize( &dc
, iconSpacing
);
2783 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2785 for (int i
= 0; i
< GetColumnCount(); i
++)
2787 line
->SetColumnPosition( i
, col_x
);
2788 col_x
+= GetColumnWidth( i
);
2790 entireWidth
= wxMax( entireWidth
, col_x
) ;
2791 #if wxUSE_GENERIC_LIST_EXTENSIONS
2792 line
->SetPosition( &dc
, x
, y
, col_x
);
2794 y
+= lineSpacing
; // one pixel blank line between items
2796 m_visibleLines
= clientHeight
/ lineSpacing
;
2797 #if wxUSE_GENERIC_LIST_EXTENSIONS
2798 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2803 // at first we try without any scrollbar. if the items don't
2804 // fit into the window, we recalculate after subtracting an
2805 // approximated 15 pt for the horizontal scrollbar
2807 GetSize( &clientWidth
, &clientHeight
);
2808 clientHeight
-= 4; // sunken frame
2810 int entireWidth
= 0;
2812 for (int tries
= 0; tries
< 2; tries
++)
2819 int m_currentVisibleLines
= 0;
2820 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2822 m_currentVisibleLines
++;
2823 wxListLineData
*line
= &m_lines
[i
];
2824 line
->CalculateSize( &dc
, iconSpacing
);
2825 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2826 line
->GetSize( lineWidth
, lineHeight
);
2827 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2829 if (m_currentVisibleLines
> m_visibleLines
)
2830 m_visibleLines
= m_currentVisibleLines
;
2831 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2833 m_currentVisibleLines
= 0;
2836 entireWidth
+= maxWidth
+6;
2839 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2840 if ((tries
== 0) && (entireWidth
> clientWidth
))
2842 clientHeight
-= 15; // scrollbar height
2844 m_currentVisibleLines
= 0;
2847 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2851 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2852 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2856 void wxListMainWindow::RealizeChanges()
2860 if (!m_lines
.IsEmpty())
2861 m_current
= &m_lines
[0];
2865 FocusLine( m_current
);
2866 // TODO: MSW doesn't automatically hilight the
2868 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2872 long wxListMainWindow::GetNextItem( long item
,
2873 int WXUNUSED(geometry
),
2877 max
= GetItemCount();
2878 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2879 _T("invalid listctrl index in GetNextItem()") );
2881 // notice that we start with the next item (or the first one if item == -1)
2882 // and this is intentional to allow writing a simple loop to iterate over
2883 // all selected items
2887 // this is not an error because the index was ok initially, just no
2892 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2894 wxListLineData
*line
= &m_lines
[i
];
2895 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2897 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2907 void wxListMainWindow::DeleteItem( long index
)
2910 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2912 wxListLineData
*line
= &m_lines
[(size_t)index
];
2913 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2915 m_lines
.RemoveAt( (size_t)index
);
2919 void wxListMainWindow::DeleteColumn( int col
)
2921 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2922 wxT("attempting to delete inexistent column in wxListView") );
2925 wxNode
*node
= m_columns
.Nth( col
);
2926 if (node
) m_columns
.DeleteNode( node
);
2929 void wxListMainWindow::DeleteAllItems()
2932 m_current
= (wxListLineData
*) NULL
;
2934 // to make the deletion of all items faster, we don't send the
2935 // notifications in this case: this is compatible with wxMSW and
2936 // documented in DeleteAllItems() description
2938 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2939 event
.SetEventObject( GetParent() );
2940 GetParent()->GetEventHandler()->ProcessEvent( event
);
2945 void wxListMainWindow::DeleteEverything()
2952 void wxListMainWindow::EnsureVisible( long index
)
2954 // We have to call this here because the label in
2955 // question might just have been added and no screen
2956 // update taken place.
2957 if (m_dirty
) wxYield();
2959 wxListLineData
*oldCurrent
= m_current
;
2960 m_current
= (wxListLineData
*) NULL
;
2961 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2962 m_current
= &m_lines
[(size_t)index
];
2963 if (m_current
) MoveToFocus();
2964 m_current
= oldCurrent
;
2967 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2971 if (pos
< 0) pos
= 0;
2972 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2974 wxListLineData
*line
= &m_lines
[i
];
2976 line
->GetText( 0, s
);
2977 if (s
== tmp
) return pos
;
2983 long wxListMainWindow::FindItem(long start
, long data
)
2986 if (pos
< 0) pos
= 0;
2987 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2989 wxListLineData
*line
= &m_lines
[i
];
2991 line
->GetItem( 0, item
);
2992 if (item
.m_data
== data
) return pos
;
2998 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3000 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3003 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3005 wxListLineData
*line
= &m_lines
[i
];
3006 long ret
= line
->IsHit( x
, y
);
3007 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3017 void wxListMainWindow::InsertItem( wxListItem
&item
)
3021 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3022 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3023 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3024 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3026 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3028 if (m_mode
& wxLC_REPORT
)
3030 line
->InitItems( GetColumnCount() );
3031 item
.m_width
= GetColumnWidth( 0 )-3;
3035 line
->InitItems( 1 );
3038 line
->SetItem( 0, item
);
3039 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3041 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3045 m_lines
.Add( line
);
3046 item
.m_itemId
= m_lines
.GetCount()-1;
3050 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3053 if (m_mode
& wxLC_REPORT
)
3055 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3056 wxListHeaderData
*column
= new wxListHeaderData( item
);
3057 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3059 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3061 m_columns
.Insert( node
, column
);
3065 m_columns
.Append( column
);
3070 wxListCtrlCompare list_ctrl_compare_func_2
;
3071 long list_ctrl_compare_data
;
3073 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3075 wxListLineData
*line1
= *arg1
;
3076 wxListLineData
*line2
= *arg2
;
3078 line1
->GetItem( 0, item
);
3079 long data1
= item
.m_data
;
3080 line2
->GetItem( 0, item
);
3081 long data2
= item
.m_data
;
3082 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3085 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3087 list_ctrl_compare_func_2
= fn
;
3088 list_ctrl_compare_data
= data
;
3089 m_lines
.Sort( list_ctrl_compare_func_1
);
3093 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3095 wxScrolledWindow::OnScroll( event
) ;
3096 #if wxUSE_GENERIC_LIST_EXTENSIONS
3098 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3100 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3103 lc
->m_headerWin
->Refresh() ;
3105 lc
->m_headerWin
->MacUpdateImmediately() ;
3112 // -------------------------------------------------------------------------------------
3114 // -------------------------------------------------------------------------------------
3116 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3118 wxListItem::wxListItem()
3127 m_format
= wxLIST_FORMAT_CENTRE
;
3133 void wxListItem::Clear()
3142 m_format
= wxLIST_FORMAT_CENTRE
;
3144 m_text
= wxEmptyString
;
3146 if (m_attr
) delete m_attr
;
3150 void wxListItem::ClearAttributes()
3152 if (m_attr
) delete m_attr
;
3156 // -------------------------------------------------------------------------------------
3158 // -------------------------------------------------------------------------------------
3160 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3162 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3163 wxNotifyEvent( commandType
, id
)
3169 m_cancelled
= FALSE
;
3174 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3176 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3178 wxNotifyEvent::CopyObject(object_dest
);
3180 obj
->m_code
= m_code
;
3181 obj
->m_itemIndex
= m_itemIndex
;
3182 obj
->m_oldItemIndex
= m_oldItemIndex
;
3184 obj
->m_cancelled
= m_cancelled
;
3185 obj
->m_pointDrag
= m_pointDrag
;
3186 obj
->m_item
.m_mask
= m_item
.m_mask
;
3187 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3188 obj
->m_item
.m_col
= m_item
.m_col
;
3189 obj
->m_item
.m_state
= m_item
.m_state
;
3190 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3191 obj
->m_item
.m_text
= m_item
.m_text
;
3192 obj
->m_item
.m_image
= m_item
.m_image
;
3193 obj
->m_item
.m_data
= m_item
.m_data
;
3194 obj
->m_item
.m_format
= m_item
.m_format
;
3195 obj
->m_item
.m_width
= m_item
.m_width
;
3197 if ( m_item
.HasAttributes() )
3199 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3203 // -------------------------------------------------------------------------------------
3205 // -------------------------------------------------------------------------------------
3207 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3209 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3210 EVT_SIZE (wxListCtrl::OnSize
)
3211 EVT_IDLE (wxListCtrl::OnIdle
)
3214 wxListCtrl::wxListCtrl()
3216 m_imageListNormal
= (wxImageList
*) NULL
;
3217 m_imageListSmall
= (wxImageList
*) NULL
;
3218 m_imageListState
= (wxImageList
*) NULL
;
3219 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3220 m_mainWin
= (wxListMainWindow
*) NULL
;
3221 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3224 wxListCtrl::~wxListCtrl()
3226 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3227 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3228 if (m_ownsImageListState
) delete m_imageListState
;
3231 bool wxListCtrl::Create(wxWindow
*parent
,
3236 const wxValidator
&validator
,
3237 const wxString
&name
)
3239 m_imageListNormal
= (wxImageList
*) NULL
;
3240 m_imageListSmall
= (wxImageList
*) NULL
;
3241 m_imageListState
= (wxImageList
*) NULL
;
3242 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3243 m_mainWin
= (wxListMainWindow
*) NULL
;
3244 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3246 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3248 style
= style
| wxLC_LIST
;
3251 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3254 if (style
& wxSUNKEN_BORDER
)
3255 style
-= wxSUNKEN_BORDER
;
3257 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3259 if (HasFlag(wxLC_REPORT
))
3261 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3262 if (HasFlag(wxLC_NO_HEADER
))
3263 m_headerWin
->Show( FALSE
);
3267 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3273 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3275 /* handled in OnIdle */
3277 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3280 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3282 long flag
= GetWindowStyle();
3286 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3287 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3288 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3297 if (flag
& style
) flag
-= style
;
3300 SetWindowStyleFlag( flag
);
3303 void wxListCtrl::SetWindowStyleFlag( long flag
)
3307 m_mainWin
->DeleteEverything();
3311 GetClientSize( &width
, &height
);
3313 m_mainWin
->SetMode( flag
);
3315 if (flag
& wxLC_REPORT
)
3317 if (!HasFlag(wxLC_REPORT
))
3321 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3322 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3323 if (HasFlag(wxLC_NO_HEADER
))
3324 m_headerWin
->Show( FALSE
);
3328 if (flag
& wxLC_NO_HEADER
)
3329 m_headerWin
->Show( FALSE
);
3331 m_headerWin
->Show( TRUE
);
3337 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3339 m_headerWin
->Show( FALSE
);
3344 wxWindow::SetWindowStyleFlag( flag
);
3347 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3349 m_mainWin
->GetColumn( col
, item
);
3353 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3355 m_mainWin
->SetColumn( col
, item
);
3359 int wxListCtrl::GetColumnWidth( int col
) const
3361 return m_mainWin
->GetColumnWidth( col
);
3364 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3366 m_mainWin
->SetColumnWidth( col
, width
);
3370 int wxListCtrl::GetCountPerPage() const
3372 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3375 bool wxListCtrl::GetItem( wxListItem
&info
) const
3377 m_mainWin
->GetItem( info
);
3381 bool wxListCtrl::SetItem( wxListItem
&info
)
3383 m_mainWin
->SetItem( info
);
3387 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3390 info
.m_text
= label
;
3391 info
.m_mask
= wxLIST_MASK_TEXT
;
3392 info
.m_itemId
= index
;
3396 info
.m_image
= imageId
;
3397 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3399 m_mainWin
->SetItem(info
);
3403 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3405 return m_mainWin
->GetItemState( item
, stateMask
);
3408 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3410 m_mainWin
->SetItemState( item
, state
, stateMask
);
3414 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3417 info
.m_image
= image
;
3418 info
.m_mask
= wxLIST_MASK_IMAGE
;
3419 info
.m_itemId
= item
;
3420 m_mainWin
->SetItem( info
);
3424 wxString
wxListCtrl::GetItemText( long item
) const
3427 info
.m_itemId
= item
;
3428 m_mainWin
->GetItem( info
);
3432 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3435 info
.m_mask
= wxLIST_MASK_TEXT
;
3436 info
.m_itemId
= item
;
3438 m_mainWin
->SetItem( info
);
3441 long wxListCtrl::GetItemData( long item
) const
3444 info
.m_itemId
= item
;
3445 m_mainWin
->GetItem( info
);
3449 bool wxListCtrl::SetItemData( long item
, long data
)
3452 info
.m_mask
= wxLIST_MASK_DATA
;
3453 info
.m_itemId
= item
;
3455 m_mainWin
->SetItem( info
);
3459 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3461 m_mainWin
->GetItemRect( item
, rect
);
3465 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3467 m_mainWin
->GetItemPosition( item
, pos
);
3471 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3476 int wxListCtrl::GetItemCount() const
3478 return m_mainWin
->GetItemCount();
3481 int wxListCtrl::GetColumnCount() const
3483 return m_mainWin
->GetColumnCount();
3486 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3488 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3491 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3493 return m_mainWin
->GetItemSpacing( isSmall
);
3496 int wxListCtrl::GetSelectedItemCount() const
3498 return m_mainWin
->GetSelectedItemCount();
3501 wxColour
wxListCtrl::GetTextColour() const
3503 return GetForegroundColour();
3506 void wxListCtrl::SetTextColour(const wxColour
& col
)
3508 SetForegroundColour(col
);
3511 long wxListCtrl::GetTopItem() const
3516 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3518 return m_mainWin
->GetNextItem( item
, geom
, state
);
3521 wxImageList
*wxListCtrl::GetImageList(int which
) const
3523 if (which
== wxIMAGE_LIST_NORMAL
)
3525 return m_imageListNormal
;
3527 else if (which
== wxIMAGE_LIST_SMALL
)
3529 return m_imageListSmall
;
3531 else if (which
== wxIMAGE_LIST_STATE
)
3533 return m_imageListState
;
3535 return (wxImageList
*) NULL
;
3538 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3540 if ( which
== wxIMAGE_LIST_NORMAL
)
3542 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3543 m_imageListNormal
= imageList
;
3544 m_ownsImageListNormal
= FALSE
;
3546 else if ( which
== wxIMAGE_LIST_SMALL
)
3548 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3549 m_imageListSmall
= imageList
;
3550 m_ownsImageListSmall
= FALSE
;
3552 else if ( which
== wxIMAGE_LIST_STATE
)
3554 if (m_ownsImageListState
) delete m_imageListState
;
3555 m_imageListState
= imageList
;
3556 m_ownsImageListState
= FALSE
;
3559 m_mainWin
->SetImageList( imageList
, which
);
3562 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3564 SetImageList(imageList
, which
);
3565 if ( which
== wxIMAGE_LIST_NORMAL
)
3566 m_ownsImageListNormal
= TRUE
;
3567 else if ( which
== wxIMAGE_LIST_SMALL
)
3568 m_ownsImageListSmall
= TRUE
;
3569 else if ( which
== wxIMAGE_LIST_STATE
)
3570 m_ownsImageListState
= TRUE
;
3573 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3578 bool wxListCtrl::DeleteItem( long item
)
3580 m_mainWin
->DeleteItem( item
);
3584 bool wxListCtrl::DeleteAllItems()
3586 m_mainWin
->DeleteAllItems();
3590 bool wxListCtrl::DeleteAllColumns()
3592 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3598 void wxListCtrl::ClearAll()
3600 m_mainWin
->DeleteEverything();
3603 bool wxListCtrl::DeleteColumn( int col
)
3605 m_mainWin
->DeleteColumn( col
);
3609 void wxListCtrl::Edit( long item
)
3611 m_mainWin
->Edit( item
);
3614 bool wxListCtrl::EnsureVisible( long item
)
3616 m_mainWin
->EnsureVisible( item
);
3620 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3622 return m_mainWin
->FindItem( start
, str
, partial
);
3625 long wxListCtrl::FindItem( long start
, long data
)
3627 return m_mainWin
->FindItem( start
, data
);
3630 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3631 int WXUNUSED(direction
))
3636 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3638 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3641 long wxListCtrl::InsertItem( wxListItem
& info
)
3643 m_mainWin
->InsertItem( info
);
3644 return info
.m_itemId
;
3647 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3650 info
.m_text
= label
;
3651 info
.m_mask
= wxLIST_MASK_TEXT
;
3652 info
.m_itemId
= index
;
3653 return InsertItem( info
);
3656 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3659 info
.m_mask
= wxLIST_MASK_IMAGE
;
3660 info
.m_image
= imageIndex
;
3661 info
.m_itemId
= index
;
3662 return InsertItem( info
);
3665 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3668 info
.m_text
= label
;
3669 info
.m_image
= imageIndex
;
3670 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3671 info
.m_itemId
= index
;
3672 return InsertItem( info
);
3675 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3677 wxASSERT( m_headerWin
);
3678 m_mainWin
->InsertColumn( col
, item
);
3679 m_headerWin
->Refresh();
3684 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3685 int format
, int width
)
3688 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3689 item
.m_text
= heading
;
3692 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3693 item
.m_width
= width
;
3695 item
.m_format
= format
;
3697 return InsertColumn( col
, item
);
3700 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3706 // fn is a function which takes 3 long arguments: item1, item2, data.
3707 // item1 is the long data associated with a first item (NOT the index).
3708 // item2 is the long data associated with a second item (NOT the index).
3709 // data is the same value as passed to SortItems.
3710 // The return value is a negative number if the first item should precede the second
3711 // item, a positive number of the second item should precede the first,
3712 // or zero if the two items are equivalent.
3713 // data is arbitrary data to be passed to the sort function.
3715 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3717 m_mainWin
->SortItems( fn
, data
);
3721 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3723 if (!m_mainWin
->m_dirty
) return;
3727 GetClientSize( &cw
, &ch
);
3734 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3736 m_headerWin
->GetPosition( &x
, &y
);
3737 m_headerWin
->GetSize( &w
, &h
);
3738 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3739 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3741 m_mainWin
->GetPosition( &x
, &y
);
3742 m_mainWin
->GetSize( &w
, &h
);
3743 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3744 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3748 m_mainWin
->GetPosition( &x
, &y
);
3749 m_mainWin
->GetSize( &w
, &h
);
3750 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3751 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3754 m_mainWin
->CalculatePositions();
3755 m_mainWin
->RealizeChanges();
3756 m_mainWin
->m_dirty
= FALSE
;
3757 m_mainWin
->Refresh();
3759 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3761 m_headerWin
->m_dirty
= FALSE
;
3762 m_headerWin
->Refresh();
3766 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3770 m_mainWin
->SetBackgroundColour( colour
);
3771 m_mainWin
->m_dirty
= TRUE
;
3777 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3779 if ( !wxWindow::SetForegroundColour( colour
) )
3784 m_mainWin
->SetForegroundColour( colour
);
3785 m_mainWin
->m_dirty
= TRUE
;
3790 m_headerWin
->SetForegroundColour( colour
);
3796 bool wxListCtrl::SetFont( const wxFont
&font
)
3798 if ( !wxWindow::SetFont( font
) )
3803 m_mainWin
->SetFont( font
);
3804 m_mainWin
->m_dirty
= TRUE
;
3809 m_headerWin
->SetFont( font
);
3815 #if wxUSE_DRAG_AND_DROP
3817 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3819 m_mainWin
->SetDropTarget( dropTarget
);
3822 wxDropTarget
*wxListCtrl::GetDropTarget() const
3824 return m_mainWin
->GetDropTarget();
3827 #endif // wxUSE_DRAG_AND_DROP
3829 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3831 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3834 wxColour
wxListCtrl::GetBackgroundColour() const
3836 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3839 wxColour
wxListCtrl::GetForegroundColour() const
3841 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3844 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3846 return m_mainWin
->PopupMenu( menu
, x
, y
);
3849 void wxListCtrl::SetFocus()
3851 /* The test in window.cpp fails as we are a composite
3852 window, so it checks against "this", but not m_mainWin. */
3853 if ( FindFocus() != this )
3854 m_mainWin
->SetFocus();