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 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
19 #pragma implementation "listctrl.h"
20 #pragma implementation "listctrlbase.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
32 #include "wx/dcscreen.h"
34 #include "wx/listctrl.h"
35 #include "wx/generic/imaglist.h"
36 #include "wx/dynarray.h"
40 #include "wx/gtk/win_gtk.h"
43 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
44 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
59 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
62 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
63 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
64 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
65 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
66 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
68 // ============================================================================
70 // ============================================================================
72 //-----------------------------------------------------------------------------
73 // wxListItemData (internal)
74 //-----------------------------------------------------------------------------
76 class WXDLLEXPORT wxListItemData
: public wxObject
80 ~wxListItemData() { delete m_attr
; }
82 wxListItemData( const wxListItem
&info
);
83 void SetItem( const wxListItem
&info
);
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 HasText() const { return !m_text
.empty(); }
91 const wxString
& GetText() const { return m_text
; }
92 void SetText(const wxString
& text
) { m_text
= text
; }
94 bool IsHit( int x
, int y
) const;
96 int GetX( void ) const;
97 int GetY( void ) const;
99 int GetHeight() const;
100 int GetImage() const;
101 void GetItem( wxListItem
&info
) const;
103 wxListItemAttr
*GetAttributes() const { return m_attr
; }
113 wxListItemAttr
*m_attr
;
119 DECLARE_DYNAMIC_CLASS(wxListItemData
);
122 //-----------------------------------------------------------------------------
123 // wxListHeaderData (internal)
124 //-----------------------------------------------------------------------------
126 class WXDLLEXPORT wxListHeaderData
: public wxObject
140 wxListHeaderData( const wxListItem
&info
);
141 void SetItem( const wxListItem
&item
);
142 void SetPosition( int x
, int y
);
143 void SetWidth( int w
);
144 void SetFormat( int format
);
145 void SetHeight( int h
);
146 bool HasImage() const;
148 bool HasText() const { return !m_text
.empty(); }
149 const wxString
& GetText() const { return m_text
; }
150 void SetText(const wxString
& text
) { m_text
= text
; }
152 void GetItem( wxListItem
&item
);
154 bool IsHit( int x
, int y
) const;
155 int GetImage() const;
156 int GetWidth() const;
157 int GetFormat() const;
160 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
163 //-----------------------------------------------------------------------------
164 // wxListLineData (internal)
165 //-----------------------------------------------------------------------------
167 WX_DECLARE_LIST(wxListItemData
, wxListItemDataList
);
168 #include "wx/listimpl.cpp"
169 WX_DEFINE_LIST(wxListItemDataList
);
171 class WXDLLEXPORT wxListLineData
: public wxObject
174 wxListItemDataList m_items
;
176 wxRect m_bound_label
;
178 wxRect m_bound_hilight
;
181 wxBrush
*m_hilightBrush
;
183 wxListMainWindow
*m_owner
;
185 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
189 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
190 void CalculateSize( wxDC
*dc
, int spacing
);
191 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
192 void SetColumnPosition( int index
, int x
);
193 void GetSize( int &width
, int &height
);
194 void GetExtent( int &x
, int &y
, int &width
, int &height
);
195 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
196 long IsHit( int x
, int y
);
197 void InitItems( int num
);
198 void SetItem( int index
, const wxListItem
&info
);
199 void GetItem( int index
, wxListItem
&info
);
200 wxString
GetText(int index
) const;
201 void SetText( int index
, const wxString s
);
202 int GetImage( int index
);
203 void GetRect( wxRect
&rect
);
204 void Hilight( bool on
);
205 void ReverseHilight();
206 void DrawRubberBand( wxDC
*dc
, bool on
);
207 void Draw( wxDC
*dc
);
208 bool IsInRect( int x
, int y
, const wxRect
&rect
);
210 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
211 void AssignRect( wxRect
&dest
, const wxRect
&source
);
214 void SetAttributes(wxDC
*dc
,
215 const wxListItemAttr
*attr
,
216 const wxColour
& colText
, const wxFont
& font
,
219 DECLARE_DYNAMIC_CLASS(wxListLineData
);
223 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
224 #include "wx/arrimpl.cpp"
225 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
227 //-----------------------------------------------------------------------------
228 // wxListHeaderWindow (internal)
229 //-----------------------------------------------------------------------------
231 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
234 wxListMainWindow
*m_owner
;
235 wxCursor
*m_currentCursor
;
236 wxCursor
*m_resizeCursor
;
239 // column being resized
242 // divider line position in logical (unscrolled) coords
245 // minimal position beyond which the divider line can't be dragged in
250 wxListHeaderWindow();
251 virtual ~wxListHeaderWindow();
253 wxListHeaderWindow( wxWindow
*win
,
255 wxListMainWindow
*owner
,
256 const wxPoint
&pos
= wxDefaultPosition
,
257 const wxSize
&size
= wxDefaultSize
,
259 const wxString
&name
= "wxlistctrlcolumntitles" );
261 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
263 void AdjustDC(wxDC
& dc
);
265 void OnPaint( wxPaintEvent
&event
);
266 void OnMouse( wxMouseEvent
&event
);
267 void OnSetFocus( wxFocusEvent
&event
);
273 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
274 DECLARE_EVENT_TABLE()
277 //-----------------------------------------------------------------------------
278 // wxListRenameTimer (internal)
279 //-----------------------------------------------------------------------------
281 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
284 wxListMainWindow
*m_owner
;
287 wxListRenameTimer( wxListMainWindow
*owner
);
291 //-----------------------------------------------------------------------------
292 // wxListTextCtrl (internal)
293 //-----------------------------------------------------------------------------
295 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
300 wxListMainWindow
*m_owner
;
301 wxString m_startValue
;
305 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
306 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
307 const wxString
&value
= "",
308 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
310 const wxValidator
& validator
= wxDefaultValidator
,
311 const wxString
&name
= "listctrltextctrl" );
312 void OnChar( wxKeyEvent
&event
);
313 void OnKeyUp( wxKeyEvent
&event
);
314 void OnKillFocus( wxFocusEvent
&event
);
317 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
318 DECLARE_EVENT_TABLE()
321 //-----------------------------------------------------------------------------
322 // wxListMainWindow (internal)
323 //-----------------------------------------------------------------------------
325 WX_DECLARE_LIST(wxListHeaderData
, wxListHeaderDataList
);
326 #include "wx/listimpl.cpp"
327 WX_DEFINE_LIST(wxListHeaderDataList
);
329 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
332 // the style of the control (combination of wxLC_XXX)
335 // the array of all line objects for a non virtual list control
336 wxListLineDataArray m_lines
;
338 // the total count of items in a virtual list control
341 // the list of column objects
342 wxListHeaderDataList m_columns
;
344 // currently focused item or NULL
345 wxListLineData
*m_current
;
347 // the item currently being edited or -1
348 size_t m_currentEdit
;
351 wxBrush
*m_hilightBrush
;
352 wxColour
*m_hilightColour
;
356 wxImageList
*m_small_image_list
;
357 wxImageList
*m_normal_image_list
;
359 int m_normal_spacing
;
363 wxTimer
*m_renameTimer
;
365 wxString m_renameRes
;
370 // for double click logic
371 size_t m_lineLastClicked
,
372 m_lineBeforeLastClicked
;
376 wxListMainWindow( wxWindow
*parent
,
378 const wxPoint
& pos
= wxDefaultPosition
,
379 const wxSize
& size
= wxDefaultSize
,
381 const wxString
&name
= _T("listctrlmainwindow") );
383 virtual ~wxListMainWindow();
385 // return true if this is a virtual list control
386 bool IsVirtual() const { return (m_mode
& wxLC_VIRTUAL
) != 0; }
388 void RefreshLine( wxListLineData
*line
);
389 void OnPaint( wxPaintEvent
&event
);
390 void HilightAll( bool on
);
391 void SendNotify( wxListLineData
*line
,
393 wxPoint point
= wxDefaultPosition
);
394 void FocusLine( wxListLineData
*line
);
395 void UnfocusLine( wxListLineData
*line
);
396 void SelectLine( wxListLineData
*line
);
397 void DeselectLine( wxListLineData
*line
);
398 void DeleteLine( wxListLineData
*line
);
400 void EditLabel( long item
);
401 void Edit( long item
) { EditLabel(item
); } // deprecated
402 void OnRenameTimer();
403 void OnRenameAccept();
405 void OnMouse( wxMouseEvent
&event
);
407 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
408 void OnChar( wxKeyEvent
&event
);
409 void OnKeyDown( wxKeyEvent
&event
);
410 void OnSetFocus( wxFocusEvent
&event
);
411 void OnKillFocus( wxFocusEvent
&event
);
412 void OnSize( wxSizeEvent
&event
);
413 void OnScroll(wxScrollWinEvent
& event
) ;
415 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
416 void GetImageSize( int index
, int &width
, int &height
);
417 int GetIndexOfLine( const wxListLineData
*line
);
418 int GetTextLength( wxString
&s
); // should be const
420 void SetImageList( wxImageList
*imageList
, int which
);
421 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
422 int GetItemSpacing( bool isSmall
= FALSE
);
423 void SetColumn( int col
, wxListItem
&item
);
424 void SetColumnWidth( int col
, int width
);
425 void GetColumn( int col
, wxListItem
&item
);
426 int GetColumnWidth( int vol
);
427 int GetColumnCount();
428 int GetCountPerPage();
429 void SetItem( wxListItem
&item
);
430 void GetItem( wxListItem
&item
);
431 void SetItemState( long item
, long state
, long stateMask
);
432 int GetItemState( long item
, long stateMask
);
433 void GetItemRect( long index
, wxRect
&rect
);
434 bool GetItemPosition( long item
, wxPoint
& pos
);
435 int GetSelectedItemCount();
436 void SetMode( long mode
);
437 long GetMode() const;
438 void CalculatePositions();
439 void RealizeChanges();
440 long GetNextItem( long item
, int geometry
, int state
);
441 void DeleteItem( long index
);
442 void DeleteAllItems();
443 void DeleteColumn( int col
);
444 void DeleteEverything();
445 void EnsureVisible( long index
);
446 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
447 long FindItem( long start
, long data
);
448 long HitTest( int x
, int y
, int &flags
);
449 void InsertItem( wxListItem
&item
);
450 // void AddItem( wxListItem &item );
451 void InsertColumn( long col
, wxListItem
&item
);
452 // void AddColumn( wxListItem &item );
453 void SortItems( wxListCtrlCompare fn
, long data
);
455 int GetItemCount() const;
456 bool IsEmpty() const { return GetItemCount() == 0; }
457 void SetItemCount(long count
);
460 // common part of all ctors
463 // get the line data for the given index
464 wxListLineData
*GetLine(size_t n
) const
466 wxASSERT_MSG( n
!= (size_t)-1, _T("invalid line index") );
472 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
473 DECLARE_EVENT_TABLE()
476 // ============================================================================
478 // ============================================================================
480 //-----------------------------------------------------------------------------
482 //-----------------------------------------------------------------------------
484 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
486 wxListItemData::wxListItemData()
497 wxListItemData::wxListItemData( const wxListItem
&info
)
506 void wxListItemData::SetItem( const wxListItem
&info
)
508 if (info
.m_mask
& wxLIST_MASK_TEXT
)
509 SetText(info
.m_text
);
510 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
511 m_image
= info
.m_image
;
512 if (info
.m_mask
& wxLIST_MASK_DATA
)
513 m_data
= info
.m_data
;
515 if ( info
.HasAttributes() )
518 *m_attr
= *info
.GetAttributes();
520 m_attr
= new wxListItemAttr(*info
.GetAttributes());
525 m_width
= info
.m_width
;
529 void wxListItemData::SetImage( int image
)
534 void wxListItemData::SetData( long data
)
539 void wxListItemData::SetPosition( int x
, int y
)
545 void wxListItemData::SetSize( int width
, int height
)
547 if (width
!= -1) m_width
= width
;
548 if (height
!= -1) m_height
= height
;
551 bool wxListItemData::HasImage() const
553 return (m_image
>= 0);
556 bool wxListItemData::IsHit( int x
, int y
) const
558 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
561 int wxListItemData::GetX() const
566 int wxListItemData::GetY() const
571 int wxListItemData::GetWidth() const
576 int wxListItemData::GetHeight() const
581 int wxListItemData::GetImage() const
586 void wxListItemData::GetItem( wxListItem
&info
) const
588 info
.m_text
= m_text
;
589 info
.m_image
= m_image
;
590 info
.m_data
= m_data
;
594 if ( m_attr
->HasTextColour() )
595 info
.SetTextColour(m_attr
->GetTextColour());
596 if ( m_attr
->HasBackgroundColour() )
597 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
598 if ( m_attr
->HasFont() )
599 info
.SetFont(m_attr
->GetFont());
603 //-----------------------------------------------------------------------------
605 //-----------------------------------------------------------------------------
607 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
609 wxListHeaderData::wxListHeaderData()
620 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
628 void wxListHeaderData::SetItem( const wxListItem
&item
)
630 m_mask
= item
.m_mask
;
631 m_text
= item
.m_text
;
632 m_image
= item
.m_image
;
633 m_format
= item
.m_format
;
634 m_width
= item
.m_width
;
635 if (m_width
< 0) m_width
= 80;
636 if (m_width
< 6) m_width
= 6;
639 void wxListHeaderData::SetPosition( int x
, int y
)
645 void wxListHeaderData::SetHeight( int h
)
650 void wxListHeaderData::SetWidth( int w
)
653 if (m_width
< 0) m_width
= 80;
654 if (m_width
< 6) m_width
= 6;
657 void wxListHeaderData::SetFormat( int format
)
662 bool wxListHeaderData::HasImage() const
664 return (m_image
!= 0);
667 bool wxListHeaderData::IsHit( int x
, int y
) const
669 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
672 void wxListHeaderData::GetItem( wxListItem
&item
)
674 item
.m_mask
= m_mask
;
675 item
.m_text
= m_text
;
676 item
.m_image
= m_image
;
677 item
.m_format
= m_format
;
678 item
.m_width
= m_width
;
681 int wxListHeaderData::GetImage() const
686 int wxListHeaderData::GetWidth() const
691 int wxListHeaderData::GetFormat() const
696 //-----------------------------------------------------------------------------
698 //-----------------------------------------------------------------------------
700 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
702 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
707 m_hilightBrush
= hilightBrush
;
708 m_items
.DeleteContents( TRUE
);
712 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
714 wxListItemDataList::Node
*node
= m_items
.GetFirst();
721 m_bound_all
.width
= m_spacing
;
724 wxListItemData
*item
= node
->GetData();
725 wxString s
= item
->GetText();
730 dc
->GetTextExtent( s
, &lw
, &lh
);
736 m_bound_all
.height
= m_spacing
+lh
;
738 m_bound_all
.width
= lw
;
739 m_bound_label
.width
= lw
;
740 m_bound_label
.height
= lh
;
742 if (item
->HasImage())
746 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
747 m_bound_icon
.width
= w
+ 8;
748 m_bound_icon
.height
= h
+ 8;
750 if ( m_bound_icon
.width
> m_bound_all
.width
)
751 m_bound_all
.width
= m_bound_icon
.width
;
752 if ( h
+ lh
> m_bound_all
.height
- 4 )
753 m_bound_all
.height
= h
+ lh
+ 4;
756 if (!item
->HasText())
758 m_bound_hilight
.width
= m_bound_icon
.width
;
759 m_bound_hilight
.height
= m_bound_icon
.height
;
763 m_bound_hilight
.width
= m_bound_label
.width
;
764 m_bound_hilight
.height
= m_bound_label
.height
;
773 wxListItemData
*item
= node
->GetData();
775 wxString s
= item
->GetText();
780 dc
->GetTextExtent( s
, &lw
, &lh
);
786 m_bound_label
.width
= lw
;
787 m_bound_label
.height
= lh
;
789 m_bound_all
.width
= lw
;
790 m_bound_all
.height
= lh
;
792 if (item
->HasImage())
796 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
797 m_bound_icon
.width
= w
;
798 m_bound_icon
.height
= h
;
800 m_bound_all
.width
+= 4 + w
;
801 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
804 m_bound_hilight
.width
= m_bound_all
.width
;
805 m_bound_hilight
.height
= m_bound_all
.height
;
811 m_bound_all
.width
= 0;
812 m_bound_all
.height
= 0;
815 wxListItemData
*item
= node
->GetData();
816 if (item
->HasImage())
820 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
821 m_bound_icon
.width
= w
;
822 m_bound_icon
.height
= h
;
826 m_bound_icon
.width
= 0;
827 m_bound_icon
.height
= 0;
833 wxListItemData
*item
= node
->GetData();
834 wxString s
= item
->GetText();
839 dc
->GetTextExtent( s
, &lw
, &lh
);
845 item
->SetSize( item
->GetWidth(), lh
);
846 m_bound_all
.width
+= lw
;
847 m_bound_all
.height
= lh
;
848 node
= node
->GetNext();
850 m_bound_label
.width
= m_bound_all
.width
;
851 m_bound_label
.height
= m_bound_all
.height
;
857 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
858 int x
, int y
, int window_width
)
860 wxListItemDataList::Node
*node
= m_items
.GetFirst();
871 wxListItemData
*item
= node
->GetData();
872 if (item
->HasImage())
874 m_bound_icon
.x
= m_bound_all
.x
+ 4
875 + (m_spacing
- m_bound_icon
.width
)/2;
876 m_bound_icon
.y
= m_bound_all
.y
+ 4;
880 if (m_bound_all
.width
> m_spacing
)
881 m_bound_label
.x
= m_bound_all
.x
+ 2;
883 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
884 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
885 m_bound_hilight
.x
= m_bound_label
.x
- 2;
886 m_bound_hilight
.y
= m_bound_label
.y
- 2;
890 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
891 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
898 m_bound_hilight
.x
= m_bound_all
.x
;
899 m_bound_hilight
.y
= m_bound_all
.y
;
900 m_bound_label
.y
= m_bound_all
.y
+ 2;
903 wxListItemData
*item
= node
->GetData();
904 if (item
->HasImage())
906 m_bound_icon
.x
= m_bound_all
.x
+ 2;
907 m_bound_icon
.y
= m_bound_all
.y
+ 2;
908 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
912 m_bound_label
.x
= m_bound_all
.x
+ 2;
920 m_bound_all
.width
= window_width
;
921 AssignRect( m_bound_hilight
, m_bound_all
);
922 m_bound_label
.x
= m_bound_all
.x
+ 2;
923 m_bound_label
.y
= m_bound_all
.y
+ 2;
926 wxListItemData
*item
= node
->GetData();
927 if (item
->HasImage())
929 m_bound_icon
.x
= m_bound_all
.x
+ 2;
930 m_bound_icon
.y
= m_bound_all
.y
+ 2;
931 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
939 void wxListLineData::SetColumnPosition( int index
, int x
)
941 wxListItemDataList::Node
*node
= m_items
.Item( (size_t)index
);
944 wxListItemData
*item
= node
->GetData();
945 item
->SetPosition( x
, m_bound_all
.y
+1 );
949 void wxListLineData::GetSize( int &width
, int &height
)
951 width
= m_bound_all
.width
;
952 height
= m_bound_all
.height
;
955 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
959 width
= m_bound_all
.width
;
960 height
= m_bound_all
.height
;
963 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
967 width
= m_bound_label
.width
;
968 height
= m_bound_label
.height
;
971 void wxListLineData::GetRect( wxRect
&rect
)
973 AssignRect( rect
, m_bound_all
);
976 long wxListLineData::IsHit( int x
, int y
)
978 wxListItemDataList::Node
*node
= m_items
.GetFirst();
981 wxListItemData
*item
= node
->GetData();
982 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
))
983 return wxLIST_HITTEST_ONITEMICON
;
984 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
))
985 return wxLIST_HITTEST_ONITEMLABEL
;
989 // if there is no icon or text = empty
990 if (IsInRect( x
, y
, m_bound_all
))
991 return wxLIST_HITTEST_ONITEMICON
;
996 void wxListLineData::InitItems( int num
)
998 for (int i
= 0; i
< num
; i
++)
999 m_items
.Append( new wxListItemData() );
1002 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
1004 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1005 wxCHECK_RET( node
, _T("invalid column index in SetItem") );
1007 wxListItemData
*item
= node
->GetData();
1008 item
->SetItem( info
);
1011 void wxListLineData::GetItem( int index
, wxListItem
&info
)
1013 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1016 wxListItemData
*item
= node
->GetData();
1017 item
->GetItem( info
);
1021 wxString
wxListLineData::GetText(int index
) const
1025 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1028 wxListItemData
*item
= node
->GetData();
1029 s
= item
->GetText();
1035 void wxListLineData::SetText( int index
, const wxString s
)
1037 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1040 wxListItemData
*item
= node
->GetData();
1045 int wxListLineData::GetImage( int index
)
1047 wxListItemDataList::Node
*node
= m_items
.Item( index
);
1050 wxListItemData
*item
= node
->GetData();
1051 return item
->GetImage();
1056 void wxListLineData::SetAttributes(wxDC
*dc
,
1057 const wxListItemAttr
*attr
,
1058 const wxColour
& colText
,
1062 // don't use foregroud colour for drawing highlighted items - this might
1063 // make them completely invisible (and there is no way to do bit
1064 // arithmetics on wxColour, unfortunately)
1065 if ( !hilight
&& attr
&& attr
->HasTextColour() )
1067 dc
->SetTextForeground(attr
->GetTextColour());
1071 dc
->SetTextForeground(colText
);
1074 if ( attr
&& attr
->HasFont() )
1076 dc
->SetFont(attr
->GetFont());
1084 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1088 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1089 wxCoord dev_w
= m_bound_all
.width
;
1090 wxCoord dev_h
= m_bound_all
.height
;
1092 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1095 wxWindow
*listctrl
= m_owner
->GetParent();
1097 // default foreground colour
1101 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1105 colText
= listctrl
->GetForegroundColour();
1109 wxFont font
= listctrl
->GetFont();
1111 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1112 // using SetAttributes() inside the loop), it will be trivial to
1113 // customize the subitems (in report mode) too.
1114 wxListItemData
*item
= m_items
.GetFirst()->GetData();
1115 wxListItemAttr
*attr
= item
->GetAttributes();
1116 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1118 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1119 if ( paintBG
|| hasBgCol
)
1123 dc
->SetBrush( * m_hilightBrush
);
1128 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1130 dc
->SetBrush( * wxWHITE_BRUSH
);
1133 dc
->SetPen( * wxTRANSPARENT_PEN
);
1134 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1135 m_bound_hilight
.width
, m_bound_hilight
.height
);
1138 wxListItemDataList::Node
*node
= m_items
.GetFirst();
1140 if (m_mode
== wxLC_REPORT
)
1144 wxListItemData
*item
= node
->GetData();
1145 int x
= item
->GetX();
1146 if (item
->HasImage())
1149 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1150 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1151 x
+= item
->GetX() + 5;
1153 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1154 if (item
->HasText())
1156 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1158 dc
->DestroyClippingRegion();
1159 node
= node
->GetNext();
1166 wxListItemData
*item
= node
->GetData();
1167 if (item
->HasImage())
1169 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1171 if (item
->HasText())
1173 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1179 void wxListLineData::Hilight( bool on
)
1181 if (on
== m_hilighted
) return;
1184 m_owner
->SelectLine( this );
1186 m_owner
->DeselectLine( this );
1189 void wxListLineData::ReverseHilight( void )
1191 m_hilighted
= !m_hilighted
;
1193 m_owner
->SelectLine( this );
1195 m_owner
->DeselectLine( this );
1198 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1202 dc
->SetPen( * wxBLACK_PEN
);
1203 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1204 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1205 m_bound_hilight
.width
, m_bound_hilight
.height
);
1209 void wxListLineData::Draw( wxDC
*dc
)
1211 DoDraw( dc
, m_hilighted
, m_hilighted
);
1214 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1216 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1217 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1220 bool wxListLineData::IsHilighted( void )
1225 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1230 dest
.height
= height
;
1233 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1237 dest
.width
= source
.width
;
1238 dest
.height
= source
.height
;
1241 //-----------------------------------------------------------------------------
1242 // wxListHeaderWindow
1243 //-----------------------------------------------------------------------------
1245 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1247 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1248 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1249 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1250 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1253 wxListHeaderWindow::wxListHeaderWindow( void )
1255 m_owner
= (wxListMainWindow
*) NULL
;
1256 m_currentCursor
= (wxCursor
*) NULL
;
1257 m_resizeCursor
= (wxCursor
*) NULL
;
1258 m_isDragging
= FALSE
;
1261 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1262 const wxPoint
&pos
, const wxSize
&size
,
1263 long style
, const wxString
&name
) :
1264 wxWindow( win
, id
, pos
, size
, style
, name
)
1267 // m_currentCursor = wxSTANDARD_CURSOR;
1268 m_currentCursor
= (wxCursor
*) NULL
;
1269 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1270 m_isDragging
= FALSE
;
1273 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1276 wxListHeaderWindow::~wxListHeaderWindow( void )
1278 delete m_resizeCursor
;
1281 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1284 GtkStateType state
= GTK_STATE_NORMAL
;
1285 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1287 x
= dc
->XLOG2DEV( x
);
1289 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1290 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1292 const int m_corner
= 1;
1294 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1296 dc
->SetPen( *wxBLACK_PEN
);
1297 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1298 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1300 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1303 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1304 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1306 dc
->SetPen( *wxWHITE_PEN
);
1307 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1308 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1309 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1310 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1314 // shift the DC origin to match the position of the main window horz
1315 // scrollbar: this allows us to always use logical coords
1316 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1318 #if wxUSE_GENERIC_LIST_EXTENSIONS
1320 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1323 m_owner
->GetViewStart( &x
, NULL
);
1325 // account for the horz scrollbar offset
1326 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1327 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1330 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1333 wxClientDC
dc( this );
1335 wxPaintDC
dc( this );
1343 dc
.SetFont( GetFont() );
1345 // width and height of the entire header window
1347 GetClientSize( &w
, &h
);
1348 #if wxUSE_GENERIC_LIST_EXTENSIONS
1349 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1350 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1352 dc
.SetBackgroundMode(wxTRANSPARENT
);
1354 // do *not* use the listctrl colour for headers - one day we will have a
1355 // function to set it separately
1356 //dc.SetTextForeground( *wxBLACK );
1357 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1359 int x
= 1; // left of the header rect
1360 const int y
= 1; // top
1361 int numColumns
= m_owner
->GetColumnCount();
1363 for (int i
= 0; i
< numColumns
; i
++)
1365 m_owner
->GetColumn( i
, item
);
1366 int wCol
= item
.m_width
;
1367 int cw
= wCol
- 2; // the width of the rect to draw
1369 int xEnd
= x
+ wCol
;
1371 // VZ: no, draw it normally - this is better now as we allow resizing
1372 // of the last column as well
1374 // let the last column occupy all available space
1375 if ( i
== numColumns
- 1 )
1379 dc
.SetPen( *wxWHITE_PEN
);
1381 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1382 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1383 dc
.DrawText( item
.GetText(), x
+4, y
+3 );
1384 dc
.DestroyClippingRegion();
1393 void wxListHeaderWindow::DrawCurrent()
1395 int x1
= m_currentX
;
1397 ClientToScreen( &x1
, &y1
);
1399 int x2
= m_currentX
-1;
1401 m_owner
->GetClientSize( NULL
, &y2
);
1402 m_owner
->ClientToScreen( &x2
, &y2
);
1405 dc
.SetLogicalFunction( wxINVERT
);
1406 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1407 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1411 dc
.DrawLine( x1
, y1
, x2
, y2
);
1413 dc
.SetLogicalFunction( wxCOPY
);
1415 dc
.SetPen( wxNullPen
);
1416 dc
.SetBrush( wxNullBrush
);
1419 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1421 // we want to work with logical coords
1422 #if wxUSE_GENERIC_LIST_EXTENSIONS
1424 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1425 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1426 int x
= event
.GetX();
1427 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1428 int y
= event
.GetY();
1432 // we don't draw the line beyond our window, but we allow dragging it
1435 GetClientSize( &w
, NULL
);
1436 #if wxUSE_GENERIC_LIST_EXTENSIONS
1437 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1438 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1441 // erase the line if it was drawn
1442 if ( m_currentX
< w
)
1445 if (event
.ButtonUp())
1448 m_isDragging
= FALSE
;
1450 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1457 m_currentX
= m_minX
+ 7;
1459 // draw in the new location
1460 if ( m_currentX
< w
)
1464 else // not dragging
1467 bool hit_border
= FALSE
;
1469 // end of the current column
1472 // find the column where this event occured
1473 int countCol
= m_owner
->GetColumnCount();
1474 for (int j
= 0; j
< countCol
; j
++)
1476 xpos
+= m_owner
->GetColumnWidth( j
);
1479 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1481 // near the column border
1488 // inside the column
1495 if (event
.LeftDown())
1499 m_isDragging
= TRUE
;
1506 wxWindow
*parent
= GetParent();
1507 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1508 le
.SetEventObject( parent
);
1509 le
.m_col
= m_column
;
1510 parent
->GetEventHandler()->ProcessEvent( le
);
1513 else if (event
.Moving())
1518 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1519 m_currentCursor
= m_resizeCursor
;
1523 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1524 m_currentCursor
= wxSTANDARD_CURSOR
;
1528 SetCursor(*m_currentCursor
);
1533 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1535 m_owner
->SetFocus();
1538 //-----------------------------------------------------------------------------
1539 // wxListRenameTimer (internal)
1540 //-----------------------------------------------------------------------------
1542 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1547 void wxListRenameTimer::Notify()
1549 m_owner
->OnRenameTimer();
1552 //-----------------------------------------------------------------------------
1553 // wxListTextCtrl (internal)
1554 //-----------------------------------------------------------------------------
1556 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1558 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1559 EVT_CHAR (wxListTextCtrl::OnChar
)
1560 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1561 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1564 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1565 const wxWindowID id
,
1568 wxListMainWindow
*owner
,
1569 const wxString
&value
,
1573 const wxValidator
& validator
,
1574 const wxString
&name
)
1575 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1580 (*m_accept
) = FALSE
;
1582 m_startValue
= value
;
1585 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1587 if (event
.m_keyCode
== WXK_RETURN
)
1590 (*m_res
) = GetValue();
1592 if (!wxPendingDelete
.Member(this))
1593 wxPendingDelete
.Append(this);
1595 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1596 m_owner
->OnRenameAccept();
1600 if (event
.m_keyCode
== WXK_ESCAPE
)
1602 (*m_accept
) = FALSE
;
1605 if (!wxPendingDelete
.Member(this))
1606 wxPendingDelete
.Append(this);
1614 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1616 // auto-grow the textctrl:
1617 wxSize parentSize
= m_owner
->GetSize();
1618 wxPoint myPos
= GetPosition();
1619 wxSize mySize
= GetSize();
1621 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1622 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1623 if (mySize
.x
> sx
) sx
= mySize
.x
;
1629 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1631 if (!wxPendingDelete
.Member(this))
1632 wxPendingDelete
.Append(this);
1634 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1635 m_owner
->OnRenameAccept();
1638 //-----------------------------------------------------------------------------
1640 //-----------------------------------------------------------------------------
1642 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1644 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1645 EVT_PAINT (wxListMainWindow::OnPaint
)
1646 EVT_SIZE (wxListMainWindow::OnSize
)
1647 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1648 EVT_CHAR (wxListMainWindow::OnChar
)
1649 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1650 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1651 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1652 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1655 void wxListMainWindow::Init()
1657 m_columns
.DeleteContents( TRUE
);
1658 m_current
= (wxListLineData
*) NULL
;
1662 m_small_image_list
= (wxImageList
*) NULL
;
1663 m_normal_image_list
= (wxImageList
*) NULL
;
1665 m_small_spacing
= 30;
1666 m_normal_spacing
= 40;
1670 m_isCreated
= FALSE
;
1673 m_lastOnSame
= FALSE
;
1674 m_renameTimer
= new wxListRenameTimer( this );
1675 m_renameAccept
= FALSE
;
1677 m_currentEdit
= (size_t)-1;
1680 m_lineBeforeLastClicked
= (size_t)-1;
1683 wxListMainWindow::wxListMainWindow()
1689 m_hilightBrush
= (wxBrush
*) NULL
;
1695 wxListMainWindow::wxListMainWindow( wxWindow
*parent
,
1700 const wxString
&name
)
1701 : wxScrolledWindow( parent
, id
, pos
, size
,
1702 style
| wxHSCROLL
| wxVSCROLL
, name
)
1707 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1711 if (m_mode
& wxLC_REPORT
)
1713 #if wxUSE_GENERIC_LIST_EXTENSIONS
1725 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1727 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1730 wxListMainWindow::~wxListMainWindow()
1734 if (m_hilightBrush
) delete m_hilightBrush
;
1736 delete m_renameTimer
;
1739 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1741 if (m_dirty
) return;
1749 line
->GetExtent( x
, y
, w
, h
);
1750 CalcScrolledPosition( x
, y
, &x
, &y
);
1751 wxRect
rect( x
, y
, w
, h
);
1752 Refresh( TRUE
, &rect
);
1755 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1757 // Note: a wxPaintDC must be constructed even if no drawing is
1758 // done (a Windows requirement).
1759 wxPaintDC
dc( this );
1763 // postpone redrawing until the next OnIdle() call to minimize flicker
1770 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
1772 if ( GetItemCount() == 0 )
1774 // empty control. nothing to draw
1780 dc
.SetFont( GetFont() );
1782 if (m_mode
& wxLC_REPORT
)
1784 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1785 wxSize clientSize
= GetClientSize();
1787 int lineSpacing
= 0;
1788 wxListLineData
*line
= &m_lines
[0];
1790 line
->GetSize( dummy
, lineSpacing
);
1793 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1795 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1796 if (i_to
>= m_lines
.GetCount())
1797 i_to
= m_lines
.GetCount();
1800 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1802 m_lines
[i
].Draw( &dc
);
1803 // Draw horizontal rule if required
1804 if (m_mode
& wxLC_HRULES
)
1807 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1808 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1812 // Draw last horizontal rule
1813 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (m_mode
& wxLC_HRULES
))
1816 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1817 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1820 // Draw vertical rules if required
1821 if ((m_mode
& wxLC_VRULES
) && (GetItemCount() > 0))
1824 wxRect firstItemRect
;
1825 wxRect lastItemRect
;
1826 GetItemRect(0, firstItemRect
);
1827 GetItemRect(GetItemCount() - 1, lastItemRect
);
1828 int x
= firstItemRect
.GetX();
1830 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1831 for (col
= 0; col
< GetColumnCount(); col
++)
1833 int colWidth
= GetColumnWidth(col
);
1835 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
, x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
1839 else // !report mode
1841 size_t count
= GetItemCount();
1842 for (size_t i
= 0; i
< count
; i
++)
1843 m_lines
[i
].Draw( &dc
);
1847 m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1852 void wxListMainWindow::HilightAll( bool on
)
1854 size_t count
= GetItemCount();
1855 for (size_t i
= 0; i
< count
; i
++)
1857 wxListLineData
*line
= &m_lines
[i
];
1858 if (line
->IsHilighted() != on
)
1860 line
->Hilight( on
);
1861 RefreshLine( line
);
1866 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1867 wxEventType command
,
1870 wxListEvent
le( command
, GetParent()->GetId() );
1871 le
.SetEventObject( GetParent() );
1872 le
.m_itemIndex
= GetIndexOfLine( line
);
1874 // set only for events which have position
1875 if ( point
!= wxDefaultPosition
)
1876 le
.m_pointDrag
= point
;
1878 line
->GetItem( 0, le
.m_item
);
1879 GetParent()->GetEventHandler()->ProcessEvent( le
);
1880 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1883 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1885 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1888 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1890 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1893 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1895 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1898 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1900 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1903 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1905 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1910 void wxListMainWindow::EditLabel( long item
)
1912 wxCHECK_RET( (item
>= 0) && (item
< GetItemCount()),
1913 wxT("wrong index in wxListCtrl::Edit()") );
1915 m_currentEdit
= (size_t)item
;
1917 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1918 le
.SetEventObject( GetParent() );
1919 le
.m_itemIndex
= item
;
1920 wxListLineData
*data
= GetLine(m_currentEdit
);
1921 wxCHECK_RET( data
, _T("invalid index in EditLabel()") );
1922 data
->GetItem( 0, le
.m_item
);
1923 GetParent()->GetEventHandler()->ProcessEvent( le
);
1925 if (!le
.IsAllowed())
1928 // We have to call this here because the label in
1929 // question might just have been added and no screen
1930 // update taken place.
1931 if (m_dirty
) wxYield();
1933 wxString s
= data
->GetText(0);
1938 data
->GetLabelExtent( x
, y
, w
, h
);
1940 wxClientDC
dc(this);
1942 x
= dc
.LogicalToDeviceX( x
);
1943 y
= dc
.LogicalToDeviceY( y
);
1945 wxListTextCtrl
*text
= new wxListTextCtrl(
1946 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1950 void wxListMainWindow::OnRenameTimer()
1952 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1954 Edit( m_lines
.Index( *m_current
) );
1957 void wxListMainWindow::OnRenameAccept()
1959 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1960 le
.SetEventObject( GetParent() );
1961 le
.m_itemIndex
= m_currentEdit
;
1963 wxListLineData
*data
= GetLine(m_currentEdit
);
1964 wxCHECK_RET( data
, _T("invalid index in OnRenameAccept()") );
1966 data
->GetItem( 0, le
.m_item
);
1967 le
.m_item
.m_text
= m_renameRes
;
1968 GetParent()->GetEventHandler()->ProcessEvent( le
);
1970 if (!le
.IsAllowed()) return;
1973 info
.m_mask
= wxLIST_MASK_TEXT
;
1974 info
.m_itemId
= le
.m_itemIndex
;
1975 info
.m_text
= m_renameRes
;
1976 info
.SetTextColour(le
.m_item
.GetTextColour());
1980 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1982 event
.SetEventObject( GetParent() );
1983 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1985 if (!m_current
) return;
1986 if (m_dirty
) return;
1987 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1989 int x
= event
.GetX();
1990 int y
= event
.GetY();
1991 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1993 /* Did we actually hit an item ? */
1995 wxListLineData
*line
= (wxListLineData
*) NULL
;
1998 for (idx
= 0; idx
< m_lines
.GetCount(); idx
++)
2000 line
= &m_lines
[idx
];
2001 hitResult
= line
->IsHit( x
, y
);
2004 line
= (wxListLineData
*) NULL
;
2007 if (event
.Dragging())
2009 if (m_dragCount
== 0)
2010 m_dragStart
= wxPoint(x
,y
);
2014 if (m_dragCount
!= 3) return;
2016 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
2017 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
2019 wxListEvent
le( command
, GetParent()->GetId() );
2020 le
.SetEventObject( GetParent() );
2021 le
.m_pointDrag
= m_dragStart
;
2022 GetParent()->GetEventHandler()->ProcessEvent( le
);
2033 bool forceClick
= FALSE
;
2034 if (event
.ButtonDClick())
2036 m_renameTimer
->Stop();
2037 m_lastOnSame
= FALSE
;
2039 if ( idx
== m_lineBeforeLastClicked
)
2043 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2049 // the first click was on another item, so don't interpret this as
2050 // a double click, but as a simple click instead
2055 if (event
.LeftUp() && m_lastOnSame
)
2058 if ((line
== m_current
) &&
2059 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
2060 (m_mode
& wxLC_EDIT_LABELS
) )
2062 m_renameTimer
->Start( 100, TRUE
);
2064 m_lastOnSame
= FALSE
;
2068 if (event
.RightDown())
2070 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
2071 event
.GetPosition() );
2075 if (event
.MiddleDown())
2077 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
2081 if ( event
.LeftDown() || forceClick
)
2083 m_lineBeforeLastClicked
= m_lineLastClicked
;
2084 m_lineLastClicked
= idx
;
2087 wxListLineData
*oldCurrent
= m_current
;
2088 if (m_mode
& wxLC_SINGLE_SEL
)
2091 HilightAll( FALSE
);
2092 m_current
->ReverseHilight();
2093 RefreshLine( m_current
);
2097 if (event
.ControlDown())
2100 m_current
->ReverseHilight();
2101 RefreshLine( m_current
);
2103 else if (event
.ShiftDown())
2109 int numOfCurrent
= -1;
2110 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2112 wxListLineData
*test_line
= &m_lines
[j
];
2114 if (test_line
== oldCurrent
) break;
2119 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2121 wxListLineData
*test_line
= &m_lines
[j
];
2123 if (test_line
== line
) break;
2126 if (numOfLine
< numOfCurrent
)
2129 numOfLine
= numOfCurrent
;
2133 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2135 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2136 test_line
->Hilight(TRUE
);
2137 RefreshLine( test_line
);
2143 HilightAll( FALSE
);
2144 m_current
->ReverseHilight();
2145 RefreshLine( m_current
);
2148 if (m_current
!= oldCurrent
)
2150 RefreshLine( oldCurrent
);
2151 UnfocusLine( oldCurrent
);
2152 FocusLine( m_current
);
2155 // forceClick is only set if the previous click was on another item
2156 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2162 void wxListMainWindow::MoveToFocus()
2164 if (!m_current
) return;
2170 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2174 GetClientSize( &client_w
, &client_h
);
2176 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2177 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2179 if (m_mode
& wxLC_REPORT
)
2181 if (item_y
< view_y
)
2182 Scroll( -1, (item_y
)/m_yScroll
);
2183 if (item_y
+item_h
+5 > view_y
+client_h
)
2184 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2188 if (item_x
-view_x
< 5)
2189 Scroll( (item_x
-5)/m_xScroll
, -1 );
2190 if (item_x
+item_w
-5 > view_x
+client_w
)
2191 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2195 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2197 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2198 wxListLineData
*oldCurrent
= m_current
;
2199 m_current
= newCurrent
;
2200 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2201 RefreshLine( m_current
);
2202 RefreshLine( oldCurrent
);
2203 FocusLine( m_current
);
2204 UnfocusLine( oldCurrent
);
2208 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2210 wxWindow
*parent
= GetParent();
2212 /* we propagate the key event up */
2213 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2214 ke
.m_shiftDown
= event
.m_shiftDown
;
2215 ke
.m_controlDown
= event
.m_controlDown
;
2216 ke
.m_altDown
= event
.m_altDown
;
2217 ke
.m_metaDown
= event
.m_metaDown
;
2218 ke
.m_keyCode
= event
.m_keyCode
;
2221 ke
.SetEventObject( parent
);
2222 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2227 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2229 wxWindow
*parent
= GetParent();
2231 /* we send a list_key event up */
2234 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2235 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2236 m_current
->GetItem( 0, le
.m_item
);
2237 le
.m_code
= (int)event
.KeyCode();
2238 le
.SetEventObject( parent
);
2239 parent
->GetEventHandler()->ProcessEvent( le
);
2242 /* we propagate the char event up */
2243 wxKeyEvent
ke( wxEVT_CHAR
);
2244 ke
.m_shiftDown
= event
.m_shiftDown
;
2245 ke
.m_controlDown
= event
.m_controlDown
;
2246 ke
.m_altDown
= event
.m_altDown
;
2247 ke
.m_metaDown
= event
.m_metaDown
;
2248 ke
.m_keyCode
= event
.m_keyCode
;
2251 ke
.SetEventObject( parent
);
2252 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2254 if (event
.KeyCode() == WXK_TAB
)
2256 wxNavigationKeyEvent nevent
;
2257 nevent
.SetWindowChange( event
.ControlDown() );
2258 nevent
.SetDirection( !event
.ShiftDown() );
2259 nevent
.SetEventObject( GetParent()->GetParent() );
2260 nevent
.SetCurrentFocus( m_parent
);
2261 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2264 /* no item -> nothing to do */
2271 switch (event
.KeyCode())
2275 int index
= m_lines
.Index(*m_current
);
2276 if (index
!= wxNOT_FOUND
&& index
> 0)
2277 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2282 int index
= m_lines
.Index(*m_current
);
2283 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2284 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2290 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2296 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2302 int index
= m_lines
.Index(*m_current
);
2303 if (m_mode
& wxLC_REPORT
)
2305 steps
= m_visibleLines
-1;
2309 steps
= index
% m_visibleLines
;
2311 if (index
!= wxNOT_FOUND
)
2314 if (index
< 0) index
= 0;
2315 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2322 int index
= m_lines
.Index(*m_current
);
2323 if (m_mode
& wxLC_REPORT
)
2325 steps
= m_visibleLines
-1;
2329 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2332 if (index
!= wxNOT_FOUND
)
2335 if ((size_t)index
>= m_lines
.GetCount())
2336 index
= m_lines
.GetCount()-1;
2337 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2343 if (!(m_mode
& wxLC_REPORT
))
2345 int index
= m_lines
.Index(*m_current
);
2346 if (index
!= wxNOT_FOUND
)
2348 index
-= m_visibleLines
;
2349 if (index
< 0) index
= 0;
2350 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2357 if (!(m_mode
& wxLC_REPORT
))
2359 int index
= m_lines
.Index(*m_current
);
2360 if (index
!= wxNOT_FOUND
)
2362 index
+= m_visibleLines
;
2363 if ((size_t)index
>= m_lines
.GetCount())
2364 index
= m_lines
.GetCount()-1;
2365 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2372 if (m_mode
& wxLC_SINGLE_SEL
)
2374 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2375 le
.SetEventObject( GetParent() );
2376 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2377 m_current
->GetItem( 0, le
.m_item
);
2378 GetParent()->GetEventHandler()->ProcessEvent( le
);
2382 m_current
->ReverseHilight();
2383 RefreshLine( m_current
);
2389 if (!(m_mode
& wxLC_SINGLE_SEL
))
2391 wxListLineData
*oldCurrent
= m_current
;
2392 m_current
->ReverseHilight();
2393 int index
= m_lines
.Index( *m_current
) + 1;
2394 if ( (size_t)index
< m_lines
.GetCount() )
2395 m_current
= &m_lines
[index
];
2396 RefreshLine( oldCurrent
);
2397 RefreshLine( m_current
);
2398 UnfocusLine( oldCurrent
);
2399 FocusLine( m_current
);
2407 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2408 le
.SetEventObject( GetParent() );
2409 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2410 m_current
->GetItem( 0, le
.m_item
);
2411 GetParent()->GetEventHandler()->ProcessEvent( le
);
2424 extern wxWindow
*g_focusWindow
;
2427 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2430 RefreshLine( m_current
);
2432 if (!GetParent()) return;
2435 g_focusWindow
= GetParent();
2438 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2439 event
.SetEventObject( GetParent() );
2440 GetParent()->GetEventHandler()->ProcessEvent( event
);
2443 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2446 RefreshLine( m_current
);
2449 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2452 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2458 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2460 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2462 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2465 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2467 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2469 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2471 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2473 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2475 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2480 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2482 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2484 m_normal_image_list
->GetSize( index
, width
, height
);
2487 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2489 m_small_image_list
->GetSize( index
, width
, height
);
2492 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2494 m_small_image_list
->GetSize( index
, width
, height
);
2497 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2499 m_small_image_list
->GetSize( index
, width
, height
);
2506 int wxListMainWindow::GetTextLength( wxString
&s
)
2508 wxClientDC
dc( this );
2511 dc
.GetTextExtent( s
, &lw
, &lh
);
2515 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2517 return m_lines
.Index(*line
);
2520 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2524 // calc the spacing from the icon size
2527 if ((imageList
) && (imageList
->GetImageCount()) )
2529 imageList
->GetSize(0, width
, height
);
2532 if (which
== wxIMAGE_LIST_NORMAL
)
2534 m_normal_image_list
= imageList
;
2535 m_normal_spacing
= width
+ 8;
2538 if (which
== wxIMAGE_LIST_SMALL
)
2540 m_small_image_list
= imageList
;
2541 m_small_spacing
= width
+ 14;
2545 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2550 m_small_spacing
= spacing
;
2554 m_normal_spacing
= spacing
;
2558 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2560 return isSmall
? m_small_spacing
: m_normal_spacing
;
2563 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2566 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2569 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2570 item
.m_width
= GetTextLength( item
.m_text
)+7;
2571 wxListHeaderData
*column
= node
->GetData();
2572 column
->SetItem( item
);
2575 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2577 headerWin
->m_dirty
= TRUE
;
2580 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2582 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2583 _T("SetColumnWidth() can only be called in report mode.") );
2587 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2589 // TODO do use the header
2592 else if (width
== wxLIST_AUTOSIZE
)
2594 wxClientDC
dc(this);
2595 dc
.SetFont( GetFont() );
2598 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2600 wxListLineData
*line
= &m_lines
[i
];
2601 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2604 wxListItemData
*item
= n
->GetData();
2605 int current
= 0, ix
= 0, iy
= 0;
2606 wxCoord lx
= 0, ly
= 0;
2607 if (item
->HasImage())
2609 GetImageSize( item
->GetImage(), ix
, iy
);
2612 if (item
->HasText())
2614 wxString str
= item
->GetText();
2615 dc
.GetTextExtent( str
, &lx
, &ly
);
2625 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2628 wxListHeaderData
*column
= node
->GetData();
2629 column
->SetWidth( width
);
2632 size_t count
= m_lines
.GetCount();
2633 for (size_t i
= 0; i
< count
; i
++)
2635 wxListLineData
*line
= &m_lines
[i
];
2636 wxListItemDataList::Node
*n
= line
->m_items
.Item( col
);
2639 wxListItemData
*item
= n
->GetData();
2640 item
->SetSize( width
, -1 );
2644 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2646 headerWin
->m_dirty
= TRUE
;
2649 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2651 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2654 wxListHeaderData
*column
= node
->GetData();
2655 column
->GetItem( item
);
2661 item
.m_text
= _T("");
2667 int wxListMainWindow::GetColumnWidth( int col
)
2669 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
2670 wxCHECK_MSG( node
, 0, _T("invalid column index") );
2672 wxListHeaderData
*column
= node
->GetData();
2673 return column
->GetWidth();
2676 int wxListMainWindow::GetColumnCount()
2678 return m_columns
.GetCount();
2681 int wxListMainWindow::GetCountPerPage()
2683 return m_visibleLines
;
2686 void wxListMainWindow::SetItem( wxListItem
&item
)
2689 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2691 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2692 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2693 line
->SetItem( item
.m_col
, item
);
2697 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2699 wxCHECK_RET( item
>= 0 && (size_t)item
< m_lines
.GetCount(),
2700 _T("invalid list ctrl item index in SetItem") );
2702 // m_dirty = TRUE; no recalcs needed
2704 wxListLineData
*oldCurrent
= m_current
;
2706 if ( stateMask
& wxLIST_STATE_FOCUSED
)
2708 wxListLineData
*line
= &m_lines
[(size_t)item
];
2709 if ( state
& wxLIST_STATE_FOCUSED
)
2711 // don't do anything if this item is already focused
2712 if ( line
!= m_current
)
2714 UnfocusLine( m_current
);
2716 FocusLine( m_current
);
2717 if ( (m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
)
2718 oldCurrent
->Hilight( FALSE
);
2720 RefreshLine( m_current
);
2722 RefreshLine( oldCurrent
);
2727 // don't do anything if this item is not focused
2728 if ( line
== m_current
)
2730 UnfocusLine( m_current
);
2736 if ( stateMask
& wxLIST_STATE_SELECTED
)
2738 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2739 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
))
2742 wxListLineData
*line
= &m_lines
[(size_t)item
];
2743 if (m_mode
& wxLC_SINGLE_SEL
)
2745 UnfocusLine( m_current
);
2747 FocusLine( m_current
);
2749 oldCurrent
->Hilight( FALSE
);
2750 RefreshLine( m_current
);
2752 RefreshLine( oldCurrent
);
2755 if (on
!= line
->IsHilighted())
2757 line
->Hilight( on
);
2758 RefreshLine( line
);
2763 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2765 int ret
= wxLIST_STATE_DONTCARE
;
2766 if (stateMask
& wxLIST_STATE_FOCUSED
)
2768 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2770 wxListLineData
*line
= &m_lines
[(size_t)item
];
2771 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2774 if (stateMask
& wxLIST_STATE_SELECTED
)
2776 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2778 wxListLineData
*line
= &m_lines
[(size_t)item
];
2779 if (line
->IsHilighted()) ret
|= wxLIST_STATE_SELECTED
;
2785 void wxListMainWindow::GetItem( wxListItem
&item
)
2787 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2789 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2790 line
->GetItem( item
.m_col
, item
);
2795 item
.m_text
= _T("");
2801 int wxListMainWindow::GetItemCount() const
2803 return IsVirtual() ? m_countVirt
: m_lines
.GetCount();
2806 void wxListMainWindow::SetItemCount(long count
)
2808 m_countVirt
= count
;
2813 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2815 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2817 m_lines
[(size_t)index
].GetRect( rect
);
2818 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2829 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2832 this->GetItemRect(item
,rect
);
2833 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2837 int wxListMainWindow::GetSelectedItemCount()
2840 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2842 if (m_lines
[i
].IsHilighted()) ret
++;
2847 void wxListMainWindow::SetMode( long mode
)
2854 if (m_mode
& wxLC_REPORT
)
2856 #if wxUSE_GENERIC_LIST_EXTENSIONS
2870 long wxListMainWindow::GetMode() const
2875 void wxListMainWindow::CalculatePositions()
2880 wxClientDC
dc( this );
2881 dc
.SetFont( GetFont() );
2883 int iconSpacing
= 0;
2884 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2885 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2887 // we take the first line (which also can be an icon or
2888 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2889 // measure the size of the line
2893 int lineSpacing
= 0;
2895 wxListLineData
*line
= &m_lines
[0];
2896 line
->CalculateSize( &dc
, iconSpacing
);
2898 line
->GetSize( dummy
, lineSpacing
);
2901 int clientWidth
= 0;
2902 int clientHeight
= 0;
2904 if (m_mode
& wxLC_REPORT
)
2906 // scroll one line per step
2907 m_yScroll
= lineSpacing
;
2911 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2912 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2913 #if wxUSE_GENERIC_LIST_EXTENSIONS
2914 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2916 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2918 GetClientSize( &clientWidth
, &clientHeight
);
2920 int entireWidth
= 0 ;
2921 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2923 wxListLineData
*line
= &m_lines
[j
];
2924 line
->CalculateSize( &dc
, iconSpacing
);
2925 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2927 for (int i
= 0; i
< GetColumnCount(); i
++)
2929 line
->SetColumnPosition( i
, col_x
);
2930 col_x
+= GetColumnWidth( i
);
2932 entireWidth
= wxMax( entireWidth
, col_x
) ;
2933 #if wxUSE_GENERIC_LIST_EXTENSIONS
2934 line
->SetPosition( &dc
, x
, y
, col_x
);
2936 y
+= lineSpacing
; // one pixel blank line between items
2938 m_visibleLines
= clientHeight
/ lineSpacing
;
2939 #if wxUSE_GENERIC_LIST_EXTENSIONS
2940 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2945 // at first we try without any scrollbar. if the items don't
2946 // fit into the window, we recalculate after subtracting an
2947 // approximated 15 pt for the horizontal scrollbar
2949 GetSize( &clientWidth
, &clientHeight
);
2950 clientHeight
-= 4; // sunken frame
2952 int entireWidth
= 0;
2954 for (int tries
= 0; tries
< 2; tries
++)
2961 int m_currentVisibleLines
= 0;
2962 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2964 m_currentVisibleLines
++;
2965 wxListLineData
*line
= &m_lines
[i
];
2966 line
->CalculateSize( &dc
, iconSpacing
);
2967 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2968 line
->GetSize( lineWidth
, lineHeight
);
2969 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2971 if (m_currentVisibleLines
> m_visibleLines
)
2972 m_visibleLines
= m_currentVisibleLines
;
2973 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2975 m_currentVisibleLines
= 0;
2978 entireWidth
+= maxWidth
+6;
2981 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2982 if ((tries
== 0) && (entireWidth
> clientWidth
))
2984 clientHeight
-= 15; // scrollbar height
2986 m_currentVisibleLines
= 0;
2989 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2993 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2994 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2998 void wxListMainWindow::RealizeChanges()
3003 m_current
= &m_lines
[0];
3007 FocusLine( m_current
);
3008 // TODO: MSW doesn't automatically hilight the
3010 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
3014 long wxListMainWindow::GetNextItem( long item
,
3015 int WXUNUSED(geometry
),
3019 max
= GetItemCount();
3020 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
3021 _T("invalid listctrl index in GetNextItem()") );
3023 // notice that we start with the next item (or the first one if item == -1)
3024 // and this is intentional to allow writing a simple loop to iterate over
3025 // all selected items
3029 // this is not an error because the index was ok initially, just no
3034 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
3036 wxListLineData
*line
= &m_lines
[i
];
3037 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
3039 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
3049 void wxListMainWindow::DeleteItem( long index
)
3052 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
3054 wxListLineData
*line
= &m_lines
[(size_t)index
];
3055 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
3057 m_lines
.RemoveAt( (size_t)index
);
3061 void wxListMainWindow::DeleteColumn( int col
)
3063 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3065 wxCHECK_RET( node
, wxT("invalid column index in DeleteColumn()") );
3068 m_columns
.DeleteNode( node
);
3071 void wxListMainWindow::DeleteAllItems()
3074 m_current
= (wxListLineData
*) NULL
;
3076 // to make the deletion of all items faster, we don't send the
3077 // notifications in this case: this is compatible with wxMSW and
3078 // documented in DeleteAllItems() description
3080 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
3081 event
.SetEventObject( GetParent() );
3082 GetParent()->GetEventHandler()->ProcessEvent( event
);
3087 void wxListMainWindow::DeleteEverything()
3094 void wxListMainWindow::EnsureVisible( long index
)
3096 // We have to call this here because the label in
3097 // question might just have been added and no screen
3098 // update taken place.
3099 if (m_dirty
) wxYield();
3101 wxListLineData
*oldCurrent
= m_current
;
3102 m_current
= (wxListLineData
*) NULL
;
3103 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
3104 m_current
= &m_lines
[(size_t)index
];
3105 if (m_current
) MoveToFocus();
3106 m_current
= oldCurrent
;
3109 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3113 if (pos
< 0) pos
= 0;
3114 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3116 wxListLineData
*line
= &m_lines
[i
];
3117 wxString s
= line
->GetText(0);
3126 long wxListMainWindow::FindItem(long start
, long data
)
3129 if (pos
< 0) pos
= 0;
3130 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3132 wxListLineData
*line
= &m_lines
[i
];
3134 line
->GetItem( 0, item
);
3135 if (item
.m_data
== data
) return pos
;
3141 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3143 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3146 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3148 wxListLineData
*line
= &m_lines
[i
];
3149 long ret
= line
->IsHit( x
, y
);
3150 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3160 void wxListMainWindow::InsertItem( wxListItem
&item
)
3164 if (m_mode
& wxLC_REPORT
)
3166 else if (m_mode
& wxLC_LIST
)
3168 else if (m_mode
& wxLC_ICON
)
3170 else if (m_mode
& wxLC_SMALL_ICON
)
3171 mode
= wxLC_ICON
; // no typo
3174 wxFAIL_MSG( _T("unknown mode") );
3177 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3179 if (m_mode
& wxLC_REPORT
)
3181 line
->InitItems( GetColumnCount() );
3182 item
.m_width
= GetColumnWidth( 0 )-3;
3186 line
->InitItems( 1 );
3189 line
->SetItem( 0, item
);
3190 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3192 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3196 m_lines
.Add( line
);
3197 item
.m_itemId
= m_lines
.GetCount()-1;
3201 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3204 if (m_mode
& wxLC_REPORT
)
3206 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3207 item
.m_width
= GetTextLength( item
.m_text
);
3208 wxListHeaderData
*column
= new wxListHeaderData( item
);
3209 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3211 wxListHeaderDataList::Node
*node
= m_columns
.Item( col
);
3212 m_columns
.Insert( node
, column
);
3216 m_columns
.Append( column
);
3221 wxListCtrlCompare list_ctrl_compare_func_2
;
3222 long list_ctrl_compare_data
;
3224 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3226 wxListLineData
*line1
= *arg1
;
3227 wxListLineData
*line2
= *arg2
;
3229 line1
->GetItem( 0, item
);
3230 long data1
= item
.m_data
;
3231 line2
->GetItem( 0, item
);
3232 long data2
= item
.m_data
;
3233 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3236 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3238 list_ctrl_compare_func_2
= fn
;
3239 list_ctrl_compare_data
= data
;
3240 m_lines
.Sort( list_ctrl_compare_func_1
);
3244 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3247 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
3248 wxScrolledWindow::OnScroll(event
);
3250 HandleOnScroll( event
);
3253 #if wxUSE_GENERIC_LIST_EXTENSIONS
3255 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3257 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3260 lc
->m_headerWin
->Refresh() ;
3262 lc
->m_headerWin
->MacUpdateImmediately() ;
3269 // -------------------------------------------------------------------------------------
3271 // -------------------------------------------------------------------------------------
3273 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3275 wxListItem::wxListItem()
3284 m_format
= wxLIST_FORMAT_CENTRE
;
3290 void wxListItem::Clear()
3299 m_format
= wxLIST_FORMAT_CENTRE
;
3303 if (m_attr
) delete m_attr
;
3307 void wxListItem::ClearAttributes()
3309 if (m_attr
) delete m_attr
;
3313 // -------------------------------------------------------------------------------------
3315 // -------------------------------------------------------------------------------------
3317 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3319 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3320 wxNotifyEvent( commandType
, id
)
3326 m_cancelled
= FALSE
;
3331 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3333 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3335 wxNotifyEvent::CopyObject(object_dest
);
3337 obj
->m_code
= m_code
;
3338 obj
->m_itemIndex
= m_itemIndex
;
3339 obj
->m_oldItemIndex
= m_oldItemIndex
;
3341 obj
->m_cancelled
= m_cancelled
;
3342 obj
->m_pointDrag
= m_pointDrag
;
3343 obj
->m_item
.m_mask
= m_item
.m_mask
;
3344 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3345 obj
->m_item
.m_col
= m_item
.m_col
;
3346 obj
->m_item
.m_state
= m_item
.m_state
;
3347 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3348 obj
->m_item
.m_text
= m_item
.m_text
;
3349 obj
->m_item
.m_image
= m_item
.m_image
;
3350 obj
->m_item
.m_data
= m_item
.m_data
;
3351 obj
->m_item
.m_format
= m_item
.m_format
;
3352 obj
->m_item
.m_width
= m_item
.m_width
;
3354 if ( m_item
.HasAttributes() )
3356 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3360 // -------------------------------------------------------------------------------------
3362 // -------------------------------------------------------------------------------------
3364 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3366 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3367 EVT_SIZE (wxListCtrl::OnSize
)
3368 EVT_IDLE (wxListCtrl::OnIdle
)
3371 wxListCtrl::wxListCtrl()
3373 m_imageListNormal
= (wxImageList
*) NULL
;
3374 m_imageListSmall
= (wxImageList
*) NULL
;
3375 m_imageListState
= (wxImageList
*) NULL
;
3376 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3377 m_mainWin
= (wxListMainWindow
*) NULL
;
3378 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3381 wxListCtrl::~wxListCtrl()
3383 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3384 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3385 if (m_ownsImageListState
) delete m_imageListState
;
3388 bool wxListCtrl::Create(wxWindow
*parent
,
3393 const wxValidator
&validator
,
3394 const wxString
&name
)
3396 m_imageListNormal
= (wxImageList
*) NULL
;
3397 m_imageListSmall
= (wxImageList
*) NULL
;
3398 m_imageListState
= (wxImageList
*) NULL
;
3399 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3400 m_mainWin
= (wxListMainWindow
*) NULL
;
3401 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3403 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3405 style
= style
| wxLC_LIST
;
3408 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3411 if (style
& wxSUNKEN_BORDER
)
3412 style
-= wxSUNKEN_BORDER
;
3414 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3416 if (HasFlag(wxLC_REPORT
))
3418 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3419 if (HasFlag(wxLC_NO_HEADER
))
3420 m_headerWin
->Show( FALSE
);
3424 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3430 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3432 /* handled in OnIdle */
3434 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3437 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3439 long flag
= GetWindowStyle();
3443 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3444 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3445 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3454 if (flag
& style
) flag
-= style
;
3457 SetWindowStyleFlag( flag
);
3460 void wxListCtrl::SetWindowStyleFlag( long flag
)
3464 m_mainWin
->DeleteEverything();
3468 GetClientSize( &width
, &height
);
3470 m_mainWin
->SetMode( flag
);
3472 if (flag
& wxLC_REPORT
)
3474 if (!HasFlag(wxLC_REPORT
))
3478 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3479 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3480 if (HasFlag(wxLC_NO_HEADER
))
3481 m_headerWin
->Show( FALSE
);
3485 if (flag
& wxLC_NO_HEADER
)
3486 m_headerWin
->Show( FALSE
);
3488 m_headerWin
->Show( TRUE
);
3494 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3496 m_headerWin
->Show( FALSE
);
3501 wxWindow::SetWindowStyleFlag( flag
);
3504 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3506 m_mainWin
->GetColumn( col
, item
);
3510 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3512 m_mainWin
->SetColumn( col
, item
);
3516 int wxListCtrl::GetColumnWidth( int col
) const
3518 return m_mainWin
->GetColumnWidth( col
);
3521 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3523 m_mainWin
->SetColumnWidth( col
, width
);
3527 int wxListCtrl::GetCountPerPage() const
3529 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3532 bool wxListCtrl::GetItem( wxListItem
&info
) const
3534 m_mainWin
->GetItem( info
);
3538 bool wxListCtrl::SetItem( wxListItem
&info
)
3540 m_mainWin
->SetItem( info
);
3544 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3547 info
.m_text
= label
;
3548 info
.m_mask
= wxLIST_MASK_TEXT
;
3549 info
.m_itemId
= index
;
3553 info
.m_image
= imageId
;
3554 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3556 m_mainWin
->SetItem(info
);
3560 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3562 return m_mainWin
->GetItemState( item
, stateMask
);
3565 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3567 m_mainWin
->SetItemState( item
, state
, stateMask
);
3571 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3574 info
.m_image
= image
;
3575 info
.m_mask
= wxLIST_MASK_IMAGE
;
3576 info
.m_itemId
= item
;
3577 m_mainWin
->SetItem( info
);
3581 wxString
wxListCtrl::GetItemText( long item
) const
3584 info
.m_itemId
= item
;
3585 m_mainWin
->GetItem( info
);
3589 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3592 info
.m_mask
= wxLIST_MASK_TEXT
;
3593 info
.m_itemId
= item
;
3595 m_mainWin
->SetItem( info
);
3598 long wxListCtrl::GetItemData( long item
) const
3601 info
.m_itemId
= item
;
3602 m_mainWin
->GetItem( info
);
3606 bool wxListCtrl::SetItemData( long item
, long data
)
3609 info
.m_mask
= wxLIST_MASK_DATA
;
3610 info
.m_itemId
= item
;
3612 m_mainWin
->SetItem( info
);
3616 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3618 m_mainWin
->GetItemRect( item
, rect
);
3622 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3624 m_mainWin
->GetItemPosition( item
, pos
);
3628 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3633 int wxListCtrl::GetItemCount() const
3635 return m_mainWin
->GetItemCount();
3638 int wxListCtrl::GetColumnCount() const
3640 return m_mainWin
->GetColumnCount();
3643 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3645 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3648 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3650 return m_mainWin
->GetItemSpacing( isSmall
);
3653 int wxListCtrl::GetSelectedItemCount() const
3655 return m_mainWin
->GetSelectedItemCount();
3658 wxColour
wxListCtrl::GetTextColour() const
3660 return GetForegroundColour();
3663 void wxListCtrl::SetTextColour(const wxColour
& col
)
3665 SetForegroundColour(col
);
3668 long wxListCtrl::GetTopItem() const
3673 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3675 return m_mainWin
->GetNextItem( item
, geom
, state
);
3678 wxImageList
*wxListCtrl::GetImageList(int which
) const
3680 if (which
== wxIMAGE_LIST_NORMAL
)
3682 return m_imageListNormal
;
3684 else if (which
== wxIMAGE_LIST_SMALL
)
3686 return m_imageListSmall
;
3688 else if (which
== wxIMAGE_LIST_STATE
)
3690 return m_imageListState
;
3692 return (wxImageList
*) NULL
;
3695 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3697 if ( which
== wxIMAGE_LIST_NORMAL
)
3699 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3700 m_imageListNormal
= imageList
;
3701 m_ownsImageListNormal
= FALSE
;
3703 else if ( which
== wxIMAGE_LIST_SMALL
)
3705 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3706 m_imageListSmall
= imageList
;
3707 m_ownsImageListSmall
= FALSE
;
3709 else if ( which
== wxIMAGE_LIST_STATE
)
3711 if (m_ownsImageListState
) delete m_imageListState
;
3712 m_imageListState
= imageList
;
3713 m_ownsImageListState
= FALSE
;
3716 m_mainWin
->SetImageList( imageList
, which
);
3719 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3721 SetImageList(imageList
, which
);
3722 if ( which
== wxIMAGE_LIST_NORMAL
)
3723 m_ownsImageListNormal
= TRUE
;
3724 else if ( which
== wxIMAGE_LIST_SMALL
)
3725 m_ownsImageListSmall
= TRUE
;
3726 else if ( which
== wxIMAGE_LIST_STATE
)
3727 m_ownsImageListState
= TRUE
;
3730 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3735 bool wxListCtrl::DeleteItem( long item
)
3737 m_mainWin
->DeleteItem( item
);
3741 bool wxListCtrl::DeleteAllItems()
3743 m_mainWin
->DeleteAllItems();
3747 bool wxListCtrl::DeleteAllColumns()
3749 size_t count
= m_mainWin
->m_columns
.GetCount();
3750 for ( size_t n
= 0; n
< count
; n
++ )
3756 void wxListCtrl::ClearAll()
3758 m_mainWin
->DeleteEverything();
3761 bool wxListCtrl::DeleteColumn( int col
)
3763 m_mainWin
->DeleteColumn( col
);
3767 void wxListCtrl::Edit( long item
)
3769 m_mainWin
->Edit( item
);
3772 bool wxListCtrl::EnsureVisible( long item
)
3774 m_mainWin
->EnsureVisible( item
);
3778 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3780 return m_mainWin
->FindItem( start
, str
, partial
);
3783 long wxListCtrl::FindItem( long start
, long data
)
3785 return m_mainWin
->FindItem( start
, data
);
3788 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3789 int WXUNUSED(direction
))
3794 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3796 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3799 long wxListCtrl::InsertItem( wxListItem
& info
)
3801 m_mainWin
->InsertItem( info
);
3802 return info
.m_itemId
;
3805 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3808 info
.m_text
= label
;
3809 info
.m_mask
= wxLIST_MASK_TEXT
;
3810 info
.m_itemId
= index
;
3811 return InsertItem( info
);
3814 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3817 info
.m_mask
= wxLIST_MASK_IMAGE
;
3818 info
.m_image
= imageIndex
;
3819 info
.m_itemId
= index
;
3820 return InsertItem( info
);
3823 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3826 info
.m_text
= label
;
3827 info
.m_image
= imageIndex
;
3828 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3829 info
.m_itemId
= index
;
3830 return InsertItem( info
);
3833 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3835 wxASSERT( m_headerWin
);
3836 m_mainWin
->InsertColumn( col
, item
);
3837 m_headerWin
->Refresh();
3842 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3843 int format
, int width
)
3846 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3847 item
.m_text
= heading
;
3850 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3851 item
.m_width
= width
;
3853 item
.m_format
= format
;
3855 return InsertColumn( col
, item
);
3858 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3864 // fn is a function which takes 3 long arguments: item1, item2, data.
3865 // item1 is the long data associated with a first item (NOT the index).
3866 // item2 is the long data associated with a second item (NOT the index).
3867 // data is the same value as passed to SortItems.
3868 // The return value is a negative number if the first item should precede the second
3869 // item, a positive number of the second item should precede the first,
3870 // or zero if the two items are equivalent.
3871 // data is arbitrary data to be passed to the sort function.
3873 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3875 m_mainWin
->SortItems( fn
, data
);
3879 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3881 if (!m_mainWin
->m_dirty
) return;
3885 GetClientSize( &cw
, &ch
);
3892 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3894 m_headerWin
->GetPosition( &x
, &y
);
3895 m_headerWin
->GetSize( &w
, &h
);
3896 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3897 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3899 m_mainWin
->GetPosition( &x
, &y
);
3900 m_mainWin
->GetSize( &w
, &h
);
3901 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3902 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3906 m_mainWin
->GetPosition( &x
, &y
);
3907 m_mainWin
->GetSize( &w
, &h
);
3908 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3909 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3912 m_mainWin
->CalculatePositions();
3913 m_mainWin
->RealizeChanges();
3914 m_mainWin
->m_dirty
= FALSE
;
3915 m_mainWin
->Refresh();
3917 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3919 m_headerWin
->m_dirty
= FALSE
;
3920 m_headerWin
->Refresh();
3924 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3928 m_mainWin
->SetBackgroundColour( colour
);
3929 m_mainWin
->m_dirty
= TRUE
;
3935 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3937 if ( !wxWindow::SetForegroundColour( colour
) )
3942 m_mainWin
->SetForegroundColour( colour
);
3943 m_mainWin
->m_dirty
= TRUE
;
3948 m_headerWin
->SetForegroundColour( colour
);
3954 bool wxListCtrl::SetFont( const wxFont
&font
)
3956 if ( !wxWindow::SetFont( font
) )
3961 m_mainWin
->SetFont( font
);
3962 m_mainWin
->m_dirty
= TRUE
;
3967 m_headerWin
->SetFont( font
);
3973 #if wxUSE_DRAG_AND_DROP
3975 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3977 m_mainWin
->SetDropTarget( dropTarget
);
3980 wxDropTarget
*wxListCtrl::GetDropTarget() const
3982 return m_mainWin
->GetDropTarget();
3985 #endif // wxUSE_DRAG_AND_DROP
3987 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3989 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3992 wxColour
wxListCtrl::GetBackgroundColour() const
3994 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3997 wxColour
wxListCtrl::GetForegroundColour() const
3999 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
4002 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
4005 return m_mainWin
->PopupMenu( menu
, x
, y
);
4008 #endif // wxUSE_MENUS
4011 void wxListCtrl::SetFocus()
4013 /* The test in window.cpp fails as we are a composite
4014 window, so it checks against "this", but not m_mainWin. */
4015 if ( FindFocus() != this )
4016 m_mainWin
->SetFocus();
4019 // ----------------------------------------------------------------------------
4020 // virtual list control support
4021 // ----------------------------------------------------------------------------
4023 wxString
wxListCtrl::OnGetItemText(long item
, long col
) const
4025 // this is a pure virtual function, in fact - which is not really pure
4026 // because the controls which are not virtual don't need to implement it
4027 wxFAIL_MSG( _T("not supposed to be called") );
4029 return wxEmptyString
;
4032 int wxListCtrl::OnGetItemImage(long item
) const
4035 wxFAIL_MSG( _T("not supposed to be called") );
4040 void wxListCtrl::SetItemCount(long count
)
4042 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
4044 m_mainWin
->SetItemCount(count
);
4047 #endif // wxUSE_LISTCTRL