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 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
318 #include "wx/listimpl.cpp"
319 WX_DEFINE_LIST(wxListHeaderDataList
);
321 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
325 wxListLineDataArray m_lines
;
326 wxListHeaderDataList m_columns
;
327 wxListLineData
*m_current
;
328 wxListLineData
*m_currentEdit
;
330 wxBrush
*m_hilightBrush
;
331 wxColour
*m_hilightColour
;
332 int m_xScroll
,m_yScroll
;
334 wxImageList
*m_small_image_list
;
335 wxImageList
*m_normal_image_list
;
337 int m_normal_spacing
;
341 wxTimer
*m_renameTimer
;
343 wxString m_renameRes
;
348 // for double click logic
349 wxListLineData
*m_lineLastClicked
,
350 *m_lineBeforeLastClicked
;
354 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
355 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
356 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
358 void RefreshLine( wxListLineData
*line
);
359 void OnPaint( wxPaintEvent
&event
);
360 void HilightAll( bool on
);
361 void SendNotify( wxListLineData
*line
,
363 wxPoint point
= wxDefaultPosition
);
364 void FocusLine( wxListLineData
*line
);
365 void UnfocusLine( wxListLineData
*line
);
366 void SelectLine( wxListLineData
*line
);
367 void DeselectLine( wxListLineData
*line
);
368 void DeleteLine( wxListLineData
*line
);
370 void EditLabel( long item
);
371 void Edit( long item
) { EditLabel(item
); } // deprecated
372 void OnRenameTimer();
373 void OnRenameAccept();
375 void OnMouse( wxMouseEvent
&event
);
377 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
378 void OnChar( wxKeyEvent
&event
);
379 void OnKeyDown( wxKeyEvent
&event
);
380 void OnSetFocus( wxFocusEvent
&event
);
381 void OnKillFocus( wxFocusEvent
&event
);
382 void OnSize( wxSizeEvent
&event
);
383 void OnScroll(wxScrollWinEvent
& event
) ;
385 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
386 void GetImageSize( int index
, int &width
, int &height
);
387 int GetIndexOfLine( const wxListLineData
*line
);
388 int GetTextLength( wxString
&s
); // should be const
390 void SetImageList( wxImageList
*imageList
, int which
);
391 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
392 int GetItemSpacing( bool isSmall
= FALSE
);
393 void SetColumn( int col
, wxListItem
&item
);
394 void SetColumnWidth( int col
, int width
);
395 void GetColumn( int col
, wxListItem
&item
);
396 int GetColumnWidth( int vol
);
397 int GetColumnCount();
398 int GetCountPerPage();
399 void SetItem( wxListItem
&item
);
400 void GetItem( wxListItem
&item
);
401 void SetItemState( long item
, long state
, long stateMask
);
402 int GetItemState( long item
, long stateMask
);
404 void GetItemRect( long index
, wxRect
&rect
);
405 bool GetItemPosition( long item
, wxPoint
& pos
);
406 int GetSelectedItemCount();
407 void SetMode( long mode
);
408 long GetMode() const;
409 void CalculatePositions();
410 void RealizeChanges();
411 long GetNextItem( long item
, int geometry
, int state
);
412 void DeleteItem( long index
);
413 void DeleteAllItems();
414 void DeleteColumn( int col
);
415 void DeleteEverything();
416 void EnsureVisible( long index
);
417 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
418 long FindItem( long start
, long data
);
419 long HitTest( int x
, int y
, int &flags
);
420 void InsertItem( wxListItem
&item
);
421 // void AddItem( wxListItem &item );
422 void InsertColumn( long col
, wxListItem
&item
);
423 // void AddColumn( wxListItem &item );
424 void SortItems( wxListCtrlCompare fn
, long data
);
426 void SetItemCount(long count
);
429 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
430 DECLARE_EVENT_TABLE()
433 // ============================================================================
435 // ============================================================================
437 //-----------------------------------------------------------------------------
439 //-----------------------------------------------------------------------------
441 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
443 wxListItemData::wxListItemData()
454 wxListItemData::wxListItemData( const wxListItem
&info
)
463 void wxListItemData::SetItem( const wxListItem
&info
)
465 if (info
.m_mask
& wxLIST_MASK_TEXT
)
466 SetText(info
.m_text
);
467 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
468 m_image
= info
.m_image
;
469 if (info
.m_mask
& wxLIST_MASK_DATA
)
470 m_data
= info
.m_data
;
472 if ( info
.HasAttributes() )
475 *m_attr
= *info
.GetAttributes();
477 m_attr
= new wxListItemAttr(*info
.GetAttributes());
482 m_width
= info
.m_width
;
486 void wxListItemData::SetImage( int image
)
491 void wxListItemData::SetData( long data
)
496 void wxListItemData::SetPosition( int x
, int y
)
502 void wxListItemData::SetSize( int width
, int height
)
504 if (width
!= -1) m_width
= width
;
505 if (height
!= -1) m_height
= height
;
508 bool wxListItemData::HasImage() const
510 return (m_image
>= 0);
513 bool wxListItemData::IsHit( int x
, int y
) const
515 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
518 int wxListItemData::GetX() const
523 int wxListItemData::GetY() const
528 int wxListItemData::GetWidth() const
533 int wxListItemData::GetHeight() const
538 int wxListItemData::GetImage() const
543 void wxListItemData::GetItem( wxListItem
&info
) const
545 info
.m_text
= m_text
;
546 info
.m_image
= m_image
;
547 info
.m_data
= m_data
;
551 if ( m_attr
->HasTextColour() )
552 info
.SetTextColour(m_attr
->GetTextColour());
553 if ( m_attr
->HasBackgroundColour() )
554 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
555 if ( m_attr
->HasFont() )
556 info
.SetFont(m_attr
->GetFont());
560 //-----------------------------------------------------------------------------
562 //-----------------------------------------------------------------------------
564 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
566 wxListHeaderData::wxListHeaderData()
577 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
585 void wxListHeaderData::SetItem( const wxListItem
&item
)
587 m_mask
= item
.m_mask
;
588 m_text
= item
.m_text
;
589 m_image
= item
.m_image
;
590 m_format
= item
.m_format
;
591 m_width
= item
.m_width
;
592 if (m_width
< 0) m_width
= 80;
593 if (m_width
< 6) m_width
= 6;
596 void wxListHeaderData::SetPosition( int x
, int y
)
602 void wxListHeaderData::SetHeight( int h
)
607 void wxListHeaderData::SetWidth( int w
)
610 if (m_width
< 0) m_width
= 80;
611 if (m_width
< 6) m_width
= 6;
614 void wxListHeaderData::SetFormat( int format
)
619 bool wxListHeaderData::HasImage() const
621 return (m_image
!= 0);
624 bool wxListHeaderData::IsHit( int x
, int y
) const
626 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
629 void wxListHeaderData::GetItem( wxListItem
&item
)
631 item
.m_mask
= m_mask
;
632 item
.m_text
= m_text
;
633 item
.m_image
= m_image
;
634 item
.m_format
= m_format
;
635 item
.m_width
= m_width
;
638 int wxListHeaderData::GetImage() const
643 int wxListHeaderData::GetWidth() const
648 int wxListHeaderData::GetFormat() const
653 //-----------------------------------------------------------------------------
655 //-----------------------------------------------------------------------------
657 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
659 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
664 m_hilightBrush
= hilightBrush
;
665 m_items
.DeleteContents( TRUE
);
669 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
671 wxListItemDataList::Node
*node
= m_items
.GetFirst();
678 m_bound_all
.width
= m_spacing
;
681 wxListItemData
*item
= node
->GetData();
682 wxString s
= item
->GetText();
687 dc
->GetTextExtent( s
, &lw
, &lh
);
693 m_bound_all
.height
= m_spacing
+lh
;
695 m_bound_all
.width
= lw
;
696 m_bound_label
.width
= lw
;
697 m_bound_label
.height
= lh
;
699 if (item
->HasImage())
703 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
704 m_bound_icon
.width
= w
+ 8;
705 m_bound_icon
.height
= h
+ 8;
707 if ( m_bound_icon
.width
> m_bound_all
.width
)
708 m_bound_all
.width
= m_bound_icon
.width
;
709 if ( h
+ lh
> m_bound_all
.height
- 4 )
710 m_bound_all
.height
= h
+ lh
+ 4;
713 if (!item
->HasText())
715 m_bound_hilight
.width
= m_bound_icon
.width
;
716 m_bound_hilight
.height
= m_bound_icon
.height
;
720 m_bound_hilight
.width
= m_bound_label
.width
;
721 m_bound_hilight
.height
= m_bound_label
.height
;
730 wxListItemData
*item
= node
->GetData();
732 wxString s
= item
->GetText();
737 dc
->GetTextExtent( s
, &lw
, &lh
);
743 m_bound_label
.width
= lw
;
744 m_bound_label
.height
= lh
;
746 m_bound_all
.width
= lw
;
747 m_bound_all
.height
= lh
;
749 if (item
->HasImage())
753 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
754 m_bound_icon
.width
= w
;
755 m_bound_icon
.height
= h
;
757 m_bound_all
.width
+= 4 + w
;
758 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
761 m_bound_hilight
.width
= m_bound_all
.width
;
762 m_bound_hilight
.height
= m_bound_all
.height
;
768 m_bound_all
.width
= 0;
769 m_bound_all
.height
= 0;
772 wxListItemData
*item
= node
->GetData();
773 if (item
->HasImage())
777 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
778 m_bound_icon
.width
= w
;
779 m_bound_icon
.height
= h
;
783 m_bound_icon
.width
= 0;
784 m_bound_icon
.height
= 0;
790 wxListItemData
*item
= node
->GetData();
791 wxString s
= item
->GetText();
796 dc
->GetTextExtent( s
, &lw
, &lh
);
802 item
->SetSize( item
->GetWidth(), lh
);
803 m_bound_all
.width
+= lw
;
804 m_bound_all
.height
= lh
;
805 node
= node
->GetNext();
807 m_bound_label
.width
= m_bound_all
.width
;
808 m_bound_label
.height
= m_bound_all
.height
;
814 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
815 int x
, int y
, int window_width
)
817 wxListItemDataList::Node
*node
= m_items
.GetFirst();
828 wxListItemData
*item
= node
->GetData();
829 if (item
->HasImage())
831 m_bound_icon
.x
= m_bound_all
.x
+ 4
832 + (m_spacing
- m_bound_icon
.width
)/2;
833 m_bound_icon
.y
= m_bound_all
.y
+ 4;
837 if (m_bound_all
.width
> m_spacing
)
838 m_bound_label
.x
= m_bound_all
.x
+ 2;
840 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
841 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
842 m_bound_hilight
.x
= m_bound_label
.x
- 2;
843 m_bound_hilight
.y
= m_bound_label
.y
- 2;
847 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
848 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
855 m_bound_hilight
.x
= m_bound_all
.x
;
856 m_bound_hilight
.y
= m_bound_all
.y
;
857 m_bound_label
.y
= m_bound_all
.y
+ 2;
860 wxListItemData
*item
= node
->GetData();
861 if (item
->HasImage())
863 m_bound_icon
.x
= m_bound_all
.x
+ 2;
864 m_bound_icon
.y
= m_bound_all
.y
+ 2;
865 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
869 m_bound_label
.x
= m_bound_all
.x
+ 2;
877 m_bound_all
.width
= window_width
;
878 AssignRect( m_bound_hilight
, m_bound_all
);
879 m_bound_label
.x
= m_bound_all
.x
+ 2;
880 m_bound_label
.y
= m_bound_all
.y
+ 2;
883 wxListItemData
*item
= node
->GetData();
884 if (item
->HasImage())
886 m_bound_icon
.x
= m_bound_all
.x
+ 2;
887 m_bound_icon
.y
= m_bound_all
.y
+ 2;
888 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
896 void wxListLineData::SetColumnPosition( int index
, int x
)
898 wxListItemDataList::Node
*node
= m_items
.Item( (size_t)index
);
901 wxListItemData
*item
= node
->GetData();
902 item
->SetPosition( x
, m_bound_all
.y
+1 );
906 void wxListLineData::GetSize( int &width
, int &height
)
908 width
= m_bound_all
.width
;
909 height
= m_bound_all
.height
;
912 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
916 width
= m_bound_all
.width
;
917 height
= m_bound_all
.height
;
920 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
924 width
= m_bound_label
.width
;
925 height
= m_bound_label
.height
;
928 void wxListLineData::GetRect( wxRect
&rect
)
930 AssignRect( rect
, m_bound_all
);
933 long wxListLineData::IsHit( int x
, int y
)
935 wxListItemDataList::Node
*node
= m_items
.GetFirst();
938 wxListItemData
*item
= node
->GetData();
939 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
))
940 return wxLIST_HITTEST_ONITEMICON
;
941 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
))
942 return wxLIST_HITTEST_ONITEMLABEL
;
946 // if there is no icon or text = empty
947 if (IsInRect( x
, y
, m_bound_all
))
948 return wxLIST_HITTEST_ONITEMICON
;
953 void wxListLineData::InitItems( int num
)
955 for (int i
= 0; i
< num
; i
++)
956 m_items
.Append( new wxListItemData() );
959 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
961 wxListItemDataList::Node
*node
= m_items
.Item( index
);
964 wxListItemData
*item
= node
->GetData();
965 item
->SetItem( info
);
969 void wxListLineData::GetItem( int index
, wxListItem
&info
)
971 wxListItemDataList::Node
*node
= m_items
.Item( index
);
974 wxListItemData
*item
= node
->GetData();
975 item
->GetItem( info
);
979 wxString
wxListLineData::GetText(int index
) const
983 wxListItemDataList::Node
*node
= m_items
.Item( index
);
986 wxListItemData
*item
= node
->GetData();
993 void wxListLineData::SetText( int index
, const wxString s
)
995 wxListItemDataList::Node
*node
= m_items
.Item( index
);
998 wxListItemData
*item
= node
->GetData();
1003 int wxListLineData::GetImage( int index
)
1005 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1008 wxListItemData
*item
= node
->GetData();
1009 return item
->GetImage();
1014 void wxListLineData::SetAttributes(wxDC
*dc
,
1015 const wxListItemAttr
*attr
,
1016 const wxColour
& colText
,
1020 // don't use foregroud colour for drawing highlighted items - this might
1021 // make them completely invisible (and there is no way to do bit
1022 // arithmetics on wxColour, unfortunately)
1023 if ( !hilight
&& attr
&& attr
->HasTextColour() )
1025 dc
->SetTextForeground(attr
->GetTextColour());
1029 dc
->SetTextForeground(colText
);
1032 if ( attr
&& attr
->HasFont() )
1034 dc
->SetFont(attr
->GetFont());
1042 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1046 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1047 wxCoord dev_w
= m_bound_all
.width
;
1048 wxCoord dev_h
= m_bound_all
.height
;
1050 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1053 wxWindow
*listctrl
= m_owner
->GetParent();
1055 // default foreground colour
1059 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1063 colText
= listctrl
->GetForegroundColour();
1067 wxFont font
= listctrl
->GetFont();
1069 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1070 // using SetAttributes() inside the loop), it will be trivial to
1071 // customize the subitems (in report mode) too.
1072 wxListItemData
*item
= m_items
.GetFirst()->GetData();
1073 wxListItemAttr
*attr
= item
->GetAttributes();
1074 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1076 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1077 if ( paintBG
|| hasBgCol
)
1081 dc
->SetBrush( * m_hilightBrush
);
1086 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1088 dc
->SetBrush( * wxWHITE_BRUSH
);
1091 dc
->SetPen( * wxTRANSPARENT_PEN
);
1092 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1093 m_bound_hilight
.width
, m_bound_hilight
.height
);
1096 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1098 if (m_mode
== wxLC_REPORT
)
1102 wxListItemData
*item
= node
->GetData();
1103 int x
= item
->GetX();
1104 if (item
->HasImage())
1107 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1108 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1109 x
+= item
->GetX() + 5;
1111 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1112 if (item
->HasText())
1114 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1116 dc
->DestroyClippingRegion();
1117 node
= node
->GetNext();
1124 wxListItemData
*item
= node
->GetData();
1125 if (item
->HasImage())
1127 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1129 if (item
->HasText())
1131 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1137 void wxListLineData::Hilight( bool on
)
1139 if (on
== m_hilighted
) return;
1142 m_owner
->SelectLine( this );
1144 m_owner
->DeselectLine( this );
1147 void wxListLineData::ReverseHilight( void )
1149 m_hilighted
= !m_hilighted
;
1151 m_owner
->SelectLine( this );
1153 m_owner
->DeselectLine( this );
1156 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1160 dc
->SetPen( * wxBLACK_PEN
);
1161 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1162 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1163 m_bound_hilight
.width
, m_bound_hilight
.height
);
1167 void wxListLineData::Draw( wxDC
*dc
)
1169 DoDraw( dc
, m_hilighted
, m_hilighted
);
1172 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1174 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1175 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1178 bool wxListLineData::IsHilighted( void )
1183 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1188 dest
.height
= height
;
1191 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1195 dest
.width
= source
.width
;
1196 dest
.height
= source
.height
;
1199 //-----------------------------------------------------------------------------
1200 // wxListHeaderWindow
1201 //-----------------------------------------------------------------------------
1203 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1205 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1206 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1207 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1208 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1211 wxListHeaderWindow::wxListHeaderWindow( void )
1213 m_owner
= (wxListMainWindow
*) NULL
;
1214 m_currentCursor
= (wxCursor
*) NULL
;
1215 m_resizeCursor
= (wxCursor
*) NULL
;
1216 m_isDragging
= FALSE
;
1219 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1220 const wxPoint
&pos
, const wxSize
&size
,
1221 long style
, const wxString
&name
) :
1222 wxWindow( win
, id
, pos
, size
, style
, name
)
1225 // m_currentCursor = wxSTANDARD_CURSOR;
1226 m_currentCursor
= (wxCursor
*) NULL
;
1227 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1228 m_isDragging
= FALSE
;
1231 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1234 wxListHeaderWindow::~wxListHeaderWindow( void )
1236 delete m_resizeCursor
;
1239 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1242 GtkStateType state
= GTK_STATE_NORMAL
;
1243 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1245 x
= dc
->XLOG2DEV( x
);
1247 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1248 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1250 const int m_corner
= 1;
1252 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1254 dc
->SetPen( *wxBLACK_PEN
);
1255 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1256 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1258 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1261 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1262 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1264 dc
->SetPen( *wxWHITE_PEN
);
1265 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1266 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1267 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1268 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1272 // shift the DC origin to match the position of the main window horz
1273 // scrollbar: this allows us to always use logical coords
1274 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1276 #if wxUSE_GENERIC_LIST_EXTENSIONS
1278 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1281 m_owner
->GetViewStart( &x
, NULL
);
1283 // account for the horz scrollbar offset
1284 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1285 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1288 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1291 wxClientDC
dc( this );
1293 wxPaintDC
dc( this );
1301 dc
.SetFont( GetFont() );
1303 // width and height of the entire header window
1305 GetClientSize( &w
, &h
);
1306 #if wxUSE_GENERIC_LIST_EXTENSIONS
1307 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1308 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1310 dc
.SetBackgroundMode(wxTRANSPARENT
);
1312 // do *not* use the listctrl colour for headers - one day we will have a
1313 // function to set it separately
1314 //dc.SetTextForeground( *wxBLACK );
1315 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1317 int x
= 1; // left of the header rect
1318 const int y
= 1; // top
1319 int numColumns
= m_owner
->GetColumnCount();
1321 for (int i
= 0; i
< numColumns
; i
++)
1323 m_owner
->GetColumn( i
, item
);
1324 int wCol
= item
.m_width
;
1325 int cw
= wCol
- 2; // the width of the rect to draw
1327 int xEnd
= x
+ wCol
;
1329 // VZ: no, draw it normally - this is better now as we allow resizing
1330 // of the last column as well
1332 // let the last column occupy all available space
1333 if ( i
== numColumns
- 1 )
1337 dc
.SetPen( *wxWHITE_PEN
);
1339 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1340 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1341 dc
.DrawText( item
.GetText(), x
+4, y
+3 );
1342 dc
.DestroyClippingRegion();
1351 void wxListHeaderWindow::DrawCurrent()
1353 int x1
= m_currentX
;
1355 ClientToScreen( &x1
, &y1
);
1357 int x2
= m_currentX
-1;
1359 m_owner
->GetClientSize( NULL
, &y2
);
1360 m_owner
->ClientToScreen( &x2
, &y2
);
1363 dc
.SetLogicalFunction( wxINVERT
);
1364 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1365 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1369 dc
.DrawLine( x1
, y1
, x2
, y2
);
1371 dc
.SetLogicalFunction( wxCOPY
);
1373 dc
.SetPen( wxNullPen
);
1374 dc
.SetBrush( wxNullBrush
);
1377 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1379 // we want to work with logical coords
1380 #if wxUSE_GENERIC_LIST_EXTENSIONS
1382 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1383 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1384 int x
= event
.GetX();
1385 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1386 int y
= event
.GetY();
1390 // we don't draw the line beyond our window, but we allow dragging it
1393 GetClientSize( &w
, NULL
);
1394 #if wxUSE_GENERIC_LIST_EXTENSIONS
1395 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1396 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1399 // erase the line if it was drawn
1400 if ( m_currentX
< w
)
1403 if (event
.ButtonUp())
1406 m_isDragging
= FALSE
;
1408 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1415 m_currentX
= m_minX
+ 7;
1417 // draw in the new location
1418 if ( m_currentX
< w
)
1422 else // not dragging
1425 bool hit_border
= FALSE
;
1427 // end of the current column
1430 // find the column where this event occured
1431 int countCol
= m_owner
->GetColumnCount();
1432 for (int j
= 0; j
< countCol
; j
++)
1434 xpos
+= m_owner
->GetColumnWidth( j
);
1437 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1439 // near the column border
1446 // inside the column
1453 if (event
.LeftDown())
1457 m_isDragging
= TRUE
;
1464 wxWindow
*parent
= GetParent();
1465 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1466 le
.SetEventObject( parent
);
1467 le
.m_col
= m_column
;
1468 parent
->GetEventHandler()->ProcessEvent( le
);
1471 else if (event
.Moving())
1476 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1477 m_currentCursor
= m_resizeCursor
;
1481 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1482 m_currentCursor
= wxSTANDARD_CURSOR
;
1486 SetCursor(*m_currentCursor
);
1491 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1493 m_owner
->SetFocus();
1496 //-----------------------------------------------------------------------------
1497 // wxListRenameTimer (internal)
1498 //-----------------------------------------------------------------------------
1500 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1505 void wxListRenameTimer::Notify()
1507 m_owner
->OnRenameTimer();
1510 //-----------------------------------------------------------------------------
1511 // wxListTextCtrl (internal)
1512 //-----------------------------------------------------------------------------
1514 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1516 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1517 EVT_CHAR (wxListTextCtrl::OnChar
)
1518 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1519 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1522 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1523 const wxWindowID id
,
1526 wxListMainWindow
*owner
,
1527 const wxString
&value
,
1531 const wxValidator
& validator
,
1532 const wxString
&name
)
1533 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1538 (*m_accept
) = FALSE
;
1540 m_startValue
= value
;
1543 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1545 if (event
.m_keyCode
== WXK_RETURN
)
1548 (*m_res
) = GetValue();
1550 if (!wxPendingDelete
.Member(this))
1551 wxPendingDelete
.Append(this);
1553 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1554 m_owner
->OnRenameAccept();
1558 if (event
.m_keyCode
== WXK_ESCAPE
)
1560 (*m_accept
) = FALSE
;
1563 if (!wxPendingDelete
.Member(this))
1564 wxPendingDelete
.Append(this);
1572 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1574 // auto-grow the textctrl:
1575 wxSize parentSize
= m_owner
->GetSize();
1576 wxPoint myPos
= GetPosition();
1577 wxSize mySize
= GetSize();
1579 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1580 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1581 if (mySize
.x
> sx
) sx
= mySize
.x
;
1587 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1589 if (!wxPendingDelete
.Member(this))
1590 wxPendingDelete
.Append(this);
1592 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1593 m_owner
->OnRenameAccept();
1596 //-----------------------------------------------------------------------------
1598 //-----------------------------------------------------------------------------
1600 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1602 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1603 EVT_PAINT (wxListMainWindow::OnPaint
)
1604 EVT_SIZE (wxListMainWindow::OnSize
)
1605 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1606 EVT_CHAR (wxListMainWindow::OnChar
)
1607 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1608 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1609 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1610 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1613 wxListMainWindow::wxListMainWindow()
1616 m_columns
.DeleteContents( TRUE
);
1617 m_current
= (wxListLineData
*) NULL
;
1619 m_hilightBrush
= (wxBrush
*) NULL
;
1623 m_small_image_list
= (wxImageList
*) NULL
;
1624 m_normal_image_list
= (wxImageList
*) NULL
;
1625 m_small_spacing
= 30;
1626 m_normal_spacing
= 40;
1629 m_lastOnSame
= FALSE
;
1630 m_renameTimer
= new wxListRenameTimer( this );
1631 m_isCreated
= FALSE
;
1635 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1638 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1639 const wxPoint
&pos
, const wxSize
&size
,
1640 long style
, const wxString
&name
) :
1641 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1644 m_columns
.DeleteContents( TRUE
);
1645 m_current
= (wxListLineData
*) NULL
;
1648 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1649 m_small_image_list
= (wxImageList
*) NULL
;
1650 m_normal_image_list
= (wxImageList
*) NULL
;
1651 m_small_spacing
= 30;
1652 m_normal_spacing
= 40;
1655 m_isCreated
= FALSE
;
1659 if (m_mode
& wxLC_REPORT
)
1661 #if wxUSE_GENERIC_LIST_EXTENSIONS
1673 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1676 m_lastOnSame
= FALSE
;
1677 m_renameTimer
= new wxListRenameTimer( this );
1678 m_renameAccept
= FALSE
;
1680 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1683 wxListMainWindow::~wxListMainWindow()
1687 if (m_hilightBrush
) delete m_hilightBrush
;
1689 delete m_renameTimer
;
1692 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1694 if (m_dirty
) return;
1702 line
->GetExtent( x
, y
, w
, h
);
1703 CalcScrolledPosition( x
, y
, &x
, &y
);
1704 wxRect
rect( x
, y
, w
, h
);
1705 Refresh( TRUE
, &rect
);
1708 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1710 // Note: a wxPaintDC must be constructed even if no drawing is
1711 // done (a Windows requirement).
1712 wxPaintDC
dc( this );
1716 // postpone redrawing until the next OnIdle() call to minimize flicker
1723 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
1725 if (m_lines
.GetCount() == 0)
1727 // empty control. nothing to draw
1733 dc
.SetFont( GetFont() );
1735 if (m_mode
& wxLC_REPORT
)
1737 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1738 wxSize clientSize
= GetClientSize();
1740 int lineSpacing
= 0;
1741 wxListLineData
*line
= &m_lines
[0];
1743 line
->GetSize( dummy
, lineSpacing
);
1746 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1748 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1749 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1751 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1753 m_lines
[i
].Draw( &dc
);
1754 // Draw horizontal rule if required
1755 if (m_mode
& wxLC_HRULES
)
1758 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1759 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1763 // Draw last horizontal rule
1764 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (m_mode
& wxLC_HRULES
))
1767 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1768 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1771 // Draw vertical rules if required
1772 if ((m_mode
& wxLC_VRULES
) && (GetItemCount() > 0))
1775 wxRect firstItemRect
;
1776 wxRect lastItemRect
;
1777 GetItemRect(0, firstItemRect
);
1778 GetItemRect(GetItemCount() - 1, lastItemRect
);
1779 int x
= firstItemRect
.GetX();
1781 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1782 for (col
= 0; col
< GetColumnCount(); col
++)
1784 int colWidth
= GetColumnWidth(col
);
1786 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
, x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
1790 else // !report mode
1792 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1793 m_lines
[i
].Draw( &dc
);
1797 m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1802 void wxListMainWindow::HilightAll( bool on
)
1804 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1806 wxListLineData
*line
= &m_lines
[i
];
1807 if (line
->IsHilighted() != on
)
1809 line
->Hilight( on
);
1810 RefreshLine( line
);
1815 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1816 wxEventType command
,
1819 wxListEvent
le( command
, GetParent()->GetId() );
1820 le
.SetEventObject( GetParent() );
1821 le
.m_itemIndex
= GetIndexOfLine( line
);
1823 // set only for events which have position
1824 if ( point
!= wxDefaultPosition
)
1825 le
.m_pointDrag
= point
;
1827 line
->GetItem( 0, le
.m_item
);
1828 GetParent()->GetEventHandler()->ProcessEvent( le
);
1829 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1832 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1834 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1837 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1839 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1842 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1844 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1847 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1849 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1852 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1854 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1859 void wxListMainWindow::EditLabel( long item
)
1861 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1862 wxT("wrong index in wxListCtrl::Edit()") );
1864 m_currentEdit
= &m_lines
[(size_t)item
];
1866 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1867 le
.SetEventObject( GetParent() );
1868 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1869 m_currentEdit
->GetItem( 0, le
.m_item
);
1870 GetParent()->GetEventHandler()->ProcessEvent( le
);
1872 if (!le
.IsAllowed())
1875 // We have to call this here because the label in
1876 // question might just have been added and no screen
1877 // update taken place.
1878 if (m_dirty
) wxYield();
1880 wxString s
= m_currentEdit
->GetText(0);
1885 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1887 wxClientDC
dc(this);
1889 x
= dc
.LogicalToDeviceX( x
);
1890 y
= dc
.LogicalToDeviceY( y
);
1892 wxListTextCtrl
*text
= new wxListTextCtrl(
1893 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1897 void wxListMainWindow::OnRenameTimer()
1899 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1901 Edit( m_lines
.Index( *m_current
) );
1904 void wxListMainWindow::OnRenameAccept()
1906 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1907 le
.SetEventObject( GetParent() );
1908 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1909 m_currentEdit
->GetItem( 0, le
.m_item
);
1910 le
.m_item
.m_text
= m_renameRes
;
1911 GetParent()->GetEventHandler()->ProcessEvent( le
);
1913 if (!le
.IsAllowed()) return;
1916 info
.m_mask
= wxLIST_MASK_TEXT
;
1917 info
.m_itemId
= le
.m_itemIndex
;
1918 info
.m_text
= m_renameRes
;
1919 info
.SetTextColour(le
.m_item
.GetTextColour());
1923 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1925 event
.SetEventObject( GetParent() );
1926 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1928 if (!m_current
) return;
1929 if (m_dirty
) return;
1930 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1932 int x
= event
.GetX();
1933 int y
= event
.GetY();
1934 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1936 /* Did we actually hit an item ? */
1938 wxListLineData
*line
= (wxListLineData
*) NULL
;
1939 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1942 hitResult
= line
->IsHit( x
, y
);
1943 if (hitResult
) break;
1944 line
= (wxListLineData
*) NULL
;
1947 if (event
.Dragging())
1949 if (m_dragCount
== 0)
1950 m_dragStart
= wxPoint(x
,y
);
1954 if (m_dragCount
!= 3) return;
1956 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1957 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1959 wxListEvent
le( command
, GetParent()->GetId() );
1960 le
.SetEventObject( GetParent() );
1961 le
.m_pointDrag
= m_dragStart
;
1962 GetParent()->GetEventHandler()->ProcessEvent( le
);
1973 bool forceClick
= FALSE
;
1974 if (event
.ButtonDClick())
1976 m_renameTimer
->Stop();
1977 m_lastOnSame
= FALSE
;
1979 if ( line
== m_lineBeforeLastClicked
)
1983 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1989 // the first click was on another item, so don't interpret this as
1990 // a double click, but as a simple click instead
1995 if (event
.LeftUp() && m_lastOnSame
)
1998 if ((line
== m_current
) &&
1999 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2000 (m_mode
& wxLC_EDIT_LABELS
) )
2002 m_renameTimer
->Start( 100, TRUE
);
2004 m_lastOnSame
= FALSE
;
2008 if (event
.RightDown())
2010 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2011 event
.GetPosition() );
2015 if (event
.MiddleDown())
2017 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2021 if ( event
.LeftDown() || forceClick
)
2023 m_lineBeforeLastClicked
= m_lineLastClicked
;
2024 m_lineLastClicked
= line
;
2027 wxListLineData
*oldCurrent
= m_current
;
2028 if (m_mode
& wxLC_SINGLE_SEL
)
2031 HilightAll( FALSE
);
2032 m_current
->ReverseHilight();
2033 RefreshLine( m_current
);
2037 if (event
.ControlDown())
2040 m_current
->ReverseHilight();
2041 RefreshLine( m_current
);
2043 else if (event
.ShiftDown())
2049 int numOfCurrent
= -1;
2050 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2052 wxListLineData
*test_line
= &m_lines
[j
];
2054 if (test_line
== oldCurrent
) break;
2059 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2061 wxListLineData
*test_line
= &m_lines
[j
];
2063 if (test_line
== line
) break;
2066 if (numOfLine
< numOfCurrent
)
2069 numOfLine
= numOfCurrent
;
2073 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2075 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2076 test_line
->Hilight(TRUE
);
2077 RefreshLine( test_line
);
2083 HilightAll( FALSE
);
2084 m_current
->ReverseHilight();
2085 RefreshLine( m_current
);
2088 if (m_current
!= oldCurrent
)
2090 RefreshLine( oldCurrent
);
2091 UnfocusLine( oldCurrent
);
2092 FocusLine( m_current
);
2095 // forceClick is only set if the previous click was on another item
2096 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2102 void wxListMainWindow::MoveToFocus()
2104 if (!m_current
) return;
2110 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2114 GetClientSize( &client_w
, &client_h
);
2116 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2117 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2119 if (m_mode
& wxLC_REPORT
)
2121 if (item_y
< view_y
)
2122 Scroll( -1, (item_y
)/m_yScroll
);
2123 if (item_y
+item_h
+5 > view_y
+client_h
)
2124 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2128 if (item_x
-view_x
< 5)
2129 Scroll( (item_x
-5)/m_xScroll
, -1 );
2130 if (item_x
+item_w
-5 > view_x
+client_w
)
2131 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2135 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2137 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2138 wxListLineData
*oldCurrent
= m_current
;
2139 m_current
= newCurrent
;
2140 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2141 RefreshLine( m_current
);
2142 RefreshLine( oldCurrent
);
2143 FocusLine( m_current
);
2144 UnfocusLine( oldCurrent
);
2148 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2150 wxWindow
*parent
= GetParent();
2152 /* we propagate the key event up */
2153 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2154 ke
.m_shiftDown
= event
.m_shiftDown
;
2155 ke
.m_controlDown
= event
.m_controlDown
;
2156 ke
.m_altDown
= event
.m_altDown
;
2157 ke
.m_metaDown
= event
.m_metaDown
;
2158 ke
.m_keyCode
= event
.m_keyCode
;
2161 ke
.SetEventObject( parent
);
2162 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2167 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2169 wxWindow
*parent
= GetParent();
2171 /* we send a list_key event up */
2174 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2175 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2176 m_current
->GetItem( 0, le
.m_item
);
2177 le
.m_code
= (int)event
.KeyCode();
2178 le
.SetEventObject( parent
);
2179 parent
->GetEventHandler()->ProcessEvent( le
);
2182 /* we propagate the char event up */
2183 wxKeyEvent
ke( wxEVT_CHAR
);
2184 ke
.m_shiftDown
= event
.m_shiftDown
;
2185 ke
.m_controlDown
= event
.m_controlDown
;
2186 ke
.m_altDown
= event
.m_altDown
;
2187 ke
.m_metaDown
= event
.m_metaDown
;
2188 ke
.m_keyCode
= event
.m_keyCode
;
2191 ke
.SetEventObject( parent
);
2192 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2194 if (event
.KeyCode() == WXK_TAB
)
2196 wxNavigationKeyEvent nevent
;
2197 nevent
.SetWindowChange( event
.ControlDown() );
2198 nevent
.SetDirection( !event
.ShiftDown() );
2199 nevent
.SetEventObject( GetParent()->GetParent() );
2200 nevent
.SetCurrentFocus( m_parent
);
2201 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2204 /* no item -> nothing to do */
2211 switch (event
.KeyCode())
2215 int index
= m_lines
.Index(*m_current
);
2216 if (index
!= wxNOT_FOUND
&& index
> 0)
2217 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2222 int index
= m_lines
.Index(*m_current
);
2223 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2224 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2229 if (!m_lines
.IsEmpty())
2230 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2235 if (!m_lines
.IsEmpty())
2236 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2242 int index
= m_lines
.Index(*m_current
);
2243 if (m_mode
& wxLC_REPORT
)
2245 steps
= m_visibleLines
-1;
2249 steps
= index
% m_visibleLines
;
2251 if (index
!= wxNOT_FOUND
)
2254 if (index
< 0) index
= 0;
2255 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2262 int index
= m_lines
.Index(*m_current
);
2263 if (m_mode
& wxLC_REPORT
)
2265 steps
= m_visibleLines
-1;
2269 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2272 if (index
!= wxNOT_FOUND
)
2275 if ((size_t)index
>= m_lines
.GetCount())
2276 index
= m_lines
.GetCount()-1;
2277 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2283 if (!(m_mode
& wxLC_REPORT
))
2285 int index
= m_lines
.Index(*m_current
);
2286 if (index
!= wxNOT_FOUND
)
2288 index
-= m_visibleLines
;
2289 if (index
< 0) index
= 0;
2290 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2297 if (!(m_mode
& wxLC_REPORT
))
2299 int index
= m_lines
.Index(*m_current
);
2300 if (index
!= wxNOT_FOUND
)
2302 index
+= m_visibleLines
;
2303 if ((size_t)index
>= m_lines
.GetCount())
2304 index
= m_lines
.GetCount()-1;
2305 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2312 if (m_mode
& wxLC_SINGLE_SEL
)
2314 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2315 le
.SetEventObject( GetParent() );
2316 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2317 m_current
->GetItem( 0, le
.m_item
);
2318 GetParent()->GetEventHandler()->ProcessEvent( le
);
2322 m_current
->ReverseHilight();
2323 RefreshLine( m_current
);
2329 if (!(m_mode
& wxLC_SINGLE_SEL
))
2331 wxListLineData
*oldCurrent
= m_current
;
2332 m_current
->ReverseHilight();
2333 int index
= m_lines
.Index( *m_current
) + 1;
2334 if ( (size_t)index
< m_lines
.GetCount() )
2335 m_current
= &m_lines
[index
];
2336 RefreshLine( oldCurrent
);
2337 RefreshLine( m_current
);
2338 UnfocusLine( oldCurrent
);
2339 FocusLine( m_current
);
2347 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2348 le
.SetEventObject( GetParent() );
2349 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2350 m_current
->GetItem( 0, le
.m_item
);
2351 GetParent()->GetEventHandler()->ProcessEvent( le
);
2364 extern wxWindow
*g_focusWindow
;
2367 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2370 RefreshLine( m_current
);
2372 if (!GetParent()) return;
2375 g_focusWindow
= GetParent();
2378 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2379 event
.SetEventObject( GetParent() );
2380 GetParent()->GetEventHandler()->ProcessEvent( event
);
2383 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2386 RefreshLine( m_current
);
2389 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2392 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2398 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2400 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2402 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2405 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2407 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2409 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2411 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2413 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2415 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2420 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2422 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2424 m_normal_image_list
->GetSize( index
, width
, height
);
2427 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2429 m_small_image_list
->GetSize( index
, width
, height
);
2432 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2434 m_small_image_list
->GetSize( index
, width
, height
);
2437 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2439 m_small_image_list
->GetSize( index
, width
, height
);
2446 int wxListMainWindow::GetTextLength( wxString
&s
)
2448 wxClientDC
dc( this );
2451 dc
.GetTextExtent( s
, &lw
, &lh
);
2455 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2457 int i
= m_lines
.Index(*line
);
2458 if (i
== wxNOT_FOUND
) return -1;
2462 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2466 // calc the spacing from the icon size
2469 if ((imageList
) && (imageList
->GetImageCount()) )
2471 imageList
->GetSize(0, width
, height
);
2474 if (which
== wxIMAGE_LIST_NORMAL
)
2476 m_normal_image_list
= imageList
;
2477 m_normal_spacing
= width
+ 8;
2480 if (which
== wxIMAGE_LIST_SMALL
)
2482 m_small_image_list
= imageList
;
2483 m_small_spacing
= width
+ 14;
2487 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2492 m_small_spacing
= spacing
;
2496 m_normal_spacing
= spacing
;
2500 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2502 return isSmall
? m_small_spacing
: m_normal_spacing
;
2505 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2508 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2511 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2512 item
.m_width
= GetTextLength( item
.m_text
)+7;
2513 wxListHeaderData
*column
= node
->GetData();
2514 column
->SetItem( item
);
2517 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2519 headerWin
->m_dirty
= TRUE
;
2522 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2524 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2525 _T("SetColumnWidth() can only be called in report mode.") );
2529 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2531 // TODO do use the header
2534 else if (width
== wxLIST_AUTOSIZE
)
2536 wxClientDC
dc(this);
2537 dc
.SetFont( GetFont() );
2540 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2542 wxListLineData
*line
= &m_lines
[i
];
2543 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2546 wxListItemData
*item
= n
->GetData();
2547 int current
= 0, ix
= 0, iy
= 0;
2548 wxCoord lx
= 0, ly
= 0;
2549 if (item
->HasImage())
2551 GetImageSize( item
->GetImage(), ix
, iy
);
2554 if (item
->HasText())
2556 wxString str
= item
->GetText();
2557 dc
.GetTextExtent( str
, &lx
, &ly
);
2567 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2570 wxListHeaderData
*column
= node
->GetData();
2571 column
->SetWidth( width
);
2574 size_t count
= m_lines
.GetCount();
2575 for (size_t i
= 0; i
< count
; i
++)
2577 wxListLineData
*line
= &m_lines
[i
];
2578 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2581 wxListItemData
*item
= n
->GetData();
2582 item
->SetSize( width
, -1 );
2586 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2588 headerWin
->m_dirty
= TRUE
;
2591 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2593 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2596 wxListHeaderData
*column
= node
->GetData();
2597 column
->GetItem( item
);
2603 item
.m_text
= _T("");
2609 int wxListMainWindow::GetColumnWidth( int col
)
2611 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2612 wxCHECK_MSG( node
, 0, _T("invalid column index") );
2614 wxListHeaderData
*column
= node
->GetData();
2615 return column
->GetWidth();
2618 int wxListMainWindow::GetColumnCount()
2620 return m_columns
.GetCount();
2623 int wxListMainWindow::GetCountPerPage()
2625 return m_visibleLines
;
2628 void wxListMainWindow::SetItem( wxListItem
&item
)
2631 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2633 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2634 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2635 line
->SetItem( item
.m_col
, item
);
2639 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2641 wxCHECK_RET( item
>= 0 && (size_t)item
< m_lines
.GetCount(),
2642 _T("invalid list ctrl item index in SetItem") );
2644 // m_dirty = TRUE; no recalcs needed
2646 wxListLineData
*oldCurrent
= m_current
;
2648 if ( stateMask
& wxLIST_STATE_FOCUSED
)
2650 wxListLineData
*line
= &m_lines
[(size_t)item
];
2651 if ( state
& wxLIST_STATE_FOCUSED
)
2653 // don't do anything if this item is already focused
2654 if ( line
!= m_current
)
2656 UnfocusLine( m_current
);
2658 FocusLine( m_current
);
2659 if ( (m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
)
2660 oldCurrent
->Hilight( FALSE
);
2662 RefreshLine( m_current
);
2664 RefreshLine( oldCurrent
);
2669 // don't do anything if this item is not focused
2670 if ( line
== m_current
)
2672 UnfocusLine( m_current
);
2678 if ( stateMask
& wxLIST_STATE_SELECTED
)
2680 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2681 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
))
2684 wxListLineData
*line
= &m_lines
[(size_t)item
];
2685 if (m_mode
& wxLC_SINGLE_SEL
)
2687 UnfocusLine( m_current
);
2689 FocusLine( m_current
);
2691 oldCurrent
->Hilight( FALSE
);
2692 RefreshLine( m_current
);
2694 RefreshLine( oldCurrent
);
2697 if (on
!= line
->IsHilighted())
2699 line
->Hilight( on
);
2700 RefreshLine( line
);
2705 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2707 int ret
= wxLIST_STATE_DONTCARE
;
2708 if (stateMask
& wxLIST_STATE_FOCUSED
)
2710 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2712 wxListLineData
*line
= &m_lines
[(size_t)item
];
2713 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2716 if (stateMask
& wxLIST_STATE_SELECTED
)
2718 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2720 wxListLineData
*line
= &m_lines
[(size_t)item
];
2721 if (line
->IsHilighted()) ret
|= wxLIST_STATE_SELECTED
;
2727 void wxListMainWindow::GetItem( wxListItem
&item
)
2729 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2731 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2732 line
->GetItem( item
.m_col
, item
);
2737 item
.m_text
= _T("");
2743 int wxListMainWindow::GetItemCount()
2745 return m_lines
.GetCount();
2748 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2750 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2752 m_lines
[(size_t)index
].GetRect( rect
);
2753 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2764 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2767 this->GetItemRect(item
,rect
);
2768 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2772 int wxListMainWindow::GetSelectedItemCount()
2775 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2777 if (m_lines
[i
].IsHilighted()) ret
++;
2782 void wxListMainWindow::SetMode( long mode
)
2789 if (m_mode
& wxLC_REPORT
)
2791 #if wxUSE_GENERIC_LIST_EXTENSIONS
2805 long wxListMainWindow::GetMode() const
2810 void wxListMainWindow::CalculatePositions()
2812 if (m_lines
.IsEmpty()) return;
2814 wxClientDC
dc( this );
2815 dc
.SetFont( GetFont() );
2817 int iconSpacing
= 0;
2818 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2819 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2821 // we take the first line (which also can be an icon or
2822 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2823 // measure the size of the line
2827 int lineSpacing
= 0;
2829 wxListLineData
*line
= &m_lines
[0];
2830 line
->CalculateSize( &dc
, iconSpacing
);
2832 line
->GetSize( dummy
, lineSpacing
);
2835 int clientWidth
= 0;
2836 int clientHeight
= 0;
2838 if (m_mode
& wxLC_REPORT
)
2840 // scroll one line per step
2841 m_yScroll
= lineSpacing
;
2845 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2846 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2847 #if wxUSE_GENERIC_LIST_EXTENSIONS
2848 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2850 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2852 GetClientSize( &clientWidth
, &clientHeight
);
2854 int entireWidth
= 0 ;
2855 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2857 wxListLineData
*line
= &m_lines
[j
];
2858 line
->CalculateSize( &dc
, iconSpacing
);
2859 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2861 for (int i
= 0; i
< GetColumnCount(); i
++)
2863 line
->SetColumnPosition( i
, col_x
);
2864 col_x
+= GetColumnWidth( i
);
2866 entireWidth
= wxMax( entireWidth
, col_x
) ;
2867 #if wxUSE_GENERIC_LIST_EXTENSIONS
2868 line
->SetPosition( &dc
, x
, y
, col_x
);
2870 y
+= lineSpacing
; // one pixel blank line between items
2872 m_visibleLines
= clientHeight
/ lineSpacing
;
2873 #if wxUSE_GENERIC_LIST_EXTENSIONS
2874 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2879 // at first we try without any scrollbar. if the items don't
2880 // fit into the window, we recalculate after subtracting an
2881 // approximated 15 pt for the horizontal scrollbar
2883 GetSize( &clientWidth
, &clientHeight
);
2884 clientHeight
-= 4; // sunken frame
2886 int entireWidth
= 0;
2888 for (int tries
= 0; tries
< 2; tries
++)
2895 int m_currentVisibleLines
= 0;
2896 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2898 m_currentVisibleLines
++;
2899 wxListLineData
*line
= &m_lines
[i
];
2900 line
->CalculateSize( &dc
, iconSpacing
);
2901 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2902 line
->GetSize( lineWidth
, lineHeight
);
2903 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2905 if (m_currentVisibleLines
> m_visibleLines
)
2906 m_visibleLines
= m_currentVisibleLines
;
2907 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2909 m_currentVisibleLines
= 0;
2912 entireWidth
+= maxWidth
+6;
2915 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2916 if ((tries
== 0) && (entireWidth
> clientWidth
))
2918 clientHeight
-= 15; // scrollbar height
2920 m_currentVisibleLines
= 0;
2923 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2927 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2928 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2932 void wxListMainWindow::RealizeChanges()
2936 if (!m_lines
.IsEmpty())
2937 m_current
= &m_lines
[0];
2941 FocusLine( m_current
);
2942 // TODO: MSW doesn't automatically hilight the
2944 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2948 long wxListMainWindow::GetNextItem( long item
,
2949 int WXUNUSED(geometry
),
2953 max
= GetItemCount();
2954 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2955 _T("invalid listctrl index in GetNextItem()") );
2957 // notice that we start with the next item (or the first one if item == -1)
2958 // and this is intentional to allow writing a simple loop to iterate over
2959 // all selected items
2963 // this is not an error because the index was ok initially, just no
2968 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2970 wxListLineData
*line
= &m_lines
[i
];
2971 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2973 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2983 void wxListMainWindow::DeleteItem( long index
)
2986 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2988 wxListLineData
*line
= &m_lines
[(size_t)index
];
2989 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2991 m_lines
.RemoveAt( (size_t)index
);
2995 void wxListMainWindow::DeleteColumn( int col
)
2997 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2999 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3002 m_columns
.DeleteNode( node
);
3005 void wxListMainWindow::DeleteAllItems()
3008 m_current
= (wxListLineData
*) NULL
;
3010 // to make the deletion of all items faster, we don't send the
3011 // notifications in this case: this is compatible with wxMSW and
3012 // documented in DeleteAllItems() description
3014 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3015 event
.SetEventObject( GetParent() );
3016 GetParent()->GetEventHandler()->ProcessEvent( event
);
3021 void wxListMainWindow::DeleteEverything()
3028 void wxListMainWindow::EnsureVisible( long index
)
3030 // We have to call this here because the label in
3031 // question might just have been added and no screen
3032 // update taken place.
3033 if (m_dirty
) wxYield();
3035 wxListLineData
*oldCurrent
= m_current
;
3036 m_current
= (wxListLineData
*) NULL
;
3037 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
3038 m_current
= &m_lines
[(size_t)index
];
3039 if (m_current
) MoveToFocus();
3040 m_current
= oldCurrent
;
3043 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3047 if (pos
< 0) pos
= 0;
3048 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3050 wxListLineData
*line
= &m_lines
[i
];
3051 wxString s
= line
->GetText(0);
3060 long wxListMainWindow::FindItem(long start
, long data
)
3063 if (pos
< 0) pos
= 0;
3064 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3066 wxListLineData
*line
= &m_lines
[i
];
3068 line
->GetItem( 0, item
);
3069 if (item
.m_data
== data
) return pos
;
3075 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3077 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3080 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3082 wxListLineData
*line
= &m_lines
[i
];
3083 long ret
= line
->IsHit( x
, y
);
3084 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3094 void wxListMainWindow::InsertItem( wxListItem
&item
)
3098 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3099 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3100 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3101 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3103 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3105 if (m_mode
& wxLC_REPORT
)
3107 line
->InitItems( GetColumnCount() );
3108 item
.m_width
= GetColumnWidth( 0 )-3;
3112 line
->InitItems( 1 );
3115 line
->SetItem( 0, item
);
3116 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3118 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3122 m_lines
.Add( line
);
3123 item
.m_itemId
= m_lines
.GetCount()-1;
3127 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3130 if (m_mode
& wxLC_REPORT
)
3132 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3133 item
.m_width
= GetTextLength( item
.m_text
);
3134 wxListHeaderData
*column
= new wxListHeaderData( item
);
3135 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3137 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3138 m_columns
.Insert( node
, column
);
3142 m_columns
.Append( column
);
3147 wxListCtrlCompare list_ctrl_compare_func_2
;
3148 long list_ctrl_compare_data
;
3150 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3152 wxListLineData
*line1
= *arg1
;
3153 wxListLineData
*line2
= *arg2
;
3155 line1
->GetItem( 0, item
);
3156 long data1
= item
.m_data
;
3157 line2
->GetItem( 0, item
);
3158 long data2
= item
.m_data
;
3159 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3162 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3164 list_ctrl_compare_func_2
= fn
;
3165 list_ctrl_compare_data
= data
;
3166 m_lines
.Sort( list_ctrl_compare_func_1
);
3170 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3173 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
3174 wxScrolledWindow::OnScroll(event
);
3176 HandleOnScroll( event
);
3179 #if wxUSE_GENERIC_LIST_EXTENSIONS
3181 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3183 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3186 lc
->m_headerWin
->Refresh() ;
3188 lc
->m_headerWin
->MacUpdateImmediately() ;
3195 // -------------------------------------------------------------------------------------
3197 // -------------------------------------------------------------------------------------
3199 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3201 wxListItem::wxListItem()
3210 m_format
= wxLIST_FORMAT_CENTRE
;
3216 void wxListItem::Clear()
3225 m_format
= wxLIST_FORMAT_CENTRE
;
3229 if (m_attr
) delete m_attr
;
3233 void wxListItem::ClearAttributes()
3235 if (m_attr
) delete m_attr
;
3239 // -------------------------------------------------------------------------------------
3241 // -------------------------------------------------------------------------------------
3243 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3245 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3246 wxNotifyEvent( commandType
, id
)
3252 m_cancelled
= FALSE
;
3257 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3259 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3261 wxNotifyEvent::CopyObject(object_dest
);
3263 obj
->m_code
= m_code
;
3264 obj
->m_itemIndex
= m_itemIndex
;
3265 obj
->m_oldItemIndex
= m_oldItemIndex
;
3267 obj
->m_cancelled
= m_cancelled
;
3268 obj
->m_pointDrag
= m_pointDrag
;
3269 obj
->m_item
.m_mask
= m_item
.m_mask
;
3270 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3271 obj
->m_item
.m_col
= m_item
.m_col
;
3272 obj
->m_item
.m_state
= m_item
.m_state
;
3273 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3274 obj
->m_item
.m_text
= m_item
.m_text
;
3275 obj
->m_item
.m_image
= m_item
.m_image
;
3276 obj
->m_item
.m_data
= m_item
.m_data
;
3277 obj
->m_item
.m_format
= m_item
.m_format
;
3278 obj
->m_item
.m_width
= m_item
.m_width
;
3280 if ( m_item
.HasAttributes() )
3282 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3286 // -------------------------------------------------------------------------------------
3288 // -------------------------------------------------------------------------------------
3290 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3292 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3293 EVT_SIZE (wxListCtrl::OnSize
)
3294 EVT_IDLE (wxListCtrl::OnIdle
)
3297 wxListCtrl::wxListCtrl()
3299 m_imageListNormal
= (wxImageList
*) NULL
;
3300 m_imageListSmall
= (wxImageList
*) NULL
;
3301 m_imageListState
= (wxImageList
*) NULL
;
3302 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3303 m_mainWin
= (wxListMainWindow
*) NULL
;
3304 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3307 wxListCtrl::~wxListCtrl()
3309 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3310 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3311 if (m_ownsImageListState
) delete m_imageListState
;
3314 bool wxListCtrl::Create(wxWindow
*parent
,
3319 const wxValidator
&validator
,
3320 const wxString
&name
)
3322 m_imageListNormal
= (wxImageList
*) NULL
;
3323 m_imageListSmall
= (wxImageList
*) NULL
;
3324 m_imageListState
= (wxImageList
*) NULL
;
3325 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3326 m_mainWin
= (wxListMainWindow
*) NULL
;
3327 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3329 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3331 style
= style
| wxLC_LIST
;
3334 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3337 if (style
& wxSUNKEN_BORDER
)
3338 style
-= wxSUNKEN_BORDER
;
3340 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3342 if (HasFlag(wxLC_REPORT
))
3344 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3345 if (HasFlag(wxLC_NO_HEADER
))
3346 m_headerWin
->Show( FALSE
);
3350 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3356 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3358 /* handled in OnIdle */
3360 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3363 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3365 long flag
= GetWindowStyle();
3369 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3370 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3371 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3380 if (flag
& style
) flag
-= style
;
3383 SetWindowStyleFlag( flag
);
3386 void wxListCtrl::SetWindowStyleFlag( long flag
)
3390 m_mainWin
->DeleteEverything();
3394 GetClientSize( &width
, &height
);
3396 m_mainWin
->SetMode( flag
);
3398 if (flag
& wxLC_REPORT
)
3400 if (!HasFlag(wxLC_REPORT
))
3404 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3405 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3406 if (HasFlag(wxLC_NO_HEADER
))
3407 m_headerWin
->Show( FALSE
);
3411 if (flag
& wxLC_NO_HEADER
)
3412 m_headerWin
->Show( FALSE
);
3414 m_headerWin
->Show( TRUE
);
3420 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3422 m_headerWin
->Show( FALSE
);
3427 wxWindow::SetWindowStyleFlag( flag
);
3430 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3432 m_mainWin
->GetColumn( col
, item
);
3436 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3438 m_mainWin
->SetColumn( col
, item
);
3442 int wxListCtrl::GetColumnWidth( int col
) const
3444 return m_mainWin
->GetColumnWidth( col
);
3447 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3449 m_mainWin
->SetColumnWidth( col
, width
);
3453 int wxListCtrl::GetCountPerPage() const
3455 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3458 bool wxListCtrl::GetItem( wxListItem
&info
) const
3460 m_mainWin
->GetItem( info
);
3464 bool wxListCtrl::SetItem( wxListItem
&info
)
3466 m_mainWin
->SetItem( info
);
3470 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3473 info
.m_text
= label
;
3474 info
.m_mask
= wxLIST_MASK_TEXT
;
3475 info
.m_itemId
= index
;
3479 info
.m_image
= imageId
;
3480 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3482 m_mainWin
->SetItem(info
);
3486 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3488 return m_mainWin
->GetItemState( item
, stateMask
);
3491 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3493 m_mainWin
->SetItemState( item
, state
, stateMask
);
3497 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3500 info
.m_image
= image
;
3501 info
.m_mask
= wxLIST_MASK_IMAGE
;
3502 info
.m_itemId
= item
;
3503 m_mainWin
->SetItem( info
);
3507 wxString
wxListCtrl::GetItemText( long item
) const
3510 info
.m_itemId
= item
;
3511 m_mainWin
->GetItem( info
);
3515 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3518 info
.m_mask
= wxLIST_MASK_TEXT
;
3519 info
.m_itemId
= item
;
3521 m_mainWin
->SetItem( info
);
3524 long wxListCtrl::GetItemData( long item
) const
3527 info
.m_itemId
= item
;
3528 m_mainWin
->GetItem( info
);
3532 bool wxListCtrl::SetItemData( long item
, long data
)
3535 info
.m_mask
= wxLIST_MASK_DATA
;
3536 info
.m_itemId
= item
;
3538 m_mainWin
->SetItem( info
);
3542 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3544 m_mainWin
->GetItemRect( item
, rect
);
3548 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3550 m_mainWin
->GetItemPosition( item
, pos
);
3554 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3559 int wxListCtrl::GetItemCount() const
3561 return m_mainWin
->GetItemCount();
3564 int wxListCtrl::GetColumnCount() const
3566 return m_mainWin
->GetColumnCount();
3569 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3571 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3574 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3576 return m_mainWin
->GetItemSpacing( isSmall
);
3579 int wxListCtrl::GetSelectedItemCount() const
3581 return m_mainWin
->GetSelectedItemCount();
3584 wxColour
wxListCtrl::GetTextColour() const
3586 return GetForegroundColour();
3589 void wxListCtrl::SetTextColour(const wxColour
& col
)
3591 SetForegroundColour(col
);
3594 long wxListCtrl::GetTopItem() const
3599 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3601 return m_mainWin
->GetNextItem( item
, geom
, state
);
3604 wxImageList
*wxListCtrl::GetImageList(int which
) const
3606 if (which
== wxIMAGE_LIST_NORMAL
)
3608 return m_imageListNormal
;
3610 else if (which
== wxIMAGE_LIST_SMALL
)
3612 return m_imageListSmall
;
3614 else if (which
== wxIMAGE_LIST_STATE
)
3616 return m_imageListState
;
3618 return (wxImageList
*) NULL
;
3621 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3623 if ( which
== wxIMAGE_LIST_NORMAL
)
3625 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3626 m_imageListNormal
= imageList
;
3627 m_ownsImageListNormal
= FALSE
;
3629 else if ( which
== wxIMAGE_LIST_SMALL
)
3631 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3632 m_imageListSmall
= imageList
;
3633 m_ownsImageListSmall
= FALSE
;
3635 else if ( which
== wxIMAGE_LIST_STATE
)
3637 if (m_ownsImageListState
) delete m_imageListState
;
3638 m_imageListState
= imageList
;
3639 m_ownsImageListState
= FALSE
;
3642 m_mainWin
->SetImageList( imageList
, which
);
3645 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3647 SetImageList(imageList
, which
);
3648 if ( which
== wxIMAGE_LIST_NORMAL
)
3649 m_ownsImageListNormal
= TRUE
;
3650 else if ( which
== wxIMAGE_LIST_SMALL
)
3651 m_ownsImageListSmall
= TRUE
;
3652 else if ( which
== wxIMAGE_LIST_STATE
)
3653 m_ownsImageListState
= TRUE
;
3656 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3661 bool wxListCtrl::DeleteItem( long item
)
3663 m_mainWin
->DeleteItem( item
);
3667 bool wxListCtrl::DeleteAllItems()
3669 m_mainWin
->DeleteAllItems();
3673 bool wxListCtrl::DeleteAllColumns()
3675 size_t count
= m_mainWin
->m_columns
.GetCount();
3676 for ( size_t n
= 0; n
< count
; n
++ )
3682 void wxListCtrl::ClearAll()
3684 m_mainWin
->DeleteEverything();
3687 bool wxListCtrl::DeleteColumn( int col
)
3689 m_mainWin
->DeleteColumn( col
);
3693 void wxListCtrl::Edit( long item
)
3695 m_mainWin
->Edit( item
);
3698 bool wxListCtrl::EnsureVisible( long item
)
3700 m_mainWin
->EnsureVisible( item
);
3704 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3706 return m_mainWin
->FindItem( start
, str
, partial
);
3709 long wxListCtrl::FindItem( long start
, long data
)
3711 return m_mainWin
->FindItem( start
, data
);
3714 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3715 int WXUNUSED(direction
))
3720 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3722 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3725 long wxListCtrl::InsertItem( wxListItem
& info
)
3727 m_mainWin
->InsertItem( info
);
3728 return info
.m_itemId
;
3731 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3734 info
.m_text
= label
;
3735 info
.m_mask
= wxLIST_MASK_TEXT
;
3736 info
.m_itemId
= index
;
3737 return InsertItem( info
);
3740 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3743 info
.m_mask
= wxLIST_MASK_IMAGE
;
3744 info
.m_image
= imageIndex
;
3745 info
.m_itemId
= index
;
3746 return InsertItem( info
);
3749 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3752 info
.m_text
= label
;
3753 info
.m_image
= imageIndex
;
3754 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3755 info
.m_itemId
= index
;
3756 return InsertItem( info
);
3759 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3761 wxASSERT( m_headerWin
);
3762 m_mainWin
->InsertColumn( col
, item
);
3763 m_headerWin
->Refresh();
3768 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3769 int format
, int width
)
3772 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3773 item
.m_text
= heading
;
3776 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3777 item
.m_width
= width
;
3779 item
.m_format
= format
;
3781 return InsertColumn( col
, item
);
3784 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3790 // fn is a function which takes 3 long arguments: item1, item2, data.
3791 // item1 is the long data associated with a first item (NOT the index).
3792 // item2 is the long data associated with a second item (NOT the index).
3793 // data is the same value as passed to SortItems.
3794 // The return value is a negative number if the first item should precede the second
3795 // item, a positive number of the second item should precede the first,
3796 // or zero if the two items are equivalent.
3797 // data is arbitrary data to be passed to the sort function.
3799 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3801 m_mainWin
->SortItems( fn
, data
);
3805 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3807 if (!m_mainWin
->m_dirty
) return;
3811 GetClientSize( &cw
, &ch
);
3818 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3820 m_headerWin
->GetPosition( &x
, &y
);
3821 m_headerWin
->GetSize( &w
, &h
);
3822 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3823 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3825 m_mainWin
->GetPosition( &x
, &y
);
3826 m_mainWin
->GetSize( &w
, &h
);
3827 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3828 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3832 m_mainWin
->GetPosition( &x
, &y
);
3833 m_mainWin
->GetSize( &w
, &h
);
3834 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3835 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3838 m_mainWin
->CalculatePositions();
3839 m_mainWin
->RealizeChanges();
3840 m_mainWin
->m_dirty
= FALSE
;
3841 m_mainWin
->Refresh();
3843 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3845 m_headerWin
->m_dirty
= FALSE
;
3846 m_headerWin
->Refresh();
3850 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3854 m_mainWin
->SetBackgroundColour( colour
);
3855 m_mainWin
->m_dirty
= TRUE
;
3861 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3863 if ( !wxWindow::SetForegroundColour( colour
) )
3868 m_mainWin
->SetForegroundColour( colour
);
3869 m_mainWin
->m_dirty
= TRUE
;
3874 m_headerWin
->SetForegroundColour( colour
);
3880 bool wxListCtrl::SetFont( const wxFont
&font
)
3882 if ( !wxWindow::SetFont( font
) )
3887 m_mainWin
->SetFont( font
);
3888 m_mainWin
->m_dirty
= TRUE
;
3893 m_headerWin
->SetFont( font
);
3899 #if wxUSE_DRAG_AND_DROP
3901 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3903 m_mainWin
->SetDropTarget( dropTarget
);
3906 wxDropTarget
*wxListCtrl::GetDropTarget() const
3908 return m_mainWin
->GetDropTarget();
3911 #endif // wxUSE_DRAG_AND_DROP
3913 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3915 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3918 wxColour
wxListCtrl::GetBackgroundColour() const
3920 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3923 wxColour
wxListCtrl::GetForegroundColour() const
3925 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3928 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3931 return m_mainWin
->PopupMenu( menu
, x
, y
);
3934 #endif // wxUSE_MENUS
3937 void wxListCtrl::SetFocus()
3939 /* The test in window.cpp fails as we are a composite
3940 window, so it checks against "this", but not m_mainWin. */
3941 if ( FindFocus() != this )
3942 m_mainWin
->SetFocus();
3945 // ----------------------------------------------------------------------------
3946 // virtual list control support
3947 // ----------------------------------------------------------------------------
3949 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
3951 // this is a pure virtual function, in fact - which is not really pure
3952 // because the controls which are not virtual don't need to implement it
3953 wxFAIL_MSG( _T("not supposed to be called") );
3955 return wxEmptyString
;
3958 int wxListCtrl::OnGetItemImage(long item
) const
3961 wxFAIL_MSG( _T("not supposed to be called") );
3966 void wxListCtrl::SetItemCount(long count
)
3968 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
3970 m_mainWin
->SetItemCount(count
);
3973 #endif // wxUSE_LISTCTRL