1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
26 #include "wx/dynarray.h"
30 #include "wx/gtk/win_gtk.h"
33 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
34 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
37 // ============================================================================
39 // ============================================================================
41 //-----------------------------------------------------------------------------
42 // wxListItemData (internal)
43 //-----------------------------------------------------------------------------
45 class WXDLLEXPORT wxListItemData
: public wxObject
54 wxListItemAttr
*m_attr
;
58 ~wxListItemData() { delete m_attr
; }
60 wxListItemData( const wxListItem
&info
);
61 void SetItem( const wxListItem
&info
);
62 void SetText( const wxString
&s
);
63 void SetImage( int image
);
64 void SetData( long data
);
65 void SetPosition( int x
, int y
);
66 void SetSize( int width
, int height
);
67 bool HasImage() const;
69 bool IsHit( int x
, int y
) const;
70 void GetText( wxString
&s
);
71 const wxString
& GetText() { return m_text
; }
72 int GetX( void ) const;
73 int GetY( void ) const;
75 int GetHeight() const;
77 void GetItem( wxListItem
&info
) const;
79 wxListItemAttr
*GetAttributes() const { return m_attr
; }
82 DECLARE_DYNAMIC_CLASS(wxListItemData
);
85 //-----------------------------------------------------------------------------
86 // wxListHeaderData (internal)
87 //-----------------------------------------------------------------------------
89 class WXDLLEXPORT wxListHeaderData
: public wxObject
102 wxListHeaderData( const wxListItem
&info
);
103 void SetItem( const wxListItem
&item
);
104 void SetPosition( int x
, int y
);
105 void SetWidth( int w
);
106 void SetFormat( int format
);
107 void SetHeight( int h
);
108 bool HasImage() const;
109 bool HasText() const;
110 bool IsHit( int x
, int y
) const;
111 void GetItem( wxListItem
&item
);
112 void GetText( wxString
&s
);
113 int GetImage() const;
114 int GetWidth() const;
115 int GetFormat() const;
118 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
121 //-----------------------------------------------------------------------------
122 // wxListLineData (internal)
123 //-----------------------------------------------------------------------------
125 class WXDLLEXPORT wxListLineData
: public wxObject
130 wxRect m_bound_label
;
132 wxRect m_bound_hilight
;
135 wxBrush
*m_hilightBrush
;
137 wxListMainWindow
*m_owner
;
139 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
143 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
144 void CalculateSize( wxDC
*dc
, int spacing
);
145 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
146 void SetColumnPosition( int index
, int x
);
147 void GetSize( int &width
, int &height
);
148 void GetExtent( int &x
, int &y
, int &width
, int &height
);
149 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
150 long IsHit( int x
, int y
);
151 void InitItems( int num
);
152 void SetItem( int index
, const wxListItem
&info
);
153 void GetItem( int index
, wxListItem
&info
);
154 void GetText( int index
, wxString
&s
);
155 void SetText( int index
, const wxString s
);
156 int GetImage( int index
);
157 void GetRect( wxRect
&rect
);
158 void Hilight( bool on
);
159 void ReverseHilight();
160 void DrawRubberBand( wxDC
*dc
, bool on
);
161 void Draw( wxDC
*dc
);
162 bool IsInRect( int x
, int y
, const wxRect
&rect
);
164 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
165 void AssignRect( wxRect
&dest
, const wxRect
&source
);
168 void SetAttributes(wxDC
*dc
,
169 const wxListItemAttr
*attr
,
170 const wxColour
& colText
, const wxFont
& font
,
173 DECLARE_DYNAMIC_CLASS(wxListLineData
);
177 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
178 #include "wx/arrimpl.cpp"
179 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
181 //-----------------------------------------------------------------------------
182 // wxListHeaderWindow (internal)
183 //-----------------------------------------------------------------------------
185 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
188 wxListMainWindow
*m_owner
;
189 wxCursor
*m_currentCursor
;
190 wxCursor
*m_resizeCursor
;
193 // column being resized
196 // divider line position in logical (unscrolled) coords
199 // minimal position beyond which the divider line can't be dragged in
204 wxListHeaderWindow();
205 virtual ~wxListHeaderWindow();
207 wxListHeaderWindow( wxWindow
*win
,
209 wxListMainWindow
*owner
,
210 const wxPoint
&pos
= wxDefaultPosition
,
211 const wxSize
&size
= wxDefaultSize
,
213 const wxString
&name
= "wxlistctrlcolumntitles" );
215 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
217 void AdjustDC(wxDC
& dc
);
219 void OnPaint( wxPaintEvent
&event
);
220 void OnMouse( wxMouseEvent
&event
);
221 void OnSetFocus( wxFocusEvent
&event
);
227 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
228 DECLARE_EVENT_TABLE()
231 //-----------------------------------------------------------------------------
232 // wxListRenameTimer (internal)
233 //-----------------------------------------------------------------------------
235 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
238 wxListMainWindow
*m_owner
;
241 wxListRenameTimer( wxListMainWindow
*owner
);
245 //-----------------------------------------------------------------------------
246 // wxListTextCtrl (internal)
247 //-----------------------------------------------------------------------------
249 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
254 wxListMainWindow
*m_owner
;
255 wxString m_startValue
;
259 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
260 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
261 const wxString
&value
= "",
262 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
264 const wxValidator
& validator
= wxDefaultValidator
,
265 const wxString
&name
= "listctrltextctrl" );
266 void OnChar( wxKeyEvent
&event
);
267 void OnKillFocus( wxFocusEvent
&event
);
270 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
271 DECLARE_EVENT_TABLE()
274 //-----------------------------------------------------------------------------
275 // wxListMainWindow (internal)
276 //-----------------------------------------------------------------------------
278 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
282 wxListLineDataArray m_lines
;
284 wxListLineData
*m_current
;
285 wxListLineData
*m_currentEdit
;
287 wxBrush
*m_hilightBrush
;
288 wxColour
*m_hilightColour
;
289 int m_xScroll
,m_yScroll
;
291 wxImageList
*m_small_image_list
;
292 wxImageList
*m_normal_image_list
;
294 int m_normal_spacing
;
298 wxTimer
*m_renameTimer
;
300 wxString m_renameRes
;
305 // for double click logic
306 wxListLineData
*m_lineLastClicked
,
307 *m_lineBeforeLastClicked
;
311 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
312 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
313 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
315 void RefreshLine( wxListLineData
*line
);
316 void OnPaint( wxPaintEvent
&event
);
317 void HilightAll( bool on
);
318 void SendNotify( wxListLineData
*line
, wxEventType command
);
319 void FocusLine( wxListLineData
*line
);
320 void UnfocusLine( wxListLineData
*line
);
321 void SelectLine( wxListLineData
*line
);
322 void DeselectLine( wxListLineData
*line
);
323 void DeleteLine( wxListLineData
*line
);
325 void EditLabel( long item
);
326 void Edit( long item
) { EditLabel(item
); } // deprecated
327 void OnRenameTimer();
328 void OnRenameAccept();
330 void OnMouse( wxMouseEvent
&event
);
332 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
333 void OnChar( wxKeyEvent
&event
);
334 void OnKeyDown( wxKeyEvent
&event
);
335 void OnSetFocus( wxFocusEvent
&event
);
336 void OnKillFocus( wxFocusEvent
&event
);
337 void OnSize( wxSizeEvent
&event
);
338 void OnScroll(wxScrollWinEvent
& event
) ;
340 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
341 void GetImageSize( int index
, int &width
, int &height
);
342 int GetIndexOfLine( const wxListLineData
*line
);
343 int GetTextLength( wxString
&s
); // should be const
345 void SetImageList( wxImageList
*imageList
, int which
);
346 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
347 int GetItemSpacing( bool isSmall
= FALSE
);
348 void SetColumn( int col
, wxListItem
&item
);
349 void SetColumnWidth( int col
, int width
);
350 void GetColumn( int col
, wxListItem
&item
);
351 int GetColumnWidth( int vol
);
352 int GetColumnCount();
353 int GetCountPerPage();
354 void SetItem( wxListItem
&item
);
355 void GetItem( wxListItem
&item
);
356 void SetItemState( long item
, long state
, long stateMask
);
357 int GetItemState( long item
, long stateMask
);
359 void GetItemRect( long index
, wxRect
&rect
);
360 bool GetItemPosition( long item
, wxPoint
& pos
);
361 int GetSelectedItemCount();
362 void SetMode( long mode
);
363 long GetMode() const;
364 void CalculatePositions();
365 void RealizeChanges();
366 long GetNextItem( long item
, int geometry
, int state
);
367 void DeleteItem( long index
);
368 void DeleteAllItems();
369 void DeleteColumn( int col
);
370 void DeleteEverything();
371 void EnsureVisible( long index
);
372 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
373 long FindItem( long start
, long data
);
374 long HitTest( int x
, int y
, int &flags
);
375 void InsertItem( wxListItem
&item
);
376 // void AddItem( wxListItem &item );
377 void InsertColumn( long col
, wxListItem
&item
);
378 // void AddColumn( wxListItem &item );
379 void SortItems( wxListCtrlCompare fn
, long data
);
382 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
383 DECLARE_EVENT_TABLE()
386 // ============================================================================
388 // ============================================================================
390 //-----------------------------------------------------------------------------
392 //-----------------------------------------------------------------------------
394 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
396 wxListItemData::wxListItemData()
407 wxListItemData::wxListItemData( const wxListItem
&info
)
416 void wxListItemData::SetItem( const wxListItem
&info
)
418 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
419 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
420 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
422 if ( info
.HasAttributes() )
425 *m_attr
= *info
.GetAttributes();
427 m_attr
= new wxListItemAttr(*info
.GetAttributes());
432 m_width
= info
.m_width
;
436 void wxListItemData::SetText( const wxString
&s
)
441 void wxListItemData::SetImage( int image
)
446 void wxListItemData::SetData( long data
)
451 void wxListItemData::SetPosition( int x
, int y
)
457 void wxListItemData::SetSize( int width
, int height
)
459 if (width
!= -1) m_width
= width
;
460 if (height
!= -1) m_height
= height
;
463 bool wxListItemData::HasImage() const
465 return (m_image
>= 0);
468 bool wxListItemData::HasText() const
470 return (!m_text
.IsNull());
473 bool wxListItemData::IsHit( int x
, int y
) const
475 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
478 void wxListItemData::GetText( wxString
&s
)
483 int wxListItemData::GetX() const
488 int wxListItemData::GetY() const
493 int wxListItemData::GetWidth() const
498 int wxListItemData::GetHeight() const
503 int wxListItemData::GetImage() const
508 void wxListItemData::GetItem( wxListItem
&info
) const
510 info
.m_text
= m_text
;
511 info
.m_image
= m_image
;
512 info
.m_data
= m_data
;
516 if ( m_attr
->HasTextColour() )
517 info
.SetTextColour(m_attr
->GetTextColour());
518 if ( m_attr
->HasBackgroundColour() )
519 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
520 if ( m_attr
->HasFont() )
521 info
.SetFont(m_attr
->GetFont());
525 //-----------------------------------------------------------------------------
527 //-----------------------------------------------------------------------------
529 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
531 wxListHeaderData::wxListHeaderData()
542 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
550 void wxListHeaderData::SetItem( const wxListItem
&item
)
552 m_mask
= item
.m_mask
;
553 m_text
= item
.m_text
;
554 m_image
= item
.m_image
;
555 m_format
= item
.m_format
;
556 m_width
= item
.m_width
;
557 if (m_width
< 0) m_width
= 80;
558 if (m_width
< 6) m_width
= 6;
561 void wxListHeaderData::SetPosition( int x
, int y
)
567 void wxListHeaderData::SetHeight( int h
)
572 void wxListHeaderData::SetWidth( int w
)
575 if (m_width
< 0) m_width
= 80;
576 if (m_width
< 6) m_width
= 6;
579 void wxListHeaderData::SetFormat( int format
)
584 bool wxListHeaderData::HasImage() const
586 return (m_image
!= 0);
589 bool wxListHeaderData::HasText() const
591 return (m_text
.Length() > 0);
594 bool wxListHeaderData::IsHit( int x
, int y
) const
596 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
599 void wxListHeaderData::GetItem( wxListItem
&item
)
601 item
.m_mask
= m_mask
;
602 item
.m_text
= m_text
;
603 item
.m_image
= m_image
;
604 item
.m_format
= m_format
;
605 item
.m_width
= m_width
;
608 void wxListHeaderData::GetText( wxString
&s
)
613 int wxListHeaderData::GetImage() const
618 int wxListHeaderData::GetWidth() const
623 int wxListHeaderData::GetFormat() const
628 //-----------------------------------------------------------------------------
630 //-----------------------------------------------------------------------------
632 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
634 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
639 m_hilightBrush
= hilightBrush
;
640 m_items
.DeleteContents( TRUE
);
644 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
651 m_bound_all
.width
= m_spacing
;
652 wxNode
*node
= m_items
.First();
655 wxListItemData
*item
= (wxListItemData
*)node
->Data();
656 wxString s
= item
->GetText();
657 if (s
.IsEmpty()) s
= wxT("H");
659 dc
->GetTextExtent( s
, &lw
, &lh
);
660 if (lh
< 15) lh
= 15;
664 m_bound_all
.height
= m_spacing
+lh
;
665 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
666 m_bound_label
.width
= lw
;
667 m_bound_label
.height
= lh
;
669 if (item
->HasImage())
673 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
674 m_bound_icon
.width
= w
+ 8;
675 m_bound_icon
.height
= h
+ 8;
677 if ( m_bound_icon
.width
> m_bound_all
.width
)
678 m_bound_all
.width
= m_bound_icon
.width
;
679 if ( h
+ lh
> m_bound_all
.height
- 4 )
680 m_bound_all
.height
= h
+ lh
+ 4;
683 if (!item
->HasText())
685 m_bound_hilight
.width
= m_bound_icon
.width
;
686 m_bound_hilight
.height
= m_bound_icon
.height
;
690 m_bound_hilight
.width
= m_bound_label
.width
;
691 m_bound_hilight
.height
= m_bound_label
.height
;
698 wxNode
*node
= m_items
.First();
701 wxListItemData
*item
= (wxListItemData
*)node
->Data();
703 wxString s
= item
->GetText();
704 if (s
.IsEmpty()) s
= wxT("H");
706 dc
->GetTextExtent( s
, &lw
, &lh
);
707 if (lh
< 15) lh
= 15;
710 m_bound_label
.width
= lw
;
711 m_bound_label
.height
= lh
;
713 m_bound_all
.width
= lw
;
714 m_bound_all
.height
= lh
;
716 if (item
->HasImage())
720 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
721 m_bound_icon
.width
= w
;
722 m_bound_icon
.height
= h
;
724 m_bound_all
.width
+= 4 + w
;
725 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
728 m_bound_hilight
.width
= m_bound_all
.width
;
729 m_bound_hilight
.height
= m_bound_all
.height
;
735 m_bound_all
.width
= 0;
736 m_bound_all
.height
= 0;
737 wxNode
*node
= m_items
.First();
740 wxListItemData
*item
= (wxListItemData
*)node
->Data();
741 if (item
->HasImage())
745 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
746 m_bound_icon
.width
= w
;
747 m_bound_icon
.height
= h
;
751 m_bound_icon
.width
= 0;
752 m_bound_icon
.height
= 0;
757 wxListItemData
*item
= (wxListItemData
*)node
->Data();
758 wxString s
= item
->GetText();
759 if (s
.IsEmpty()) s
= wxT("H");
761 dc
->GetTextExtent( s
, &lw
, &lh
);
762 if (lh
< 15) lh
= 15;
766 item
->SetSize( item
->GetWidth(), lh
);
767 m_bound_all
.width
+= lw
;
768 m_bound_all
.height
= lh
;
771 m_bound_label
.width
= m_bound_all
.width
;
772 m_bound_label
.height
= m_bound_all
.height
;
778 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
779 int x
, int y
, int window_width
)
787 wxNode
*node
= m_items
.First();
790 wxListItemData
*item
= (wxListItemData
*)node
->Data();
791 if (item
->HasImage())
793 m_bound_icon
.x
= m_bound_all
.x
+ 4
794 + (m_spacing
- m_bound_icon
.width
)/2;
795 m_bound_icon
.y
= m_bound_all
.y
+ 4;
799 if (m_bound_all
.width
> m_spacing
)
800 m_bound_label
.x
= m_bound_all
.x
+ 2;
802 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
803 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
804 m_bound_hilight
.x
= m_bound_label
.x
- 2;
805 m_bound_hilight
.y
= m_bound_label
.y
- 2;
809 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
810 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
817 m_bound_hilight
.x
= m_bound_all
.x
;
818 m_bound_hilight
.y
= m_bound_all
.y
;
819 m_bound_label
.y
= m_bound_all
.y
+ 2;
820 wxNode
*node
= m_items
.First();
823 wxListItemData
*item
= (wxListItemData
*)node
->Data();
824 if (item
->HasImage())
826 m_bound_icon
.x
= m_bound_all
.x
+ 2;
827 m_bound_icon
.y
= m_bound_all
.y
+ 2;
828 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
832 m_bound_label
.x
= m_bound_all
.x
+ 2;
840 m_bound_all
.width
= window_width
;
841 AssignRect( m_bound_hilight
, m_bound_all
);
842 m_bound_label
.x
= m_bound_all
.x
+ 2;
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
+= 4 + m_bound_icon
.width
;
860 void wxListLineData::SetColumnPosition( int index
, int x
)
862 wxNode
*node
= m_items
.Nth( (size_t)index
);
865 wxListItemData
*item
= (wxListItemData
*)node
->Data();
866 item
->SetPosition( x
, m_bound_all
.y
+1 );
870 void wxListLineData::GetSize( int &width
, int &height
)
872 width
= m_bound_all
.width
;
873 height
= m_bound_all
.height
;
876 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
880 width
= m_bound_all
.width
;
881 height
= m_bound_all
.height
;
884 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
888 width
= m_bound_label
.width
;
889 height
= m_bound_label
.height
;
892 void wxListLineData::GetRect( wxRect
&rect
)
894 AssignRect( rect
, m_bound_all
);
897 long wxListLineData::IsHit( int x
, int y
)
899 wxNode
*node
= m_items
.First();
902 wxListItemData
*item
= (wxListItemData
*)node
->Data();
903 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
904 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
905 // if (!(item->HasImage() || item->HasText())) return 0;
907 // if there is no icon or text = empty
908 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
912 void wxListLineData::InitItems( int num
)
914 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
917 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
919 wxNode
*node
= m_items
.Nth( index
);
922 wxListItemData
*item
= (wxListItemData
*)node
->Data();
923 item
->SetItem( info
);
927 void wxListLineData::GetItem( int index
, wxListItem
&info
)
930 wxNode
*node
= m_items
.Nth( i
);
933 wxListItemData
*item
= (wxListItemData
*)node
->Data();
934 item
->GetItem( info
);
938 void wxListLineData::GetText( int index
, wxString
&s
)
941 wxNode
*node
= m_items
.Nth( i
);
945 wxListItemData
*item
= (wxListItemData
*)node
->Data();
950 void wxListLineData::SetText( int index
, const wxString s
)
953 wxNode
*node
= m_items
.Nth( i
);
956 wxListItemData
*item
= (wxListItemData
*)node
->Data();
961 int wxListLineData::GetImage( int index
)
964 wxNode
*node
= m_items
.Nth( i
);
967 wxListItemData
*item
= (wxListItemData
*)node
->Data();
968 return item
->GetImage();
973 void wxListLineData::SetAttributes(wxDC
*dc
,
974 const wxListItemAttr
*attr
,
975 const wxColour
& colText
,
979 // don't use foregroud colour for drawing highlighted items - this might
980 // make them completely invisible (and there is no way to do bit
981 // arithmetics on wxColour, unfortunately)
982 if ( !hilight
&& attr
&& attr
->HasTextColour() )
984 dc
->SetTextForeground(attr
->GetTextColour());
988 dc
->SetTextForeground(colText
);
991 if ( attr
&& attr
->HasFont() )
993 dc
->SetFont(attr
->GetFont());
1001 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1005 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1006 wxCoord dev_w
= m_bound_all
.width
;
1007 wxCoord dev_h
= m_bound_all
.height
;
1009 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1012 wxWindow
*listctrl
= m_owner
->GetParent();
1014 // default foreground colour
1018 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1022 colText
= listctrl
->GetForegroundColour();
1026 wxFont font
= listctrl
->GetFont();
1028 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1029 // using SetAttributes() inside the loop), it will be trivial to
1030 // customize the subitems (in report mode) too.
1031 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1032 wxListItemAttr
*attr
= item
->GetAttributes();
1033 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1035 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1036 if ( paintBG
|| hasBgCol
)
1040 dc
->SetBrush( * m_hilightBrush
);
1045 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1047 dc
->SetBrush( * wxWHITE_BRUSH
);
1050 dc
->SetPen( * wxTRANSPARENT_PEN
);
1051 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1052 m_bound_hilight
.width
, m_bound_hilight
.height
);
1055 if (m_mode
== wxLC_REPORT
)
1057 wxNode
*node
= m_items
.First();
1060 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1061 int x
= item
->GetX();
1062 if (item
->HasImage())
1065 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1066 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1067 x
+= item
->GetX() + 5;
1069 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1070 if (item
->HasText())
1072 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1074 dc
->DestroyClippingRegion();
1075 node
= node
->Next();
1080 wxNode
*node
= m_items
.First();
1083 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1084 if (item
->HasImage())
1086 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1088 if (item
->HasText())
1090 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1096 void wxListLineData::Hilight( bool on
)
1098 if (on
== m_hilighted
) return;
1101 m_owner
->SelectLine( this );
1103 m_owner
->DeselectLine( this );
1106 void wxListLineData::ReverseHilight( void )
1108 m_hilighted
= !m_hilighted
;
1110 m_owner
->SelectLine( this );
1112 m_owner
->DeselectLine( this );
1115 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1119 dc
->SetPen( * wxBLACK_PEN
);
1120 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1121 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1122 m_bound_hilight
.width
, m_bound_hilight
.height
);
1126 void wxListLineData::Draw( wxDC
*dc
)
1128 DoDraw( dc
, m_hilighted
, m_hilighted
);
1131 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1133 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1134 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1137 bool wxListLineData::IsHilighted( void )
1142 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1147 dest
.height
= height
;
1150 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1154 dest
.width
= source
.width
;
1155 dest
.height
= source
.height
;
1158 //-----------------------------------------------------------------------------
1159 // wxListHeaderWindow
1160 //-----------------------------------------------------------------------------
1162 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1164 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1165 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1166 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1167 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1170 wxListHeaderWindow::wxListHeaderWindow( void )
1172 m_owner
= (wxListMainWindow
*) NULL
;
1173 m_currentCursor
= (wxCursor
*) NULL
;
1174 m_resizeCursor
= (wxCursor
*) NULL
;
1175 m_isDragging
= FALSE
;
1178 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1179 const wxPoint
&pos
, const wxSize
&size
,
1180 long style
, const wxString
&name
) :
1181 wxWindow( win
, id
, pos
, size
, style
, name
)
1184 // m_currentCursor = wxSTANDARD_CURSOR;
1185 m_currentCursor
= (wxCursor
*) NULL
;
1186 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1187 m_isDragging
= FALSE
;
1190 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1193 wxListHeaderWindow::~wxListHeaderWindow( void )
1195 delete m_resizeCursor
;
1198 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1201 GtkStateType state
= GTK_STATE_NORMAL
;
1202 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1204 x
= dc
->XLOG2DEV( x
);
1206 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1207 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1209 const int m_corner
= 1;
1211 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1213 dc
->SetPen( *wxBLACK_PEN
);
1214 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1215 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1217 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1220 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1221 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1223 dc
->SetPen( *wxWHITE_PEN
);
1224 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1225 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1226 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1227 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1231 // shift the DC origin to match the position of the main window horz
1232 // scrollbar: this allows us to always use logical coords
1233 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1235 #if wxUSE_GENERIC_LIST_EXTENSIONS
1237 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1240 m_owner
->GetViewStart( &x
, NULL
);
1242 // account for the horz scrollbar offset
1243 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1244 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1247 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1249 wxPaintDC
dc( this );
1255 dc
.SetFont( GetFont() );
1257 // width and height of the entire header window
1259 GetClientSize( &w
, &h
);
1260 #if wxUSE_GENERIC_LIST_EXTENSIONS
1261 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1262 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1264 dc
.SetBackgroundMode(wxTRANSPARENT
);
1266 // do *not* use the listctrl colour for headers - one day we will have a
1267 // function to set it separately
1268 //dc.SetTextForeground( *wxBLACK );
1269 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1271 int x
= 1; // left of the header rect
1272 const int y
= 1; // top
1273 int numColumns
= m_owner
->GetColumnCount();
1275 for (int i
= 0; i
< numColumns
; i
++)
1277 m_owner
->GetColumn( i
, item
);
1278 int wCol
= item
.m_width
;
1279 int cw
= wCol
- 2; // the width of the rect to draw
1281 int xEnd
= x
+ wCol
;
1283 // VZ: no, draw it normally - this is better now as we allow resizing
1284 // of the last column as well
1286 // let the last column occupy all available space
1287 if ( i
== numColumns
- 1 )
1291 dc
.SetPen( *wxWHITE_PEN
);
1293 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1294 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1295 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1296 dc
.DestroyClippingRegion();
1305 void wxListHeaderWindow::DrawCurrent()
1307 int x1
= m_currentX
;
1309 ClientToScreen( &x1
, &y1
);
1311 int x2
= m_currentX
-1;
1313 m_owner
->GetClientSize( NULL
, &y2
);
1314 m_owner
->ClientToScreen( &x2
, &y2
);
1317 dc
.SetLogicalFunction( wxINVERT
);
1318 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1319 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1323 dc
.DrawLine( x1
, y1
, x2
, y2
);
1325 dc
.SetLogicalFunction( wxCOPY
);
1327 dc
.SetPen( wxNullPen
);
1328 dc
.SetBrush( wxNullBrush
);
1331 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1333 // we want to work with logical coords
1334 #if wxUSE_GENERIC_LIST_EXTENSIONS
1336 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1337 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1338 int x
= event
.GetX();
1339 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1340 int y
= event
.GetY();
1344 // we don't draw the line beyond our window, but we allow dragging it
1347 GetClientSize( &w
, NULL
);
1348 #if wxUSE_GENERIC_LIST_EXTENSIONS
1349 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1350 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1353 // erase the line if it was drawn
1354 if ( m_currentX
< w
)
1357 if (event
.ButtonUp())
1360 m_isDragging
= FALSE
;
1362 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1369 m_currentX
= m_minX
+ 7;
1371 // draw in the new location
1372 if ( m_currentX
< w
)
1376 else // not dragging
1379 bool hit_border
= FALSE
;
1381 // end of the current column
1384 // find the column where this event occured
1385 int countCol
= m_owner
->GetColumnCount();
1386 for (int j
= 0; j
< countCol
; j
++)
1388 xpos
+= m_owner
->GetColumnWidth( j
);
1391 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1393 // near the column border
1400 // inside the column
1407 if (event
.LeftDown())
1411 m_isDragging
= TRUE
;
1418 wxWindow
*parent
= GetParent();
1419 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1420 le
.SetEventObject( parent
);
1421 le
.m_col
= m_column
;
1422 parent
->GetEventHandler()->ProcessEvent( le
);
1425 else if (event
.Moving())
1430 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1431 m_currentCursor
= m_resizeCursor
;
1435 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1436 m_currentCursor
= wxSTANDARD_CURSOR
;
1440 SetCursor(*m_currentCursor
);
1445 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1447 m_owner
->SetFocus();
1450 //-----------------------------------------------------------------------------
1451 // wxListRenameTimer (internal)
1452 //-----------------------------------------------------------------------------
1454 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1459 void wxListRenameTimer::Notify()
1461 m_owner
->OnRenameTimer();
1464 //-----------------------------------------------------------------------------
1465 // wxListTextCtrl (internal)
1466 //-----------------------------------------------------------------------------
1468 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1470 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1471 EVT_CHAR (wxListTextCtrl::OnChar
)
1472 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1475 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1476 const wxWindowID id
,
1479 wxListMainWindow
*owner
,
1480 const wxString
&value
,
1484 const wxValidator
& validator
,
1485 const wxString
&name
)
1486 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1491 (*m_accept
) = FALSE
;
1493 m_startValue
= value
;
1496 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1498 if (event
.m_keyCode
== WXK_RETURN
)
1501 (*m_res
) = GetValue();
1503 if (!wxPendingDelete
.Member(this))
1504 wxPendingDelete
.Append(this);
1506 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1507 m_owner
->OnRenameAccept();
1511 if (event
.m_keyCode
== WXK_ESCAPE
)
1513 (*m_accept
) = FALSE
;
1516 if (!wxPendingDelete
.Member(this))
1517 wxPendingDelete
.Append(this);
1525 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1527 if (!wxPendingDelete
.Member(this))
1528 wxPendingDelete
.Append(this);
1530 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1531 m_owner
->OnRenameAccept();
1534 //-----------------------------------------------------------------------------
1536 //-----------------------------------------------------------------------------
1538 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1540 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1541 EVT_PAINT (wxListMainWindow::OnPaint
)
1542 EVT_SIZE (wxListMainWindow::OnSize
)
1543 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1544 EVT_CHAR (wxListMainWindow::OnChar
)
1545 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1546 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1547 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1548 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1551 wxListMainWindow::wxListMainWindow()
1554 m_columns
.DeleteContents( TRUE
);
1555 m_current
= (wxListLineData
*) NULL
;
1557 m_hilightBrush
= (wxBrush
*) NULL
;
1561 m_small_image_list
= (wxImageList
*) NULL
;
1562 m_normal_image_list
= (wxImageList
*) NULL
;
1563 m_small_spacing
= 30;
1564 m_normal_spacing
= 40;
1567 m_lastOnSame
= FALSE
;
1568 m_renameTimer
= new wxListRenameTimer( this );
1569 m_isCreated
= FALSE
;
1573 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1576 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1577 const wxPoint
&pos
, const wxSize
&size
,
1578 long style
, const wxString
&name
) :
1579 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1582 m_columns
.DeleteContents( TRUE
);
1583 m_current
= (wxListLineData
*) NULL
;
1586 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1587 m_small_image_list
= (wxImageList
*) NULL
;
1588 m_normal_image_list
= (wxImageList
*) NULL
;
1589 m_small_spacing
= 30;
1590 m_normal_spacing
= 40;
1593 m_isCreated
= FALSE
;
1597 if (m_mode
& wxLC_REPORT
)
1599 #if wxUSE_GENERIC_LIST_EXTENSIONS
1611 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1614 m_lastOnSame
= FALSE
;
1615 m_renameTimer
= new wxListRenameTimer( this );
1616 m_renameAccept
= FALSE
;
1618 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1621 wxListMainWindow::~wxListMainWindow()
1625 if (m_hilightBrush
) delete m_hilightBrush
;
1627 delete m_renameTimer
;
1630 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1632 if (m_dirty
) return;
1640 line
->GetExtent( x
, y
, w
, h
);
1641 CalcScrolledPosition( x
, y
, &x
, &y
);
1642 wxRect
rect( x
, y
, w
, h
);
1643 Refresh( TRUE
, &rect
);
1646 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1648 // Note: a wxPaintDC must be constructed even if no drawing is
1649 // done (a Windows requirement).
1650 wxPaintDC
dc( this );
1653 if (m_dirty
) return;
1655 if (m_lines
.GetCount() == 0) return;
1659 dc
.SetFont( GetFont() );
1661 if (m_mode
& wxLC_REPORT
)
1663 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1665 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1667 wxSize clientSize
= GetClientSize();
1669 int lineSpacing
= 0;
1670 wxListLineData
*line
= &m_lines
[0];
1672 line
->GetSize( dummy
, lineSpacing
);
1675 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1677 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1678 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1680 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1682 m_lines
[i
].Draw( &dc
);
1683 // Draw horizontal rule if required
1684 if (GetWindowStyle() & wxLC_HRULES
)
1685 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1688 // Draw last horizontal rule
1689 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1690 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1692 // Draw vertical rules if required
1693 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1696 wxRect firstItemRect
;
1697 wxRect lastItemRect
;
1698 GetItemRect(0, firstItemRect
);
1699 GetItemRect(GetItemCount() - 1, lastItemRect
);
1700 int x
= firstItemRect
.GetX();
1701 for (col
= 0; col
< GetColumnCount(); col
++)
1703 int colWidth
= GetColumnWidth(col
);
1705 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1711 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1712 m_lines
[i
].Draw( &dc
);
1715 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1720 void wxListMainWindow::HilightAll( bool on
)
1722 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1724 wxListLineData
*line
= &m_lines
[i
];
1725 if (line
->IsHilighted() != on
)
1727 line
->Hilight( on
);
1728 RefreshLine( line
);
1733 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1735 wxListEvent
le( command
, GetParent()->GetId() );
1736 le
.SetEventObject( GetParent() );
1737 le
.m_itemIndex
= GetIndexOfLine( line
);
1738 line
->GetItem( 0, le
.m_item
);
1739 GetParent()->GetEventHandler()->ProcessEvent( le
);
1740 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1743 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1745 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1748 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1750 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1753 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1755 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1758 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1760 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1763 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1765 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1770 void wxListMainWindow::EditLabel( long item
)
1772 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1773 wxT("wrong index in wxListCtrl::Edit()") );
1775 m_currentEdit
= &m_lines
[(size_t)item
];
1777 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1778 le
.SetEventObject( GetParent() );
1779 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1780 m_currentEdit
->GetItem( 0, le
.m_item
);
1781 GetParent()->GetEventHandler()->ProcessEvent( le
);
1783 if (!le
.IsAllowed())
1786 // We have to call this here because the label in
1787 // question might just have been added and no screen
1788 // update taken place.
1789 if (m_dirty
) wxYield();
1792 m_currentEdit
->GetText( 0, s
);
1797 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1799 wxClientDC
dc(this);
1801 x
= dc
.LogicalToDeviceX( x
);
1802 y
= dc
.LogicalToDeviceY( y
);
1804 wxListTextCtrl
*text
= new wxListTextCtrl(
1805 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1809 void wxListMainWindow::OnRenameTimer()
1811 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1813 Edit( m_lines
.Index( *m_current
) );
1816 void wxListMainWindow::OnRenameAccept()
1818 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1819 le
.SetEventObject( GetParent() );
1820 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1821 m_currentEdit
->GetItem( 0, le
.m_item
);
1822 le
.m_item
.m_text
= m_renameRes
;
1823 GetParent()->GetEventHandler()->ProcessEvent( le
);
1825 if (!le
.IsAllowed()) return;
1828 info
.m_mask
= wxLIST_MASK_TEXT
;
1829 info
.m_itemId
= le
.m_itemIndex
;
1830 info
.m_text
= m_renameRes
;
1831 info
.SetTextColour(le
.m_item
.GetTextColour());
1835 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1837 event
.SetEventObject( GetParent() );
1838 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1840 if (!m_current
) return;
1841 if (m_dirty
) return;
1842 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1844 int x
= event
.GetX();
1845 int y
= event
.GetY();
1846 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1848 /* Did we actually hit an item ? */
1850 wxListLineData
*line
= (wxListLineData
*) NULL
;
1851 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1854 hitResult
= line
->IsHit( x
, y
);
1855 if (hitResult
) break;
1856 line
= (wxListLineData
*) NULL
;
1859 if (event
.Dragging())
1861 if (m_dragCount
== 0)
1862 m_dragStart
= wxPoint(x
,y
);
1866 if (m_dragCount
!= 3) return;
1868 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1869 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1871 wxListEvent
le( command
, GetParent()->GetId() );
1872 le
.SetEventObject( GetParent() );
1873 le
.m_pointDrag
= m_dragStart
;
1874 GetParent()->GetEventHandler()->ProcessEvent( le
);
1885 bool forceClick
= FALSE
;
1886 if (event
.ButtonDClick())
1888 m_renameTimer
->Stop();
1889 m_lastOnSame
= FALSE
;
1891 if ( line
== m_lineBeforeLastClicked
)
1895 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1901 // the first click was on another item, so don't interpret this as
1902 // a double click, but as a simple click instead
1907 if (event
.LeftUp() && m_lastOnSame
)
1910 if ((line
== m_current
) &&
1911 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1912 (m_mode
& wxLC_EDIT_LABELS
) )
1914 m_renameTimer
->Start( 100, TRUE
);
1916 m_lastOnSame
= FALSE
;
1920 if (event
.RightDown())
1922 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1926 if (event
.MiddleDown())
1928 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1932 if ( event
.LeftDown() || forceClick
)
1934 m_lineBeforeLastClicked
= m_lineLastClicked
;
1935 m_lineLastClicked
= line
;
1938 wxListLineData
*oldCurrent
= m_current
;
1939 if (m_mode
& wxLC_SINGLE_SEL
)
1942 HilightAll( FALSE
);
1943 m_current
->ReverseHilight();
1944 RefreshLine( m_current
);
1948 if (event
.ControlDown())
1951 m_current
->ReverseHilight();
1952 RefreshLine( m_current
);
1954 else if (event
.ShiftDown())
1960 int numOfCurrent
= -1;
1961 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1963 wxListLineData
*test_line
= &m_lines
[j
];
1965 if (test_line
== oldCurrent
) break;
1970 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1972 wxListLineData
*test_line
= &m_lines
[j
];
1974 if (test_line
== line
) break;
1977 if (numOfLine
< numOfCurrent
)
1980 numOfLine
= numOfCurrent
;
1984 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1986 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
1987 test_line
->Hilight(TRUE
);
1988 RefreshLine( test_line
);
1994 HilightAll( FALSE
);
1995 m_current
->ReverseHilight();
1996 RefreshLine( m_current
);
1999 if (m_current
!= oldCurrent
)
2001 RefreshLine( oldCurrent
);
2002 UnfocusLine( oldCurrent
);
2003 FocusLine( m_current
);
2006 // forceClick is only set if the previous click was on another item
2007 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2013 void wxListMainWindow::MoveToFocus()
2015 if (!m_current
) return;
2021 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2025 GetClientSize( &client_w
, &client_h
);
2027 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2028 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2030 if (m_mode
& wxLC_REPORT
)
2032 if (item_y
-5 < view_y
)
2033 Scroll( -1, (item_y
-5)/m_yScroll
);
2034 if (item_y
+item_h
+5 > view_y
+client_h
)
2035 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2039 if (item_x
-view_x
< 5)
2040 Scroll( (item_x
-5)/m_xScroll
, -1 );
2041 if (item_x
+item_w
-5 > view_x
+client_w
)
2042 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2046 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2048 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2049 wxListLineData
*oldCurrent
= m_current
;
2050 m_current
= newCurrent
;
2051 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2052 RefreshLine( m_current
);
2053 RefreshLine( oldCurrent
);
2054 FocusLine( m_current
);
2055 UnfocusLine( oldCurrent
);
2059 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2061 wxWindow
*parent
= GetParent();
2063 /* we propagate the key event up */
2064 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2065 ke
.m_shiftDown
= event
.m_shiftDown
;
2066 ke
.m_controlDown
= event
.m_controlDown
;
2067 ke
.m_altDown
= event
.m_altDown
;
2068 ke
.m_metaDown
= event
.m_metaDown
;
2069 ke
.m_keyCode
= event
.m_keyCode
;
2072 ke
.SetEventObject( parent
);
2073 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2078 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2080 wxWindow
*parent
= GetParent();
2082 /* we send a list_key event up */
2085 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2086 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2087 m_current
->GetItem( 0, le
.m_item
);
2088 le
.m_code
= (int)event
.KeyCode();
2089 le
.SetEventObject( parent
);
2090 parent
->GetEventHandler()->ProcessEvent( le
);
2093 /* we propagate the char event up */
2094 wxKeyEvent
ke( wxEVT_CHAR
);
2095 ke
.m_shiftDown
= event
.m_shiftDown
;
2096 ke
.m_controlDown
= event
.m_controlDown
;
2097 ke
.m_altDown
= event
.m_altDown
;
2098 ke
.m_metaDown
= event
.m_metaDown
;
2099 ke
.m_keyCode
= event
.m_keyCode
;
2102 ke
.SetEventObject( parent
);
2103 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2105 if (event
.KeyCode() == WXK_TAB
)
2107 wxNavigationKeyEvent nevent
;
2108 nevent
.SetWindowChange( event
.ControlDown() );
2109 nevent
.SetDirection( !event
.ShiftDown() );
2110 nevent
.SetEventObject( GetParent()->GetParent() );
2111 nevent
.SetCurrentFocus( m_parent
);
2112 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2115 /* no item -> nothing to do */
2122 switch (event
.KeyCode())
2126 int index
= m_lines
.Index(*m_current
);
2127 if (index
!= wxNOT_FOUND
&& index
> 0)
2128 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2133 int index
= m_lines
.Index(*m_current
);
2134 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2135 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2140 if (!m_lines
.IsEmpty())
2141 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2146 if (!m_lines
.IsEmpty())
2147 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2153 int index
= m_lines
.Index(*m_current
);
2154 if (m_mode
& wxLC_REPORT
)
2156 steps
= m_visibleLines
-1;
2160 steps
= index
% m_visibleLines
;
2162 if (index
!= wxNOT_FOUND
)
2165 if (index
< 0) index
= 0;
2166 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2173 int index
= m_lines
.Index(*m_current
);
2174 if (m_mode
& wxLC_REPORT
)
2176 steps
= m_visibleLines
-1;
2180 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2183 if (index
!= wxNOT_FOUND
)
2186 if ((size_t)index
>= m_lines
.GetCount())
2187 index
= m_lines
.GetCount()-1;
2188 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2194 if (!(m_mode
& wxLC_REPORT
))
2196 int index
= m_lines
.Index(*m_current
);
2197 if (index
!= wxNOT_FOUND
)
2199 index
-= m_visibleLines
;
2200 if (index
< 0) index
= 0;
2201 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2208 if (!(m_mode
& wxLC_REPORT
))
2210 int index
= m_lines
.Index(*m_current
);
2211 if (index
!= wxNOT_FOUND
)
2213 index
+= m_visibleLines
;
2214 if ((size_t)index
>= m_lines
.GetCount())
2215 index
= m_lines
.GetCount()-1;
2216 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2223 if (m_mode
& wxLC_SINGLE_SEL
)
2225 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2226 le
.SetEventObject( GetParent() );
2227 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2228 m_current
->GetItem( 0, le
.m_item
);
2229 GetParent()->GetEventHandler()->ProcessEvent( le
);
2233 m_current
->ReverseHilight();
2234 RefreshLine( m_current
);
2240 if (!(m_mode
& wxLC_SINGLE_SEL
))
2242 wxListLineData
*oldCurrent
= m_current
;
2243 m_current
->ReverseHilight();
2244 int index
= m_lines
.Index( *m_current
) + 1;
2245 if ( (size_t)index
< m_lines
.GetCount() )
2246 m_current
= &m_lines
[index
];
2247 RefreshLine( oldCurrent
);
2248 RefreshLine( m_current
);
2249 UnfocusLine( oldCurrent
);
2250 FocusLine( m_current
);
2258 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2259 le
.SetEventObject( GetParent() );
2260 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2261 m_current
->GetItem( 0, le
.m_item
);
2262 GetParent()->GetEventHandler()->ProcessEvent( le
);
2275 extern wxWindow
*g_focusWindow
;
2278 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2281 RefreshLine( m_current
);
2283 if (!GetParent()) return;
2286 g_focusWindow
= GetParent();
2289 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2290 event
.SetEventObject( GetParent() );
2291 GetParent()->GetEventHandler()->ProcessEvent( event
);
2294 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2297 RefreshLine( m_current
);
2300 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2303 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2309 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2311 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2313 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2316 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2318 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2320 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2322 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2324 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2326 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2331 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2333 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2335 m_normal_image_list
->GetSize( index
, width
, height
);
2338 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2340 m_small_image_list
->GetSize( index
, width
, height
);
2343 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2345 m_small_image_list
->GetSize( index
, width
, height
);
2348 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2350 m_small_image_list
->GetSize( index
, width
, height
);
2357 int wxListMainWindow::GetTextLength( wxString
&s
)
2359 wxClientDC
dc( this );
2362 dc
.GetTextExtent( s
, &lw
, &lh
);
2366 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2368 int i
= m_lines
.Index(*line
);
2369 if (i
== wxNOT_FOUND
) return -1;
2373 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2377 // calc the spacing from the icon size
2380 if ((imageList
) && (imageList
->GetImageCount()) )
2382 imageList
->GetSize(0, width
, height
);
2385 if (which
== wxIMAGE_LIST_NORMAL
)
2387 m_normal_image_list
= imageList
;
2388 m_normal_spacing
= width
+ 8;
2391 if (which
== wxIMAGE_LIST_SMALL
)
2393 m_small_image_list
= imageList
;
2394 m_small_spacing
= width
+ 14;
2398 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2403 m_small_spacing
= spacing
;
2407 m_normal_spacing
= spacing
;
2411 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2413 return isSmall
? m_small_spacing
: m_normal_spacing
;
2416 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2419 wxNode
*node
= m_columns
.Nth( col
);
2422 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2423 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2424 column
->SetItem( item
);
2427 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2429 headerWin
->m_dirty
= TRUE
;
2432 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2434 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2435 _T("SetColumnWidth() can only be called in report mode.") );
2439 wxNode
*node
= (wxNode
*) NULL
;
2441 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2443 // TODO do use the header
2446 else if (width
== wxLIST_AUTOSIZE
)
2448 wxClientDC
dc(this);
2449 dc
.SetFont( GetFont() );
2452 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2454 wxListLineData
*line
= &m_lines
[i
];
2455 wxNode
*n
= line
->m_items
.Nth( col
);
2458 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2459 int current
= 0, ix
= 0, iy
= 0;
2460 wxCoord lx
= 0, ly
= 0;
2461 if (item
->HasImage())
2463 GetImageSize( item
->GetImage(), ix
, iy
);
2466 if (item
->HasText())
2469 item
->GetText( str
);
2470 dc
.GetTextExtent( str
, &lx
, &ly
);
2473 if (current
> max
) max
= current
;
2479 node
= m_columns
.Nth( col
);
2482 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2483 column
->SetWidth( width
);
2486 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2488 wxListLineData
*line
= &m_lines
[i
];
2489 wxNode
*n
= line
->m_items
.Nth( col
);
2492 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2493 item
->SetSize( width
, -1 );
2497 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2499 headerWin
->m_dirty
= TRUE
;
2502 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2504 wxNode
*node
= m_columns
.Nth( col
);
2507 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2508 column
->GetItem( item
);
2520 int wxListMainWindow::GetColumnWidth( int col
)
2522 wxNode
*node
= m_columns
.Nth( col
);
2525 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2526 return column
->GetWidth();
2534 int wxListMainWindow::GetColumnCount()
2536 return m_columns
.Number();
2539 int wxListMainWindow::GetCountPerPage()
2541 return m_visibleLines
;
2544 void wxListMainWindow::SetItem( wxListItem
&item
)
2547 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2549 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2550 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2551 line
->SetItem( item
.m_col
, item
);
2555 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2557 // m_dirty = TRUE; no recalcs needed
2559 wxListLineData
*oldCurrent
= m_current
;
2561 if (stateMask
& wxLIST_STATE_FOCUSED
)
2563 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2565 wxListLineData
*line
= &m_lines
[(size_t)item
];
2566 UnfocusLine( m_current
);
2568 FocusLine( m_current
);
2569 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2570 RefreshLine( m_current
);
2571 if (oldCurrent
) RefreshLine( oldCurrent
);
2575 if (stateMask
& wxLIST_STATE_SELECTED
)
2577 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2578 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2580 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2582 wxListLineData
*line
= &m_lines
[(size_t)item
];
2583 if (m_mode
& wxLC_SINGLE_SEL
)
2585 UnfocusLine( m_current
);
2587 FocusLine( m_current
);
2588 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2589 RefreshLine( m_current
);
2590 if (oldCurrent
) RefreshLine( oldCurrent
);
2592 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2593 if (on
!= line
->IsHilighted())
2595 line
->Hilight( on
);
2596 RefreshLine( line
);
2602 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2604 int ret
= wxLIST_STATE_DONTCARE
;
2605 if (stateMask
& wxLIST_STATE_FOCUSED
)
2607 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2609 wxListLineData
*line
= &m_lines
[(size_t)item
];
2610 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2613 if (stateMask
& wxLIST_STATE_SELECTED
)
2615 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2617 wxListLineData
*line
= &m_lines
[(size_t)item
];
2618 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2624 void wxListMainWindow::GetItem( wxListItem
&item
)
2626 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2628 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2629 line
->GetItem( item
.m_col
, item
);
2640 int wxListMainWindow::GetItemCount()
2642 return m_lines
.GetCount();
2645 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2647 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2649 m_lines
[(size_t)index
].GetRect( rect
);
2660 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2662 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2665 m_lines
[(size_t)item
].GetRect( rect
);
2677 int wxListMainWindow::GetSelectedItemCount()
2680 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2682 if (m_lines
[i
].IsHilighted()) ret
++;
2687 void wxListMainWindow::SetMode( long mode
)
2694 if (m_mode
& wxLC_REPORT
)
2696 #if wxUSE_GENERIC_LIST_EXTENSIONS
2710 long wxListMainWindow::GetMode() const
2715 void wxListMainWindow::CalculatePositions()
2717 if (m_lines
.IsEmpty()) return;
2719 wxClientDC
dc( this );
2720 dc
.SetFont( GetFont() );
2722 int iconSpacing
= 0;
2723 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2724 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2726 // we take the first line (which also can be an icon or
2727 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2728 // measure the size of the line
2732 int lineSpacing
= 0;
2734 wxListLineData
*line
= &m_lines
[0];
2735 line
->CalculateSize( &dc
, iconSpacing
);
2737 line
->GetSize( dummy
, lineSpacing
);
2740 int clientWidth
= 0;
2741 int clientHeight
= 0;
2743 if (m_mode
& wxLC_REPORT
)
2747 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2748 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2749 #if wxUSE_GENERIC_LIST_EXTENSIONS
2750 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2752 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2754 GetClientSize( &clientWidth
, &clientHeight
);
2756 int entireWidth
= 0 ;
2757 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2759 wxListLineData
*line
= &m_lines
[j
];
2760 line
->CalculateSize( &dc
, iconSpacing
);
2761 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2763 for (int i
= 0; i
< GetColumnCount(); i
++)
2765 line
->SetColumnPosition( i
, col_x
);
2766 col_x
+= GetColumnWidth( i
);
2768 entireWidth
= wxMax( entireWidth
, col_x
) ;
2769 #if wxUSE_GENERIC_LIST_EXTENSIONS
2770 line
->SetPosition( &dc
, x
, y
, col_x
);
2772 y
+= lineSpacing
; // one pixel blank line between items
2774 m_visibleLines
= clientHeight
/ lineSpacing
;
2775 #if wxUSE_GENERIC_LIST_EXTENSIONS
2776 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2781 // at first we try without any scrollbar. if the items don't
2782 // fit into the window, we recalculate after subtracting an
2783 // approximated 15 pt for the horizontal scrollbar
2785 GetSize( &clientWidth
, &clientHeight
);
2786 clientHeight
-= 4; // sunken frame
2788 int entireWidth
= 0;
2790 for (int tries
= 0; tries
< 2; tries
++)
2797 int m_currentVisibleLines
= 0;
2798 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2800 m_currentVisibleLines
++;
2801 wxListLineData
*line
= &m_lines
[i
];
2802 line
->CalculateSize( &dc
, iconSpacing
);
2803 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2804 line
->GetSize( lineWidth
, lineHeight
);
2805 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2807 if (m_currentVisibleLines
> m_visibleLines
)
2808 m_visibleLines
= m_currentVisibleLines
;
2809 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2811 m_currentVisibleLines
= 0;
2814 entireWidth
+= maxWidth
+6;
2817 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2818 if ((tries
== 0) && (entireWidth
> clientWidth
))
2820 clientHeight
-= 15; // scrollbar height
2822 m_currentVisibleLines
= 0;
2825 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2829 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2830 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2834 void wxListMainWindow::RealizeChanges()
2838 if (!m_lines
.IsEmpty())
2839 m_current
= &m_lines
[0];
2843 FocusLine( m_current
);
2844 // TODO: MSW doesn't automatically hilight the
2846 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2850 long wxListMainWindow::GetNextItem( long item
,
2851 int WXUNUSED(geometry
),
2855 max
= GetItemCount();
2856 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2857 _T("invalid listctrl index in GetNextItem()") );
2859 // notice that we start with the next item (or the first one if item == -1)
2860 // and this is intentional to allow writing a simple loop to iterate over
2861 // all selected items
2865 // this is not an error because the index was ok initially, just no
2870 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2872 wxListLineData
*line
= &m_lines
[i
];
2873 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2875 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2885 void wxListMainWindow::DeleteItem( long index
)
2888 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2890 wxListLineData
*line
= &m_lines
[(size_t)index
];
2891 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2893 m_lines
.RemoveAt( (size_t)index
);
2897 void wxListMainWindow::DeleteColumn( int col
)
2899 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2900 wxT("attempting to delete inexistent column in wxListView") );
2903 wxNode
*node
= m_columns
.Nth( col
);
2904 if (node
) m_columns
.DeleteNode( node
);
2907 void wxListMainWindow::DeleteAllItems()
2910 m_current
= (wxListLineData
*) NULL
;
2912 // to make the deletion of all items faster, we don't send the
2913 // notifications in this case: this is compatible with wxMSW and
2914 // documented in DeleteAllItems() description
2916 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2917 event
.SetEventObject( GetParent() );
2918 GetParent()->GetEventHandler()->ProcessEvent( event
);
2923 void wxListMainWindow::DeleteEverything()
2930 void wxListMainWindow::EnsureVisible( long index
)
2932 // We have to call this here because the label in
2933 // question might just have been added and no screen
2934 // update taken place.
2935 if (m_dirty
) wxYield();
2937 wxListLineData
*oldCurrent
= m_current
;
2938 m_current
= (wxListLineData
*) NULL
;
2939 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2940 m_current
= &m_lines
[(size_t)index
];
2941 if (m_current
) MoveToFocus();
2942 m_current
= oldCurrent
;
2945 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2949 if (pos
< 0) pos
= 0;
2950 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2952 wxListLineData
*line
= &m_lines
[i
];
2954 line
->GetText( 0, s
);
2955 if (s
== tmp
) return pos
;
2961 long wxListMainWindow::FindItem(long start
, long data
)
2964 if (pos
< 0) pos
= 0;
2965 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2967 wxListLineData
*line
= &m_lines
[i
];
2969 line
->GetItem( 0, item
);
2970 if (item
.m_data
== data
) return pos
;
2976 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2978 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2981 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2983 wxListLineData
*line
= &m_lines
[i
];
2984 long ret
= line
->IsHit( x
, y
);
2985 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
2995 void wxListMainWindow::InsertItem( wxListItem
&item
)
2999 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3000 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3001 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3002 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3004 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3006 if (m_mode
& wxLC_REPORT
)
3008 line
->InitItems( GetColumnCount() );
3009 item
.m_width
= GetColumnWidth( 0 )-3;
3013 line
->InitItems( 1 );
3016 line
->SetItem( 0, item
);
3017 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3019 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3023 m_lines
.Add( line
);
3024 item
.m_itemId
= m_lines
.GetCount()-1;
3028 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3031 if (m_mode
& wxLC_REPORT
)
3033 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3034 wxListHeaderData
*column
= new wxListHeaderData( item
);
3035 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3037 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3039 m_columns
.Insert( node
, column
);
3043 m_columns
.Append( column
);
3048 wxListCtrlCompare list_ctrl_compare_func_2
;
3049 long list_ctrl_compare_data
;
3051 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3053 wxListLineData
*line1
= *arg1
;
3054 wxListLineData
*line2
= *arg2
;
3056 line1
->GetItem( 0, item
);
3057 long data1
= item
.m_data
;
3058 line2
->GetItem( 0, item
);
3059 long data2
= item
.m_data
;
3060 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3063 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3065 list_ctrl_compare_func_2
= fn
;
3066 list_ctrl_compare_data
= data
;
3067 m_lines
.Sort( list_ctrl_compare_func_1
);
3071 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3073 wxScrolledWindow::OnScroll( event
) ;
3074 #if wxUSE_GENERIC_LIST_EXTENSIONS
3076 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3078 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3081 lc
->m_headerWin
->Refresh() ;
3083 lc
->m_headerWin
->MacUpdateImmediately() ;
3090 // -------------------------------------------------------------------------------------
3092 // -------------------------------------------------------------------------------------
3094 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3096 wxListItem::wxListItem()
3105 m_format
= wxLIST_FORMAT_CENTRE
;
3111 void wxListItem::Clear()
3120 m_format
= wxLIST_FORMAT_CENTRE
;
3122 m_text
= wxEmptyString
;
3124 if (m_attr
) delete m_attr
;
3128 void wxListItem::ClearAttributes()
3130 if (m_attr
) delete m_attr
;
3134 // -------------------------------------------------------------------------------------
3136 // -------------------------------------------------------------------------------------
3138 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3140 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3141 wxNotifyEvent( commandType
, id
)
3147 m_cancelled
= FALSE
;
3152 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3154 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3156 wxNotifyEvent::CopyObject(object_dest
);
3158 obj
->m_code
= m_code
;
3159 obj
->m_itemIndex
= m_itemIndex
;
3160 obj
->m_oldItemIndex
= m_oldItemIndex
;
3162 obj
->m_cancelled
= m_cancelled
;
3163 obj
->m_pointDrag
= m_pointDrag
;
3164 obj
->m_item
.m_mask
= m_item
.m_mask
;
3165 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3166 obj
->m_item
.m_col
= m_item
.m_col
;
3167 obj
->m_item
.m_state
= m_item
.m_state
;
3168 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3169 obj
->m_item
.m_text
= m_item
.m_text
;
3170 obj
->m_item
.m_image
= m_item
.m_image
;
3171 obj
->m_item
.m_data
= m_item
.m_data
;
3172 obj
->m_item
.m_format
= m_item
.m_format
;
3173 obj
->m_item
.m_width
= m_item
.m_width
;
3175 if ( m_item
.HasAttributes() )
3177 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3181 // -------------------------------------------------------------------------------------
3183 // -------------------------------------------------------------------------------------
3185 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3187 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3188 EVT_SIZE (wxListCtrl::OnSize
)
3189 EVT_IDLE (wxListCtrl::OnIdle
)
3192 wxListCtrl::wxListCtrl()
3194 m_imageListNormal
= (wxImageList
*) NULL
;
3195 m_imageListSmall
= (wxImageList
*) NULL
;
3196 m_imageListState
= (wxImageList
*) NULL
;
3197 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3198 m_mainWin
= (wxListMainWindow
*) NULL
;
3199 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3202 wxListCtrl::~wxListCtrl()
3204 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3205 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3206 if (m_ownsImageListState
) delete m_imageListState
;
3209 bool wxListCtrl::Create(wxWindow
*parent
,
3214 const wxValidator
&validator
,
3215 const wxString
&name
)
3217 m_imageListNormal
= (wxImageList
*) NULL
;
3218 m_imageListSmall
= (wxImageList
*) NULL
;
3219 m_imageListState
= (wxImageList
*) NULL
;
3220 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3221 m_mainWin
= (wxListMainWindow
*) NULL
;
3222 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3224 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3226 style
= style
| wxLC_LIST
;
3229 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3232 if (style
& wxSUNKEN_BORDER
)
3233 style
-= wxSUNKEN_BORDER
;
3235 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3237 if (HasFlag(wxLC_REPORT
))
3239 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3240 if (HasFlag(wxLC_NO_HEADER
))
3241 m_headerWin
->Show( FALSE
);
3245 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3251 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3253 /* handled in OnIdle */
3255 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3258 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3260 long flag
= GetWindowStyle();
3264 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3265 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3266 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3275 if (flag
& style
) flag
-= style
;
3278 SetWindowStyleFlag( flag
);
3281 void wxListCtrl::SetWindowStyleFlag( long flag
)
3285 m_mainWin
->DeleteEverything();
3289 GetClientSize( &width
, &height
);
3291 m_mainWin
->SetMode( flag
);
3293 if (flag
& wxLC_REPORT
)
3295 if (!HasFlag(wxLC_REPORT
))
3299 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3300 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3301 if (HasFlag(wxLC_NO_HEADER
))
3302 m_headerWin
->Show( FALSE
);
3306 if (flag
& wxLC_NO_HEADER
)
3307 m_headerWin
->Show( FALSE
);
3309 m_headerWin
->Show( TRUE
);
3315 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3317 m_headerWin
->Show( FALSE
);
3322 wxWindow::SetWindowStyleFlag( flag
);
3325 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3327 m_mainWin
->GetColumn( col
, item
);
3331 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3333 m_mainWin
->SetColumn( col
, item
);
3337 int wxListCtrl::GetColumnWidth( int col
) const
3339 return m_mainWin
->GetColumnWidth( col
);
3342 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3344 m_mainWin
->SetColumnWidth( col
, width
);
3348 int wxListCtrl::GetCountPerPage() const
3350 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3353 bool wxListCtrl::GetItem( wxListItem
&info
) const
3355 m_mainWin
->GetItem( info
);
3359 bool wxListCtrl::SetItem( wxListItem
&info
)
3361 m_mainWin
->SetItem( info
);
3365 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3368 info
.m_text
= label
;
3369 info
.m_mask
= wxLIST_MASK_TEXT
;
3370 info
.m_itemId
= index
;
3374 info
.m_image
= imageId
;
3375 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3377 m_mainWin
->SetItem(info
);
3381 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3383 return m_mainWin
->GetItemState( item
, stateMask
);
3386 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3388 m_mainWin
->SetItemState( item
, state
, stateMask
);
3392 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3395 info
.m_image
= image
;
3396 info
.m_mask
= wxLIST_MASK_IMAGE
;
3397 info
.m_itemId
= item
;
3398 m_mainWin
->SetItem( info
);
3402 wxString
wxListCtrl::GetItemText( long item
) const
3405 info
.m_itemId
= item
;
3406 m_mainWin
->GetItem( info
);
3410 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3413 info
.m_mask
= wxLIST_MASK_TEXT
;
3414 info
.m_itemId
= item
;
3416 m_mainWin
->SetItem( info
);
3419 long wxListCtrl::GetItemData( long item
) const
3422 info
.m_itemId
= item
;
3423 m_mainWin
->GetItem( info
);
3427 bool wxListCtrl::SetItemData( long item
, long data
)
3430 info
.m_mask
= wxLIST_MASK_DATA
;
3431 info
.m_itemId
= item
;
3433 m_mainWin
->SetItem( info
);
3437 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3439 m_mainWin
->GetItemRect( item
, rect
);
3443 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3445 m_mainWin
->GetItemPosition( item
, pos
);
3449 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3454 int wxListCtrl::GetItemCount() const
3456 return m_mainWin
->GetItemCount();
3459 int wxListCtrl::GetColumnCount() const
3461 return m_mainWin
->GetColumnCount();
3464 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3466 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3469 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3471 return m_mainWin
->GetItemSpacing( isSmall
);
3474 int wxListCtrl::GetSelectedItemCount() const
3476 return m_mainWin
->GetSelectedItemCount();
3479 wxColour
wxListCtrl::GetTextColour() const
3481 return GetForegroundColour();
3484 void wxListCtrl::SetTextColour(const wxColour
& col
)
3486 SetForegroundColour(col
);
3489 long wxListCtrl::GetTopItem() const
3494 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3496 return m_mainWin
->GetNextItem( item
, geom
, state
);
3499 wxImageList
*wxListCtrl::GetImageList(int which
) const
3501 if (which
== wxIMAGE_LIST_NORMAL
)
3503 return m_imageListNormal
;
3505 else if (which
== wxIMAGE_LIST_SMALL
)
3507 return m_imageListSmall
;
3509 else if (which
== wxIMAGE_LIST_STATE
)
3511 return m_imageListState
;
3513 return (wxImageList
*) NULL
;
3516 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3518 if ( which
== wxIMAGE_LIST_NORMAL
)
3520 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3521 m_imageListNormal
= imageList
;
3522 m_ownsImageListNormal
= FALSE
;
3524 else if ( which
== wxIMAGE_LIST_SMALL
)
3526 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3527 m_imageListSmall
= imageList
;
3528 m_ownsImageListSmall
= FALSE
;
3530 else if ( which
== wxIMAGE_LIST_STATE
)
3532 if (m_ownsImageListState
) delete m_imageListState
;
3533 m_imageListState
= imageList
;
3534 m_ownsImageListState
= FALSE
;
3537 m_mainWin
->SetImageList( imageList
, which
);
3540 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3542 SetImageList(imageList
, which
);
3543 if ( which
== wxIMAGE_LIST_NORMAL
)
3544 m_ownsImageListNormal
= TRUE
;
3545 else if ( which
== wxIMAGE_LIST_SMALL
)
3546 m_ownsImageListSmall
= TRUE
;
3547 else if ( which
== wxIMAGE_LIST_STATE
)
3548 m_ownsImageListState
= TRUE
;
3551 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3556 bool wxListCtrl::DeleteItem( long item
)
3558 m_mainWin
->DeleteItem( item
);
3562 bool wxListCtrl::DeleteAllItems()
3564 m_mainWin
->DeleteAllItems();
3568 bool wxListCtrl::DeleteAllColumns()
3570 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3576 void wxListCtrl::ClearAll()
3578 m_mainWin
->DeleteEverything();
3581 bool wxListCtrl::DeleteColumn( int col
)
3583 m_mainWin
->DeleteColumn( col
);
3587 void wxListCtrl::Edit( long item
)
3589 m_mainWin
->Edit( item
);
3592 bool wxListCtrl::EnsureVisible( long item
)
3594 m_mainWin
->EnsureVisible( item
);
3598 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3600 return m_mainWin
->FindItem( start
, str
, partial
);
3603 long wxListCtrl::FindItem( long start
, long data
)
3605 return m_mainWin
->FindItem( start
, data
);
3608 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3609 int WXUNUSED(direction
))
3614 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3616 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3619 long wxListCtrl::InsertItem( wxListItem
& info
)
3621 m_mainWin
->InsertItem( info
);
3622 return info
.m_itemId
;
3625 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3628 info
.m_text
= label
;
3629 info
.m_mask
= wxLIST_MASK_TEXT
;
3630 info
.m_itemId
= index
;
3631 return InsertItem( info
);
3634 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3637 info
.m_mask
= wxLIST_MASK_IMAGE
;
3638 info
.m_image
= imageIndex
;
3639 info
.m_itemId
= index
;
3640 return InsertItem( info
);
3643 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3646 info
.m_text
= label
;
3647 info
.m_image
= imageIndex
;
3648 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3649 info
.m_itemId
= index
;
3650 return InsertItem( info
);
3653 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3655 wxASSERT( m_headerWin
);
3656 m_mainWin
->InsertColumn( col
, item
);
3657 m_headerWin
->Refresh();
3662 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3663 int format
, int width
)
3666 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3667 item
.m_text
= heading
;
3670 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3671 item
.m_width
= width
;
3673 item
.m_format
= format
;
3675 return InsertColumn( col
, item
);
3678 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3684 // fn is a function which takes 3 long arguments: item1, item2, data.
3685 // item1 is the long data associated with a first item (NOT the index).
3686 // item2 is the long data associated with a second item (NOT the index).
3687 // data is the same value as passed to SortItems.
3688 // The return value is a negative number if the first item should precede the second
3689 // item, a positive number of the second item should precede the first,
3690 // or zero if the two items are equivalent.
3691 // data is arbitrary data to be passed to the sort function.
3693 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3695 m_mainWin
->SortItems( fn
, data
);
3699 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3701 if (!m_mainWin
->m_dirty
) return;
3705 GetClientSize( &cw
, &ch
);
3712 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3714 m_headerWin
->GetPosition( &x
, &y
);
3715 m_headerWin
->GetSize( &w
, &h
);
3716 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3717 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3719 m_mainWin
->GetPosition( &x
, &y
);
3720 m_mainWin
->GetSize( &w
, &h
);
3721 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3722 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3726 m_mainWin
->GetPosition( &x
, &y
);
3727 m_mainWin
->GetSize( &w
, &h
);
3728 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3729 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3732 m_mainWin
->CalculatePositions();
3733 m_mainWin
->RealizeChanges();
3734 m_mainWin
->m_dirty
= FALSE
;
3735 m_mainWin
->Refresh();
3737 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3739 m_headerWin
->m_dirty
= FALSE
;
3740 m_headerWin
->Refresh();
3744 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3748 m_mainWin
->SetBackgroundColour( colour
);
3749 m_mainWin
->m_dirty
= TRUE
;
3755 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3757 if ( !wxWindow::SetForegroundColour( colour
) )
3762 m_mainWin
->SetForegroundColour( colour
);
3763 m_mainWin
->m_dirty
= TRUE
;
3768 m_headerWin
->SetForegroundColour( colour
);
3774 bool wxListCtrl::SetFont( const wxFont
&font
)
3776 if ( !wxWindow::SetFont( font
) )
3781 m_mainWin
->SetFont( font
);
3782 m_mainWin
->m_dirty
= TRUE
;
3787 m_headerWin
->SetFont( font
);
3793 #if wxUSE_DRAG_AND_DROP
3795 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3797 m_mainWin
->SetDropTarget( dropTarget
);
3800 wxDropTarget
*wxListCtrl::GetDropTarget() const
3802 return m_mainWin
->GetDropTarget();
3805 #endif // wxUSE_DRAG_AND_DROP
3807 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3809 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3812 wxColour
wxListCtrl::GetBackgroundColour() const
3814 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3817 wxColour
wxListCtrl::GetForegroundColour() const
3819 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3822 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3824 return m_mainWin
->PopupMenu( menu
, x
, y
);
3827 void wxListCtrl::SetFocus()
3829 /* The test in window.cpp fails as we are a composite
3830 window, so it checks against "this", but not m_mainWin. */
3831 if ( FindFocus() != this )
3832 m_mainWin
->SetFocus();