1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
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"
24 #include "wx/dcscreen.h"
26 #include "wx/listctrl.h"
27 #include "wx/generic/imaglist.h"
28 #include "wx/dynarray.h"
32 #include "wx/gtk/win_gtk.h"
35 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
36 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
60 // ============================================================================
62 // ============================================================================
64 //-----------------------------------------------------------------------------
65 // wxListItemData (internal)
66 //-----------------------------------------------------------------------------
68 class WXDLLEXPORT wxListItemData
: public wxObject
72 ~wxListItemData() { delete m_attr
; }
74 wxListItemData( const wxListItem
&info
);
75 void SetItem( const wxListItem
&info
);
76 void SetImage( int image
);
77 void SetData( long data
);
78 void SetPosition( int x
, int y
);
79 void SetSize( int width
, int height
);
80 bool HasImage() const;
82 bool HasText() const { return !m_text
.empty(); }
83 const wxString
& GetText() const { return m_text
; }
84 void SetText(const wxString
& text
) { m_text
= text
; }
86 bool IsHit( int x
, int y
) const;
88 int GetX( void ) const;
89 int GetY( void ) const;
91 int GetHeight() const;
93 void GetItem( wxListItem
&info
) const;
95 wxListItemAttr
*GetAttributes() const { return m_attr
; }
105 wxListItemAttr
*m_attr
;
111 DECLARE_DYNAMIC_CLASS(wxListItemData
);
114 //-----------------------------------------------------------------------------
115 // wxListHeaderData (internal)
116 //-----------------------------------------------------------------------------
118 class WXDLLEXPORT wxListHeaderData
: public wxObject
132 wxListHeaderData( const wxListItem
&info
);
133 void SetItem( const wxListItem
&item
);
134 void SetPosition( int x
, int y
);
135 void SetWidth( int w
);
136 void SetFormat( int format
);
137 void SetHeight( int h
);
138 bool HasImage() const;
140 bool HasText() const { return !m_text
.empty(); }
141 const wxString
& GetText() const { return m_text
; }
142 void SetText(const wxString
& text
) { m_text
= text
; }
144 void GetItem( wxListItem
&item
);
146 bool IsHit( int x
, int y
) const;
147 int GetImage() const;
148 int GetWidth() const;
149 int GetFormat() const;
152 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
155 //-----------------------------------------------------------------------------
156 // wxListLineData (internal)
157 //-----------------------------------------------------------------------------
159 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
160 #include "wx/listimpl.cpp"
161 WX_DEFINE_LIST(wxListItemDataList
);
163 class WXDLLEXPORT wxListLineData
: public wxObject
166 wxListItemDataList m_items
;
168 wxRect m_bound_label
;
170 wxRect m_bound_hilight
;
173 wxBrush
*m_hilightBrush
;
175 wxListMainWindow
*m_owner
;
177 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
181 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
182 void CalculateSize( wxDC
*dc
, int spacing
);
183 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
184 void SetColumnPosition( int index
, int x
);
185 void GetSize( int &width
, int &height
);
186 void GetExtent( int &x
, int &y
, int &width
, int &height
);
187 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
188 long IsHit( int x
, int y
);
189 void InitItems( int num
);
190 void SetItem( int index
, const wxListItem
&info
);
191 void GetItem( int index
, wxListItem
&info
);
192 wxString
GetText(int index
) const;
193 void SetText( int index
, const wxString s
);
194 int GetImage( int index
);
195 void GetRect( wxRect
&rect
);
196 void Hilight( bool on
);
197 void ReverseHilight();
198 void DrawRubberBand( wxDC
*dc
, bool on
);
199 void Draw( wxDC
*dc
);
200 bool IsInRect( int x
, int y
, const wxRect
&rect
);
202 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
203 void AssignRect( wxRect
&dest
, const wxRect
&source
);
206 void SetAttributes(wxDC
*dc
,
207 const wxListItemAttr
*attr
,
208 const wxColour
& colText
, const wxFont
& font
,
211 DECLARE_DYNAMIC_CLASS(wxListLineData
);
215 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
216 #include "wx/arrimpl.cpp"
217 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
219 //-----------------------------------------------------------------------------
220 // wxListHeaderWindow (internal)
221 //-----------------------------------------------------------------------------
223 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
226 wxListMainWindow
*m_owner
;
227 wxCursor
*m_currentCursor
;
228 wxCursor
*m_resizeCursor
;
231 // column being resized
234 // divider line position in logical (unscrolled) coords
237 // minimal position beyond which the divider line can't be dragged in
242 wxListHeaderWindow();
243 virtual ~wxListHeaderWindow();
245 wxListHeaderWindow( wxWindow
*win
,
247 wxListMainWindow
*owner
,
248 const wxPoint
&pos
= wxDefaultPosition
,
249 const wxSize
&size
= wxDefaultSize
,
251 const wxString
&name
= "wxlistctrlcolumntitles" );
253 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
255 void AdjustDC(wxDC
& dc
);
257 void OnPaint( wxPaintEvent
&event
);
258 void OnMouse( wxMouseEvent
&event
);
259 void OnSetFocus( wxFocusEvent
&event
);
265 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
266 DECLARE_EVENT_TABLE()
269 //-----------------------------------------------------------------------------
270 // wxListRenameTimer (internal)
271 //-----------------------------------------------------------------------------
273 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
276 wxListMainWindow
*m_owner
;
279 wxListRenameTimer( wxListMainWindow
*owner
);
283 //-----------------------------------------------------------------------------
284 // wxListTextCtrl (internal)
285 //-----------------------------------------------------------------------------
287 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
292 wxListMainWindow
*m_owner
;
293 wxString m_startValue
;
297 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
298 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
299 const wxString
&value
= "",
300 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
302 const wxValidator
& validator
= wxDefaultValidator
,
303 const wxString
&name
= "listctrltextctrl" );
304 void OnChar( wxKeyEvent
&event
);
305 void OnKeyUp( wxKeyEvent
&event
);
306 void OnKillFocus( wxFocusEvent
&event
);
309 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
310 DECLARE_EVENT_TABLE()
313 //-----------------------------------------------------------------------------
314 // wxListMainWindow (internal)
315 //-----------------------------------------------------------------------------
317 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
321 wxListLineDataArray m_lines
;
323 wxListLineData
*m_current
;
324 wxListLineData
*m_currentEdit
;
326 wxBrush
*m_hilightBrush
;
327 wxColour
*m_hilightColour
;
328 int m_xScroll
,m_yScroll
;
330 wxImageList
*m_small_image_list
;
331 wxImageList
*m_normal_image_list
;
333 int m_normal_spacing
;
337 wxTimer
*m_renameTimer
;
339 wxString m_renameRes
;
344 // for double click logic
345 wxListLineData
*m_lineLastClicked
,
346 *m_lineBeforeLastClicked
;
350 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
351 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
352 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
354 void RefreshLine( wxListLineData
*line
);
355 void OnPaint( wxPaintEvent
&event
);
356 void HilightAll( bool on
);
357 void SendNotify( wxListLineData
*line
,
359 wxPoint point
= wxDefaultPosition
);
360 void FocusLine( wxListLineData
*line
);
361 void UnfocusLine( wxListLineData
*line
);
362 void SelectLine( wxListLineData
*line
);
363 void DeselectLine( wxListLineData
*line
);
364 void DeleteLine( wxListLineData
*line
);
366 void EditLabel( long item
);
367 void Edit( long item
) { EditLabel(item
); } // deprecated
368 void OnRenameTimer();
369 void OnRenameAccept();
371 void OnMouse( wxMouseEvent
&event
);
373 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
374 void OnChar( wxKeyEvent
&event
);
375 void OnKeyDown( wxKeyEvent
&event
);
376 void OnSetFocus( wxFocusEvent
&event
);
377 void OnKillFocus( wxFocusEvent
&event
);
378 void OnSize( wxSizeEvent
&event
);
379 void OnScroll(wxScrollWinEvent
& event
) ;
381 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
382 void GetImageSize( int index
, int &width
, int &height
);
383 int GetIndexOfLine( const wxListLineData
*line
);
384 int GetTextLength( wxString
&s
); // should be const
386 void SetImageList( wxImageList
*imageList
, int which
);
387 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
388 int GetItemSpacing( bool isSmall
= FALSE
);
389 void SetColumn( int col
, wxListItem
&item
);
390 void SetColumnWidth( int col
, int width
);
391 void GetColumn( int col
, wxListItem
&item
);
392 int GetColumnWidth( int vol
);
393 int GetColumnCount();
394 int GetCountPerPage();
395 void SetItem( wxListItem
&item
);
396 void GetItem( wxListItem
&item
);
397 void SetItemState( long item
, long state
, long stateMask
);
398 int GetItemState( long item
, long stateMask
);
400 void GetItemRect( long index
, wxRect
&rect
);
401 bool GetItemPosition( long item
, wxPoint
& pos
);
402 int GetSelectedItemCount();
403 void SetMode( long mode
);
404 long GetMode() const;
405 void CalculatePositions();
406 void RealizeChanges();
407 long GetNextItem( long item
, int geometry
, int state
);
408 void DeleteItem( long index
);
409 void DeleteAllItems();
410 void DeleteColumn( int col
);
411 void DeleteEverything();
412 void EnsureVisible( long index
);
413 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
414 long FindItem( long start
, long data
);
415 long HitTest( int x
, int y
, int &flags
);
416 void InsertItem( wxListItem
&item
);
417 // void AddItem( wxListItem &item );
418 void InsertColumn( long col
, wxListItem
&item
);
419 // void AddColumn( wxListItem &item );
420 void SortItems( wxListCtrlCompare fn
, long data
);
422 void SetItemCount(long count
);
425 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
426 DECLARE_EVENT_TABLE()
429 // ============================================================================
431 // ============================================================================
433 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
437 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
439 wxListItemData::wxListItemData()
450 wxListItemData::wxListItemData( const wxListItem
&info
)
459 void wxListItemData::SetItem( const wxListItem
&info
)
461 if (info
.m_mask
& wxLIST_MASK_TEXT
)
462 SetText(info
.m_text
);
463 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
464 m_image
= info
.m_image
;
465 if (info
.m_mask
& wxLIST_MASK_DATA
)
466 m_data
= info
.m_data
;
468 if ( info
.HasAttributes() )
471 *m_attr
= *info
.GetAttributes();
473 m_attr
= new wxListItemAttr(*info
.GetAttributes());
478 m_width
= info
.m_width
;
482 void wxListItemData::SetImage( int image
)
487 void wxListItemData::SetData( long data
)
492 void wxListItemData::SetPosition( int x
, int y
)
498 void wxListItemData::SetSize( int width
, int height
)
500 if (width
!= -1) m_width
= width
;
501 if (height
!= -1) m_height
= height
;
504 bool wxListItemData::HasImage() const
506 return (m_image
>= 0);
509 bool wxListItemData::IsHit( int x
, int y
) const
511 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
514 int wxListItemData::GetX() const
519 int wxListItemData::GetY() const
524 int wxListItemData::GetWidth() const
529 int wxListItemData::GetHeight() const
534 int wxListItemData::GetImage() const
539 void wxListItemData::GetItem( wxListItem
&info
) const
541 info
.m_text
= m_text
;
542 info
.m_image
= m_image
;
543 info
.m_data
= m_data
;
547 if ( m_attr
->HasTextColour() )
548 info
.SetTextColour(m_attr
->GetTextColour());
549 if ( m_attr
->HasBackgroundColour() )
550 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
551 if ( m_attr
->HasFont() )
552 info
.SetFont(m_attr
->GetFont());
556 //-----------------------------------------------------------------------------
558 //-----------------------------------------------------------------------------
560 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
562 wxListHeaderData::wxListHeaderData()
573 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
581 void wxListHeaderData::SetItem( const wxListItem
&item
)
583 m_mask
= item
.m_mask
;
584 m_text
= item
.m_text
;
585 m_image
= item
.m_image
;
586 m_format
= item
.m_format
;
587 m_width
= item
.m_width
;
588 if (m_width
< 0) m_width
= 80;
589 if (m_width
< 6) m_width
= 6;
592 void wxListHeaderData::SetPosition( int x
, int y
)
598 void wxListHeaderData::SetHeight( int h
)
603 void wxListHeaderData::SetWidth( int w
)
606 if (m_width
< 0) m_width
= 80;
607 if (m_width
< 6) m_width
= 6;
610 void wxListHeaderData::SetFormat( int format
)
615 bool wxListHeaderData::HasImage() const
617 return (m_image
!= 0);
620 bool wxListHeaderData::IsHit( int x
, int y
) const
622 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
625 void wxListHeaderData::GetItem( wxListItem
&item
)
627 item
.m_mask
= m_mask
;
628 item
.m_text
= m_text
;
629 item
.m_image
= m_image
;
630 item
.m_format
= m_format
;
631 item
.m_width
= m_width
;
634 int wxListHeaderData::GetImage() const
639 int wxListHeaderData::GetWidth() const
644 int wxListHeaderData::GetFormat() const
649 //-----------------------------------------------------------------------------
651 //-----------------------------------------------------------------------------
653 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
655 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
660 m_hilightBrush
= hilightBrush
;
661 m_items
.DeleteContents( TRUE
);
665 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
667 wxListItemDataList::Node
*node
= m_items
.GetFirst();
674 m_bound_all
.width
= m_spacing
;
677 wxListItemData
*item
= node
->GetData();
678 wxString s
= item
->GetText();
683 dc
->GetTextExtent( s
, &lw
, &lh
);
689 m_bound_all
.height
= m_spacing
+lh
;
691 m_bound_all
.width
= lw
;
692 m_bound_label
.width
= lw
;
693 m_bound_label
.height
= lh
;
695 if (item
->HasImage())
699 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
700 m_bound_icon
.width
= w
+ 8;
701 m_bound_icon
.height
= h
+ 8;
703 if ( m_bound_icon
.width
> m_bound_all
.width
)
704 m_bound_all
.width
= m_bound_icon
.width
;
705 if ( h
+ lh
> m_bound_all
.height
- 4 )
706 m_bound_all
.height
= h
+ lh
+ 4;
709 if (!item
->HasText())
711 m_bound_hilight
.width
= m_bound_icon
.width
;
712 m_bound_hilight
.height
= m_bound_icon
.height
;
716 m_bound_hilight
.width
= m_bound_label
.width
;
717 m_bound_hilight
.height
= m_bound_label
.height
;
726 wxListItemData
*item
= node
->GetData();
728 wxString s
= item
->GetText();
733 dc
->GetTextExtent( s
, &lw
, &lh
);
739 m_bound_label
.width
= lw
;
740 m_bound_label
.height
= lh
;
742 m_bound_all
.width
= lw
;
743 m_bound_all
.height
= lh
;
745 if (item
->HasImage())
749 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
750 m_bound_icon
.width
= w
;
751 m_bound_icon
.height
= h
;
753 m_bound_all
.width
+= 4 + w
;
754 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
757 m_bound_hilight
.width
= m_bound_all
.width
;
758 m_bound_hilight
.height
= m_bound_all
.height
;
764 m_bound_all
.width
= 0;
765 m_bound_all
.height
= 0;
768 wxListItemData
*item
= node
->GetData();
769 if (item
->HasImage())
773 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
774 m_bound_icon
.width
= w
;
775 m_bound_icon
.height
= h
;
779 m_bound_icon
.width
= 0;
780 m_bound_icon
.height
= 0;
786 wxListItemData
*item
= node
->GetData();
787 wxString s
= item
->GetText();
792 dc
->GetTextExtent( s
, &lw
, &lh
);
798 item
->SetSize( item
->GetWidth(), lh
);
799 m_bound_all
.width
+= lw
;
800 m_bound_all
.height
= lh
;
801 node
= node
->GetNext();
803 m_bound_label
.width
= m_bound_all
.width
;
804 m_bound_label
.height
= m_bound_all
.height
;
810 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
811 int x
, int y
, int window_width
)
813 wxListItemDataList::Node
*node
= m_items
.GetFirst();
824 wxListItemData
*item
= node
->GetData();
825 if (item
->HasImage())
827 m_bound_icon
.x
= m_bound_all
.x
+ 4
828 + (m_spacing
- m_bound_icon
.width
)/2;
829 m_bound_icon
.y
= m_bound_all
.y
+ 4;
833 if (m_bound_all
.width
> m_spacing
)
834 m_bound_label
.x
= m_bound_all
.x
+ 2;
836 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
837 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
838 m_bound_hilight
.x
= m_bound_label
.x
- 2;
839 m_bound_hilight
.y
= m_bound_label
.y
- 2;
843 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
844 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
851 m_bound_hilight
.x
= m_bound_all
.x
;
852 m_bound_hilight
.y
= m_bound_all
.y
;
853 m_bound_label
.y
= m_bound_all
.y
+ 2;
856 wxListItemData
*item
= node
->GetData();
857 if (item
->HasImage())
859 m_bound_icon
.x
= m_bound_all
.x
+ 2;
860 m_bound_icon
.y
= m_bound_all
.y
+ 2;
861 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
865 m_bound_label
.x
= m_bound_all
.x
+ 2;
873 m_bound_all
.width
= window_width
;
874 AssignRect( m_bound_hilight
, m_bound_all
);
875 m_bound_label
.x
= m_bound_all
.x
+ 2;
876 m_bound_label
.y
= m_bound_all
.y
+ 2;
879 wxListItemData
*item
= node
->GetData();
880 if (item
->HasImage())
882 m_bound_icon
.x
= m_bound_all
.x
+ 2;
883 m_bound_icon
.y
= m_bound_all
.y
+ 2;
884 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
892 void wxListLineData::SetColumnPosition( int index
, int x
)
894 wxListItemDataList::Node
*node
= m_items
.Item( (size_t)index
);
897 wxListItemData
*item
= node
->GetData();
898 item
->SetPosition( x
, m_bound_all
.y
+1 );
902 void wxListLineData::GetSize( int &width
, int &height
)
904 width
= m_bound_all
.width
;
905 height
= m_bound_all
.height
;
908 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
912 width
= m_bound_all
.width
;
913 height
= m_bound_all
.height
;
916 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
920 width
= m_bound_label
.width
;
921 height
= m_bound_label
.height
;
924 void wxListLineData::GetRect( wxRect
&rect
)
926 AssignRect( rect
, m_bound_all
);
929 long wxListLineData::IsHit( int x
, int y
)
931 wxListItemDataList::Node
*node
= m_items
.GetFirst();
934 wxListItemData
*item
= node
->GetData();
935 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
))
936 return wxLIST_HITTEST_ONITEMICON
;
937 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
))
938 return wxLIST_HITTEST_ONITEMLABEL
;
942 // if there is no icon or text = empty
943 if (IsInRect( x
, y
, m_bound_all
))
944 return wxLIST_HITTEST_ONITEMICON
;
949 void wxListLineData::InitItems( int num
)
951 for (int i
= 0; i
< num
; i
++)
952 m_items
.Append( new wxListItemData() );
955 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
957 wxListItemDataList::Node
*node
= m_items
.Item( index
);
960 wxListItemData
*item
= node
->GetData();
961 item
->SetItem( info
);
965 void wxListLineData::GetItem( int index
, wxListItem
&info
)
967 wxListItemDataList::Node
*node
= m_items
.Item( index
);
970 wxListItemData
*item
= node
->GetData();
971 item
->GetItem( info
);
975 wxString
wxListLineData::GetText(int index
) const
979 wxListItemDataList::Node
*node
= m_items
.Item( index
);
982 wxListItemData
*item
= node
->GetData();
989 void wxListLineData::SetText( int index
, const wxString s
)
991 wxListItemDataList::Node
*node
= m_items
.Item( index
);
994 wxListItemData
*item
= node
->GetData();
999 int wxListLineData::GetImage( int index
)
1001 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1004 wxListItemData
*item
= node
->GetData();
1005 return item
->GetImage();
1010 void wxListLineData::SetAttributes(wxDC
*dc
,
1011 const wxListItemAttr
*attr
,
1012 const wxColour
& colText
,
1016 // don't use foregroud colour for drawing highlighted items - this might
1017 // make them completely invisible (and there is no way to do bit
1018 // arithmetics on wxColour, unfortunately)
1019 if ( !hilight
&& attr
&& attr
->HasTextColour() )
1021 dc
->SetTextForeground(attr
->GetTextColour());
1025 dc
->SetTextForeground(colText
);
1028 if ( attr
&& attr
->HasFont() )
1030 dc
->SetFont(attr
->GetFont());
1038 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1042 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1043 wxCoord dev_w
= m_bound_all
.width
;
1044 wxCoord dev_h
= m_bound_all
.height
;
1046 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1049 wxWindow
*listctrl
= m_owner
->GetParent();
1051 // default foreground colour
1055 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1059 colText
= listctrl
->GetForegroundColour();
1063 wxFont font
= listctrl
->GetFont();
1065 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1066 // using SetAttributes() inside the loop), it will be trivial to
1067 // customize the subitems (in report mode) too.
1068 wxListItemData
*item
= m_items
.GetFirst()->GetData();
1069 wxListItemAttr
*attr
= item
->GetAttributes();
1070 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1072 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1073 if ( paintBG
|| hasBgCol
)
1077 dc
->SetBrush( * m_hilightBrush
);
1082 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1084 dc
->SetBrush( * wxWHITE_BRUSH
);
1087 dc
->SetPen( * wxTRANSPARENT_PEN
);
1088 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1089 m_bound_hilight
.width
, m_bound_hilight
.height
);
1092 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1094 if (m_mode
== wxLC_REPORT
)
1098 wxListItemData
*item
= node
->GetData();
1099 int x
= item
->GetX();
1100 if (item
->HasImage())
1103 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1104 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1105 x
+= item
->GetX() + 5;
1107 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1108 if (item
->HasText())
1110 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1112 dc
->DestroyClippingRegion();
1113 node
= node
->GetNext();
1120 wxListItemData
*item
= node
->GetData();
1121 if (item
->HasImage())
1123 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1125 if (item
->HasText())
1127 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1133 void wxListLineData::Hilight( bool on
)
1135 if (on
== m_hilighted
) return;
1138 m_owner
->SelectLine( this );
1140 m_owner
->DeselectLine( this );
1143 void wxListLineData::ReverseHilight( void )
1145 m_hilighted
= !m_hilighted
;
1147 m_owner
->SelectLine( this );
1149 m_owner
->DeselectLine( this );
1152 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1156 dc
->SetPen( * wxBLACK_PEN
);
1157 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1158 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1159 m_bound_hilight
.width
, m_bound_hilight
.height
);
1163 void wxListLineData::Draw( wxDC
*dc
)
1165 DoDraw( dc
, m_hilighted
, m_hilighted
);
1168 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1170 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1171 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1174 bool wxListLineData::IsHilighted( void )
1179 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1184 dest
.height
= height
;
1187 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1191 dest
.width
= source
.width
;
1192 dest
.height
= source
.height
;
1195 //-----------------------------------------------------------------------------
1196 // wxListHeaderWindow
1197 //-----------------------------------------------------------------------------
1199 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1201 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1202 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1203 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1204 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1207 wxListHeaderWindow::wxListHeaderWindow( void )
1209 m_owner
= (wxListMainWindow
*) NULL
;
1210 m_currentCursor
= (wxCursor
*) NULL
;
1211 m_resizeCursor
= (wxCursor
*) NULL
;
1212 m_isDragging
= FALSE
;
1215 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1216 const wxPoint
&pos
, const wxSize
&size
,
1217 long style
, const wxString
&name
) :
1218 wxWindow( win
, id
, pos
, size
, style
, name
)
1221 // m_currentCursor = wxSTANDARD_CURSOR;
1222 m_currentCursor
= (wxCursor
*) NULL
;
1223 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1224 m_isDragging
= FALSE
;
1227 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1230 wxListHeaderWindow::~wxListHeaderWindow( void )
1232 delete m_resizeCursor
;
1235 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1238 GtkStateType state
= GTK_STATE_NORMAL
;
1239 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1241 x
= dc
->XLOG2DEV( x
);
1243 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1244 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1246 const int m_corner
= 1;
1248 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1250 dc
->SetPen( *wxBLACK_PEN
);
1251 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1252 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1254 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1257 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1258 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1260 dc
->SetPen( *wxWHITE_PEN
);
1261 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1262 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1263 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1264 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1268 // shift the DC origin to match the position of the main window horz
1269 // scrollbar: this allows us to always use logical coords
1270 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1272 #if wxUSE_GENERIC_LIST_EXTENSIONS
1274 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1277 m_owner
->GetViewStart( &x
, NULL
);
1279 // account for the horz scrollbar offset
1280 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1281 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1284 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1287 wxClientDC
dc( this );
1289 wxPaintDC
dc( this );
1297 dc
.SetFont( GetFont() );
1299 // width and height of the entire header window
1301 GetClientSize( &w
, &h
);
1302 #if wxUSE_GENERIC_LIST_EXTENSIONS
1303 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1304 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1306 dc
.SetBackgroundMode(wxTRANSPARENT
);
1308 // do *not* use the listctrl colour for headers - one day we will have a
1309 // function to set it separately
1310 //dc.SetTextForeground( *wxBLACK );
1311 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1313 int x
= 1; // left of the header rect
1314 const int y
= 1; // top
1315 int numColumns
= m_owner
->GetColumnCount();
1317 for (int i
= 0; i
< numColumns
; i
++)
1319 m_owner
->GetColumn( i
, item
);
1320 int wCol
= item
.m_width
;
1321 int cw
= wCol
- 2; // the width of the rect to draw
1323 int xEnd
= x
+ wCol
;
1325 // VZ: no, draw it normally - this is better now as we allow resizing
1326 // of the last column as well
1328 // let the last column occupy all available space
1329 if ( i
== numColumns
- 1 )
1333 dc
.SetPen( *wxWHITE_PEN
);
1335 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1336 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1337 dc
.DrawText( item
.GetText(), x
+4, y
+3 );
1338 dc
.DestroyClippingRegion();
1347 void wxListHeaderWindow::DrawCurrent()
1349 int x1
= m_currentX
;
1351 ClientToScreen( &x1
, &y1
);
1353 int x2
= m_currentX
-1;
1355 m_owner
->GetClientSize( NULL
, &y2
);
1356 m_owner
->ClientToScreen( &x2
, &y2
);
1359 dc
.SetLogicalFunction( wxINVERT
);
1360 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1361 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1365 dc
.DrawLine( x1
, y1
, x2
, y2
);
1367 dc
.SetLogicalFunction( wxCOPY
);
1369 dc
.SetPen( wxNullPen
);
1370 dc
.SetBrush( wxNullBrush
);
1373 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1375 // we want to work with logical coords
1376 #if wxUSE_GENERIC_LIST_EXTENSIONS
1378 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1379 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1380 int x
= event
.GetX();
1381 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1382 int y
= event
.GetY();
1386 // we don't draw the line beyond our window, but we allow dragging it
1389 GetClientSize( &w
, NULL
);
1390 #if wxUSE_GENERIC_LIST_EXTENSIONS
1391 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1392 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1395 // erase the line if it was drawn
1396 if ( m_currentX
< w
)
1399 if (event
.ButtonUp())
1402 m_isDragging
= FALSE
;
1404 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1411 m_currentX
= m_minX
+ 7;
1413 // draw in the new location
1414 if ( m_currentX
< w
)
1418 else // not dragging
1421 bool hit_border
= FALSE
;
1423 // end of the current column
1426 // find the column where this event occured
1427 int countCol
= m_owner
->GetColumnCount();
1428 for (int j
= 0; j
< countCol
; j
++)
1430 xpos
+= m_owner
->GetColumnWidth( j
);
1433 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1435 // near the column border
1442 // inside the column
1449 if (event
.LeftDown())
1453 m_isDragging
= TRUE
;
1460 wxWindow
*parent
= GetParent();
1461 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1462 le
.SetEventObject( parent
);
1463 le
.m_col
= m_column
;
1464 parent
->GetEventHandler()->ProcessEvent( le
);
1467 else if (event
.Moving())
1472 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1473 m_currentCursor
= m_resizeCursor
;
1477 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1478 m_currentCursor
= wxSTANDARD_CURSOR
;
1482 SetCursor(*m_currentCursor
);
1487 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1489 m_owner
->SetFocus();
1492 //-----------------------------------------------------------------------------
1493 // wxListRenameTimer (internal)
1494 //-----------------------------------------------------------------------------
1496 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1501 void wxListRenameTimer::Notify()
1503 m_owner
->OnRenameTimer();
1506 //-----------------------------------------------------------------------------
1507 // wxListTextCtrl (internal)
1508 //-----------------------------------------------------------------------------
1510 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1512 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1513 EVT_CHAR (wxListTextCtrl::OnChar
)
1514 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1515 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1518 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1519 const wxWindowID id
,
1522 wxListMainWindow
*owner
,
1523 const wxString
&value
,
1527 const wxValidator
& validator
,
1528 const wxString
&name
)
1529 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1534 (*m_accept
) = FALSE
;
1536 m_startValue
= value
;
1539 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1541 if (event
.m_keyCode
== WXK_RETURN
)
1544 (*m_res
) = GetValue();
1546 if (!wxPendingDelete
.Member(this))
1547 wxPendingDelete
.Append(this);
1549 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1550 m_owner
->OnRenameAccept();
1554 if (event
.m_keyCode
== WXK_ESCAPE
)
1556 (*m_accept
) = FALSE
;
1559 if (!wxPendingDelete
.Member(this))
1560 wxPendingDelete
.Append(this);
1568 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1570 // auto-grow the textctrl:
1571 wxSize parentSize
= m_owner
->GetSize();
1572 wxPoint myPos
= GetPosition();
1573 wxSize mySize
= GetSize();
1575 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1576 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1577 if (mySize
.x
> sx
) sx
= mySize
.x
;
1583 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1585 if (!wxPendingDelete
.Member(this))
1586 wxPendingDelete
.Append(this);
1588 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1589 m_owner
->OnRenameAccept();
1592 //-----------------------------------------------------------------------------
1594 //-----------------------------------------------------------------------------
1596 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1598 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1599 EVT_PAINT (wxListMainWindow::OnPaint
)
1600 EVT_SIZE (wxListMainWindow::OnSize
)
1601 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1602 EVT_CHAR (wxListMainWindow::OnChar
)
1603 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1604 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1605 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1606 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1609 wxListMainWindow::wxListMainWindow()
1612 m_columns
.DeleteContents( TRUE
);
1613 m_current
= (wxListLineData
*) NULL
;
1615 m_hilightBrush
= (wxBrush
*) NULL
;
1619 m_small_image_list
= (wxImageList
*) NULL
;
1620 m_normal_image_list
= (wxImageList
*) NULL
;
1621 m_small_spacing
= 30;
1622 m_normal_spacing
= 40;
1625 m_lastOnSame
= FALSE
;
1626 m_renameTimer
= new wxListRenameTimer( this );
1627 m_isCreated
= FALSE
;
1631 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1634 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1635 const wxPoint
&pos
, const wxSize
&size
,
1636 long style
, const wxString
&name
) :
1637 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1640 m_columns
.DeleteContents( TRUE
);
1641 m_current
= (wxListLineData
*) NULL
;
1644 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1645 m_small_image_list
= (wxImageList
*) NULL
;
1646 m_normal_image_list
= (wxImageList
*) NULL
;
1647 m_small_spacing
= 30;
1648 m_normal_spacing
= 40;
1651 m_isCreated
= FALSE
;
1655 if (m_mode
& wxLC_REPORT
)
1657 #if wxUSE_GENERIC_LIST_EXTENSIONS
1669 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1672 m_lastOnSame
= FALSE
;
1673 m_renameTimer
= new wxListRenameTimer( this );
1674 m_renameAccept
= FALSE
;
1676 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1679 wxListMainWindow::~wxListMainWindow()
1683 if (m_hilightBrush
) delete m_hilightBrush
;
1685 delete m_renameTimer
;
1688 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1690 if (m_dirty
) return;
1698 line
->GetExtent( x
, y
, w
, h
);
1699 CalcScrolledPosition( x
, y
, &x
, &y
);
1700 wxRect
rect( x
, y
, w
, h
);
1701 Refresh( TRUE
, &rect
);
1704 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1706 // Note: a wxPaintDC must be constructed even if no drawing is
1707 // done (a Windows requirement).
1708 wxPaintDC
dc( this );
1712 // postpone redrawing until the next OnIdle() call to minimize flicker
1719 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
1721 if (m_lines
.GetCount() == 0)
1723 // empty control. nothing to draw
1729 dc
.SetFont( GetFont() );
1731 if (m_mode
& wxLC_REPORT
)
1733 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1734 wxSize clientSize
= GetClientSize();
1736 int lineSpacing
= 0;
1737 wxListLineData
*line
= &m_lines
[0];
1739 line
->GetSize( dummy
, lineSpacing
);
1742 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1744 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1745 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1747 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1749 m_lines
[i
].Draw( &dc
);
1750 // Draw horizontal rule if required
1751 if (m_mode
& wxLC_HRULES
)
1754 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1755 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1759 // Draw last horizontal rule
1760 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (m_mode
& wxLC_HRULES
))
1763 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1764 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1767 // Draw vertical rules if required
1768 if ((m_mode
& wxLC_VRULES
) && (GetItemCount() > 0))
1771 wxRect firstItemRect
;
1772 wxRect lastItemRect
;
1773 GetItemRect(0, firstItemRect
);
1774 GetItemRect(GetItemCount() - 1, lastItemRect
);
1775 int x
= firstItemRect
.GetX();
1777 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1778 for (col
= 0; col
< GetColumnCount(); col
++)
1780 int colWidth
= GetColumnWidth(col
);
1782 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
, x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
1786 else // !report mode
1788 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1789 m_lines
[i
].Draw( &dc
);
1793 m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1798 void wxListMainWindow::HilightAll( bool on
)
1800 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1802 wxListLineData
*line
= &m_lines
[i
];
1803 if (line
->IsHilighted() != on
)
1805 line
->Hilight( on
);
1806 RefreshLine( line
);
1811 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1812 wxEventType command
,
1815 wxListEvent
le( command
, GetParent()->GetId() );
1816 le
.SetEventObject( GetParent() );
1817 le
.m_itemIndex
= GetIndexOfLine( line
);
1819 // set only for events which have position
1820 if ( point
!= wxDefaultPosition
)
1821 le
.m_pointDrag
= point
;
1823 line
->GetItem( 0, le
.m_item
);
1824 GetParent()->GetEventHandler()->ProcessEvent( le
);
1825 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1828 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1830 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1833 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1835 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1838 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1840 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1843 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1845 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1848 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1850 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1855 void wxListMainWindow::EditLabel( long item
)
1857 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1858 wxT("wrong index in wxListCtrl::Edit()") );
1860 m_currentEdit
= &m_lines
[(size_t)item
];
1862 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1863 le
.SetEventObject( GetParent() );
1864 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1865 m_currentEdit
->GetItem( 0, le
.m_item
);
1866 GetParent()->GetEventHandler()->ProcessEvent( le
);
1868 if (!le
.IsAllowed())
1871 // We have to call this here because the label in
1872 // question might just have been added and no screen
1873 // update taken place.
1874 if (m_dirty
) wxYield();
1876 wxString s
= m_currentEdit
->GetText(0);
1881 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1883 wxClientDC
dc(this);
1885 x
= dc
.LogicalToDeviceX( x
);
1886 y
= dc
.LogicalToDeviceY( y
);
1888 wxListTextCtrl
*text
= new wxListTextCtrl(
1889 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1893 void wxListMainWindow::OnRenameTimer()
1895 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1897 Edit( m_lines
.Index( *m_current
) );
1900 void wxListMainWindow::OnRenameAccept()
1902 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1903 le
.SetEventObject( GetParent() );
1904 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1905 m_currentEdit
->GetItem( 0, le
.m_item
);
1906 le
.m_item
.m_text
= m_renameRes
;
1907 GetParent()->GetEventHandler()->ProcessEvent( le
);
1909 if (!le
.IsAllowed()) return;
1912 info
.m_mask
= wxLIST_MASK_TEXT
;
1913 info
.m_itemId
= le
.m_itemIndex
;
1914 info
.m_text
= m_renameRes
;
1915 info
.SetTextColour(le
.m_item
.GetTextColour());
1919 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1921 event
.SetEventObject( GetParent() );
1922 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1924 if (!m_current
) return;
1925 if (m_dirty
) return;
1926 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1928 int x
= event
.GetX();
1929 int y
= event
.GetY();
1930 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1932 /* Did we actually hit an item ? */
1934 wxListLineData
*line
= (wxListLineData
*) NULL
;
1935 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1938 hitResult
= line
->IsHit( x
, y
);
1939 if (hitResult
) break;
1940 line
= (wxListLineData
*) NULL
;
1943 if (event
.Dragging())
1945 if (m_dragCount
== 0)
1946 m_dragStart
= wxPoint(x
,y
);
1950 if (m_dragCount
!= 3) return;
1952 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1953 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1955 wxListEvent
le( command
, GetParent()->GetId() );
1956 le
.SetEventObject( GetParent() );
1957 le
.m_pointDrag
= m_dragStart
;
1958 GetParent()->GetEventHandler()->ProcessEvent( le
);
1969 bool forceClick
= FALSE
;
1970 if (event
.ButtonDClick())
1972 m_renameTimer
->Stop();
1973 m_lastOnSame
= FALSE
;
1975 if ( line
== m_lineBeforeLastClicked
)
1979 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1985 // the first click was on another item, so don't interpret this as
1986 // a double click, but as a simple click instead
1991 if (event
.LeftUp() && m_lastOnSame
)
1994 if ((line
== m_current
) &&
1995 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1996 (m_mode
& wxLC_EDIT_LABELS
) )
1998 m_renameTimer
->Start( 100, TRUE
);
2000 m_lastOnSame
= FALSE
;
2004 if (event
.RightDown())
2006 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2007 event
.GetPosition() );
2011 if (event
.MiddleDown())
2013 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2017 if ( event
.LeftDown() || forceClick
)
2019 m_lineBeforeLastClicked
= m_lineLastClicked
;
2020 m_lineLastClicked
= line
;
2023 wxListLineData
*oldCurrent
= m_current
;
2024 if (m_mode
& wxLC_SINGLE_SEL
)
2027 HilightAll( FALSE
);
2028 m_current
->ReverseHilight();
2029 RefreshLine( m_current
);
2033 if (event
.ControlDown())
2036 m_current
->ReverseHilight();
2037 RefreshLine( m_current
);
2039 else if (event
.ShiftDown())
2045 int numOfCurrent
= -1;
2046 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2048 wxListLineData
*test_line
= &m_lines
[j
];
2050 if (test_line
== oldCurrent
) break;
2055 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2057 wxListLineData
*test_line
= &m_lines
[j
];
2059 if (test_line
== line
) break;
2062 if (numOfLine
< numOfCurrent
)
2065 numOfLine
= numOfCurrent
;
2069 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2071 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2072 test_line
->Hilight(TRUE
);
2073 RefreshLine( test_line
);
2079 HilightAll( FALSE
);
2080 m_current
->ReverseHilight();
2081 RefreshLine( m_current
);
2084 if (m_current
!= oldCurrent
)
2086 RefreshLine( oldCurrent
);
2087 UnfocusLine( oldCurrent
);
2088 FocusLine( m_current
);
2091 // forceClick is only set if the previous click was on another item
2092 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2098 void wxListMainWindow::MoveToFocus()
2100 if (!m_current
) return;
2106 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2110 GetClientSize( &client_w
, &client_h
);
2112 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2113 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2115 if (m_mode
& wxLC_REPORT
)
2117 if (item_y
< view_y
)
2118 Scroll( -1, (item_y
)/m_yScroll
);
2119 if (item_y
+item_h
+5 > view_y
+client_h
)
2120 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2124 if (item_x
-view_x
< 5)
2125 Scroll( (item_x
-5)/m_xScroll
, -1 );
2126 if (item_x
+item_w
-5 > view_x
+client_w
)
2127 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2131 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2133 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2134 wxListLineData
*oldCurrent
= m_current
;
2135 m_current
= newCurrent
;
2136 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2137 RefreshLine( m_current
);
2138 RefreshLine( oldCurrent
);
2139 FocusLine( m_current
);
2140 UnfocusLine( oldCurrent
);
2144 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2146 wxWindow
*parent
= GetParent();
2148 /* we propagate the key event up */
2149 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2150 ke
.m_shiftDown
= event
.m_shiftDown
;
2151 ke
.m_controlDown
= event
.m_controlDown
;
2152 ke
.m_altDown
= event
.m_altDown
;
2153 ke
.m_metaDown
= event
.m_metaDown
;
2154 ke
.m_keyCode
= event
.m_keyCode
;
2157 ke
.SetEventObject( parent
);
2158 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2163 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2165 wxWindow
*parent
= GetParent();
2167 /* we send a list_key event up */
2170 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2171 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2172 m_current
->GetItem( 0, le
.m_item
);
2173 le
.m_code
= (int)event
.KeyCode();
2174 le
.SetEventObject( parent
);
2175 parent
->GetEventHandler()->ProcessEvent( le
);
2178 /* we propagate the char event up */
2179 wxKeyEvent
ke( wxEVT_CHAR
);
2180 ke
.m_shiftDown
= event
.m_shiftDown
;
2181 ke
.m_controlDown
= event
.m_controlDown
;
2182 ke
.m_altDown
= event
.m_altDown
;
2183 ke
.m_metaDown
= event
.m_metaDown
;
2184 ke
.m_keyCode
= event
.m_keyCode
;
2187 ke
.SetEventObject( parent
);
2188 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2190 if (event
.KeyCode() == WXK_TAB
)
2192 wxNavigationKeyEvent nevent
;
2193 nevent
.SetWindowChange( event
.ControlDown() );
2194 nevent
.SetDirection( !event
.ShiftDown() );
2195 nevent
.SetEventObject( GetParent()->GetParent() );
2196 nevent
.SetCurrentFocus( m_parent
);
2197 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2200 /* no item -> nothing to do */
2207 switch (event
.KeyCode())
2211 int index
= m_lines
.Index(*m_current
);
2212 if (index
!= wxNOT_FOUND
&& index
> 0)
2213 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2218 int index
= m_lines
.Index(*m_current
);
2219 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2220 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2225 if (!m_lines
.IsEmpty())
2226 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2231 if (!m_lines
.IsEmpty())
2232 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2238 int index
= m_lines
.Index(*m_current
);
2239 if (m_mode
& wxLC_REPORT
)
2241 steps
= m_visibleLines
-1;
2245 steps
= index
% m_visibleLines
;
2247 if (index
!= wxNOT_FOUND
)
2250 if (index
< 0) index
= 0;
2251 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2258 int index
= m_lines
.Index(*m_current
);
2259 if (m_mode
& wxLC_REPORT
)
2261 steps
= m_visibleLines
-1;
2265 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2268 if (index
!= wxNOT_FOUND
)
2271 if ((size_t)index
>= m_lines
.GetCount())
2272 index
= m_lines
.GetCount()-1;
2273 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2279 if (!(m_mode
& wxLC_REPORT
))
2281 int index
= m_lines
.Index(*m_current
);
2282 if (index
!= wxNOT_FOUND
)
2284 index
-= m_visibleLines
;
2285 if (index
< 0) index
= 0;
2286 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2293 if (!(m_mode
& wxLC_REPORT
))
2295 int index
= m_lines
.Index(*m_current
);
2296 if (index
!= wxNOT_FOUND
)
2298 index
+= m_visibleLines
;
2299 if ((size_t)index
>= m_lines
.GetCount())
2300 index
= m_lines
.GetCount()-1;
2301 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2308 if (m_mode
& wxLC_SINGLE_SEL
)
2310 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2311 le
.SetEventObject( GetParent() );
2312 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2313 m_current
->GetItem( 0, le
.m_item
);
2314 GetParent()->GetEventHandler()->ProcessEvent( le
);
2318 m_current
->ReverseHilight();
2319 RefreshLine( m_current
);
2325 if (!(m_mode
& wxLC_SINGLE_SEL
))
2327 wxListLineData
*oldCurrent
= m_current
;
2328 m_current
->ReverseHilight();
2329 int index
= m_lines
.Index( *m_current
) + 1;
2330 if ( (size_t)index
< m_lines
.GetCount() )
2331 m_current
= &m_lines
[index
];
2332 RefreshLine( oldCurrent
);
2333 RefreshLine( m_current
);
2334 UnfocusLine( oldCurrent
);
2335 FocusLine( m_current
);
2343 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2344 le
.SetEventObject( GetParent() );
2345 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2346 m_current
->GetItem( 0, le
.m_item
);
2347 GetParent()->GetEventHandler()->ProcessEvent( le
);
2360 extern wxWindow
*g_focusWindow
;
2363 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2366 RefreshLine( m_current
);
2368 if (!GetParent()) return;
2371 g_focusWindow
= GetParent();
2374 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2375 event
.SetEventObject( GetParent() );
2376 GetParent()->GetEventHandler()->ProcessEvent( event
);
2379 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2382 RefreshLine( m_current
);
2385 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2388 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2394 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2396 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2398 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2401 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2403 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2405 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2407 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2409 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2411 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2416 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2418 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2420 m_normal_image_list
->GetSize( index
, width
, height
);
2423 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2425 m_small_image_list
->GetSize( index
, width
, height
);
2428 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2430 m_small_image_list
->GetSize( index
, width
, height
);
2433 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2435 m_small_image_list
->GetSize( index
, width
, height
);
2442 int wxListMainWindow::GetTextLength( wxString
&s
)
2444 wxClientDC
dc( this );
2447 dc
.GetTextExtent( s
, &lw
, &lh
);
2451 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2453 int i
= m_lines
.Index(*line
);
2454 if (i
== wxNOT_FOUND
) return -1;
2458 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2462 // calc the spacing from the icon size
2465 if ((imageList
) && (imageList
->GetImageCount()) )
2467 imageList
->GetSize(0, width
, height
);
2470 if (which
== wxIMAGE_LIST_NORMAL
)
2472 m_normal_image_list
= imageList
;
2473 m_normal_spacing
= width
+ 8;
2476 if (which
== wxIMAGE_LIST_SMALL
)
2478 m_small_image_list
= imageList
;
2479 m_small_spacing
= width
+ 14;
2483 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2488 m_small_spacing
= spacing
;
2492 m_normal_spacing
= spacing
;
2496 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2498 return isSmall
? m_small_spacing
: m_normal_spacing
;
2501 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2504 wxNode
*node
= m_columns
.Nth( col
);
2507 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2508 item
.m_width
= GetTextLength( item
.m_text
)+7;
2509 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2510 column
->SetItem( item
);
2513 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2515 headerWin
->m_dirty
= TRUE
;
2518 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2520 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2521 _T("SetColumnWidth() can only be called in report mode.") );
2525 wxNode
*node
= (wxNode
*) NULL
;
2527 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2529 // TODO do use the header
2532 else if (width
== wxLIST_AUTOSIZE
)
2534 wxClientDC
dc(this);
2535 dc
.SetFont( GetFont() );
2538 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2540 wxListLineData
*line
= &m_lines
[i
];
2541 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2544 wxListItemData
*item
= n
->GetData();
2545 int current
= 0, ix
= 0, iy
= 0;
2546 wxCoord lx
= 0, ly
= 0;
2547 if (item
->HasImage())
2549 GetImageSize( item
->GetImage(), ix
, iy
);
2552 if (item
->HasText())
2554 wxString str
= item
->GetText();
2555 dc
.GetTextExtent( str
, &lx
, &ly
);
2565 node
= m_columns
.Nth( col
);
2568 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2569 column
->SetWidth( width
);
2572 size_t count
= m_lines
.GetCount();
2573 for (size_t i
= 0; i
< count
; i
++)
2575 wxListLineData
*line
= &m_lines
[i
];
2576 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2579 wxListItemData
*item
= n
->GetData();
2580 item
->SetSize( width
, -1 );
2584 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2586 headerWin
->m_dirty
= TRUE
;
2589 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2591 wxNode
*node
= m_columns
.Nth( col
);
2594 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2595 column
->GetItem( item
);
2601 item
.m_text
= _T("");
2607 int wxListMainWindow::GetColumnWidth( int col
)
2609 wxNode
*node
= m_columns
.Nth( col
);
2612 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2613 return column
->GetWidth();
2621 int wxListMainWindow::GetColumnCount()
2623 return m_columns
.Number();
2626 int wxListMainWindow::GetCountPerPage()
2628 return m_visibleLines
;
2631 void wxListMainWindow::SetItem( wxListItem
&item
)
2634 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2636 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2637 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2638 line
->SetItem( item
.m_col
, item
);
2642 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2644 wxCHECK_RET( item
>= 0 && (size_t)item
< m_lines
.GetCount(),
2645 _T("invalid list ctrl item index in SetItem") );
2647 // m_dirty = TRUE; no recalcs needed
2649 wxListLineData
*oldCurrent
= m_current
;
2651 if ( stateMask
& wxLIST_STATE_FOCUSED
)
2653 wxListLineData
*line
= &m_lines
[(size_t)item
];
2654 if ( state
& wxLIST_STATE_FOCUSED
)
2656 // don't do anything if this item is already focused
2657 if ( line
!= m_current
)
2659 UnfocusLine( m_current
);
2661 FocusLine( m_current
);
2662 if ( (m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
)
2663 oldCurrent
->Hilight( FALSE
);
2665 RefreshLine( m_current
);
2667 RefreshLine( oldCurrent
);
2672 // don't do anything if this item is not focused
2673 if ( line
== m_current
)
2675 UnfocusLine( m_current
);
2681 if ( stateMask
& wxLIST_STATE_SELECTED
)
2683 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2684 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
))
2687 wxListLineData
*line
= &m_lines
[(size_t)item
];
2688 if (m_mode
& wxLC_SINGLE_SEL
)
2690 UnfocusLine( m_current
);
2692 FocusLine( m_current
);
2694 oldCurrent
->Hilight( FALSE
);
2695 RefreshLine( m_current
);
2697 RefreshLine( oldCurrent
);
2700 if (on
!= line
->IsHilighted())
2702 line
->Hilight( on
);
2703 RefreshLine( line
);
2708 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2710 int ret
= wxLIST_STATE_DONTCARE
;
2711 if (stateMask
& wxLIST_STATE_FOCUSED
)
2713 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2715 wxListLineData
*line
= &m_lines
[(size_t)item
];
2716 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2719 if (stateMask
& wxLIST_STATE_SELECTED
)
2721 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2723 wxListLineData
*line
= &m_lines
[(size_t)item
];
2724 if (line
->IsHilighted()) ret
|= wxLIST_STATE_SELECTED
;
2730 void wxListMainWindow::GetItem( wxListItem
&item
)
2732 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2734 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2735 line
->GetItem( item
.m_col
, item
);
2740 item
.m_text
= _T("");
2746 int wxListMainWindow::GetItemCount()
2748 return m_lines
.GetCount();
2751 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2753 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2755 m_lines
[(size_t)index
].GetRect( rect
);
2756 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2767 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2770 this->GetItemRect(item
,rect
);
2771 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2775 int wxListMainWindow::GetSelectedItemCount()
2778 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2780 if (m_lines
[i
].IsHilighted()) ret
++;
2785 void wxListMainWindow::SetMode( long mode
)
2792 if (m_mode
& wxLC_REPORT
)
2794 #if wxUSE_GENERIC_LIST_EXTENSIONS
2808 long wxListMainWindow::GetMode() const
2813 void wxListMainWindow::CalculatePositions()
2815 if (m_lines
.IsEmpty()) return;
2817 wxClientDC
dc( this );
2818 dc
.SetFont( GetFont() );
2820 int iconSpacing
= 0;
2821 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2822 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2824 // we take the first line (which also can be an icon or
2825 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2826 // measure the size of the line
2830 int lineSpacing
= 0;
2832 wxListLineData
*line
= &m_lines
[0];
2833 line
->CalculateSize( &dc
, iconSpacing
);
2835 line
->GetSize( dummy
, lineSpacing
);
2838 int clientWidth
= 0;
2839 int clientHeight
= 0;
2841 if (m_mode
& wxLC_REPORT
)
2843 // scroll one line per step
2844 m_yScroll
= lineSpacing
;
2848 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2849 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2850 #if wxUSE_GENERIC_LIST_EXTENSIONS
2851 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2853 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2855 GetClientSize( &clientWidth
, &clientHeight
);
2857 int entireWidth
= 0 ;
2858 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2860 wxListLineData
*line
= &m_lines
[j
];
2861 line
->CalculateSize( &dc
, iconSpacing
);
2862 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2864 for (int i
= 0; i
< GetColumnCount(); i
++)
2866 line
->SetColumnPosition( i
, col_x
);
2867 col_x
+= GetColumnWidth( i
);
2869 entireWidth
= wxMax( entireWidth
, col_x
) ;
2870 #if wxUSE_GENERIC_LIST_EXTENSIONS
2871 line
->SetPosition( &dc
, x
, y
, col_x
);
2873 y
+= lineSpacing
; // one pixel blank line between items
2875 m_visibleLines
= clientHeight
/ lineSpacing
;
2876 #if wxUSE_GENERIC_LIST_EXTENSIONS
2877 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2882 // at first we try without any scrollbar. if the items don't
2883 // fit into the window, we recalculate after subtracting an
2884 // approximated 15 pt for the horizontal scrollbar
2886 GetSize( &clientWidth
, &clientHeight
);
2887 clientHeight
-= 4; // sunken frame
2889 int entireWidth
= 0;
2891 for (int tries
= 0; tries
< 2; tries
++)
2898 int m_currentVisibleLines
= 0;
2899 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2901 m_currentVisibleLines
++;
2902 wxListLineData
*line
= &m_lines
[i
];
2903 line
->CalculateSize( &dc
, iconSpacing
);
2904 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2905 line
->GetSize( lineWidth
, lineHeight
);
2906 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2908 if (m_currentVisibleLines
> m_visibleLines
)
2909 m_visibleLines
= m_currentVisibleLines
;
2910 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2912 m_currentVisibleLines
= 0;
2915 entireWidth
+= maxWidth
+6;
2918 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2919 if ((tries
== 0) && (entireWidth
> clientWidth
))
2921 clientHeight
-= 15; // scrollbar height
2923 m_currentVisibleLines
= 0;
2926 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2930 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2931 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2935 void wxListMainWindow::RealizeChanges()
2939 if (!m_lines
.IsEmpty())
2940 m_current
= &m_lines
[0];
2944 FocusLine( m_current
);
2945 // TODO: MSW doesn't automatically hilight the
2947 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2951 long wxListMainWindow::GetNextItem( long item
,
2952 int WXUNUSED(geometry
),
2956 max
= GetItemCount();
2957 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2958 _T("invalid listctrl index in GetNextItem()") );
2960 // notice that we start with the next item (or the first one if item == -1)
2961 // and this is intentional to allow writing a simple loop to iterate over
2962 // all selected items
2966 // this is not an error because the index was ok initially, just no
2971 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2973 wxListLineData
*line
= &m_lines
[i
];
2974 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2976 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2986 void wxListMainWindow::DeleteItem( long index
)
2989 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2991 wxListLineData
*line
= &m_lines
[(size_t)index
];
2992 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2994 m_lines
.RemoveAt( (size_t)index
);
2998 void wxListMainWindow::DeleteColumn( int col
)
3000 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
3001 wxT("attempting to delete inexistent column in wxListView") );
3004 wxNode
*node
= m_columns
.Nth( col
);
3005 if (node
) m_columns
.DeleteNode( node
);
3008 void wxListMainWindow::DeleteAllItems()
3011 m_current
= (wxListLineData
*) NULL
;
3013 // to make the deletion of all items faster, we don't send the
3014 // notifications in this case: this is compatible with wxMSW and
3015 // documented in DeleteAllItems() description
3017 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3018 event
.SetEventObject( GetParent() );
3019 GetParent()->GetEventHandler()->ProcessEvent( event
);
3024 void wxListMainWindow::DeleteEverything()
3031 void wxListMainWindow::EnsureVisible( long index
)
3033 // We have to call this here because the label in
3034 // question might just have been added and no screen
3035 // update taken place.
3036 if (m_dirty
) wxYield();
3038 wxListLineData
*oldCurrent
= m_current
;
3039 m_current
= (wxListLineData
*) NULL
;
3040 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
3041 m_current
= &m_lines
[(size_t)index
];
3042 if (m_current
) MoveToFocus();
3043 m_current
= oldCurrent
;
3046 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3050 if (pos
< 0) pos
= 0;
3051 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3053 wxListLineData
*line
= &m_lines
[i
];
3054 wxString s
= line
->GetText(0);
3063 long wxListMainWindow::FindItem(long start
, long data
)
3066 if (pos
< 0) pos
= 0;
3067 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3069 wxListLineData
*line
= &m_lines
[i
];
3071 line
->GetItem( 0, item
);
3072 if (item
.m_data
== data
) return pos
;
3078 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3080 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3083 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3085 wxListLineData
*line
= &m_lines
[i
];
3086 long ret
= line
->IsHit( x
, y
);
3087 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3097 void wxListMainWindow::InsertItem( wxListItem
&item
)
3101 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3102 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3103 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3104 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3106 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3108 if (m_mode
& wxLC_REPORT
)
3110 line
->InitItems( GetColumnCount() );
3111 item
.m_width
= GetColumnWidth( 0 )-3;
3115 line
->InitItems( 1 );
3118 line
->SetItem( 0, item
);
3119 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3121 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3125 m_lines
.Add( line
);
3126 item
.m_itemId
= m_lines
.GetCount()-1;
3130 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3133 if (m_mode
& wxLC_REPORT
)
3135 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3136 item
.m_width
= GetTextLength( item
.m_text
);
3137 wxListHeaderData
*column
= new wxListHeaderData( item
);
3138 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3140 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3142 m_columns
.Insert( node
, column
);
3146 m_columns
.Append( column
);
3151 wxListCtrlCompare list_ctrl_compare_func_2
;
3152 long list_ctrl_compare_data
;
3154 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3156 wxListLineData
*line1
= *arg1
;
3157 wxListLineData
*line2
= *arg2
;
3159 line1
->GetItem( 0, item
);
3160 long data1
= item
.m_data
;
3161 line2
->GetItem( 0, item
);
3162 long data2
= item
.m_data
;
3163 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3166 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3168 list_ctrl_compare_func_2
= fn
;
3169 list_ctrl_compare_data
= data
;
3170 m_lines
.Sort( list_ctrl_compare_func_1
);
3174 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3177 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
3178 wxScrolledWindow::OnScroll(event
);
3180 HandleOnScroll( event
);
3183 #if wxUSE_GENERIC_LIST_EXTENSIONS
3185 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3187 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3190 lc
->m_headerWin
->Refresh() ;
3192 lc
->m_headerWin
->MacUpdateImmediately() ;
3199 // -------------------------------------------------------------------------------------
3201 // -------------------------------------------------------------------------------------
3203 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3205 wxListItem::wxListItem()
3214 m_format
= wxLIST_FORMAT_CENTRE
;
3220 void wxListItem::Clear()
3229 m_format
= wxLIST_FORMAT_CENTRE
;
3233 if (m_attr
) delete m_attr
;
3237 void wxListItem::ClearAttributes()
3239 if (m_attr
) delete m_attr
;
3243 // -------------------------------------------------------------------------------------
3245 // -------------------------------------------------------------------------------------
3247 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3249 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3250 wxNotifyEvent( commandType
, id
)
3256 m_cancelled
= FALSE
;
3261 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3263 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3265 wxNotifyEvent::CopyObject(object_dest
);
3267 obj
->m_code
= m_code
;
3268 obj
->m_itemIndex
= m_itemIndex
;
3269 obj
->m_oldItemIndex
= m_oldItemIndex
;
3271 obj
->m_cancelled
= m_cancelled
;
3272 obj
->m_pointDrag
= m_pointDrag
;
3273 obj
->m_item
.m_mask
= m_item
.m_mask
;
3274 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3275 obj
->m_item
.m_col
= m_item
.m_col
;
3276 obj
->m_item
.m_state
= m_item
.m_state
;
3277 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3278 obj
->m_item
.m_text
= m_item
.m_text
;
3279 obj
->m_item
.m_image
= m_item
.m_image
;
3280 obj
->m_item
.m_data
= m_item
.m_data
;
3281 obj
->m_item
.m_format
= m_item
.m_format
;
3282 obj
->m_item
.m_width
= m_item
.m_width
;
3284 if ( m_item
.HasAttributes() )
3286 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3290 // -------------------------------------------------------------------------------------
3292 // -------------------------------------------------------------------------------------
3294 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3296 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3297 EVT_SIZE (wxListCtrl::OnSize
)
3298 EVT_IDLE (wxListCtrl::OnIdle
)
3301 wxListCtrl::wxListCtrl()
3303 m_imageListNormal
= (wxImageList
*) NULL
;
3304 m_imageListSmall
= (wxImageList
*) NULL
;
3305 m_imageListState
= (wxImageList
*) NULL
;
3306 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3307 m_mainWin
= (wxListMainWindow
*) NULL
;
3308 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3311 wxListCtrl::~wxListCtrl()
3313 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3314 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3315 if (m_ownsImageListState
) delete m_imageListState
;
3318 bool wxListCtrl::Create(wxWindow
*parent
,
3323 const wxValidator
&validator
,
3324 const wxString
&name
)
3326 m_imageListNormal
= (wxImageList
*) NULL
;
3327 m_imageListSmall
= (wxImageList
*) NULL
;
3328 m_imageListState
= (wxImageList
*) NULL
;
3329 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3330 m_mainWin
= (wxListMainWindow
*) NULL
;
3331 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3333 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3335 style
= style
| wxLC_LIST
;
3338 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3341 if (style
& wxSUNKEN_BORDER
)
3342 style
-= wxSUNKEN_BORDER
;
3344 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3346 if (HasFlag(wxLC_REPORT
))
3348 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3349 if (HasFlag(wxLC_NO_HEADER
))
3350 m_headerWin
->Show( FALSE
);
3354 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3360 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3362 /* handled in OnIdle */
3364 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3367 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3369 long flag
= GetWindowStyle();
3373 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3374 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3375 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3384 if (flag
& style
) flag
-= style
;
3387 SetWindowStyleFlag( flag
);
3390 void wxListCtrl::SetWindowStyleFlag( long flag
)
3394 m_mainWin
->DeleteEverything();
3398 GetClientSize( &width
, &height
);
3400 m_mainWin
->SetMode( flag
);
3402 if (flag
& wxLC_REPORT
)
3404 if (!HasFlag(wxLC_REPORT
))
3408 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3409 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3410 if (HasFlag(wxLC_NO_HEADER
))
3411 m_headerWin
->Show( FALSE
);
3415 if (flag
& wxLC_NO_HEADER
)
3416 m_headerWin
->Show( FALSE
);
3418 m_headerWin
->Show( TRUE
);
3424 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3426 m_headerWin
->Show( FALSE
);
3431 wxWindow::SetWindowStyleFlag( flag
);
3434 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3436 m_mainWin
->GetColumn( col
, item
);
3440 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3442 m_mainWin
->SetColumn( col
, item
);
3446 int wxListCtrl::GetColumnWidth( int col
) const
3448 return m_mainWin
->GetColumnWidth( col
);
3451 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3453 m_mainWin
->SetColumnWidth( col
, width
);
3457 int wxListCtrl::GetCountPerPage() const
3459 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3462 bool wxListCtrl::GetItem( wxListItem
&info
) const
3464 m_mainWin
->GetItem( info
);
3468 bool wxListCtrl::SetItem( wxListItem
&info
)
3470 m_mainWin
->SetItem( info
);
3474 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3477 info
.m_text
= label
;
3478 info
.m_mask
= wxLIST_MASK_TEXT
;
3479 info
.m_itemId
= index
;
3483 info
.m_image
= imageId
;
3484 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3486 m_mainWin
->SetItem(info
);
3490 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3492 return m_mainWin
->GetItemState( item
, stateMask
);
3495 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3497 m_mainWin
->SetItemState( item
, state
, stateMask
);
3501 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3504 info
.m_image
= image
;
3505 info
.m_mask
= wxLIST_MASK_IMAGE
;
3506 info
.m_itemId
= item
;
3507 m_mainWin
->SetItem( info
);
3511 wxString
wxListCtrl::GetItemText( long item
) const
3514 info
.m_itemId
= item
;
3515 m_mainWin
->GetItem( info
);
3519 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3522 info
.m_mask
= wxLIST_MASK_TEXT
;
3523 info
.m_itemId
= item
;
3525 m_mainWin
->SetItem( info
);
3528 long wxListCtrl::GetItemData( long item
) const
3531 info
.m_itemId
= item
;
3532 m_mainWin
->GetItem( info
);
3536 bool wxListCtrl::SetItemData( long item
, long data
)
3539 info
.m_mask
= wxLIST_MASK_DATA
;
3540 info
.m_itemId
= item
;
3542 m_mainWin
->SetItem( info
);
3546 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3548 m_mainWin
->GetItemRect( item
, rect
);
3552 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3554 m_mainWin
->GetItemPosition( item
, pos
);
3558 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3563 int wxListCtrl::GetItemCount() const
3565 return m_mainWin
->GetItemCount();
3568 int wxListCtrl::GetColumnCount() const
3570 return m_mainWin
->GetColumnCount();
3573 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3575 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3578 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3580 return m_mainWin
->GetItemSpacing( isSmall
);
3583 int wxListCtrl::GetSelectedItemCount() const
3585 return m_mainWin
->GetSelectedItemCount();
3588 wxColour
wxListCtrl::GetTextColour() const
3590 return GetForegroundColour();
3593 void wxListCtrl::SetTextColour(const wxColour
& col
)
3595 SetForegroundColour(col
);
3598 long wxListCtrl::GetTopItem() const
3603 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3605 return m_mainWin
->GetNextItem( item
, geom
, state
);
3608 wxImageList
*wxListCtrl::GetImageList(int which
) const
3610 if (which
== wxIMAGE_LIST_NORMAL
)
3612 return m_imageListNormal
;
3614 else if (which
== wxIMAGE_LIST_SMALL
)
3616 return m_imageListSmall
;
3618 else if (which
== wxIMAGE_LIST_STATE
)
3620 return m_imageListState
;
3622 return (wxImageList
*) NULL
;
3625 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3627 if ( which
== wxIMAGE_LIST_NORMAL
)
3629 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3630 m_imageListNormal
= imageList
;
3631 m_ownsImageListNormal
= FALSE
;
3633 else if ( which
== wxIMAGE_LIST_SMALL
)
3635 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3636 m_imageListSmall
= imageList
;
3637 m_ownsImageListSmall
= FALSE
;
3639 else if ( which
== wxIMAGE_LIST_STATE
)
3641 if (m_ownsImageListState
) delete m_imageListState
;
3642 m_imageListState
= imageList
;
3643 m_ownsImageListState
= FALSE
;
3646 m_mainWin
->SetImageList( imageList
, which
);
3649 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3651 SetImageList(imageList
, which
);
3652 if ( which
== wxIMAGE_LIST_NORMAL
)
3653 m_ownsImageListNormal
= TRUE
;
3654 else if ( which
== wxIMAGE_LIST_SMALL
)
3655 m_ownsImageListSmall
= TRUE
;
3656 else if ( which
== wxIMAGE_LIST_STATE
)
3657 m_ownsImageListState
= TRUE
;
3660 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3665 bool wxListCtrl::DeleteItem( long item
)
3667 m_mainWin
->DeleteItem( item
);
3671 bool wxListCtrl::DeleteAllItems()
3673 m_mainWin
->DeleteAllItems();
3677 bool wxListCtrl::DeleteAllColumns()
3679 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3685 void wxListCtrl::ClearAll()
3687 m_mainWin
->DeleteEverything();
3690 bool wxListCtrl::DeleteColumn( int col
)
3692 m_mainWin
->DeleteColumn( col
);
3696 void wxListCtrl::Edit( long item
)
3698 m_mainWin
->Edit( item
);
3701 bool wxListCtrl::EnsureVisible( long item
)
3703 m_mainWin
->EnsureVisible( item
);
3707 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3709 return m_mainWin
->FindItem( start
, str
, partial
);
3712 long wxListCtrl::FindItem( long start
, long data
)
3714 return m_mainWin
->FindItem( start
, data
);
3717 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3718 int WXUNUSED(direction
))
3723 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3725 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3728 long wxListCtrl::InsertItem( wxListItem
& info
)
3730 m_mainWin
->InsertItem( info
);
3731 return info
.m_itemId
;
3734 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3737 info
.m_text
= label
;
3738 info
.m_mask
= wxLIST_MASK_TEXT
;
3739 info
.m_itemId
= index
;
3740 return InsertItem( info
);
3743 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3746 info
.m_mask
= wxLIST_MASK_IMAGE
;
3747 info
.m_image
= imageIndex
;
3748 info
.m_itemId
= index
;
3749 return InsertItem( info
);
3752 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3755 info
.m_text
= label
;
3756 info
.m_image
= imageIndex
;
3757 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3758 info
.m_itemId
= index
;
3759 return InsertItem( info
);
3762 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3764 wxASSERT( m_headerWin
);
3765 m_mainWin
->InsertColumn( col
, item
);
3766 m_headerWin
->Refresh();
3771 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3772 int format
, int width
)
3775 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3776 item
.m_text
= heading
;
3779 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3780 item
.m_width
= width
;
3782 item
.m_format
= format
;
3784 return InsertColumn( col
, item
);
3787 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3793 // fn is a function which takes 3 long arguments: item1, item2, data.
3794 // item1 is the long data associated with a first item (NOT the index).
3795 // item2 is the long data associated with a second item (NOT the index).
3796 // data is the same value as passed to SortItems.
3797 // The return value is a negative number if the first item should precede the second
3798 // item, a positive number of the second item should precede the first,
3799 // or zero if the two items are equivalent.
3800 // data is arbitrary data to be passed to the sort function.
3802 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3804 m_mainWin
->SortItems( fn
, data
);
3808 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3810 if (!m_mainWin
->m_dirty
) return;
3814 GetClientSize( &cw
, &ch
);
3821 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3823 m_headerWin
->GetPosition( &x
, &y
);
3824 m_headerWin
->GetSize( &w
, &h
);
3825 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3826 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3828 m_mainWin
->GetPosition( &x
, &y
);
3829 m_mainWin
->GetSize( &w
, &h
);
3830 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3831 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3835 m_mainWin
->GetPosition( &x
, &y
);
3836 m_mainWin
->GetSize( &w
, &h
);
3837 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3838 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3841 m_mainWin
->CalculatePositions();
3842 m_mainWin
->RealizeChanges();
3843 m_mainWin
->m_dirty
= FALSE
;
3844 m_mainWin
->Refresh();
3846 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3848 m_headerWin
->m_dirty
= FALSE
;
3849 m_headerWin
->Refresh();
3853 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3857 m_mainWin
->SetBackgroundColour( colour
);
3858 m_mainWin
->m_dirty
= TRUE
;
3864 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3866 if ( !wxWindow::SetForegroundColour( colour
) )
3871 m_mainWin
->SetForegroundColour( colour
);
3872 m_mainWin
->m_dirty
= TRUE
;
3877 m_headerWin
->SetForegroundColour( colour
);
3883 bool wxListCtrl::SetFont( const wxFont
&font
)
3885 if ( !wxWindow::SetFont( font
) )
3890 m_mainWin
->SetFont( font
);
3891 m_mainWin
->m_dirty
= TRUE
;
3896 m_headerWin
->SetFont( font
);
3902 #if wxUSE_DRAG_AND_DROP
3904 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3906 m_mainWin
->SetDropTarget( dropTarget
);
3909 wxDropTarget
*wxListCtrl::GetDropTarget() const
3911 return m_mainWin
->GetDropTarget();
3914 #endif // wxUSE_DRAG_AND_DROP
3916 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3918 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3921 wxColour
wxListCtrl::GetBackgroundColour() const
3923 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3926 wxColour
wxListCtrl::GetForegroundColour() const
3928 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3931 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3934 return m_mainWin
->PopupMenu( menu
, x
, y
);
3937 #endif // wxUSE_MENUS
3940 void wxListCtrl::SetFocus()
3942 /* The test in window.cpp fails as we are a composite
3943 window, so it checks against "this", but not m_mainWin. */
3944 if ( FindFocus() != this )
3945 m_mainWin
->SetFocus();
3948 // ----------------------------------------------------------------------------
3949 // virtual list control support
3950 // ----------------------------------------------------------------------------
3952 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
3954 // this is a pure virtual function, in fact - which is not really pure
3955 // because the controls which are not virtual don't need to implement it
3956 wxFAIL_MSG( _T("not supposed to be called") );
3958 return wxEmptyString
;
3961 int wxListCtrl::OnGetItemImage(long item
) const
3964 wxFAIL_MSG( _T("not supposed to be called") );
3969 void wxListCtrl::SetItemCount(long count
)
3971 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
3973 m_mainWin
->SetItemCount(count
);
3976 #endif // wxUSE_LISTCTRL