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
, wxEventType command
);
320 void FocusLine( wxListLineData
*line
);
321 void UnfocusLine( wxListLineData
*line
);
322 void SelectLine( wxListLineData
*line
);
323 void DeselectLine( wxListLineData
*line
);
324 void DeleteLine( wxListLineData
*line
);
326 void EditLabel( long item
);
327 void Edit( long item
) { EditLabel(item
); } // deprecated
328 void OnRenameTimer();
329 void OnRenameAccept();
331 void OnMouse( wxMouseEvent
&event
);
333 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
334 void OnChar( wxKeyEvent
&event
);
335 void OnKeyDown( wxKeyEvent
&event
);
336 void OnSetFocus( wxFocusEvent
&event
);
337 void OnKillFocus( wxFocusEvent
&event
);
338 void OnSize( wxSizeEvent
&event
);
339 void OnScroll(wxScrollWinEvent
& event
) ;
341 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
342 void GetImageSize( int index
, int &width
, int &height
);
343 int GetIndexOfLine( const wxListLineData
*line
);
344 int GetTextLength( wxString
&s
); // should be const
346 void SetImageList( wxImageList
*imageList
, int which
);
347 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
348 int GetItemSpacing( bool isSmall
= FALSE
);
349 void SetColumn( int col
, wxListItem
&item
);
350 void SetColumnWidth( int col
, int width
);
351 void GetColumn( int col
, wxListItem
&item
);
352 int GetColumnWidth( int vol
);
353 int GetColumnCount();
354 int GetCountPerPage();
355 void SetItem( wxListItem
&item
);
356 void GetItem( wxListItem
&item
);
357 void SetItemState( long item
, long state
, long stateMask
);
358 int GetItemState( long item
, long stateMask
);
360 void GetItemRect( long index
, wxRect
&rect
);
361 bool GetItemPosition( long item
, wxPoint
& pos
);
362 int GetSelectedItemCount();
363 void SetMode( long mode
);
364 long GetMode() const;
365 void CalculatePositions();
366 void RealizeChanges();
367 long GetNextItem( long item
, int geometry
, int state
);
368 void DeleteItem( long index
);
369 void DeleteAllItems();
370 void DeleteColumn( int col
);
371 void DeleteEverything();
372 void EnsureVisible( long index
);
373 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
374 long FindItem( long start
, long data
);
375 long HitTest( int x
, int y
, int &flags
);
376 void InsertItem( wxListItem
&item
);
377 // void AddItem( wxListItem &item );
378 void InsertColumn( long col
, wxListItem
&item
);
379 // void AddColumn( wxListItem &item );
380 void SortItems( wxListCtrlCompare fn
, long data
);
383 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
384 DECLARE_EVENT_TABLE()
387 // ============================================================================
389 // ============================================================================
391 //-----------------------------------------------------------------------------
393 //-----------------------------------------------------------------------------
395 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
397 wxListItemData::wxListItemData()
408 wxListItemData::wxListItemData( const wxListItem
&info
)
417 void wxListItemData::SetItem( const wxListItem
&info
)
419 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
420 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
421 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
423 if ( info
.HasAttributes() )
426 *m_attr
= *info
.GetAttributes();
428 m_attr
= new wxListItemAttr(*info
.GetAttributes());
433 m_width
= info
.m_width
;
437 void wxListItemData::SetText( const wxString
&s
)
442 void wxListItemData::SetImage( int image
)
447 void wxListItemData::SetData( long data
)
452 void wxListItemData::SetPosition( int x
, int y
)
458 void wxListItemData::SetSize( int width
, int height
)
460 if (width
!= -1) m_width
= width
;
461 if (height
!= -1) m_height
= height
;
464 bool wxListItemData::HasImage() const
466 return (m_image
>= 0);
469 bool wxListItemData::HasText() const
471 return (!m_text
.IsNull());
474 bool wxListItemData::IsHit( int x
, int y
) const
476 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
479 void wxListItemData::GetText( wxString
&s
)
484 int wxListItemData::GetX() const
489 int wxListItemData::GetY() const
494 int wxListItemData::GetWidth() const
499 int wxListItemData::GetHeight() const
504 int wxListItemData::GetImage() const
509 void wxListItemData::GetItem( wxListItem
&info
) const
511 info
.m_text
= m_text
;
512 info
.m_image
= m_image
;
513 info
.m_data
= m_data
;
517 if ( m_attr
->HasTextColour() )
518 info
.SetTextColour(m_attr
->GetTextColour());
519 if ( m_attr
->HasBackgroundColour() )
520 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
521 if ( m_attr
->HasFont() )
522 info
.SetFont(m_attr
->GetFont());
526 //-----------------------------------------------------------------------------
528 //-----------------------------------------------------------------------------
530 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
532 wxListHeaderData::wxListHeaderData()
543 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
551 void wxListHeaderData::SetItem( const wxListItem
&item
)
553 m_mask
= item
.m_mask
;
554 m_text
= item
.m_text
;
555 m_image
= item
.m_image
;
556 m_format
= item
.m_format
;
557 m_width
= item
.m_width
;
558 if (m_width
< 0) m_width
= 80;
559 if (m_width
< 6) m_width
= 6;
562 void wxListHeaderData::SetPosition( int x
, int y
)
568 void wxListHeaderData::SetHeight( int h
)
573 void wxListHeaderData::SetWidth( int w
)
576 if (m_width
< 0) m_width
= 80;
577 if (m_width
< 6) m_width
= 6;
580 void wxListHeaderData::SetFormat( int format
)
585 bool wxListHeaderData::HasImage() const
587 return (m_image
!= 0);
590 bool wxListHeaderData::HasText() const
592 return (m_text
.Length() > 0);
595 bool wxListHeaderData::IsHit( int x
, int y
) const
597 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
600 void wxListHeaderData::GetItem( wxListItem
&item
)
602 item
.m_mask
= m_mask
;
603 item
.m_text
= m_text
;
604 item
.m_image
= m_image
;
605 item
.m_format
= m_format
;
606 item
.m_width
= m_width
;
609 void wxListHeaderData::GetText( wxString
&s
)
614 int wxListHeaderData::GetImage() const
619 int wxListHeaderData::GetWidth() const
624 int wxListHeaderData::GetFormat() const
629 //-----------------------------------------------------------------------------
631 //-----------------------------------------------------------------------------
633 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
635 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
640 m_hilightBrush
= hilightBrush
;
641 m_items
.DeleteContents( TRUE
);
645 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
652 m_bound_all
.width
= m_spacing
;
653 wxNode
*node
= m_items
.First();
656 wxListItemData
*item
= (wxListItemData
*)node
->Data();
657 wxString s
= item
->GetText();
658 if (s
.IsEmpty()) s
= wxT("H");
660 dc
->GetTextExtent( s
, &lw
, &lh
);
661 if (lh
< 15) lh
= 15;
665 m_bound_all
.height
= m_spacing
+lh
;
666 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
667 m_bound_label
.width
= lw
;
668 m_bound_label
.height
= lh
;
670 if (item
->HasImage())
674 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
675 m_bound_icon
.width
= w
+ 8;
676 m_bound_icon
.height
= h
+ 8;
678 if ( m_bound_icon
.width
> m_bound_all
.width
)
679 m_bound_all
.width
= m_bound_icon
.width
;
680 if ( h
+ lh
> m_bound_all
.height
- 4 )
681 m_bound_all
.height
= h
+ lh
+ 4;
684 if (!item
->HasText())
686 m_bound_hilight
.width
= m_bound_icon
.width
;
687 m_bound_hilight
.height
= m_bound_icon
.height
;
691 m_bound_hilight
.width
= m_bound_label
.width
;
692 m_bound_hilight
.height
= m_bound_label
.height
;
699 wxNode
*node
= m_items
.First();
702 wxListItemData
*item
= (wxListItemData
*)node
->Data();
704 wxString s
= item
->GetText();
705 if (s
.IsEmpty()) s
= wxT("H");
707 dc
->GetTextExtent( s
, &lw
, &lh
);
708 if (lh
< 15) lh
= 15;
711 m_bound_label
.width
= lw
;
712 m_bound_label
.height
= lh
;
714 m_bound_all
.width
= lw
;
715 m_bound_all
.height
= lh
;
717 if (item
->HasImage())
721 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
722 m_bound_icon
.width
= w
;
723 m_bound_icon
.height
= h
;
725 m_bound_all
.width
+= 4 + w
;
726 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
729 m_bound_hilight
.width
= m_bound_all
.width
;
730 m_bound_hilight
.height
= m_bound_all
.height
;
736 m_bound_all
.width
= 0;
737 m_bound_all
.height
= 0;
738 wxNode
*node
= m_items
.First();
741 wxListItemData
*item
= (wxListItemData
*)node
->Data();
742 if (item
->HasImage())
746 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
747 m_bound_icon
.width
= w
;
748 m_bound_icon
.height
= h
;
752 m_bound_icon
.width
= 0;
753 m_bound_icon
.height
= 0;
758 wxListItemData
*item
= (wxListItemData
*)node
->Data();
759 wxString s
= item
->GetText();
760 if (s
.IsEmpty()) s
= wxT("H");
762 dc
->GetTextExtent( s
, &lw
, &lh
);
763 if (lh
< 15) lh
= 15;
767 item
->SetSize( item
->GetWidth(), lh
);
768 m_bound_all
.width
+= lw
;
769 m_bound_all
.height
= lh
;
772 m_bound_label
.width
= m_bound_all
.width
;
773 m_bound_label
.height
= m_bound_all
.height
;
779 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
780 int x
, int y
, int window_width
)
788 wxNode
*node
= m_items
.First();
791 wxListItemData
*item
= (wxListItemData
*)node
->Data();
792 if (item
->HasImage())
794 m_bound_icon
.x
= m_bound_all
.x
+ 4
795 + (m_spacing
- m_bound_icon
.width
)/2;
796 m_bound_icon
.y
= m_bound_all
.y
+ 4;
800 if (m_bound_all
.width
> m_spacing
)
801 m_bound_label
.x
= m_bound_all
.x
+ 2;
803 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
804 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
805 m_bound_hilight
.x
= m_bound_label
.x
- 2;
806 m_bound_hilight
.y
= m_bound_label
.y
- 2;
810 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
811 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
818 m_bound_hilight
.x
= m_bound_all
.x
;
819 m_bound_hilight
.y
= m_bound_all
.y
;
820 m_bound_label
.y
= m_bound_all
.y
+ 2;
821 wxNode
*node
= m_items
.First();
824 wxListItemData
*item
= (wxListItemData
*)node
->Data();
825 if (item
->HasImage())
827 m_bound_icon
.x
= m_bound_all
.x
+ 2;
828 m_bound_icon
.y
= m_bound_all
.y
+ 2;
829 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
833 m_bound_label
.x
= m_bound_all
.x
+ 2;
841 m_bound_all
.width
= window_width
;
842 AssignRect( m_bound_hilight
, m_bound_all
);
843 m_bound_label
.x
= m_bound_all
.x
+ 2;
844 m_bound_label
.y
= m_bound_all
.y
+ 2;
845 wxNode
*node
= m_items
.First();
848 wxListItemData
*item
= (wxListItemData
*)node
->Data();
849 if (item
->HasImage())
851 m_bound_icon
.x
= m_bound_all
.x
+ 2;
852 m_bound_icon
.y
= m_bound_all
.y
+ 2;
853 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
861 void wxListLineData::SetColumnPosition( int index
, int x
)
863 wxNode
*node
= m_items
.Nth( (size_t)index
);
866 wxListItemData
*item
= (wxListItemData
*)node
->Data();
867 item
->SetPosition( x
, m_bound_all
.y
+1 );
871 void wxListLineData::GetSize( int &width
, int &height
)
873 width
= m_bound_all
.width
;
874 height
= m_bound_all
.height
;
877 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
881 width
= m_bound_all
.width
;
882 height
= m_bound_all
.height
;
885 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
889 width
= m_bound_label
.width
;
890 height
= m_bound_label
.height
;
893 void wxListLineData::GetRect( wxRect
&rect
)
895 AssignRect( rect
, m_bound_all
);
898 long wxListLineData::IsHit( int x
, int y
)
900 wxNode
*node
= m_items
.First();
903 wxListItemData
*item
= (wxListItemData
*)node
->Data();
904 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
905 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
906 // if (!(item->HasImage() || item->HasText())) return 0;
908 // if there is no icon or text = empty
909 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
913 void wxListLineData::InitItems( int num
)
915 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
918 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
920 wxNode
*node
= m_items
.Nth( index
);
923 wxListItemData
*item
= (wxListItemData
*)node
->Data();
924 item
->SetItem( info
);
928 void wxListLineData::GetItem( int index
, wxListItem
&info
)
931 wxNode
*node
= m_items
.Nth( i
);
934 wxListItemData
*item
= (wxListItemData
*)node
->Data();
935 item
->GetItem( info
);
939 void wxListLineData::GetText( int index
, wxString
&s
)
942 wxNode
*node
= m_items
.Nth( i
);
946 wxListItemData
*item
= (wxListItemData
*)node
->Data();
951 void wxListLineData::SetText( int index
, const wxString s
)
954 wxNode
*node
= m_items
.Nth( i
);
957 wxListItemData
*item
= (wxListItemData
*)node
->Data();
962 int wxListLineData::GetImage( int index
)
965 wxNode
*node
= m_items
.Nth( i
);
968 wxListItemData
*item
= (wxListItemData
*)node
->Data();
969 return item
->GetImage();
974 void wxListLineData::SetAttributes(wxDC
*dc
,
975 const wxListItemAttr
*attr
,
976 const wxColour
& colText
,
980 // don't use foregroud colour for drawing highlighted items - this might
981 // make them completely invisible (and there is no way to do bit
982 // arithmetics on wxColour, unfortunately)
983 if ( !hilight
&& attr
&& attr
->HasTextColour() )
985 dc
->SetTextForeground(attr
->GetTextColour());
989 dc
->SetTextForeground(colText
);
992 if ( attr
&& attr
->HasFont() )
994 dc
->SetFont(attr
->GetFont());
1002 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1006 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1007 wxCoord dev_w
= m_bound_all
.width
;
1008 wxCoord dev_h
= m_bound_all
.height
;
1010 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1013 wxWindow
*listctrl
= m_owner
->GetParent();
1015 // default foreground colour
1019 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1023 colText
= listctrl
->GetForegroundColour();
1027 wxFont font
= listctrl
->GetFont();
1029 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1030 // using SetAttributes() inside the loop), it will be trivial to
1031 // customize the subitems (in report mode) too.
1032 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1033 wxListItemAttr
*attr
= item
->GetAttributes();
1034 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1036 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1037 if ( paintBG
|| hasBgCol
)
1041 dc
->SetBrush( * m_hilightBrush
);
1046 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1048 dc
->SetBrush( * wxWHITE_BRUSH
);
1051 dc
->SetPen( * wxTRANSPARENT_PEN
);
1052 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1053 m_bound_hilight
.width
, m_bound_hilight
.height
);
1056 if (m_mode
== wxLC_REPORT
)
1058 wxNode
*node
= m_items
.First();
1061 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1062 int x
= item
->GetX();
1063 if (item
->HasImage())
1066 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1067 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1068 x
+= item
->GetX() + 5;
1070 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1071 if (item
->HasText())
1073 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1075 dc
->DestroyClippingRegion();
1076 node
= node
->Next();
1081 wxNode
*node
= m_items
.First();
1084 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1085 if (item
->HasImage())
1087 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1089 if (item
->HasText())
1091 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1097 void wxListLineData::Hilight( bool on
)
1099 if (on
== m_hilighted
) return;
1102 m_owner
->SelectLine( this );
1104 m_owner
->DeselectLine( this );
1107 void wxListLineData::ReverseHilight( void )
1109 m_hilighted
= !m_hilighted
;
1111 m_owner
->SelectLine( this );
1113 m_owner
->DeselectLine( this );
1116 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1120 dc
->SetPen( * wxBLACK_PEN
);
1121 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1122 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1123 m_bound_hilight
.width
, m_bound_hilight
.height
);
1127 void wxListLineData::Draw( wxDC
*dc
)
1129 DoDraw( dc
, m_hilighted
, m_hilighted
);
1132 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1134 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1135 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1138 bool wxListLineData::IsHilighted( void )
1143 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1148 dest
.height
= height
;
1151 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1155 dest
.width
= source
.width
;
1156 dest
.height
= source
.height
;
1159 //-----------------------------------------------------------------------------
1160 // wxListHeaderWindow
1161 //-----------------------------------------------------------------------------
1163 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1165 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1166 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1167 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1168 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1171 wxListHeaderWindow::wxListHeaderWindow( void )
1173 m_owner
= (wxListMainWindow
*) NULL
;
1174 m_currentCursor
= (wxCursor
*) NULL
;
1175 m_resizeCursor
= (wxCursor
*) NULL
;
1176 m_isDragging
= FALSE
;
1179 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1180 const wxPoint
&pos
, const wxSize
&size
,
1181 long style
, const wxString
&name
) :
1182 wxWindow( win
, id
, pos
, size
, style
, name
)
1185 // m_currentCursor = wxSTANDARD_CURSOR;
1186 m_currentCursor
= (wxCursor
*) NULL
;
1187 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1188 m_isDragging
= FALSE
;
1191 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1194 wxListHeaderWindow::~wxListHeaderWindow( void )
1196 delete m_resizeCursor
;
1199 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1202 GtkStateType state
= GTK_STATE_NORMAL
;
1203 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1205 x
= dc
->XLOG2DEV( x
);
1207 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1208 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1210 const int m_corner
= 1;
1212 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1214 dc
->SetPen( *wxBLACK_PEN
);
1215 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1216 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1218 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1221 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1222 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1224 dc
->SetPen( *wxWHITE_PEN
);
1225 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1226 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1227 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1228 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1232 // shift the DC origin to match the position of the main window horz
1233 // scrollbar: this allows us to always use logical coords
1234 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1236 #if wxUSE_GENERIC_LIST_EXTENSIONS
1238 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1241 m_owner
->GetViewStart( &x
, NULL
);
1243 // account for the horz scrollbar offset
1244 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1245 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1248 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1250 wxPaintDC
dc( this );
1256 dc
.SetFont( GetFont() );
1258 // width and height of the entire header window
1260 GetClientSize( &w
, &h
);
1261 #if wxUSE_GENERIC_LIST_EXTENSIONS
1262 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1263 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1265 dc
.SetBackgroundMode(wxTRANSPARENT
);
1267 // do *not* use the listctrl colour for headers - one day we will have a
1268 // function to set it separately
1269 //dc.SetTextForeground( *wxBLACK );
1270 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1272 int x
= 1; // left of the header rect
1273 const int y
= 1; // top
1274 int numColumns
= m_owner
->GetColumnCount();
1276 for (int i
= 0; i
< numColumns
; i
++)
1278 m_owner
->GetColumn( i
, item
);
1279 int wCol
= item
.m_width
;
1280 int cw
= wCol
- 2; // the width of the rect to draw
1282 int xEnd
= x
+ wCol
;
1284 // VZ: no, draw it normally - this is better now as we allow resizing
1285 // of the last column as well
1287 // let the last column occupy all available space
1288 if ( i
== numColumns
- 1 )
1292 dc
.SetPen( *wxWHITE_PEN
);
1294 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1295 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1296 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1297 dc
.DestroyClippingRegion();
1306 void wxListHeaderWindow::DrawCurrent()
1308 int x1
= m_currentX
;
1310 ClientToScreen( &x1
, &y1
);
1312 int x2
= m_currentX
-1;
1314 m_owner
->GetClientSize( NULL
, &y2
);
1315 m_owner
->ClientToScreen( &x2
, &y2
);
1318 dc
.SetLogicalFunction( wxINVERT
);
1319 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1320 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1324 dc
.DrawLine( x1
, y1
, x2
, y2
);
1326 dc
.SetLogicalFunction( wxCOPY
);
1328 dc
.SetPen( wxNullPen
);
1329 dc
.SetBrush( wxNullBrush
);
1332 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1334 // we want to work with logical coords
1335 #if wxUSE_GENERIC_LIST_EXTENSIONS
1337 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1338 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1339 int x
= event
.GetX();
1340 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1341 int y
= event
.GetY();
1345 // we don't draw the line beyond our window, but we allow dragging it
1348 GetClientSize( &w
, NULL
);
1349 #if wxUSE_GENERIC_LIST_EXTENSIONS
1350 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1351 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1354 // erase the line if it was drawn
1355 if ( m_currentX
< w
)
1358 if (event
.ButtonUp())
1361 m_isDragging
= FALSE
;
1363 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1370 m_currentX
= m_minX
+ 7;
1372 // draw in the new location
1373 if ( m_currentX
< w
)
1377 else // not dragging
1380 bool hit_border
= FALSE
;
1382 // end of the current column
1385 // find the column where this event occured
1386 int countCol
= m_owner
->GetColumnCount();
1387 for (int j
= 0; j
< countCol
; j
++)
1389 xpos
+= m_owner
->GetColumnWidth( j
);
1392 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1394 // near the column border
1401 // inside the column
1408 if (event
.LeftDown())
1412 m_isDragging
= TRUE
;
1419 wxWindow
*parent
= GetParent();
1420 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1421 le
.SetEventObject( parent
);
1422 le
.m_col
= m_column
;
1423 parent
->GetEventHandler()->ProcessEvent( le
);
1426 else if (event
.Moving())
1431 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1432 m_currentCursor
= m_resizeCursor
;
1436 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1437 m_currentCursor
= wxSTANDARD_CURSOR
;
1441 SetCursor(*m_currentCursor
);
1446 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1448 m_owner
->SetFocus();
1451 //-----------------------------------------------------------------------------
1452 // wxListRenameTimer (internal)
1453 //-----------------------------------------------------------------------------
1455 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1460 void wxListRenameTimer::Notify()
1462 m_owner
->OnRenameTimer();
1465 //-----------------------------------------------------------------------------
1466 // wxListTextCtrl (internal)
1467 //-----------------------------------------------------------------------------
1469 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1471 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1472 EVT_CHAR (wxListTextCtrl::OnChar
)
1473 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1474 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1477 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1478 const wxWindowID id
,
1481 wxListMainWindow
*owner
,
1482 const wxString
&value
,
1486 const wxValidator
& validator
,
1487 const wxString
&name
)
1488 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1493 (*m_accept
) = FALSE
;
1495 m_startValue
= value
;
1498 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1500 if (event
.m_keyCode
== WXK_RETURN
)
1503 (*m_res
) = GetValue();
1505 if (!wxPendingDelete
.Member(this))
1506 wxPendingDelete
.Append(this);
1508 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1509 m_owner
->OnRenameAccept();
1513 if (event
.m_keyCode
== WXK_ESCAPE
)
1515 (*m_accept
) = FALSE
;
1518 if (!wxPendingDelete
.Member(this))
1519 wxPendingDelete
.Append(this);
1527 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1529 // auto-grow the textctrl:
1530 wxSize parentSize
= m_owner
->GetSize();
1531 wxPoint myPos
= GetPosition();
1532 wxSize mySize
= GetSize();
1534 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1535 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1536 if (mySize
.x
> sx
) sx
= mySize
.x
;
1542 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1544 if (!wxPendingDelete
.Member(this))
1545 wxPendingDelete
.Append(this);
1547 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1548 m_owner
->OnRenameAccept();
1551 //-----------------------------------------------------------------------------
1553 //-----------------------------------------------------------------------------
1555 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1557 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1558 EVT_PAINT (wxListMainWindow::OnPaint
)
1559 EVT_SIZE (wxListMainWindow::OnSize
)
1560 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1561 EVT_CHAR (wxListMainWindow::OnChar
)
1562 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1563 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1564 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1565 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1568 wxListMainWindow::wxListMainWindow()
1571 m_columns
.DeleteContents( TRUE
);
1572 m_current
= (wxListLineData
*) NULL
;
1574 m_hilightBrush
= (wxBrush
*) NULL
;
1578 m_small_image_list
= (wxImageList
*) NULL
;
1579 m_normal_image_list
= (wxImageList
*) NULL
;
1580 m_small_spacing
= 30;
1581 m_normal_spacing
= 40;
1584 m_lastOnSame
= FALSE
;
1585 m_renameTimer
= new wxListRenameTimer( this );
1586 m_isCreated
= FALSE
;
1590 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1593 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1594 const wxPoint
&pos
, const wxSize
&size
,
1595 long style
, const wxString
&name
) :
1596 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1599 m_columns
.DeleteContents( TRUE
);
1600 m_current
= (wxListLineData
*) NULL
;
1603 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1604 m_small_image_list
= (wxImageList
*) NULL
;
1605 m_normal_image_list
= (wxImageList
*) NULL
;
1606 m_small_spacing
= 30;
1607 m_normal_spacing
= 40;
1610 m_isCreated
= FALSE
;
1614 if (m_mode
& wxLC_REPORT
)
1616 #if wxUSE_GENERIC_LIST_EXTENSIONS
1628 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1631 m_lastOnSame
= FALSE
;
1632 m_renameTimer
= new wxListRenameTimer( this );
1633 m_renameAccept
= FALSE
;
1635 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1638 wxListMainWindow::~wxListMainWindow()
1642 if (m_hilightBrush
) delete m_hilightBrush
;
1644 delete m_renameTimer
;
1647 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1649 if (m_dirty
) return;
1657 line
->GetExtent( x
, y
, w
, h
);
1658 CalcScrolledPosition( x
, y
, &x
, &y
);
1659 wxRect
rect( x
, y
, w
, h
);
1660 Refresh( TRUE
, &rect
);
1663 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1665 // Note: a wxPaintDC must be constructed even if no drawing is
1666 // done (a Windows requirement).
1667 wxPaintDC
dc( this );
1670 if (m_dirty
) return;
1672 if (m_lines
.GetCount() == 0) return;
1676 dc
.SetFont( GetFont() );
1678 if (m_mode
& wxLC_REPORT
)
1680 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1682 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1684 wxSize clientSize
= GetClientSize();
1686 int lineSpacing
= 0;
1687 wxListLineData
*line
= &m_lines
[0];
1689 line
->GetSize( dummy
, lineSpacing
);
1692 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1694 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1695 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1697 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1699 m_lines
[i
].Draw( &dc
);
1700 // Draw horizontal rule if required
1701 if (GetWindowStyle() & wxLC_HRULES
)
1702 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1705 // Draw last horizontal rule
1706 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1707 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1709 // Draw vertical rules if required
1710 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1713 wxRect firstItemRect
;
1714 wxRect lastItemRect
;
1715 GetItemRect(0, firstItemRect
);
1716 GetItemRect(GetItemCount() - 1, lastItemRect
);
1717 int x
= firstItemRect
.GetX();
1718 for (col
= 0; col
< GetColumnCount(); col
++)
1720 int colWidth
= GetColumnWidth(col
);
1722 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1728 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1729 m_lines
[i
].Draw( &dc
);
1732 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1737 void wxListMainWindow::HilightAll( bool on
)
1739 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1741 wxListLineData
*line
= &m_lines
[i
];
1742 if (line
->IsHilighted() != on
)
1744 line
->Hilight( on
);
1745 RefreshLine( line
);
1750 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1752 wxListEvent
le( command
, GetParent()->GetId() );
1753 le
.SetEventObject( GetParent() );
1754 le
.m_itemIndex
= GetIndexOfLine( line
);
1755 line
->GetItem( 0, le
.m_item
);
1756 GetParent()->GetEventHandler()->ProcessEvent( le
);
1757 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1760 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1762 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1765 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1767 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1770 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1772 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1775 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1777 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1780 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1782 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1787 void wxListMainWindow::EditLabel( long item
)
1789 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1790 wxT("wrong index in wxListCtrl::Edit()") );
1792 m_currentEdit
= &m_lines
[(size_t)item
];
1794 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1795 le
.SetEventObject( GetParent() );
1796 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1797 m_currentEdit
->GetItem( 0, le
.m_item
);
1798 GetParent()->GetEventHandler()->ProcessEvent( le
);
1800 if (!le
.IsAllowed())
1803 // We have to call this here because the label in
1804 // question might just have been added and no screen
1805 // update taken place.
1806 if (m_dirty
) wxYield();
1809 m_currentEdit
->GetText( 0, s
);
1814 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1816 wxClientDC
dc(this);
1818 x
= dc
.LogicalToDeviceX( x
);
1819 y
= dc
.LogicalToDeviceY( y
);
1821 wxListTextCtrl
*text
= new wxListTextCtrl(
1822 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1826 void wxListMainWindow::OnRenameTimer()
1828 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1830 Edit( m_lines
.Index( *m_current
) );
1833 void wxListMainWindow::OnRenameAccept()
1835 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1836 le
.SetEventObject( GetParent() );
1837 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1838 m_currentEdit
->GetItem( 0, le
.m_item
);
1839 le
.m_item
.m_text
= m_renameRes
;
1840 GetParent()->GetEventHandler()->ProcessEvent( le
);
1842 if (!le
.IsAllowed()) return;
1845 info
.m_mask
= wxLIST_MASK_TEXT
;
1846 info
.m_itemId
= le
.m_itemIndex
;
1847 info
.m_text
= m_renameRes
;
1848 info
.SetTextColour(le
.m_item
.GetTextColour());
1852 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1854 event
.SetEventObject( GetParent() );
1855 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1857 if (!m_current
) return;
1858 if (m_dirty
) return;
1859 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1861 int x
= event
.GetX();
1862 int y
= event
.GetY();
1863 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1865 /* Did we actually hit an item ? */
1867 wxListLineData
*line
= (wxListLineData
*) NULL
;
1868 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1871 hitResult
= line
->IsHit( x
, y
);
1872 if (hitResult
) break;
1873 line
= (wxListLineData
*) NULL
;
1876 if (event
.Dragging())
1878 if (m_dragCount
== 0)
1879 m_dragStart
= wxPoint(x
,y
);
1883 if (m_dragCount
!= 3) return;
1885 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1886 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1888 wxListEvent
le( command
, GetParent()->GetId() );
1889 le
.SetEventObject( GetParent() );
1890 le
.m_pointDrag
= m_dragStart
;
1891 GetParent()->GetEventHandler()->ProcessEvent( le
);
1902 bool forceClick
= FALSE
;
1903 if (event
.ButtonDClick())
1905 m_renameTimer
->Stop();
1906 m_lastOnSame
= FALSE
;
1908 if ( line
== m_lineBeforeLastClicked
)
1912 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1918 // the first click was on another item, so don't interpret this as
1919 // a double click, but as a simple click instead
1924 if (event
.LeftUp() && m_lastOnSame
)
1927 if ((line
== m_current
) &&
1928 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1929 (m_mode
& wxLC_EDIT_LABELS
) )
1931 m_renameTimer
->Start( 100, TRUE
);
1933 m_lastOnSame
= FALSE
;
1937 if (event
.RightDown())
1939 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1943 if (event
.MiddleDown())
1945 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1949 if ( event
.LeftDown() || forceClick
)
1951 m_lineBeforeLastClicked
= m_lineLastClicked
;
1952 m_lineLastClicked
= line
;
1955 wxListLineData
*oldCurrent
= m_current
;
1956 if (m_mode
& wxLC_SINGLE_SEL
)
1959 HilightAll( FALSE
);
1960 m_current
->ReverseHilight();
1961 RefreshLine( m_current
);
1965 if (event
.ControlDown())
1968 m_current
->ReverseHilight();
1969 RefreshLine( m_current
);
1971 else if (event
.ShiftDown())
1977 int numOfCurrent
= -1;
1978 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1980 wxListLineData
*test_line
= &m_lines
[j
];
1982 if (test_line
== oldCurrent
) break;
1987 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1989 wxListLineData
*test_line
= &m_lines
[j
];
1991 if (test_line
== line
) break;
1994 if (numOfLine
< numOfCurrent
)
1997 numOfLine
= numOfCurrent
;
2001 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2003 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2004 test_line
->Hilight(TRUE
);
2005 RefreshLine( test_line
);
2011 HilightAll( FALSE
);
2012 m_current
->ReverseHilight();
2013 RefreshLine( m_current
);
2016 if (m_current
!= oldCurrent
)
2018 RefreshLine( oldCurrent
);
2019 UnfocusLine( oldCurrent
);
2020 FocusLine( m_current
);
2023 // forceClick is only set if the previous click was on another item
2024 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2030 void wxListMainWindow::MoveToFocus()
2032 if (!m_current
) return;
2038 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2042 GetClientSize( &client_w
, &client_h
);
2044 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2045 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2047 if (m_mode
& wxLC_REPORT
)
2049 if (item_y
-5 < view_y
)
2050 Scroll( -1, (item_y
-5)/m_yScroll
);
2051 if (item_y
+item_h
+5 > view_y
+client_h
)
2052 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2056 if (item_x
-view_x
< 5)
2057 Scroll( (item_x
-5)/m_xScroll
, -1 );
2058 if (item_x
+item_w
-5 > view_x
+client_w
)
2059 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2063 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2065 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2066 wxListLineData
*oldCurrent
= m_current
;
2067 m_current
= newCurrent
;
2068 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2069 RefreshLine( m_current
);
2070 RefreshLine( oldCurrent
);
2071 FocusLine( m_current
);
2072 UnfocusLine( oldCurrent
);
2076 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2078 wxWindow
*parent
= GetParent();
2080 /* we propagate the key event up */
2081 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2082 ke
.m_shiftDown
= event
.m_shiftDown
;
2083 ke
.m_controlDown
= event
.m_controlDown
;
2084 ke
.m_altDown
= event
.m_altDown
;
2085 ke
.m_metaDown
= event
.m_metaDown
;
2086 ke
.m_keyCode
= event
.m_keyCode
;
2089 ke
.SetEventObject( parent
);
2090 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2095 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2097 wxWindow
*parent
= GetParent();
2099 /* we send a list_key event up */
2102 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2103 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2104 m_current
->GetItem( 0, le
.m_item
);
2105 le
.m_code
= (int)event
.KeyCode();
2106 le
.SetEventObject( parent
);
2107 parent
->GetEventHandler()->ProcessEvent( le
);
2110 /* we propagate the char event up */
2111 wxKeyEvent
ke( wxEVT_CHAR
);
2112 ke
.m_shiftDown
= event
.m_shiftDown
;
2113 ke
.m_controlDown
= event
.m_controlDown
;
2114 ke
.m_altDown
= event
.m_altDown
;
2115 ke
.m_metaDown
= event
.m_metaDown
;
2116 ke
.m_keyCode
= event
.m_keyCode
;
2119 ke
.SetEventObject( parent
);
2120 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2122 if (event
.KeyCode() == WXK_TAB
)
2124 wxNavigationKeyEvent nevent
;
2125 nevent
.SetWindowChange( event
.ControlDown() );
2126 nevent
.SetDirection( !event
.ShiftDown() );
2127 nevent
.SetEventObject( GetParent()->GetParent() );
2128 nevent
.SetCurrentFocus( m_parent
);
2129 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2132 /* no item -> nothing to do */
2139 switch (event
.KeyCode())
2143 int index
= m_lines
.Index(*m_current
);
2144 if (index
!= wxNOT_FOUND
&& index
> 0)
2145 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2150 int index
= m_lines
.Index(*m_current
);
2151 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2152 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2157 if (!m_lines
.IsEmpty())
2158 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2163 if (!m_lines
.IsEmpty())
2164 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2170 int index
= m_lines
.Index(*m_current
);
2171 if (m_mode
& wxLC_REPORT
)
2173 steps
= m_visibleLines
-1;
2177 steps
= index
% m_visibleLines
;
2179 if (index
!= wxNOT_FOUND
)
2182 if (index
< 0) index
= 0;
2183 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2190 int index
= m_lines
.Index(*m_current
);
2191 if (m_mode
& wxLC_REPORT
)
2193 steps
= m_visibleLines
-1;
2197 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2200 if (index
!= wxNOT_FOUND
)
2203 if ((size_t)index
>= m_lines
.GetCount())
2204 index
= m_lines
.GetCount()-1;
2205 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2211 if (!(m_mode
& wxLC_REPORT
))
2213 int index
= m_lines
.Index(*m_current
);
2214 if (index
!= wxNOT_FOUND
)
2216 index
-= m_visibleLines
;
2217 if (index
< 0) index
= 0;
2218 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2225 if (!(m_mode
& wxLC_REPORT
))
2227 int index
= m_lines
.Index(*m_current
);
2228 if (index
!= wxNOT_FOUND
)
2230 index
+= m_visibleLines
;
2231 if ((size_t)index
>= m_lines
.GetCount())
2232 index
= m_lines
.GetCount()-1;
2233 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2240 if (m_mode
& wxLC_SINGLE_SEL
)
2242 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2243 le
.SetEventObject( GetParent() );
2244 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2245 m_current
->GetItem( 0, le
.m_item
);
2246 GetParent()->GetEventHandler()->ProcessEvent( le
);
2250 m_current
->ReverseHilight();
2251 RefreshLine( m_current
);
2257 if (!(m_mode
& wxLC_SINGLE_SEL
))
2259 wxListLineData
*oldCurrent
= m_current
;
2260 m_current
->ReverseHilight();
2261 int index
= m_lines
.Index( *m_current
) + 1;
2262 if ( (size_t)index
< m_lines
.GetCount() )
2263 m_current
= &m_lines
[index
];
2264 RefreshLine( oldCurrent
);
2265 RefreshLine( m_current
);
2266 UnfocusLine( oldCurrent
);
2267 FocusLine( m_current
);
2275 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2276 le
.SetEventObject( GetParent() );
2277 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2278 m_current
->GetItem( 0, le
.m_item
);
2279 GetParent()->GetEventHandler()->ProcessEvent( le
);
2292 extern wxWindow
*g_focusWindow
;
2295 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2298 RefreshLine( m_current
);
2300 if (!GetParent()) return;
2303 g_focusWindow
= GetParent();
2306 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2307 event
.SetEventObject( GetParent() );
2308 GetParent()->GetEventHandler()->ProcessEvent( event
);
2311 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2314 RefreshLine( m_current
);
2317 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2320 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2326 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2328 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2330 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2333 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2335 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2337 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2339 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2341 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2343 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2348 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2350 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2352 m_normal_image_list
->GetSize( index
, width
, height
);
2355 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2357 m_small_image_list
->GetSize( index
, width
, height
);
2360 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2362 m_small_image_list
->GetSize( index
, width
, height
);
2365 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2367 m_small_image_list
->GetSize( index
, width
, height
);
2374 int wxListMainWindow::GetTextLength( wxString
&s
)
2376 wxClientDC
dc( this );
2379 dc
.GetTextExtent( s
, &lw
, &lh
);
2383 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2385 int i
= m_lines
.Index(*line
);
2386 if (i
== wxNOT_FOUND
) return -1;
2390 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2394 // calc the spacing from the icon size
2397 if ((imageList
) && (imageList
->GetImageCount()) )
2399 imageList
->GetSize(0, width
, height
);
2402 if (which
== wxIMAGE_LIST_NORMAL
)
2404 m_normal_image_list
= imageList
;
2405 m_normal_spacing
= width
+ 8;
2408 if (which
== wxIMAGE_LIST_SMALL
)
2410 m_small_image_list
= imageList
;
2411 m_small_spacing
= width
+ 14;
2415 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2420 m_small_spacing
= spacing
;
2424 m_normal_spacing
= spacing
;
2428 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2430 return isSmall
? m_small_spacing
: m_normal_spacing
;
2433 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2436 wxNode
*node
= m_columns
.Nth( col
);
2439 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2440 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2441 column
->SetItem( item
);
2444 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2446 headerWin
->m_dirty
= TRUE
;
2449 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2451 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2452 _T("SetColumnWidth() can only be called in report mode.") );
2456 wxNode
*node
= (wxNode
*) NULL
;
2458 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2460 // TODO do use the header
2463 else if (width
== wxLIST_AUTOSIZE
)
2465 wxClientDC
dc(this);
2466 dc
.SetFont( GetFont() );
2469 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2471 wxListLineData
*line
= &m_lines
[i
];
2472 wxNode
*n
= line
->m_items
.Nth( col
);
2475 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2476 int current
= 0, ix
= 0, iy
= 0;
2477 wxCoord lx
= 0, ly
= 0;
2478 if (item
->HasImage())
2480 GetImageSize( item
->GetImage(), ix
, iy
);
2483 if (item
->HasText())
2486 item
->GetText( str
);
2487 dc
.GetTextExtent( str
, &lx
, &ly
);
2490 if (current
> max
) max
= current
;
2496 node
= m_columns
.Nth( col
);
2499 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2500 column
->SetWidth( width
);
2503 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2505 wxListLineData
*line
= &m_lines
[i
];
2506 wxNode
*n
= line
->m_items
.Nth( col
);
2509 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2510 item
->SetSize( width
, -1 );
2514 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2516 headerWin
->m_dirty
= TRUE
;
2519 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2521 wxNode
*node
= m_columns
.Nth( col
);
2524 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2525 column
->GetItem( item
);
2537 int wxListMainWindow::GetColumnWidth( int col
)
2539 wxNode
*node
= m_columns
.Nth( col
);
2542 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2543 return column
->GetWidth();
2551 int wxListMainWindow::GetColumnCount()
2553 return m_columns
.Number();
2556 int wxListMainWindow::GetCountPerPage()
2558 return m_visibleLines
;
2561 void wxListMainWindow::SetItem( wxListItem
&item
)
2564 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2566 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2567 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2568 line
->SetItem( item
.m_col
, item
);
2572 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2574 // m_dirty = TRUE; no recalcs needed
2576 wxListLineData
*oldCurrent
= m_current
;
2578 if (stateMask
& wxLIST_STATE_FOCUSED
)
2580 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2582 wxListLineData
*line
= &m_lines
[(size_t)item
];
2583 UnfocusLine( m_current
);
2585 FocusLine( m_current
);
2586 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2587 RefreshLine( m_current
);
2588 if (oldCurrent
) RefreshLine( oldCurrent
);
2592 if (stateMask
& wxLIST_STATE_SELECTED
)
2594 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2595 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2597 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2599 wxListLineData
*line
= &m_lines
[(size_t)item
];
2600 if (m_mode
& wxLC_SINGLE_SEL
)
2602 UnfocusLine( m_current
);
2604 FocusLine( m_current
);
2605 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2606 RefreshLine( m_current
);
2607 if (oldCurrent
) RefreshLine( oldCurrent
);
2609 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2610 if (on
!= line
->IsHilighted())
2612 line
->Hilight( on
);
2613 RefreshLine( line
);
2619 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2621 int ret
= wxLIST_STATE_DONTCARE
;
2622 if (stateMask
& wxLIST_STATE_FOCUSED
)
2624 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2626 wxListLineData
*line
= &m_lines
[(size_t)item
];
2627 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2630 if (stateMask
& wxLIST_STATE_SELECTED
)
2632 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2634 wxListLineData
*line
= &m_lines
[(size_t)item
];
2635 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2641 void wxListMainWindow::GetItem( wxListItem
&item
)
2643 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2645 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2646 line
->GetItem( item
.m_col
, item
);
2657 int wxListMainWindow::GetItemCount()
2659 return m_lines
.GetCount();
2662 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2664 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2666 m_lines
[(size_t)index
].GetRect( rect
);
2677 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2679 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2682 m_lines
[(size_t)item
].GetRect( rect
);
2694 int wxListMainWindow::GetSelectedItemCount()
2697 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2699 if (m_lines
[i
].IsHilighted()) ret
++;
2704 void wxListMainWindow::SetMode( long mode
)
2711 if (m_mode
& wxLC_REPORT
)
2713 #if wxUSE_GENERIC_LIST_EXTENSIONS
2727 long wxListMainWindow::GetMode() const
2732 void wxListMainWindow::CalculatePositions()
2734 if (m_lines
.IsEmpty()) return;
2736 wxClientDC
dc( this );
2737 dc
.SetFont( GetFont() );
2739 int iconSpacing
= 0;
2740 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2741 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2743 // we take the first line (which also can be an icon or
2744 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2745 // measure the size of the line
2749 int lineSpacing
= 0;
2751 wxListLineData
*line
= &m_lines
[0];
2752 line
->CalculateSize( &dc
, iconSpacing
);
2754 line
->GetSize( dummy
, lineSpacing
);
2757 int clientWidth
= 0;
2758 int clientHeight
= 0;
2760 if (m_mode
& wxLC_REPORT
)
2764 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2765 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2766 #if wxUSE_GENERIC_LIST_EXTENSIONS
2767 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2769 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2771 GetClientSize( &clientWidth
, &clientHeight
);
2773 int entireWidth
= 0 ;
2774 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2776 wxListLineData
*line
= &m_lines
[j
];
2777 line
->CalculateSize( &dc
, iconSpacing
);
2778 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2780 for (int i
= 0; i
< GetColumnCount(); i
++)
2782 line
->SetColumnPosition( i
, col_x
);
2783 col_x
+= GetColumnWidth( i
);
2785 entireWidth
= wxMax( entireWidth
, col_x
) ;
2786 #if wxUSE_GENERIC_LIST_EXTENSIONS
2787 line
->SetPosition( &dc
, x
, y
, col_x
);
2789 y
+= lineSpacing
; // one pixel blank line between items
2791 m_visibleLines
= clientHeight
/ lineSpacing
;
2792 #if wxUSE_GENERIC_LIST_EXTENSIONS
2793 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2798 // at first we try without any scrollbar. if the items don't
2799 // fit into the window, we recalculate after subtracting an
2800 // approximated 15 pt for the horizontal scrollbar
2802 GetSize( &clientWidth
, &clientHeight
);
2803 clientHeight
-= 4; // sunken frame
2805 int entireWidth
= 0;
2807 for (int tries
= 0; tries
< 2; tries
++)
2814 int m_currentVisibleLines
= 0;
2815 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2817 m_currentVisibleLines
++;
2818 wxListLineData
*line
= &m_lines
[i
];
2819 line
->CalculateSize( &dc
, iconSpacing
);
2820 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2821 line
->GetSize( lineWidth
, lineHeight
);
2822 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2824 if (m_currentVisibleLines
> m_visibleLines
)
2825 m_visibleLines
= m_currentVisibleLines
;
2826 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2828 m_currentVisibleLines
= 0;
2831 entireWidth
+= maxWidth
+6;
2834 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2835 if ((tries
== 0) && (entireWidth
> clientWidth
))
2837 clientHeight
-= 15; // scrollbar height
2839 m_currentVisibleLines
= 0;
2842 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2846 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2847 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2851 void wxListMainWindow::RealizeChanges()
2855 if (!m_lines
.IsEmpty())
2856 m_current
= &m_lines
[0];
2860 FocusLine( m_current
);
2861 // TODO: MSW doesn't automatically hilight the
2863 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2867 long wxListMainWindow::GetNextItem( long item
,
2868 int WXUNUSED(geometry
),
2872 max
= GetItemCount();
2873 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2874 _T("invalid listctrl index in GetNextItem()") );
2876 // notice that we start with the next item (or the first one if item == -1)
2877 // and this is intentional to allow writing a simple loop to iterate over
2878 // all selected items
2882 // this is not an error because the index was ok initially, just no
2887 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2889 wxListLineData
*line
= &m_lines
[i
];
2890 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2892 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2902 void wxListMainWindow::DeleteItem( long index
)
2905 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2907 wxListLineData
*line
= &m_lines
[(size_t)index
];
2908 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2910 m_lines
.RemoveAt( (size_t)index
);
2914 void wxListMainWindow::DeleteColumn( int col
)
2916 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2917 wxT("attempting to delete inexistent column in wxListView") );
2920 wxNode
*node
= m_columns
.Nth( col
);
2921 if (node
) m_columns
.DeleteNode( node
);
2924 void wxListMainWindow::DeleteAllItems()
2927 m_current
= (wxListLineData
*) NULL
;
2929 // to make the deletion of all items faster, we don't send the
2930 // notifications in this case: this is compatible with wxMSW and
2931 // documented in DeleteAllItems() description
2933 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2934 event
.SetEventObject( GetParent() );
2935 GetParent()->GetEventHandler()->ProcessEvent( event
);
2940 void wxListMainWindow::DeleteEverything()
2947 void wxListMainWindow::EnsureVisible( long index
)
2949 // We have to call this here because the label in
2950 // question might just have been added and no screen
2951 // update taken place.
2952 if (m_dirty
) wxYield();
2954 wxListLineData
*oldCurrent
= m_current
;
2955 m_current
= (wxListLineData
*) NULL
;
2956 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2957 m_current
= &m_lines
[(size_t)index
];
2958 if (m_current
) MoveToFocus();
2959 m_current
= oldCurrent
;
2962 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2966 if (pos
< 0) pos
= 0;
2967 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2969 wxListLineData
*line
= &m_lines
[i
];
2971 line
->GetText( 0, s
);
2972 if (s
== tmp
) return pos
;
2978 long wxListMainWindow::FindItem(long start
, long data
)
2981 if (pos
< 0) pos
= 0;
2982 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2984 wxListLineData
*line
= &m_lines
[i
];
2986 line
->GetItem( 0, item
);
2987 if (item
.m_data
== data
) return pos
;
2993 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2995 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2998 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3000 wxListLineData
*line
= &m_lines
[i
];
3001 long ret
= line
->IsHit( x
, y
);
3002 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3012 void wxListMainWindow::InsertItem( wxListItem
&item
)
3016 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3017 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3018 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3019 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3021 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3023 if (m_mode
& wxLC_REPORT
)
3025 line
->InitItems( GetColumnCount() );
3026 item
.m_width
= GetColumnWidth( 0 )-3;
3030 line
->InitItems( 1 );
3033 line
->SetItem( 0, item
);
3034 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3036 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3040 m_lines
.Add( line
);
3041 item
.m_itemId
= m_lines
.GetCount()-1;
3045 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3048 if (m_mode
& wxLC_REPORT
)
3050 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3051 wxListHeaderData
*column
= new wxListHeaderData( item
);
3052 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3054 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3056 m_columns
.Insert( node
, column
);
3060 m_columns
.Append( column
);
3065 wxListCtrlCompare list_ctrl_compare_func_2
;
3066 long list_ctrl_compare_data
;
3068 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3070 wxListLineData
*line1
= *arg1
;
3071 wxListLineData
*line2
= *arg2
;
3073 line1
->GetItem( 0, item
);
3074 long data1
= item
.m_data
;
3075 line2
->GetItem( 0, item
);
3076 long data2
= item
.m_data
;
3077 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3080 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3082 list_ctrl_compare_func_2
= fn
;
3083 list_ctrl_compare_data
= data
;
3084 m_lines
.Sort( list_ctrl_compare_func_1
);
3088 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3090 wxScrolledWindow::OnScroll( event
) ;
3091 #if wxUSE_GENERIC_LIST_EXTENSIONS
3093 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3095 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3098 lc
->m_headerWin
->Refresh() ;
3100 lc
->m_headerWin
->MacUpdateImmediately() ;
3107 // -------------------------------------------------------------------------------------
3109 // -------------------------------------------------------------------------------------
3111 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3113 wxListItem::wxListItem()
3122 m_format
= wxLIST_FORMAT_CENTRE
;
3128 void wxListItem::Clear()
3137 m_format
= wxLIST_FORMAT_CENTRE
;
3139 m_text
= wxEmptyString
;
3141 if (m_attr
) delete m_attr
;
3145 void wxListItem::ClearAttributes()
3147 if (m_attr
) delete m_attr
;
3151 // -------------------------------------------------------------------------------------
3153 // -------------------------------------------------------------------------------------
3155 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3157 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3158 wxNotifyEvent( commandType
, id
)
3164 m_cancelled
= FALSE
;
3169 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3171 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3173 wxNotifyEvent::CopyObject(object_dest
);
3175 obj
->m_code
= m_code
;
3176 obj
->m_itemIndex
= m_itemIndex
;
3177 obj
->m_oldItemIndex
= m_oldItemIndex
;
3179 obj
->m_cancelled
= m_cancelled
;
3180 obj
->m_pointDrag
= m_pointDrag
;
3181 obj
->m_item
.m_mask
= m_item
.m_mask
;
3182 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3183 obj
->m_item
.m_col
= m_item
.m_col
;
3184 obj
->m_item
.m_state
= m_item
.m_state
;
3185 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3186 obj
->m_item
.m_text
= m_item
.m_text
;
3187 obj
->m_item
.m_image
= m_item
.m_image
;
3188 obj
->m_item
.m_data
= m_item
.m_data
;
3189 obj
->m_item
.m_format
= m_item
.m_format
;
3190 obj
->m_item
.m_width
= m_item
.m_width
;
3192 if ( m_item
.HasAttributes() )
3194 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3198 // -------------------------------------------------------------------------------------
3200 // -------------------------------------------------------------------------------------
3202 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3204 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3205 EVT_SIZE (wxListCtrl::OnSize
)
3206 EVT_IDLE (wxListCtrl::OnIdle
)
3209 wxListCtrl::wxListCtrl()
3211 m_imageListNormal
= (wxImageList
*) NULL
;
3212 m_imageListSmall
= (wxImageList
*) NULL
;
3213 m_imageListState
= (wxImageList
*) NULL
;
3214 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3215 m_mainWin
= (wxListMainWindow
*) NULL
;
3216 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3219 wxListCtrl::~wxListCtrl()
3221 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3222 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3223 if (m_ownsImageListState
) delete m_imageListState
;
3226 bool wxListCtrl::Create(wxWindow
*parent
,
3231 const wxValidator
&validator
,
3232 const wxString
&name
)
3234 m_imageListNormal
= (wxImageList
*) NULL
;
3235 m_imageListSmall
= (wxImageList
*) NULL
;
3236 m_imageListState
= (wxImageList
*) NULL
;
3237 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3238 m_mainWin
= (wxListMainWindow
*) NULL
;
3239 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3241 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3243 style
= style
| wxLC_LIST
;
3246 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3249 if (style
& wxSUNKEN_BORDER
)
3250 style
-= wxSUNKEN_BORDER
;
3252 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3254 if (HasFlag(wxLC_REPORT
))
3256 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3257 if (HasFlag(wxLC_NO_HEADER
))
3258 m_headerWin
->Show( FALSE
);
3262 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3268 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3270 /* handled in OnIdle */
3272 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3275 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3277 long flag
= GetWindowStyle();
3281 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3282 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3283 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3292 if (flag
& style
) flag
-= style
;
3295 SetWindowStyleFlag( flag
);
3298 void wxListCtrl::SetWindowStyleFlag( long flag
)
3302 m_mainWin
->DeleteEverything();
3306 GetClientSize( &width
, &height
);
3308 m_mainWin
->SetMode( flag
);
3310 if (flag
& wxLC_REPORT
)
3312 if (!HasFlag(wxLC_REPORT
))
3316 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3317 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3318 if (HasFlag(wxLC_NO_HEADER
))
3319 m_headerWin
->Show( FALSE
);
3323 if (flag
& wxLC_NO_HEADER
)
3324 m_headerWin
->Show( FALSE
);
3326 m_headerWin
->Show( TRUE
);
3332 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3334 m_headerWin
->Show( FALSE
);
3339 wxWindow::SetWindowStyleFlag( flag
);
3342 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3344 m_mainWin
->GetColumn( col
, item
);
3348 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3350 m_mainWin
->SetColumn( col
, item
);
3354 int wxListCtrl::GetColumnWidth( int col
) const
3356 return m_mainWin
->GetColumnWidth( col
);
3359 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3361 m_mainWin
->SetColumnWidth( col
, width
);
3365 int wxListCtrl::GetCountPerPage() const
3367 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3370 bool wxListCtrl::GetItem( wxListItem
&info
) const
3372 m_mainWin
->GetItem( info
);
3376 bool wxListCtrl::SetItem( wxListItem
&info
)
3378 m_mainWin
->SetItem( info
);
3382 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3385 info
.m_text
= label
;
3386 info
.m_mask
= wxLIST_MASK_TEXT
;
3387 info
.m_itemId
= index
;
3391 info
.m_image
= imageId
;
3392 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3394 m_mainWin
->SetItem(info
);
3398 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3400 return m_mainWin
->GetItemState( item
, stateMask
);
3403 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3405 m_mainWin
->SetItemState( item
, state
, stateMask
);
3409 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3412 info
.m_image
= image
;
3413 info
.m_mask
= wxLIST_MASK_IMAGE
;
3414 info
.m_itemId
= item
;
3415 m_mainWin
->SetItem( info
);
3419 wxString
wxListCtrl::GetItemText( long item
) const
3422 info
.m_itemId
= item
;
3423 m_mainWin
->GetItem( info
);
3427 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3430 info
.m_mask
= wxLIST_MASK_TEXT
;
3431 info
.m_itemId
= item
;
3433 m_mainWin
->SetItem( info
);
3436 long wxListCtrl::GetItemData( long item
) const
3439 info
.m_itemId
= item
;
3440 m_mainWin
->GetItem( info
);
3444 bool wxListCtrl::SetItemData( long item
, long data
)
3447 info
.m_mask
= wxLIST_MASK_DATA
;
3448 info
.m_itemId
= item
;
3450 m_mainWin
->SetItem( info
);
3454 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3456 m_mainWin
->GetItemRect( item
, rect
);
3460 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3462 m_mainWin
->GetItemPosition( item
, pos
);
3466 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3471 int wxListCtrl::GetItemCount() const
3473 return m_mainWin
->GetItemCount();
3476 int wxListCtrl::GetColumnCount() const
3478 return m_mainWin
->GetColumnCount();
3481 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3483 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3486 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3488 return m_mainWin
->GetItemSpacing( isSmall
);
3491 int wxListCtrl::GetSelectedItemCount() const
3493 return m_mainWin
->GetSelectedItemCount();
3496 wxColour
wxListCtrl::GetTextColour() const
3498 return GetForegroundColour();
3501 void wxListCtrl::SetTextColour(const wxColour
& col
)
3503 SetForegroundColour(col
);
3506 long wxListCtrl::GetTopItem() const
3511 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3513 return m_mainWin
->GetNextItem( item
, geom
, state
);
3516 wxImageList
*wxListCtrl::GetImageList(int which
) const
3518 if (which
== wxIMAGE_LIST_NORMAL
)
3520 return m_imageListNormal
;
3522 else if (which
== wxIMAGE_LIST_SMALL
)
3524 return m_imageListSmall
;
3526 else if (which
== wxIMAGE_LIST_STATE
)
3528 return m_imageListState
;
3530 return (wxImageList
*) NULL
;
3533 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3535 if ( which
== wxIMAGE_LIST_NORMAL
)
3537 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3538 m_imageListNormal
= imageList
;
3539 m_ownsImageListNormal
= FALSE
;
3541 else if ( which
== wxIMAGE_LIST_SMALL
)
3543 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3544 m_imageListSmall
= imageList
;
3545 m_ownsImageListSmall
= FALSE
;
3547 else if ( which
== wxIMAGE_LIST_STATE
)
3549 if (m_ownsImageListState
) delete m_imageListState
;
3550 m_imageListState
= imageList
;
3551 m_ownsImageListState
= FALSE
;
3554 m_mainWin
->SetImageList( imageList
, which
);
3557 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3559 SetImageList(imageList
, which
);
3560 if ( which
== wxIMAGE_LIST_NORMAL
)
3561 m_ownsImageListNormal
= TRUE
;
3562 else if ( which
== wxIMAGE_LIST_SMALL
)
3563 m_ownsImageListSmall
= TRUE
;
3564 else if ( which
== wxIMAGE_LIST_STATE
)
3565 m_ownsImageListState
= TRUE
;
3568 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3573 bool wxListCtrl::DeleteItem( long item
)
3575 m_mainWin
->DeleteItem( item
);
3579 bool wxListCtrl::DeleteAllItems()
3581 m_mainWin
->DeleteAllItems();
3585 bool wxListCtrl::DeleteAllColumns()
3587 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3593 void wxListCtrl::ClearAll()
3595 m_mainWin
->DeleteEverything();
3598 bool wxListCtrl::DeleteColumn( int col
)
3600 m_mainWin
->DeleteColumn( col
);
3604 void wxListCtrl::Edit( long item
)
3606 m_mainWin
->Edit( item
);
3609 bool wxListCtrl::EnsureVisible( long item
)
3611 m_mainWin
->EnsureVisible( item
);
3615 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3617 return m_mainWin
->FindItem( start
, str
, partial
);
3620 long wxListCtrl::FindItem( long start
, long data
)
3622 return m_mainWin
->FindItem( start
, data
);
3625 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3626 int WXUNUSED(direction
))
3631 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3633 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3636 long wxListCtrl::InsertItem( wxListItem
& info
)
3638 m_mainWin
->InsertItem( info
);
3639 return info
.m_itemId
;
3642 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3645 info
.m_text
= label
;
3646 info
.m_mask
= wxLIST_MASK_TEXT
;
3647 info
.m_itemId
= index
;
3648 return InsertItem( info
);
3651 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3654 info
.m_mask
= wxLIST_MASK_IMAGE
;
3655 info
.m_image
= imageIndex
;
3656 info
.m_itemId
= index
;
3657 return InsertItem( info
);
3660 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3663 info
.m_text
= label
;
3664 info
.m_image
= imageIndex
;
3665 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3666 info
.m_itemId
= index
;
3667 return InsertItem( info
);
3670 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3672 wxASSERT( m_headerWin
);
3673 m_mainWin
->InsertColumn( col
, item
);
3674 m_headerWin
->Refresh();
3679 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3680 int format
, int width
)
3683 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3684 item
.m_text
= heading
;
3687 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3688 item
.m_width
= width
;
3690 item
.m_format
= format
;
3692 return InsertColumn( col
, item
);
3695 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3701 // fn is a function which takes 3 long arguments: item1, item2, data.
3702 // item1 is the long data associated with a first item (NOT the index).
3703 // item2 is the long data associated with a second item (NOT the index).
3704 // data is the same value as passed to SortItems.
3705 // The return value is a negative number if the first item should precede the second
3706 // item, a positive number of the second item should precede the first,
3707 // or zero if the two items are equivalent.
3708 // data is arbitrary data to be passed to the sort function.
3710 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3712 m_mainWin
->SortItems( fn
, data
);
3716 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3718 if (!m_mainWin
->m_dirty
) return;
3722 GetClientSize( &cw
, &ch
);
3729 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3731 m_headerWin
->GetPosition( &x
, &y
);
3732 m_headerWin
->GetSize( &w
, &h
);
3733 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3734 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3736 m_mainWin
->GetPosition( &x
, &y
);
3737 m_mainWin
->GetSize( &w
, &h
);
3738 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3739 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3743 m_mainWin
->GetPosition( &x
, &y
);
3744 m_mainWin
->GetSize( &w
, &h
);
3745 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3746 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3749 m_mainWin
->CalculatePositions();
3750 m_mainWin
->RealizeChanges();
3751 m_mainWin
->m_dirty
= FALSE
;
3752 m_mainWin
->Refresh();
3754 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3756 m_headerWin
->m_dirty
= FALSE
;
3757 m_headerWin
->Refresh();
3761 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3765 m_mainWin
->SetBackgroundColour( colour
);
3766 m_mainWin
->m_dirty
= TRUE
;
3772 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3774 if ( !wxWindow::SetForegroundColour( colour
) )
3779 m_mainWin
->SetForegroundColour( colour
);
3780 m_mainWin
->m_dirty
= TRUE
;
3785 m_headerWin
->SetForegroundColour( colour
);
3791 bool wxListCtrl::SetFont( const wxFont
&font
)
3793 if ( !wxWindow::SetFont( font
) )
3798 m_mainWin
->SetFont( font
);
3799 m_mainWin
->m_dirty
= TRUE
;
3804 m_headerWin
->SetFont( font
);
3810 #if wxUSE_DRAG_AND_DROP
3812 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3814 m_mainWin
->SetDropTarget( dropTarget
);
3817 wxDropTarget
*wxListCtrl::GetDropTarget() const
3819 return m_mainWin
->GetDropTarget();
3822 #endif // wxUSE_DRAG_AND_DROP
3824 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3826 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3829 wxColour
wxListCtrl::GetBackgroundColour() const
3831 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3834 wxColour
wxListCtrl::GetForegroundColour() const
3836 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3839 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3841 return m_mainWin
->PopupMenu( menu
, x
, y
);
3844 void wxListCtrl::SetFocus()
3846 /* The test in window.cpp fails as we are a composite
3847 window, so it checks against "this", but not m_mainWin. */
3848 if ( FindFocus() != this )
3849 m_mainWin
->SetFocus();