1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
26 #include "wx/dynarray.h"
30 #include "wx/gtk/win_gtk.h"
33 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
34 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
58 // ============================================================================
60 // ============================================================================
62 //-----------------------------------------------------------------------------
63 // wxListItemData (internal)
64 //-----------------------------------------------------------------------------
66 class WXDLLEXPORT wxListItemData
: public wxObject
75 wxListItemAttr
*m_attr
;
79 ~wxListItemData() { delete m_attr
; }
81 wxListItemData( const wxListItem
&info
);
82 void SetItem( const wxListItem
&info
);
83 void SetText( const wxString
&s
);
84 void SetImage( int image
);
85 void SetData( long data
);
86 void SetPosition( int x
, int y
);
87 void SetSize( int width
, int height
);
88 bool HasImage() const;
90 bool IsHit( int x
, int y
) const;
91 void GetText( wxString
&s
);
92 const wxString
& GetText() { return m_text
; }
93 int GetX( void ) const;
94 int GetY( void ) const;
96 int GetHeight() const;
98 void GetItem( wxListItem
&info
) const;
100 wxListItemAttr
*GetAttributes() const { return m_attr
; }
103 DECLARE_DYNAMIC_CLASS(wxListItemData
);
106 //-----------------------------------------------------------------------------
107 // wxListHeaderData (internal)
108 //-----------------------------------------------------------------------------
110 class WXDLLEXPORT wxListHeaderData
: public wxObject
123 wxListHeaderData( const wxListItem
&info
);
124 void SetItem( const wxListItem
&item
);
125 void SetPosition( int x
, int y
);
126 void SetWidth( int w
);
127 void SetFormat( int format
);
128 void SetHeight( int h
);
129 bool HasImage() const;
130 bool HasText() const;
131 bool IsHit( int x
, int y
) const;
132 void GetItem( wxListItem
&item
);
133 void GetText( wxString
&s
);
134 int GetImage() const;
135 int GetWidth() const;
136 int GetFormat() const;
139 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
142 //-----------------------------------------------------------------------------
143 // wxListLineData (internal)
144 //-----------------------------------------------------------------------------
146 class WXDLLEXPORT wxListLineData
: public wxObject
151 wxRect m_bound_label
;
153 wxRect m_bound_hilight
;
156 wxBrush
*m_hilightBrush
;
158 wxListMainWindow
*m_owner
;
160 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
164 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
165 void CalculateSize( wxDC
*dc
, int spacing
);
166 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
167 void SetColumnPosition( int index
, int x
);
168 void GetSize( int &width
, int &height
);
169 void GetExtent( int &x
, int &y
, int &width
, int &height
);
170 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
171 long IsHit( int x
, int y
);
172 void InitItems( int num
);
173 void SetItem( int index
, const wxListItem
&info
);
174 void GetItem( int index
, wxListItem
&info
);
175 void GetText( int index
, wxString
&s
);
176 void SetText( int index
, const wxString s
);
177 int GetImage( int index
);
178 void GetRect( wxRect
&rect
);
179 void Hilight( bool on
);
180 void ReverseHilight();
181 void DrawRubberBand( wxDC
*dc
, bool on
);
182 void Draw( wxDC
*dc
);
183 bool IsInRect( int x
, int y
, const wxRect
&rect
);
185 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
186 void AssignRect( wxRect
&dest
, const wxRect
&source
);
189 void SetAttributes(wxDC
*dc
,
190 const wxListItemAttr
*attr
,
191 const wxColour
& colText
, const wxFont
& font
,
194 DECLARE_DYNAMIC_CLASS(wxListLineData
);
198 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
199 #include "wx/arrimpl.cpp"
200 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
202 //-----------------------------------------------------------------------------
203 // wxListHeaderWindow (internal)
204 //-----------------------------------------------------------------------------
206 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
209 wxListMainWindow
*m_owner
;
210 wxCursor
*m_currentCursor
;
211 wxCursor
*m_resizeCursor
;
214 // column being resized
217 // divider line position in logical (unscrolled) coords
220 // minimal position beyond which the divider line can't be dragged in
225 wxListHeaderWindow();
226 virtual ~wxListHeaderWindow();
228 wxListHeaderWindow( wxWindow
*win
,
230 wxListMainWindow
*owner
,
231 const wxPoint
&pos
= wxDefaultPosition
,
232 const wxSize
&size
= wxDefaultSize
,
234 const wxString
&name
= "wxlistctrlcolumntitles" );
236 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
238 void AdjustDC(wxDC
& dc
);
240 void OnPaint( wxPaintEvent
&event
);
241 void OnMouse( wxMouseEvent
&event
);
242 void OnSetFocus( wxFocusEvent
&event
);
248 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
249 DECLARE_EVENT_TABLE()
252 //-----------------------------------------------------------------------------
253 // wxListRenameTimer (internal)
254 //-----------------------------------------------------------------------------
256 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
259 wxListMainWindow
*m_owner
;
262 wxListRenameTimer( wxListMainWindow
*owner
);
266 //-----------------------------------------------------------------------------
267 // wxListTextCtrl (internal)
268 //-----------------------------------------------------------------------------
270 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
275 wxListMainWindow
*m_owner
;
276 wxString m_startValue
;
280 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
281 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
282 const wxString
&value
= "",
283 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
285 const wxValidator
& validator
= wxDefaultValidator
,
286 const wxString
&name
= "listctrltextctrl" );
287 void OnChar( wxKeyEvent
&event
);
288 void OnKeyUp( wxKeyEvent
&event
);
289 void OnKillFocus( wxFocusEvent
&event
);
292 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
293 DECLARE_EVENT_TABLE()
296 //-----------------------------------------------------------------------------
297 // wxListMainWindow (internal)
298 //-----------------------------------------------------------------------------
300 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
304 wxListLineDataArray m_lines
;
306 wxListLineData
*m_current
;
307 wxListLineData
*m_currentEdit
;
309 wxBrush
*m_hilightBrush
;
310 wxColour
*m_hilightColour
;
311 int m_xScroll
,m_yScroll
;
313 wxImageList
*m_small_image_list
;
314 wxImageList
*m_normal_image_list
;
316 int m_normal_spacing
;
320 wxTimer
*m_renameTimer
;
322 wxString m_renameRes
;
327 // for double click logic
328 wxListLineData
*m_lineLastClicked
,
329 *m_lineBeforeLastClicked
;
333 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
334 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
335 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
337 void RefreshLine( wxListLineData
*line
);
338 void OnPaint( wxPaintEvent
&event
);
339 void HilightAll( bool on
);
340 void SendNotify( wxListLineData
*line
,
342 wxPoint point
= wxDefaultPosition
);
343 void FocusLine( wxListLineData
*line
);
344 void UnfocusLine( wxListLineData
*line
);
345 void SelectLine( wxListLineData
*line
);
346 void DeselectLine( wxListLineData
*line
);
347 void DeleteLine( wxListLineData
*line
);
349 void EditLabel( long item
);
350 void Edit( long item
) { EditLabel(item
); } // deprecated
351 void OnRenameTimer();
352 void OnRenameAccept();
354 void OnMouse( wxMouseEvent
&event
);
356 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
357 void OnChar( wxKeyEvent
&event
);
358 void OnKeyDown( wxKeyEvent
&event
);
359 void OnSetFocus( wxFocusEvent
&event
);
360 void OnKillFocus( wxFocusEvent
&event
);
361 void OnSize( wxSizeEvent
&event
);
362 void OnScroll(wxScrollWinEvent
& event
) ;
364 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
365 void GetImageSize( int index
, int &width
, int &height
);
366 int GetIndexOfLine( const wxListLineData
*line
);
367 int GetTextLength( wxString
&s
); // should be const
369 void SetImageList( wxImageList
*imageList
, int which
);
370 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
371 int GetItemSpacing( bool isSmall
= FALSE
);
372 void SetColumn( int col
, wxListItem
&item
);
373 void SetColumnWidth( int col
, int width
);
374 void GetColumn( int col
, wxListItem
&item
);
375 int GetColumnWidth( int vol
);
376 int GetColumnCount();
377 int GetCountPerPage();
378 void SetItem( wxListItem
&item
);
379 void GetItem( wxListItem
&item
);
380 void SetItemState( long item
, long state
, long stateMask
);
381 int GetItemState( long item
, long stateMask
);
383 void GetItemRect( long index
, wxRect
&rect
);
384 bool GetItemPosition( long item
, wxPoint
& pos
);
385 int GetSelectedItemCount();
386 void SetMode( long mode
);
387 long GetMode() const;
388 void CalculatePositions();
389 void RealizeChanges();
390 long GetNextItem( long item
, int geometry
, int state
);
391 void DeleteItem( long index
);
392 void DeleteAllItems();
393 void DeleteColumn( int col
);
394 void DeleteEverything();
395 void EnsureVisible( long index
);
396 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
397 long FindItem( long start
, long data
);
398 long HitTest( int x
, int y
, int &flags
);
399 void InsertItem( wxListItem
&item
);
400 // void AddItem( wxListItem &item );
401 void InsertColumn( long col
, wxListItem
&item
);
402 // void AddColumn( wxListItem &item );
403 void SortItems( wxListCtrlCompare fn
, long data
);
406 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
407 DECLARE_EVENT_TABLE()
410 // ============================================================================
412 // ============================================================================
414 //-----------------------------------------------------------------------------
416 //-----------------------------------------------------------------------------
418 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
420 wxListItemData::wxListItemData()
431 wxListItemData::wxListItemData( const wxListItem
&info
)
440 void wxListItemData::SetItem( const wxListItem
&info
)
442 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
443 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
444 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
446 if ( info
.HasAttributes() )
449 *m_attr
= *info
.GetAttributes();
451 m_attr
= new wxListItemAttr(*info
.GetAttributes());
456 m_width
= info
.m_width
;
460 void wxListItemData::SetText( const wxString
&s
)
465 void wxListItemData::SetImage( int image
)
470 void wxListItemData::SetData( long data
)
475 void wxListItemData::SetPosition( int x
, int y
)
481 void wxListItemData::SetSize( int width
, int height
)
483 if (width
!= -1) m_width
= width
;
484 if (height
!= -1) m_height
= height
;
487 bool wxListItemData::HasImage() const
489 return (m_image
>= 0);
492 bool wxListItemData::HasText() const
494 return (!m_text
.IsNull());
497 bool wxListItemData::IsHit( int x
, int y
) const
499 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
502 void wxListItemData::GetText( wxString
&s
)
507 int wxListItemData::GetX() const
512 int wxListItemData::GetY() const
517 int wxListItemData::GetWidth() const
522 int wxListItemData::GetHeight() const
527 int wxListItemData::GetImage() const
532 void wxListItemData::GetItem( wxListItem
&info
) const
534 info
.m_text
= m_text
;
535 info
.m_image
= m_image
;
536 info
.m_data
= m_data
;
540 if ( m_attr
->HasTextColour() )
541 info
.SetTextColour(m_attr
->GetTextColour());
542 if ( m_attr
->HasBackgroundColour() )
543 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
544 if ( m_attr
->HasFont() )
545 info
.SetFont(m_attr
->GetFont());
549 //-----------------------------------------------------------------------------
551 //-----------------------------------------------------------------------------
553 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
555 wxListHeaderData::wxListHeaderData()
566 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
574 void wxListHeaderData::SetItem( const wxListItem
&item
)
576 m_mask
= item
.m_mask
;
577 m_text
= item
.m_text
;
578 m_image
= item
.m_image
;
579 m_format
= item
.m_format
;
580 m_width
= item
.m_width
;
581 if (m_width
< 0) m_width
= 80;
582 if (m_width
< 6) m_width
= 6;
585 void wxListHeaderData::SetPosition( int x
, int y
)
591 void wxListHeaderData::SetHeight( int h
)
596 void wxListHeaderData::SetWidth( int w
)
599 if (m_width
< 0) m_width
= 80;
600 if (m_width
< 6) m_width
= 6;
603 void wxListHeaderData::SetFormat( int format
)
608 bool wxListHeaderData::HasImage() const
610 return (m_image
!= 0);
613 bool wxListHeaderData::HasText() const
615 return (m_text
.Length() > 0);
618 bool wxListHeaderData::IsHit( int x
, int y
) const
620 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
623 void wxListHeaderData::GetItem( wxListItem
&item
)
625 item
.m_mask
= m_mask
;
626 item
.m_text
= m_text
;
627 item
.m_image
= m_image
;
628 item
.m_format
= m_format
;
629 item
.m_width
= m_width
;
632 void wxListHeaderData::GetText( wxString
&s
)
637 int wxListHeaderData::GetImage() const
642 int wxListHeaderData::GetWidth() const
647 int wxListHeaderData::GetFormat() const
652 //-----------------------------------------------------------------------------
654 //-----------------------------------------------------------------------------
656 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
658 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
663 m_hilightBrush
= hilightBrush
;
664 m_items
.DeleteContents( TRUE
);
668 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
675 m_bound_all
.width
= m_spacing
;
676 wxNode
*node
= m_items
.First();
679 wxListItemData
*item
= (wxListItemData
*)node
->Data();
680 wxString s
= item
->GetText();
681 if (s
.IsEmpty()) s
= wxT("H");
683 dc
->GetTextExtent( s
, &lw
, &lh
);
684 if (lh
< 15) lh
= 15;
688 m_bound_all
.height
= m_spacing
+lh
;
689 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
690 m_bound_label
.width
= lw
;
691 m_bound_label
.height
= lh
;
693 if (item
->HasImage())
697 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
698 m_bound_icon
.width
= w
+ 8;
699 m_bound_icon
.height
= h
+ 8;
701 if ( m_bound_icon
.width
> m_bound_all
.width
)
702 m_bound_all
.width
= m_bound_icon
.width
;
703 if ( h
+ lh
> m_bound_all
.height
- 4 )
704 m_bound_all
.height
= h
+ lh
+ 4;
707 if (!item
->HasText())
709 m_bound_hilight
.width
= m_bound_icon
.width
;
710 m_bound_hilight
.height
= m_bound_icon
.height
;
714 m_bound_hilight
.width
= m_bound_label
.width
;
715 m_bound_hilight
.height
= m_bound_label
.height
;
722 wxNode
*node
= m_items
.First();
725 wxListItemData
*item
= (wxListItemData
*)node
->Data();
727 wxString s
= item
->GetText();
728 if (s
.IsEmpty()) s
= wxT("H");
730 dc
->GetTextExtent( s
, &lw
, &lh
);
731 if (lh
< 15) lh
= 15;
734 m_bound_label
.width
= lw
;
735 m_bound_label
.height
= lh
;
737 m_bound_all
.width
= lw
;
738 m_bound_all
.height
= lh
;
740 if (item
->HasImage())
744 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
745 m_bound_icon
.width
= w
;
746 m_bound_icon
.height
= h
;
748 m_bound_all
.width
+= 4 + w
;
749 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
752 m_bound_hilight
.width
= m_bound_all
.width
;
753 m_bound_hilight
.height
= m_bound_all
.height
;
759 m_bound_all
.width
= 0;
760 m_bound_all
.height
= 0;
761 wxNode
*node
= m_items
.First();
764 wxListItemData
*item
= (wxListItemData
*)node
->Data();
765 if (item
->HasImage())
769 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
770 m_bound_icon
.width
= w
;
771 m_bound_icon
.height
= h
;
775 m_bound_icon
.width
= 0;
776 m_bound_icon
.height
= 0;
781 wxListItemData
*item
= (wxListItemData
*)node
->Data();
782 wxString s
= item
->GetText();
783 if (s
.IsEmpty()) s
= wxT("H");
785 dc
->GetTextExtent( s
, &lw
, &lh
);
786 if (lh
< 15) lh
= 15;
790 item
->SetSize( item
->GetWidth(), lh
);
791 m_bound_all
.width
+= lw
;
792 m_bound_all
.height
= lh
;
795 m_bound_label
.width
= m_bound_all
.width
;
796 m_bound_label
.height
= m_bound_all
.height
;
802 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
803 int x
, int y
, int window_width
)
811 wxNode
*node
= m_items
.First();
814 wxListItemData
*item
= (wxListItemData
*)node
->Data();
815 if (item
->HasImage())
817 m_bound_icon
.x
= m_bound_all
.x
+ 4
818 + (m_spacing
- m_bound_icon
.width
)/2;
819 m_bound_icon
.y
= m_bound_all
.y
+ 4;
823 if (m_bound_all
.width
> m_spacing
)
824 m_bound_label
.x
= m_bound_all
.x
+ 2;
826 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
827 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
828 m_bound_hilight
.x
= m_bound_label
.x
- 2;
829 m_bound_hilight
.y
= m_bound_label
.y
- 2;
833 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
834 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
841 m_bound_hilight
.x
= m_bound_all
.x
;
842 m_bound_hilight
.y
= m_bound_all
.y
;
843 m_bound_label
.y
= m_bound_all
.y
+ 2;
844 wxNode
*node
= m_items
.First();
847 wxListItemData
*item
= (wxListItemData
*)node
->Data();
848 if (item
->HasImage())
850 m_bound_icon
.x
= m_bound_all
.x
+ 2;
851 m_bound_icon
.y
= m_bound_all
.y
+ 2;
852 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
856 m_bound_label
.x
= m_bound_all
.x
+ 2;
864 m_bound_all
.width
= window_width
;
865 AssignRect( m_bound_hilight
, m_bound_all
);
866 m_bound_label
.x
= m_bound_all
.x
+ 2;
867 m_bound_label
.y
= m_bound_all
.y
+ 2;
868 wxNode
*node
= m_items
.First();
871 wxListItemData
*item
= (wxListItemData
*)node
->Data();
872 if (item
->HasImage())
874 m_bound_icon
.x
= m_bound_all
.x
+ 2;
875 m_bound_icon
.y
= m_bound_all
.y
+ 2;
876 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
884 void wxListLineData::SetColumnPosition( int index
, int x
)
886 wxNode
*node
= m_items
.Nth( (size_t)index
);
889 wxListItemData
*item
= (wxListItemData
*)node
->Data();
890 item
->SetPosition( x
, m_bound_all
.y
+1 );
894 void wxListLineData::GetSize( int &width
, int &height
)
896 width
= m_bound_all
.width
;
897 height
= m_bound_all
.height
;
900 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
904 width
= m_bound_all
.width
;
905 height
= m_bound_all
.height
;
908 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
912 width
= m_bound_label
.width
;
913 height
= m_bound_label
.height
;
916 void wxListLineData::GetRect( wxRect
&rect
)
918 AssignRect( rect
, m_bound_all
);
921 long wxListLineData::IsHit( int x
, int y
)
923 wxNode
*node
= m_items
.First();
926 wxListItemData
*item
= (wxListItemData
*)node
->Data();
927 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
928 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
929 // if (!(item->HasImage() || item->HasText())) return 0;
931 // if there is no icon or text = empty
932 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
936 void wxListLineData::InitItems( int num
)
938 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
941 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
943 wxNode
*node
= m_items
.Nth( index
);
946 wxListItemData
*item
= (wxListItemData
*)node
->Data();
947 item
->SetItem( info
);
951 void wxListLineData::GetItem( int index
, wxListItem
&info
)
954 wxNode
*node
= m_items
.Nth( i
);
957 wxListItemData
*item
= (wxListItemData
*)node
->Data();
958 item
->GetItem( info
);
962 void wxListLineData::GetText( int index
, wxString
&s
)
965 wxNode
*node
= m_items
.Nth( i
);
969 wxListItemData
*item
= (wxListItemData
*)node
->Data();
974 void wxListLineData::SetText( int index
, const wxString s
)
977 wxNode
*node
= m_items
.Nth( i
);
980 wxListItemData
*item
= (wxListItemData
*)node
->Data();
985 int wxListLineData::GetImage( int index
)
988 wxNode
*node
= m_items
.Nth( i
);
991 wxListItemData
*item
= (wxListItemData
*)node
->Data();
992 return item
->GetImage();
997 void wxListLineData::SetAttributes(wxDC
*dc
,
998 const wxListItemAttr
*attr
,
999 const wxColour
& colText
,
1003 // don't use foregroud colour for drawing highlighted items - this might
1004 // make them completely invisible (and there is no way to do bit
1005 // arithmetics on wxColour, unfortunately)
1006 if ( !hilight
&& attr
&& attr
->HasTextColour() )
1008 dc
->SetTextForeground(attr
->GetTextColour());
1012 dc
->SetTextForeground(colText
);
1015 if ( attr
&& attr
->HasFont() )
1017 dc
->SetFont(attr
->GetFont());
1025 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1029 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1030 wxCoord dev_w
= m_bound_all
.width
;
1031 wxCoord dev_h
= m_bound_all
.height
;
1033 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1036 wxWindow
*listctrl
= m_owner
->GetParent();
1038 // default foreground colour
1042 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1046 colText
= listctrl
->GetForegroundColour();
1050 wxFont font
= listctrl
->GetFont();
1052 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1053 // using SetAttributes() inside the loop), it will be trivial to
1054 // customize the subitems (in report mode) too.
1055 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1056 wxListItemAttr
*attr
= item
->GetAttributes();
1057 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1059 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1060 if ( paintBG
|| hasBgCol
)
1064 dc
->SetBrush( * m_hilightBrush
);
1069 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1071 dc
->SetBrush( * wxWHITE_BRUSH
);
1074 dc
->SetPen( * wxTRANSPARENT_PEN
);
1075 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1076 m_bound_hilight
.width
, m_bound_hilight
.height
);
1079 if (m_mode
== wxLC_REPORT
)
1081 wxNode
*node
= m_items
.First();
1084 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1085 int x
= item
->GetX();
1086 if (item
->HasImage())
1089 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1090 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1091 x
+= item
->GetX() + 5;
1093 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1094 if (item
->HasText())
1096 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1098 dc
->DestroyClippingRegion();
1099 node
= node
->Next();
1104 wxNode
*node
= m_items
.First();
1107 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1108 if (item
->HasImage())
1110 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1112 if (item
->HasText())
1114 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1120 void wxListLineData::Hilight( bool on
)
1122 if (on
== m_hilighted
) return;
1125 m_owner
->SelectLine( this );
1127 m_owner
->DeselectLine( this );
1130 void wxListLineData::ReverseHilight( void )
1132 m_hilighted
= !m_hilighted
;
1134 m_owner
->SelectLine( this );
1136 m_owner
->DeselectLine( this );
1139 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1143 dc
->SetPen( * wxBLACK_PEN
);
1144 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1145 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1146 m_bound_hilight
.width
, m_bound_hilight
.height
);
1150 void wxListLineData::Draw( wxDC
*dc
)
1152 DoDraw( dc
, m_hilighted
, m_hilighted
);
1155 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1157 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1158 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1161 bool wxListLineData::IsHilighted( void )
1166 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1171 dest
.height
= height
;
1174 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1178 dest
.width
= source
.width
;
1179 dest
.height
= source
.height
;
1182 //-----------------------------------------------------------------------------
1183 // wxListHeaderWindow
1184 //-----------------------------------------------------------------------------
1186 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1188 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1189 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1190 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1191 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1194 wxListHeaderWindow::wxListHeaderWindow( void )
1196 m_owner
= (wxListMainWindow
*) NULL
;
1197 m_currentCursor
= (wxCursor
*) NULL
;
1198 m_resizeCursor
= (wxCursor
*) NULL
;
1199 m_isDragging
= FALSE
;
1202 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1203 const wxPoint
&pos
, const wxSize
&size
,
1204 long style
, const wxString
&name
) :
1205 wxWindow( win
, id
, pos
, size
, style
, name
)
1208 // m_currentCursor = wxSTANDARD_CURSOR;
1209 m_currentCursor
= (wxCursor
*) NULL
;
1210 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1211 m_isDragging
= FALSE
;
1214 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1217 wxListHeaderWindow::~wxListHeaderWindow( void )
1219 delete m_resizeCursor
;
1222 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1225 GtkStateType state
= GTK_STATE_NORMAL
;
1226 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1228 x
= dc
->XLOG2DEV( x
);
1230 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1231 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1233 const int m_corner
= 1;
1235 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1237 dc
->SetPen( *wxBLACK_PEN
);
1238 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1239 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1241 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1244 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1245 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1247 dc
->SetPen( *wxWHITE_PEN
);
1248 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1249 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1250 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1251 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1255 // shift the DC origin to match the position of the main window horz
1256 // scrollbar: this allows us to always use logical coords
1257 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1259 #if wxUSE_GENERIC_LIST_EXTENSIONS
1261 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1264 m_owner
->GetViewStart( &x
, NULL
);
1266 // account for the horz scrollbar offset
1267 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1268 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1271 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1274 wxClientDC
dc( this );
1276 wxPaintDC
dc( this );
1284 dc
.SetFont( GetFont() );
1286 // width and height of the entire header window
1288 GetClientSize( &w
, &h
);
1289 #if wxUSE_GENERIC_LIST_EXTENSIONS
1290 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1291 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1293 dc
.SetBackgroundMode(wxTRANSPARENT
);
1295 // do *not* use the listctrl colour for headers - one day we will have a
1296 // function to set it separately
1297 //dc.SetTextForeground( *wxBLACK );
1298 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1300 int x
= 1; // left of the header rect
1301 const int y
= 1; // top
1302 int numColumns
= m_owner
->GetColumnCount();
1304 for (int i
= 0; i
< numColumns
; i
++)
1306 m_owner
->GetColumn( i
, item
);
1307 int wCol
= item
.m_width
;
1308 int cw
= wCol
- 2; // the width of the rect to draw
1310 int xEnd
= x
+ wCol
;
1312 // VZ: no, draw it normally - this is better now as we allow resizing
1313 // of the last column as well
1315 // let the last column occupy all available space
1316 if ( i
== numColumns
- 1 )
1320 dc
.SetPen( *wxWHITE_PEN
);
1322 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1323 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1324 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1325 dc
.DestroyClippingRegion();
1334 void wxListHeaderWindow::DrawCurrent()
1336 int x1
= m_currentX
;
1338 ClientToScreen( &x1
, &y1
);
1340 int x2
= m_currentX
-1;
1342 m_owner
->GetClientSize( NULL
, &y2
);
1343 m_owner
->ClientToScreen( &x2
, &y2
);
1346 dc
.SetLogicalFunction( wxINVERT
);
1347 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1348 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1352 dc
.DrawLine( x1
, y1
, x2
, y2
);
1354 dc
.SetLogicalFunction( wxCOPY
);
1356 dc
.SetPen( wxNullPen
);
1357 dc
.SetBrush( wxNullBrush
);
1360 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1362 // we want to work with logical coords
1363 #if wxUSE_GENERIC_LIST_EXTENSIONS
1365 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1366 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1367 int x
= event
.GetX();
1368 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1369 int y
= event
.GetY();
1373 // we don't draw the line beyond our window, but we allow dragging it
1376 GetClientSize( &w
, NULL
);
1377 #if wxUSE_GENERIC_LIST_EXTENSIONS
1378 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1379 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1382 // erase the line if it was drawn
1383 if ( m_currentX
< w
)
1386 if (event
.ButtonUp())
1389 m_isDragging
= FALSE
;
1391 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1398 m_currentX
= m_minX
+ 7;
1400 // draw in the new location
1401 if ( m_currentX
< w
)
1405 else // not dragging
1408 bool hit_border
= FALSE
;
1410 // end of the current column
1413 // find the column where this event occured
1414 int countCol
= m_owner
->GetColumnCount();
1415 for (int j
= 0; j
< countCol
; j
++)
1417 xpos
+= m_owner
->GetColumnWidth( j
);
1420 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1422 // near the column border
1429 // inside the column
1436 if (event
.LeftDown())
1440 m_isDragging
= TRUE
;
1447 wxWindow
*parent
= GetParent();
1448 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1449 le
.SetEventObject( parent
);
1450 le
.m_col
= m_column
;
1451 parent
->GetEventHandler()->ProcessEvent( le
);
1454 else if (event
.Moving())
1459 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1460 m_currentCursor
= m_resizeCursor
;
1464 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1465 m_currentCursor
= wxSTANDARD_CURSOR
;
1469 SetCursor(*m_currentCursor
);
1474 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1476 m_owner
->SetFocus();
1479 //-----------------------------------------------------------------------------
1480 // wxListRenameTimer (internal)
1481 //-----------------------------------------------------------------------------
1483 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1488 void wxListRenameTimer::Notify()
1490 m_owner
->OnRenameTimer();
1493 //-----------------------------------------------------------------------------
1494 // wxListTextCtrl (internal)
1495 //-----------------------------------------------------------------------------
1497 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1499 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1500 EVT_CHAR (wxListTextCtrl::OnChar
)
1501 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1502 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1505 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1506 const wxWindowID id
,
1509 wxListMainWindow
*owner
,
1510 const wxString
&value
,
1514 const wxValidator
& validator
,
1515 const wxString
&name
)
1516 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1521 (*m_accept
) = FALSE
;
1523 m_startValue
= value
;
1526 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1528 if (event
.m_keyCode
== WXK_RETURN
)
1531 (*m_res
) = GetValue();
1533 if (!wxPendingDelete
.Member(this))
1534 wxPendingDelete
.Append(this);
1536 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1537 m_owner
->OnRenameAccept();
1541 if (event
.m_keyCode
== WXK_ESCAPE
)
1543 (*m_accept
) = FALSE
;
1546 if (!wxPendingDelete
.Member(this))
1547 wxPendingDelete
.Append(this);
1555 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1557 // auto-grow the textctrl:
1558 wxSize parentSize
= m_owner
->GetSize();
1559 wxPoint myPos
= GetPosition();
1560 wxSize mySize
= GetSize();
1562 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1563 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1564 if (mySize
.x
> sx
) sx
= mySize
.x
;
1570 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1572 if (!wxPendingDelete
.Member(this))
1573 wxPendingDelete
.Append(this);
1575 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1576 m_owner
->OnRenameAccept();
1579 //-----------------------------------------------------------------------------
1581 //-----------------------------------------------------------------------------
1583 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1585 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1586 EVT_PAINT (wxListMainWindow::OnPaint
)
1587 EVT_SIZE (wxListMainWindow::OnSize
)
1588 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1589 EVT_CHAR (wxListMainWindow::OnChar
)
1590 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1591 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1592 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1593 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1596 wxListMainWindow::wxListMainWindow()
1599 m_columns
.DeleteContents( TRUE
);
1600 m_current
= (wxListLineData
*) NULL
;
1602 m_hilightBrush
= (wxBrush
*) NULL
;
1606 m_small_image_list
= (wxImageList
*) NULL
;
1607 m_normal_image_list
= (wxImageList
*) NULL
;
1608 m_small_spacing
= 30;
1609 m_normal_spacing
= 40;
1612 m_lastOnSame
= FALSE
;
1613 m_renameTimer
= new wxListRenameTimer( this );
1614 m_isCreated
= FALSE
;
1618 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1621 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1622 const wxPoint
&pos
, const wxSize
&size
,
1623 long style
, const wxString
&name
) :
1624 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1627 m_columns
.DeleteContents( TRUE
);
1628 m_current
= (wxListLineData
*) NULL
;
1631 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1632 m_small_image_list
= (wxImageList
*) NULL
;
1633 m_normal_image_list
= (wxImageList
*) NULL
;
1634 m_small_spacing
= 30;
1635 m_normal_spacing
= 40;
1638 m_isCreated
= FALSE
;
1642 if (m_mode
& wxLC_REPORT
)
1644 #if wxUSE_GENERIC_LIST_EXTENSIONS
1656 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1659 m_lastOnSame
= FALSE
;
1660 m_renameTimer
= new wxListRenameTimer( this );
1661 m_renameAccept
= FALSE
;
1663 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1666 wxListMainWindow::~wxListMainWindow()
1670 if (m_hilightBrush
) delete m_hilightBrush
;
1672 delete m_renameTimer
;
1675 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1677 if (m_dirty
) return;
1685 line
->GetExtent( x
, y
, w
, h
);
1686 CalcScrolledPosition( x
, y
, &x
, &y
);
1687 wxRect
rect( x
, y
, w
, h
);
1688 Refresh( TRUE
, &rect
);
1691 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1693 // Note: a wxPaintDC must be constructed even if no drawing is
1694 // done (a Windows requirement).
1695 wxPaintDC
dc( this );
1700 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
1702 if (m_dirty
) return;
1704 if (m_lines
.GetCount() == 0) return;
1708 dc
.SetFont( GetFont() );
1710 if (m_mode
& wxLC_REPORT
)
1712 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1713 wxSize clientSize
= GetClientSize();
1715 int lineSpacing
= 0;
1716 wxListLineData
*line
= &m_lines
[0];
1718 line
->GetSize( dummy
, lineSpacing
);
1721 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1723 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1724 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1726 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1728 m_lines
[i
].Draw( &dc
);
1729 // Draw horizontal rule if required
1730 if (GetWindowStyle() & wxLC_HRULES
)
1733 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1734 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1738 // Draw last horizontal rule
1739 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1742 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1743 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1746 // Draw vertical rules if required
1747 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1750 wxRect firstItemRect
;
1751 wxRect lastItemRect
;
1752 GetItemRect(0, firstItemRect
);
1753 GetItemRect(GetItemCount() - 1, lastItemRect
);
1754 int x
= firstItemRect
.GetX();
1756 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1757 for (col
= 0; col
< GetColumnCount(); col
++)
1759 int colWidth
= GetColumnWidth(col
);
1761 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
, x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
1767 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1768 m_lines
[i
].Draw( &dc
);
1771 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1776 void wxListMainWindow::HilightAll( bool on
)
1778 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1780 wxListLineData
*line
= &m_lines
[i
];
1781 if (line
->IsHilighted() != on
)
1783 line
->Hilight( on
);
1784 RefreshLine( line
);
1789 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1790 wxEventType command
,
1793 wxListEvent
le( command
, GetParent()->GetId() );
1794 le
.SetEventObject( GetParent() );
1795 le
.m_itemIndex
= GetIndexOfLine( line
);
1797 // set only for events which have position
1798 if ( point
!= wxDefaultPosition
)
1799 le
.m_pointDrag
= point
;
1801 line
->GetItem( 0, le
.m_item
);
1802 GetParent()->GetEventHandler()->ProcessEvent( le
);
1803 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1806 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1808 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1811 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1813 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1816 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1818 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1821 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1823 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1826 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1828 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1833 void wxListMainWindow::EditLabel( long item
)
1835 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1836 wxT("wrong index in wxListCtrl::Edit()") );
1838 m_currentEdit
= &m_lines
[(size_t)item
];
1840 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1841 le
.SetEventObject( GetParent() );
1842 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1843 m_currentEdit
->GetItem( 0, le
.m_item
);
1844 GetParent()->GetEventHandler()->ProcessEvent( le
);
1846 if (!le
.IsAllowed())
1849 // We have to call this here because the label in
1850 // question might just have been added and no screen
1851 // update taken place.
1852 if (m_dirty
) wxYield();
1855 m_currentEdit
->GetText( 0, s
);
1860 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1862 wxClientDC
dc(this);
1864 x
= dc
.LogicalToDeviceX( x
);
1865 y
= dc
.LogicalToDeviceY( y
);
1867 wxListTextCtrl
*text
= new wxListTextCtrl(
1868 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1872 void wxListMainWindow::OnRenameTimer()
1874 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1876 Edit( m_lines
.Index( *m_current
) );
1879 void wxListMainWindow::OnRenameAccept()
1881 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1882 le
.SetEventObject( GetParent() );
1883 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1884 m_currentEdit
->GetItem( 0, le
.m_item
);
1885 le
.m_item
.m_text
= m_renameRes
;
1886 GetParent()->GetEventHandler()->ProcessEvent( le
);
1888 if (!le
.IsAllowed()) return;
1891 info
.m_mask
= wxLIST_MASK_TEXT
;
1892 info
.m_itemId
= le
.m_itemIndex
;
1893 info
.m_text
= m_renameRes
;
1894 info
.SetTextColour(le
.m_item
.GetTextColour());
1898 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1900 event
.SetEventObject( GetParent() );
1901 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1903 if (!m_current
) return;
1904 if (m_dirty
) return;
1905 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1907 int x
= event
.GetX();
1908 int y
= event
.GetY();
1909 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1911 /* Did we actually hit an item ? */
1913 wxListLineData
*line
= (wxListLineData
*) NULL
;
1914 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1917 hitResult
= line
->IsHit( x
, y
);
1918 if (hitResult
) break;
1919 line
= (wxListLineData
*) NULL
;
1922 if (event
.Dragging())
1924 if (m_dragCount
== 0)
1925 m_dragStart
= wxPoint(x
,y
);
1929 if (m_dragCount
!= 3) return;
1931 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1932 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1934 wxListEvent
le( command
, GetParent()->GetId() );
1935 le
.SetEventObject( GetParent() );
1936 le
.m_pointDrag
= m_dragStart
;
1937 GetParent()->GetEventHandler()->ProcessEvent( le
);
1948 bool forceClick
= FALSE
;
1949 if (event
.ButtonDClick())
1951 m_renameTimer
->Stop();
1952 m_lastOnSame
= FALSE
;
1954 if ( line
== m_lineBeforeLastClicked
)
1958 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1964 // the first click was on another item, so don't interpret this as
1965 // a double click, but as a simple click instead
1970 if (event
.LeftUp() && m_lastOnSame
)
1973 if ((line
== m_current
) &&
1974 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1975 (m_mode
& wxLC_EDIT_LABELS
) )
1977 m_renameTimer
->Start( 100, TRUE
);
1979 m_lastOnSame
= FALSE
;
1983 if (event
.RightDown())
1985 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
1986 event
.GetPosition() );
1990 if (event
.MiddleDown())
1992 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1996 if ( event
.LeftDown() || forceClick
)
1998 m_lineBeforeLastClicked
= m_lineLastClicked
;
1999 m_lineLastClicked
= line
;
2002 wxListLineData
*oldCurrent
= m_current
;
2003 if (m_mode
& wxLC_SINGLE_SEL
)
2006 HilightAll( FALSE
);
2007 m_current
->ReverseHilight();
2008 RefreshLine( m_current
);
2012 if (event
.ControlDown())
2015 m_current
->ReverseHilight();
2016 RefreshLine( m_current
);
2018 else if (event
.ShiftDown())
2024 int numOfCurrent
= -1;
2025 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2027 wxListLineData
*test_line
= &m_lines
[j
];
2029 if (test_line
== oldCurrent
) break;
2034 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2036 wxListLineData
*test_line
= &m_lines
[j
];
2038 if (test_line
== line
) break;
2041 if (numOfLine
< numOfCurrent
)
2044 numOfLine
= numOfCurrent
;
2048 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2050 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2051 test_line
->Hilight(TRUE
);
2052 RefreshLine( test_line
);
2058 HilightAll( FALSE
);
2059 m_current
->ReverseHilight();
2060 RefreshLine( m_current
);
2063 if (m_current
!= oldCurrent
)
2065 RefreshLine( oldCurrent
);
2066 UnfocusLine( oldCurrent
);
2067 FocusLine( m_current
);
2070 // forceClick is only set if the previous click was on another item
2071 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2077 void wxListMainWindow::MoveToFocus()
2079 if (!m_current
) return;
2085 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2089 GetClientSize( &client_w
, &client_h
);
2091 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2092 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2094 if (m_mode
& wxLC_REPORT
)
2096 if (item_y
< view_y
)
2097 Scroll( -1, (item_y
)/m_yScroll
);
2098 if (item_y
+item_h
+5 > view_y
+client_h
)
2099 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2103 if (item_x
-view_x
< 5)
2104 Scroll( (item_x
-5)/m_xScroll
, -1 );
2105 if (item_x
+item_w
-5 > view_x
+client_w
)
2106 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2110 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2112 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2113 wxListLineData
*oldCurrent
= m_current
;
2114 m_current
= newCurrent
;
2115 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2116 RefreshLine( m_current
);
2117 RefreshLine( oldCurrent
);
2118 FocusLine( m_current
);
2119 UnfocusLine( oldCurrent
);
2123 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2125 wxWindow
*parent
= GetParent();
2127 /* we propagate the key event up */
2128 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2129 ke
.m_shiftDown
= event
.m_shiftDown
;
2130 ke
.m_controlDown
= event
.m_controlDown
;
2131 ke
.m_altDown
= event
.m_altDown
;
2132 ke
.m_metaDown
= event
.m_metaDown
;
2133 ke
.m_keyCode
= event
.m_keyCode
;
2136 ke
.SetEventObject( parent
);
2137 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2142 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2144 wxWindow
*parent
= GetParent();
2146 /* we send a list_key event up */
2149 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2150 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2151 m_current
->GetItem( 0, le
.m_item
);
2152 le
.m_code
= (int)event
.KeyCode();
2153 le
.SetEventObject( parent
);
2154 parent
->GetEventHandler()->ProcessEvent( le
);
2157 /* we propagate the char event up */
2158 wxKeyEvent
ke( wxEVT_CHAR
);
2159 ke
.m_shiftDown
= event
.m_shiftDown
;
2160 ke
.m_controlDown
= event
.m_controlDown
;
2161 ke
.m_altDown
= event
.m_altDown
;
2162 ke
.m_metaDown
= event
.m_metaDown
;
2163 ke
.m_keyCode
= event
.m_keyCode
;
2166 ke
.SetEventObject( parent
);
2167 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2169 if (event
.KeyCode() == WXK_TAB
)
2171 wxNavigationKeyEvent nevent
;
2172 nevent
.SetWindowChange( event
.ControlDown() );
2173 nevent
.SetDirection( !event
.ShiftDown() );
2174 nevent
.SetEventObject( GetParent()->GetParent() );
2175 nevent
.SetCurrentFocus( m_parent
);
2176 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2179 /* no item -> nothing to do */
2186 switch (event
.KeyCode())
2190 int index
= m_lines
.Index(*m_current
);
2191 if (index
!= wxNOT_FOUND
&& index
> 0)
2192 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2197 int index
= m_lines
.Index(*m_current
);
2198 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2199 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2204 if (!m_lines
.IsEmpty())
2205 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2210 if (!m_lines
.IsEmpty())
2211 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2217 int index
= m_lines
.Index(*m_current
);
2218 if (m_mode
& wxLC_REPORT
)
2220 steps
= m_visibleLines
-1;
2224 steps
= index
% m_visibleLines
;
2226 if (index
!= wxNOT_FOUND
)
2229 if (index
< 0) index
= 0;
2230 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2237 int index
= m_lines
.Index(*m_current
);
2238 if (m_mode
& wxLC_REPORT
)
2240 steps
= m_visibleLines
-1;
2244 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2247 if (index
!= wxNOT_FOUND
)
2250 if ((size_t)index
>= m_lines
.GetCount())
2251 index
= m_lines
.GetCount()-1;
2252 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2258 if (!(m_mode
& wxLC_REPORT
))
2260 int index
= m_lines
.Index(*m_current
);
2261 if (index
!= wxNOT_FOUND
)
2263 index
-= m_visibleLines
;
2264 if (index
< 0) index
= 0;
2265 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2272 if (!(m_mode
& wxLC_REPORT
))
2274 int index
= m_lines
.Index(*m_current
);
2275 if (index
!= wxNOT_FOUND
)
2277 index
+= m_visibleLines
;
2278 if ((size_t)index
>= m_lines
.GetCount())
2279 index
= m_lines
.GetCount()-1;
2280 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2287 if (m_mode
& wxLC_SINGLE_SEL
)
2289 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2290 le
.SetEventObject( GetParent() );
2291 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2292 m_current
->GetItem( 0, le
.m_item
);
2293 GetParent()->GetEventHandler()->ProcessEvent( le
);
2297 m_current
->ReverseHilight();
2298 RefreshLine( m_current
);
2304 if (!(m_mode
& wxLC_SINGLE_SEL
))
2306 wxListLineData
*oldCurrent
= m_current
;
2307 m_current
->ReverseHilight();
2308 int index
= m_lines
.Index( *m_current
) + 1;
2309 if ( (size_t)index
< m_lines
.GetCount() )
2310 m_current
= &m_lines
[index
];
2311 RefreshLine( oldCurrent
);
2312 RefreshLine( m_current
);
2313 UnfocusLine( oldCurrent
);
2314 FocusLine( m_current
);
2322 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2323 le
.SetEventObject( GetParent() );
2324 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2325 m_current
->GetItem( 0, le
.m_item
);
2326 GetParent()->GetEventHandler()->ProcessEvent( le
);
2339 extern wxWindow
*g_focusWindow
;
2342 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2345 RefreshLine( m_current
);
2347 if (!GetParent()) return;
2350 g_focusWindow
= GetParent();
2353 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2354 event
.SetEventObject( GetParent() );
2355 GetParent()->GetEventHandler()->ProcessEvent( event
);
2358 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2361 RefreshLine( m_current
);
2364 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2367 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2373 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2375 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2377 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2380 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2382 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2384 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2386 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2388 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2390 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2395 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2397 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2399 m_normal_image_list
->GetSize( index
, width
, height
);
2402 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2404 m_small_image_list
->GetSize( index
, width
, height
);
2407 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2409 m_small_image_list
->GetSize( index
, width
, height
);
2412 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2414 m_small_image_list
->GetSize( index
, width
, height
);
2421 int wxListMainWindow::GetTextLength( wxString
&s
)
2423 wxClientDC
dc( this );
2426 dc
.GetTextExtent( s
, &lw
, &lh
);
2430 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2432 int i
= m_lines
.Index(*line
);
2433 if (i
== wxNOT_FOUND
) return -1;
2437 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2441 // calc the spacing from the icon size
2444 if ((imageList
) && (imageList
->GetImageCount()) )
2446 imageList
->GetSize(0, width
, height
);
2449 if (which
== wxIMAGE_LIST_NORMAL
)
2451 m_normal_image_list
= imageList
;
2452 m_normal_spacing
= width
+ 8;
2455 if (which
== wxIMAGE_LIST_SMALL
)
2457 m_small_image_list
= imageList
;
2458 m_small_spacing
= width
+ 14;
2462 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2467 m_small_spacing
= spacing
;
2471 m_normal_spacing
= spacing
;
2475 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2477 return isSmall
? m_small_spacing
: m_normal_spacing
;
2480 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2483 wxNode
*node
= m_columns
.Nth( col
);
2486 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2487 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2488 column
->SetItem( item
);
2491 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2493 headerWin
->m_dirty
= TRUE
;
2496 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2498 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2499 _T("SetColumnWidth() can only be called in report mode.") );
2503 wxNode
*node
= (wxNode
*) NULL
;
2505 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2507 // TODO do use the header
2510 else if (width
== wxLIST_AUTOSIZE
)
2512 wxClientDC
dc(this);
2513 dc
.SetFont( GetFont() );
2516 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2518 wxListLineData
*line
= &m_lines
[i
];
2519 wxNode
*n
= line
->m_items
.Nth( col
);
2522 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2523 int current
= 0, ix
= 0, iy
= 0;
2524 wxCoord lx
= 0, ly
= 0;
2525 if (item
->HasImage())
2527 GetImageSize( item
->GetImage(), ix
, iy
);
2530 if (item
->HasText())
2533 item
->GetText( str
);
2534 dc
.GetTextExtent( str
, &lx
, &ly
);
2537 if (current
> max
) max
= current
;
2543 node
= m_columns
.Nth( col
);
2546 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2547 column
->SetWidth( width
);
2550 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2552 wxListLineData
*line
= &m_lines
[i
];
2553 wxNode
*n
= line
->m_items
.Nth( col
);
2556 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2557 item
->SetSize( width
, -1 );
2561 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2563 headerWin
->m_dirty
= TRUE
;
2566 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2568 wxNode
*node
= m_columns
.Nth( col
);
2571 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2572 column
->GetItem( item
);
2584 int wxListMainWindow::GetColumnWidth( int col
)
2586 wxNode
*node
= m_columns
.Nth( col
);
2589 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2590 return column
->GetWidth();
2598 int wxListMainWindow::GetColumnCount()
2600 return m_columns
.Number();
2603 int wxListMainWindow::GetCountPerPage()
2605 return m_visibleLines
;
2608 void wxListMainWindow::SetItem( wxListItem
&item
)
2611 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2613 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2614 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2615 line
->SetItem( item
.m_col
, item
);
2619 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2621 // m_dirty = TRUE; no recalcs needed
2623 wxListLineData
*oldCurrent
= m_current
;
2625 if (stateMask
& wxLIST_STATE_FOCUSED
)
2627 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2629 wxListLineData
*line
= &m_lines
[(size_t)item
];
2630 UnfocusLine( m_current
);
2632 FocusLine( m_current
);
2633 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2634 RefreshLine( m_current
);
2635 if (oldCurrent
) RefreshLine( oldCurrent
);
2639 if (stateMask
& wxLIST_STATE_SELECTED
)
2641 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2642 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2644 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2646 wxListLineData
*line
= &m_lines
[(size_t)item
];
2647 if (m_mode
& wxLC_SINGLE_SEL
)
2649 UnfocusLine( m_current
);
2651 FocusLine( m_current
);
2652 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2653 RefreshLine( m_current
);
2654 if (oldCurrent
) RefreshLine( oldCurrent
);
2656 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2657 if (on
!= line
->IsHilighted())
2659 line
->Hilight( on
);
2660 RefreshLine( line
);
2666 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2668 int ret
= wxLIST_STATE_DONTCARE
;
2669 if (stateMask
& wxLIST_STATE_FOCUSED
)
2671 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2673 wxListLineData
*line
= &m_lines
[(size_t)item
];
2674 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2677 if (stateMask
& wxLIST_STATE_SELECTED
)
2679 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2681 wxListLineData
*line
= &m_lines
[(size_t)item
];
2682 if (line
->IsHilighted()) ret
|= wxLIST_STATE_SELECTED
;
2688 void wxListMainWindow::GetItem( wxListItem
&item
)
2690 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2692 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2693 line
->GetItem( item
.m_col
, item
);
2704 int wxListMainWindow::GetItemCount()
2706 return m_lines
.GetCount();
2709 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2711 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2713 m_lines
[(size_t)index
].GetRect( rect
);
2714 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2725 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2728 this->GetItemRect(item
,rect
);
2729 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2733 int wxListMainWindow::GetSelectedItemCount()
2736 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2738 if (m_lines
[i
].IsHilighted()) ret
++;
2743 void wxListMainWindow::SetMode( long mode
)
2750 if (m_mode
& wxLC_REPORT
)
2752 #if wxUSE_GENERIC_LIST_EXTENSIONS
2766 long wxListMainWindow::GetMode() const
2771 void wxListMainWindow::CalculatePositions()
2773 if (m_lines
.IsEmpty()) return;
2775 wxClientDC
dc( this );
2776 dc
.SetFont( GetFont() );
2778 int iconSpacing
= 0;
2779 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2780 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2782 // we take the first line (which also can be an icon or
2783 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2784 // measure the size of the line
2788 int lineSpacing
= 0;
2790 wxListLineData
*line
= &m_lines
[0];
2791 line
->CalculateSize( &dc
, iconSpacing
);
2793 line
->GetSize( dummy
, lineSpacing
);
2796 int clientWidth
= 0;
2797 int clientHeight
= 0;
2799 if (m_mode
& wxLC_REPORT
)
2801 // scroll one line per step
2802 m_yScroll
= lineSpacing
;
2806 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2807 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2808 #if wxUSE_GENERIC_LIST_EXTENSIONS
2809 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2811 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2813 GetClientSize( &clientWidth
, &clientHeight
);
2815 int entireWidth
= 0 ;
2816 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2818 wxListLineData
*line
= &m_lines
[j
];
2819 line
->CalculateSize( &dc
, iconSpacing
);
2820 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2822 for (int i
= 0; i
< GetColumnCount(); i
++)
2824 line
->SetColumnPosition( i
, col_x
);
2825 col_x
+= GetColumnWidth( i
);
2827 entireWidth
= wxMax( entireWidth
, col_x
) ;
2828 #if wxUSE_GENERIC_LIST_EXTENSIONS
2829 line
->SetPosition( &dc
, x
, y
, col_x
);
2831 y
+= lineSpacing
; // one pixel blank line between items
2833 m_visibleLines
= clientHeight
/ lineSpacing
;
2834 #if wxUSE_GENERIC_LIST_EXTENSIONS
2835 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2840 // at first we try without any scrollbar. if the items don't
2841 // fit into the window, we recalculate after subtracting an
2842 // approximated 15 pt for the horizontal scrollbar
2844 GetSize( &clientWidth
, &clientHeight
);
2845 clientHeight
-= 4; // sunken frame
2847 int entireWidth
= 0;
2849 for (int tries
= 0; tries
< 2; tries
++)
2856 int m_currentVisibleLines
= 0;
2857 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2859 m_currentVisibleLines
++;
2860 wxListLineData
*line
= &m_lines
[i
];
2861 line
->CalculateSize( &dc
, iconSpacing
);
2862 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2863 line
->GetSize( lineWidth
, lineHeight
);
2864 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2866 if (m_currentVisibleLines
> m_visibleLines
)
2867 m_visibleLines
= m_currentVisibleLines
;
2868 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2870 m_currentVisibleLines
= 0;
2873 entireWidth
+= maxWidth
+6;
2876 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2877 if ((tries
== 0) && (entireWidth
> clientWidth
))
2879 clientHeight
-= 15; // scrollbar height
2881 m_currentVisibleLines
= 0;
2884 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2888 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2889 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2893 void wxListMainWindow::RealizeChanges()
2897 if (!m_lines
.IsEmpty())
2898 m_current
= &m_lines
[0];
2902 FocusLine( m_current
);
2903 // TODO: MSW doesn't automatically hilight the
2905 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2909 long wxListMainWindow::GetNextItem( long item
,
2910 int WXUNUSED(geometry
),
2914 max
= GetItemCount();
2915 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2916 _T("invalid listctrl index in GetNextItem()") );
2918 // notice that we start with the next item (or the first one if item == -1)
2919 // and this is intentional to allow writing a simple loop to iterate over
2920 // all selected items
2924 // this is not an error because the index was ok initially, just no
2929 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2931 wxListLineData
*line
= &m_lines
[i
];
2932 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2934 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2944 void wxListMainWindow::DeleteItem( long index
)
2947 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2949 wxListLineData
*line
= &m_lines
[(size_t)index
];
2950 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2952 m_lines
.RemoveAt( (size_t)index
);
2956 void wxListMainWindow::DeleteColumn( int col
)
2958 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2959 wxT("attempting to delete inexistent column in wxListView") );
2962 wxNode
*node
= m_columns
.Nth( col
);
2963 if (node
) m_columns
.DeleteNode( node
);
2966 void wxListMainWindow::DeleteAllItems()
2969 m_current
= (wxListLineData
*) NULL
;
2971 // to make the deletion of all items faster, we don't send the
2972 // notifications in this case: this is compatible with wxMSW and
2973 // documented in DeleteAllItems() description
2975 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2976 event
.SetEventObject( GetParent() );
2977 GetParent()->GetEventHandler()->ProcessEvent( event
);
2982 void wxListMainWindow::DeleteEverything()
2989 void wxListMainWindow::EnsureVisible( long index
)
2991 // We have to call this here because the label in
2992 // question might just have been added and no screen
2993 // update taken place.
2994 if (m_dirty
) wxYield();
2996 wxListLineData
*oldCurrent
= m_current
;
2997 m_current
= (wxListLineData
*) NULL
;
2998 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2999 m_current
= &m_lines
[(size_t)index
];
3000 if (m_current
) MoveToFocus();
3001 m_current
= oldCurrent
;
3004 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3008 if (pos
< 0) pos
= 0;
3009 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3011 wxListLineData
*line
= &m_lines
[i
];
3013 line
->GetText( 0, s
);
3014 if (s
== tmp
) return pos
;
3020 long wxListMainWindow::FindItem(long start
, long data
)
3023 if (pos
< 0) pos
= 0;
3024 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3026 wxListLineData
*line
= &m_lines
[i
];
3028 line
->GetItem( 0, item
);
3029 if (item
.m_data
== data
) return pos
;
3035 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3037 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3040 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3042 wxListLineData
*line
= &m_lines
[i
];
3043 long ret
= line
->IsHit( x
, y
);
3044 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3054 void wxListMainWindow::InsertItem( wxListItem
&item
)
3058 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3059 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3060 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3061 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3063 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3065 if (m_mode
& wxLC_REPORT
)
3067 line
->InitItems( GetColumnCount() );
3068 item
.m_width
= GetColumnWidth( 0 )-3;
3072 line
->InitItems( 1 );
3075 line
->SetItem( 0, item
);
3076 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3078 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3082 m_lines
.Add( line
);
3083 item
.m_itemId
= m_lines
.GetCount()-1;
3087 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3090 if (m_mode
& wxLC_REPORT
)
3092 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3093 wxListHeaderData
*column
= new wxListHeaderData( item
);
3094 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3096 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3098 m_columns
.Insert( node
, column
);
3102 m_columns
.Append( column
);
3107 wxListCtrlCompare list_ctrl_compare_func_2
;
3108 long list_ctrl_compare_data
;
3110 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3112 wxListLineData
*line1
= *arg1
;
3113 wxListLineData
*line2
= *arg2
;
3115 line1
->GetItem( 0, item
);
3116 long data1
= item
.m_data
;
3117 line2
->GetItem( 0, item
);
3118 long data2
= item
.m_data
;
3119 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3122 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3124 list_ctrl_compare_func_2
= fn
;
3125 list_ctrl_compare_data
= data
;
3126 m_lines
.Sort( list_ctrl_compare_func_1
);
3130 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3132 wxScrolledWindow::OnScroll( event
) ;
3134 #if wxUSE_GENERIC_LIST_EXTENSIONS
3136 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3138 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3141 lc
->m_headerWin
->Refresh() ;
3143 lc
->m_headerWin
->MacUpdateImmediately() ;
3150 // -------------------------------------------------------------------------------------
3152 // -------------------------------------------------------------------------------------
3154 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3156 wxListItem::wxListItem()
3165 m_format
= wxLIST_FORMAT_CENTRE
;
3171 void wxListItem::Clear()
3180 m_format
= wxLIST_FORMAT_CENTRE
;
3182 m_text
= wxEmptyString
;
3184 if (m_attr
) delete m_attr
;
3188 void wxListItem::ClearAttributes()
3190 if (m_attr
) delete m_attr
;
3194 // -------------------------------------------------------------------------------------
3196 // -------------------------------------------------------------------------------------
3198 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3200 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3201 wxNotifyEvent( commandType
, id
)
3207 m_cancelled
= FALSE
;
3212 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3214 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3216 wxNotifyEvent::CopyObject(object_dest
);
3218 obj
->m_code
= m_code
;
3219 obj
->m_itemIndex
= m_itemIndex
;
3220 obj
->m_oldItemIndex
= m_oldItemIndex
;
3222 obj
->m_cancelled
= m_cancelled
;
3223 obj
->m_pointDrag
= m_pointDrag
;
3224 obj
->m_item
.m_mask
= m_item
.m_mask
;
3225 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3226 obj
->m_item
.m_col
= m_item
.m_col
;
3227 obj
->m_item
.m_state
= m_item
.m_state
;
3228 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3229 obj
->m_item
.m_text
= m_item
.m_text
;
3230 obj
->m_item
.m_image
= m_item
.m_image
;
3231 obj
->m_item
.m_data
= m_item
.m_data
;
3232 obj
->m_item
.m_format
= m_item
.m_format
;
3233 obj
->m_item
.m_width
= m_item
.m_width
;
3235 if ( m_item
.HasAttributes() )
3237 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3241 // -------------------------------------------------------------------------------------
3243 // -------------------------------------------------------------------------------------
3245 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3247 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3248 EVT_SIZE (wxListCtrl::OnSize
)
3249 EVT_IDLE (wxListCtrl::OnIdle
)
3252 wxListCtrl::wxListCtrl()
3254 m_imageListNormal
= (wxImageList
*) NULL
;
3255 m_imageListSmall
= (wxImageList
*) NULL
;
3256 m_imageListState
= (wxImageList
*) NULL
;
3257 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3258 m_mainWin
= (wxListMainWindow
*) NULL
;
3259 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3262 wxListCtrl::~wxListCtrl()
3264 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3265 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3266 if (m_ownsImageListState
) delete m_imageListState
;
3269 bool wxListCtrl::Create(wxWindow
*parent
,
3274 const wxValidator
&validator
,
3275 const wxString
&name
)
3277 m_imageListNormal
= (wxImageList
*) NULL
;
3278 m_imageListSmall
= (wxImageList
*) NULL
;
3279 m_imageListState
= (wxImageList
*) NULL
;
3280 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3281 m_mainWin
= (wxListMainWindow
*) NULL
;
3282 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3284 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3286 style
= style
| wxLC_LIST
;
3289 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3292 if (style
& wxSUNKEN_BORDER
)
3293 style
-= wxSUNKEN_BORDER
;
3295 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3297 if (HasFlag(wxLC_REPORT
))
3299 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3300 if (HasFlag(wxLC_NO_HEADER
))
3301 m_headerWin
->Show( FALSE
);
3305 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3311 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3313 /* handled in OnIdle */
3315 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3318 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3320 long flag
= GetWindowStyle();
3324 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3325 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3326 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3335 if (flag
& style
) flag
-= style
;
3338 SetWindowStyleFlag( flag
);
3341 void wxListCtrl::SetWindowStyleFlag( long flag
)
3345 m_mainWin
->DeleteEverything();
3349 GetClientSize( &width
, &height
);
3351 m_mainWin
->SetMode( flag
);
3353 if (flag
& wxLC_REPORT
)
3355 if (!HasFlag(wxLC_REPORT
))
3359 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3360 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3361 if (HasFlag(wxLC_NO_HEADER
))
3362 m_headerWin
->Show( FALSE
);
3366 if (flag
& wxLC_NO_HEADER
)
3367 m_headerWin
->Show( FALSE
);
3369 m_headerWin
->Show( TRUE
);
3375 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3377 m_headerWin
->Show( FALSE
);
3382 wxWindow::SetWindowStyleFlag( flag
);
3385 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3387 m_mainWin
->GetColumn( col
, item
);
3391 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3393 m_mainWin
->SetColumn( col
, item
);
3397 int wxListCtrl::GetColumnWidth( int col
) const
3399 return m_mainWin
->GetColumnWidth( col
);
3402 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3404 m_mainWin
->SetColumnWidth( col
, width
);
3408 int wxListCtrl::GetCountPerPage() const
3410 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3413 bool wxListCtrl::GetItem( wxListItem
&info
) const
3415 m_mainWin
->GetItem( info
);
3419 bool wxListCtrl::SetItem( wxListItem
&info
)
3421 m_mainWin
->SetItem( info
);
3425 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3428 info
.m_text
= label
;
3429 info
.m_mask
= wxLIST_MASK_TEXT
;
3430 info
.m_itemId
= index
;
3434 info
.m_image
= imageId
;
3435 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3437 m_mainWin
->SetItem(info
);
3441 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3443 return m_mainWin
->GetItemState( item
, stateMask
);
3446 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3448 m_mainWin
->SetItemState( item
, state
, stateMask
);
3452 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3455 info
.m_image
= image
;
3456 info
.m_mask
= wxLIST_MASK_IMAGE
;
3457 info
.m_itemId
= item
;
3458 m_mainWin
->SetItem( info
);
3462 wxString
wxListCtrl::GetItemText( long item
) const
3465 info
.m_itemId
= item
;
3466 m_mainWin
->GetItem( info
);
3470 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3473 info
.m_mask
= wxLIST_MASK_TEXT
;
3474 info
.m_itemId
= item
;
3476 m_mainWin
->SetItem( info
);
3479 long wxListCtrl::GetItemData( long item
) const
3482 info
.m_itemId
= item
;
3483 m_mainWin
->GetItem( info
);
3487 bool wxListCtrl::SetItemData( long item
, long data
)
3490 info
.m_mask
= wxLIST_MASK_DATA
;
3491 info
.m_itemId
= item
;
3493 m_mainWin
->SetItem( info
);
3497 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3499 m_mainWin
->GetItemRect( item
, rect
);
3503 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3505 m_mainWin
->GetItemPosition( item
, pos
);
3509 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3514 int wxListCtrl::GetItemCount() const
3516 return m_mainWin
->GetItemCount();
3519 int wxListCtrl::GetColumnCount() const
3521 return m_mainWin
->GetColumnCount();
3524 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3526 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3529 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3531 return m_mainWin
->GetItemSpacing( isSmall
);
3534 int wxListCtrl::GetSelectedItemCount() const
3536 return m_mainWin
->GetSelectedItemCount();
3539 wxColour
wxListCtrl::GetTextColour() const
3541 return GetForegroundColour();
3544 void wxListCtrl::SetTextColour(const wxColour
& col
)
3546 SetForegroundColour(col
);
3549 long wxListCtrl::GetTopItem() const
3554 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3556 return m_mainWin
->GetNextItem( item
, geom
, state
);
3559 wxImageList
*wxListCtrl::GetImageList(int which
) const
3561 if (which
== wxIMAGE_LIST_NORMAL
)
3563 return m_imageListNormal
;
3565 else if (which
== wxIMAGE_LIST_SMALL
)
3567 return m_imageListSmall
;
3569 else if (which
== wxIMAGE_LIST_STATE
)
3571 return m_imageListState
;
3573 return (wxImageList
*) NULL
;
3576 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3578 if ( which
== wxIMAGE_LIST_NORMAL
)
3580 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3581 m_imageListNormal
= imageList
;
3582 m_ownsImageListNormal
= FALSE
;
3584 else if ( which
== wxIMAGE_LIST_SMALL
)
3586 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3587 m_imageListSmall
= imageList
;
3588 m_ownsImageListSmall
= FALSE
;
3590 else if ( which
== wxIMAGE_LIST_STATE
)
3592 if (m_ownsImageListState
) delete m_imageListState
;
3593 m_imageListState
= imageList
;
3594 m_ownsImageListState
= FALSE
;
3597 m_mainWin
->SetImageList( imageList
, which
);
3600 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3602 SetImageList(imageList
, which
);
3603 if ( which
== wxIMAGE_LIST_NORMAL
)
3604 m_ownsImageListNormal
= TRUE
;
3605 else if ( which
== wxIMAGE_LIST_SMALL
)
3606 m_ownsImageListSmall
= TRUE
;
3607 else if ( which
== wxIMAGE_LIST_STATE
)
3608 m_ownsImageListState
= TRUE
;
3611 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3616 bool wxListCtrl::DeleteItem( long item
)
3618 m_mainWin
->DeleteItem( item
);
3622 bool wxListCtrl::DeleteAllItems()
3624 m_mainWin
->DeleteAllItems();
3628 bool wxListCtrl::DeleteAllColumns()
3630 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3636 void wxListCtrl::ClearAll()
3638 m_mainWin
->DeleteEverything();
3641 bool wxListCtrl::DeleteColumn( int col
)
3643 m_mainWin
->DeleteColumn( col
);
3647 void wxListCtrl::Edit( long item
)
3649 m_mainWin
->Edit( item
);
3652 bool wxListCtrl::EnsureVisible( long item
)
3654 m_mainWin
->EnsureVisible( item
);
3658 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3660 return m_mainWin
->FindItem( start
, str
, partial
);
3663 long wxListCtrl::FindItem( long start
, long data
)
3665 return m_mainWin
->FindItem( start
, data
);
3668 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3669 int WXUNUSED(direction
))
3674 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3676 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3679 long wxListCtrl::InsertItem( wxListItem
& info
)
3681 m_mainWin
->InsertItem( info
);
3682 return info
.m_itemId
;
3685 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3688 info
.m_text
= label
;
3689 info
.m_mask
= wxLIST_MASK_TEXT
;
3690 info
.m_itemId
= index
;
3691 return InsertItem( info
);
3694 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3697 info
.m_mask
= wxLIST_MASK_IMAGE
;
3698 info
.m_image
= imageIndex
;
3699 info
.m_itemId
= index
;
3700 return InsertItem( info
);
3703 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3706 info
.m_text
= label
;
3707 info
.m_image
= imageIndex
;
3708 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3709 info
.m_itemId
= index
;
3710 return InsertItem( info
);
3713 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3715 wxASSERT( m_headerWin
);
3716 m_mainWin
->InsertColumn( col
, item
);
3717 m_headerWin
->Refresh();
3722 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3723 int format
, int width
)
3726 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3727 item
.m_text
= heading
;
3730 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3731 item
.m_width
= width
;
3733 item
.m_format
= format
;
3735 return InsertColumn( col
, item
);
3738 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3744 // fn is a function which takes 3 long arguments: item1, item2, data.
3745 // item1 is the long data associated with a first item (NOT the index).
3746 // item2 is the long data associated with a second item (NOT the index).
3747 // data is the same value as passed to SortItems.
3748 // The return value is a negative number if the first item should precede the second
3749 // item, a positive number of the second item should precede the first,
3750 // or zero if the two items are equivalent.
3751 // data is arbitrary data to be passed to the sort function.
3753 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3755 m_mainWin
->SortItems( fn
, data
);
3759 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3761 if (!m_mainWin
->m_dirty
) return;
3765 GetClientSize( &cw
, &ch
);
3772 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3774 m_headerWin
->GetPosition( &x
, &y
);
3775 m_headerWin
->GetSize( &w
, &h
);
3776 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3777 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3779 m_mainWin
->GetPosition( &x
, &y
);
3780 m_mainWin
->GetSize( &w
, &h
);
3781 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3782 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3786 m_mainWin
->GetPosition( &x
, &y
);
3787 m_mainWin
->GetSize( &w
, &h
);
3788 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3789 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3792 m_mainWin
->CalculatePositions();
3793 m_mainWin
->RealizeChanges();
3794 m_mainWin
->m_dirty
= FALSE
;
3795 m_mainWin
->Refresh();
3797 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3799 m_headerWin
->m_dirty
= FALSE
;
3800 m_headerWin
->Refresh();
3804 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3808 m_mainWin
->SetBackgroundColour( colour
);
3809 m_mainWin
->m_dirty
= TRUE
;
3815 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3817 if ( !wxWindow::SetForegroundColour( colour
) )
3822 m_mainWin
->SetForegroundColour( colour
);
3823 m_mainWin
->m_dirty
= TRUE
;
3828 m_headerWin
->SetForegroundColour( colour
);
3834 bool wxListCtrl::SetFont( const wxFont
&font
)
3836 if ( !wxWindow::SetFont( font
) )
3841 m_mainWin
->SetFont( font
);
3842 m_mainWin
->m_dirty
= TRUE
;
3847 m_headerWin
->SetFont( font
);
3853 #if wxUSE_DRAG_AND_DROP
3855 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3857 m_mainWin
->SetDropTarget( dropTarget
);
3860 wxDropTarget
*wxListCtrl::GetDropTarget() const
3862 return m_mainWin
->GetDropTarget();
3865 #endif // wxUSE_DRAG_AND_DROP
3867 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3869 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3872 wxColour
wxListCtrl::GetBackgroundColour() const
3874 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3877 wxColour
wxListCtrl::GetForegroundColour() const
3879 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3882 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3884 return m_mainWin
->PopupMenu( menu
, x
, y
);
3887 void wxListCtrl::SetFocus()
3889 /* The test in window.cpp fails as we are a composite
3890 window, so it checks against "this", but not m_mainWin. */
3891 if ( FindFocus() != this )
3892 m_mainWin
->SetFocus();