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"
27 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
28 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
31 // ============================================================================
33 // ============================================================================
35 //-----------------------------------------------------------------------------
36 // wxListItemData (internal)
37 //-----------------------------------------------------------------------------
39 class WXDLLEXPORT wxListItemData
: public wxObject
48 wxListItemAttr
*m_attr
;
52 ~wxListItemData() { delete m_attr
; }
54 wxListItemData( const wxListItem
&info
);
55 void SetItem( const wxListItem
&info
);
56 void SetText( const wxString
&s
);
57 void SetImage( int image
);
58 void SetData( long data
);
59 void SetPosition( int x
, int y
);
60 void SetSize( int width
, int height
);
61 bool HasImage() const;
63 bool IsHit( int x
, int y
) const;
64 void GetText( wxString
&s
);
65 const wxString
& GetText() { return m_text
; }
66 int GetX( void ) const;
67 int GetY( void ) const;
69 int GetHeight() const;
71 void GetItem( wxListItem
&info
) const;
73 wxListItemAttr
*GetAttributes() const { return m_attr
; }
76 DECLARE_DYNAMIC_CLASS(wxListItemData
);
79 //-----------------------------------------------------------------------------
80 // wxListHeaderData (internal)
81 //-----------------------------------------------------------------------------
83 class WXDLLEXPORT wxListHeaderData
: public wxObject
96 wxListHeaderData( const wxListItem
&info
);
97 void SetItem( const wxListItem
&item
);
98 void SetPosition( int x
, int y
);
99 void SetWidth( int w
);
100 void SetFormat( int format
);
101 void SetHeight( int h
);
102 bool HasImage() const;
103 bool HasText() const;
104 bool IsHit( int x
, int y
) const;
105 void GetItem( wxListItem
&item
);
106 void GetText( wxString
&s
);
107 int GetImage() const;
108 int GetWidth() const;
109 int GetFormat() const;
112 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
115 //-----------------------------------------------------------------------------
116 // wxListLineData (internal)
117 //-----------------------------------------------------------------------------
119 class WXDLLEXPORT wxListLineData
: public wxObject
124 wxRect m_bound_label
;
126 wxRect m_bound_hilight
;
129 wxBrush
*m_hilightBrush
;
131 wxListMainWindow
*m_owner
;
133 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
137 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
138 void CalculateSize( wxDC
*dc
, int spacing
);
139 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
140 void SetColumnPosition( int index
, int x
);
141 void GetSize( int &width
, int &height
);
142 void GetExtent( int &x
, int &y
, int &width
, int &height
);
143 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
144 long IsHit( int x
, int y
);
145 void InitItems( int num
);
146 void SetItem( int index
, const wxListItem
&info
);
147 void GetItem( int index
, wxListItem
&info
);
148 void GetText( int index
, wxString
&s
);
149 void SetText( int index
, const wxString s
);
150 int GetImage( int index
);
151 void GetRect( wxRect
&rect
);
152 void Hilight( bool on
);
153 void ReverseHilight();
154 void DrawRubberBand( wxDC
*dc
, bool on
);
155 void Draw( wxDC
*dc
);
156 bool IsInRect( int x
, int y
, const wxRect
&rect
);
158 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
159 void AssignRect( wxRect
&dest
, const wxRect
&source
);
162 void SetAttributes(wxDC
*dc
,
163 const wxListItemAttr
*attr
,
164 const wxColour
& colText
, const wxFont
& font
,
167 DECLARE_DYNAMIC_CLASS(wxListLineData
);
170 //-----------------------------------------------------------------------------
171 // wxListHeaderWindow (internal)
172 //-----------------------------------------------------------------------------
174 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
177 wxListMainWindow
*m_owner
;
178 wxCursor
*m_currentCursor
;
179 wxCursor
*m_resizeCursor
;
186 wxListHeaderWindow();
187 ~wxListHeaderWindow();
188 wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
189 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
190 long style
= 0, const wxString
&name
= "wxlistctrlcolumntitles" );
191 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
192 void OnPaint( wxPaintEvent
&event
);
194 void OnMouse( wxMouseEvent
&event
);
195 void OnSetFocus( wxFocusEvent
&event
);
198 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
199 DECLARE_EVENT_TABLE()
202 //-----------------------------------------------------------------------------
203 // wxListRenameTimer (internal)
204 //-----------------------------------------------------------------------------
206 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
209 wxListMainWindow
*m_owner
;
212 wxListRenameTimer( wxListMainWindow
*owner
);
216 //-----------------------------------------------------------------------------
217 // wxListTextCtrl (internal)
218 //-----------------------------------------------------------------------------
220 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
225 wxListMainWindow
*m_owner
;
226 wxString m_startValue
;
230 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
231 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
232 const wxString
&value
= "",
233 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
235 const wxValidator
& validator
= wxDefaultValidator
,
236 const wxString
&name
= "listctrltextctrl" );
237 void OnChar( wxKeyEvent
&event
);
238 void OnKillFocus( wxFocusEvent
&event
);
241 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
242 DECLARE_EVENT_TABLE()
245 //-----------------------------------------------------------------------------
246 // wxListMainWindow (internal)
247 //-----------------------------------------------------------------------------
249 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
255 wxListLineData
*m_current
;
256 wxListLineData
*m_currentEdit
;
258 wxBrush
*m_hilightBrush
;
259 wxColour
*m_hilightColour
;
260 int m_xScroll
,m_yScroll
;
262 wxImageList
*m_small_image_list
;
263 wxImageList
*m_normal_image_list
;
265 int m_normal_spacing
;
269 wxTimer
*m_renameTimer
;
271 wxString m_renameRes
;
276 // for double click logic
277 wxListLineData
*m_lineLastClicked
,
278 *m_lineBeforeLastClicked
;
282 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
283 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
284 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
286 void RefreshLine( wxListLineData
*line
);
287 void OnPaint( wxPaintEvent
&event
);
288 void HilightAll( bool on
);
289 void SendNotify( wxListLineData
*line
, wxEventType command
);
290 void FocusLine( wxListLineData
*line
);
291 void UnfocusLine( wxListLineData
*line
);
292 void SelectLine( wxListLineData
*line
);
293 void DeselectLine( wxListLineData
*line
);
294 void DeleteLine( wxListLineData
*line
);
296 void EditLabel( long item
);
297 void Edit( long item
) { EditLabel(item
); } // deprecated
298 void OnRenameTimer();
299 void OnRenameAccept();
301 void OnMouse( wxMouseEvent
&event
);
303 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
304 void OnChar( wxKeyEvent
&event
);
305 void OnKeyDown( wxKeyEvent
&event
);
306 void OnSetFocus( wxFocusEvent
&event
);
307 void OnKillFocus( wxFocusEvent
&event
);
308 void OnSize( wxSizeEvent
&event
);
309 void OnScroll(wxScrollWinEvent
& event
) ;
311 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
312 void GetImageSize( int index
, int &width
, int &height
);
313 int GetIndexOfLine( const wxListLineData
*line
);
314 int GetTextLength( wxString
&s
); // should be const
316 void SetImageList( wxImageList
*imageList
, int which
);
317 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
318 int GetItemSpacing( bool isSmall
= FALSE
);
319 void SetColumn( int col
, wxListItem
&item
);
320 void SetColumnWidth( int col
, int width
);
321 void GetColumn( int col
, wxListItem
&item
);
322 int GetColumnWidth( int vol
);
323 int GetColumnCount();
324 int GetCountPerPage();
325 void SetItem( wxListItem
&item
);
326 void GetItem( wxListItem
&item
);
327 void SetItemState( long item
, long state
, long stateMask
);
328 int GetItemState( long item
, long stateMask
);
330 void GetItemRect( long index
, wxRect
&rect
);
331 bool GetItemPosition( long item
, wxPoint
& pos
);
332 int GetSelectedItemCount();
333 void SetMode( long mode
);
334 long GetMode() const;
335 void CalculatePositions();
336 void RealizeChanges();
337 long GetNextItem( long item
, int geometry
, int state
);
338 void DeleteItem( long index
);
339 void DeleteAllItems();
340 void DeleteColumn( int col
);
341 void DeleteEverything();
342 void EnsureVisible( long index
);
343 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
344 long FindItem( long start
, long data
);
345 long HitTest( int x
, int y
, int &flags
);
346 void InsertItem( wxListItem
&item
);
347 // void AddItem( wxListItem &item );
348 void InsertColumn( long col
, wxListItem
&item
);
349 // void AddColumn( wxListItem &item );
350 void SortItems( wxListCtrlCompare fn
, long data
);
353 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
354 DECLARE_EVENT_TABLE()
357 // ============================================================================
359 // ============================================================================
361 //-----------------------------------------------------------------------------
363 //-----------------------------------------------------------------------------
365 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
367 wxListItemData::wxListItemData()
378 wxListItemData::wxListItemData( const wxListItem
&info
)
387 void wxListItemData::SetItem( const wxListItem
&info
)
389 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
390 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
391 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
393 if ( info
.HasAttributes() )
396 *m_attr
= *info
.GetAttributes();
398 m_attr
= new wxListItemAttr(*info
.GetAttributes());
403 m_width
= info
.m_width
;
407 void wxListItemData::SetText( const wxString
&s
)
412 void wxListItemData::SetImage( int image
)
417 void wxListItemData::SetData( long data
)
422 void wxListItemData::SetPosition( int x
, int y
)
428 void wxListItemData::SetSize( int width
, int height
)
430 if (width
!= -1) m_width
= width
;
431 if (height
!= -1) m_height
= height
;
434 bool wxListItemData::HasImage() const
436 return (m_image
>= 0);
439 bool wxListItemData::HasText() const
441 return (!m_text
.IsNull());
444 bool wxListItemData::IsHit( int x
, int y
) const
446 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
449 void wxListItemData::GetText( wxString
&s
)
454 int wxListItemData::GetX() const
459 int wxListItemData::GetY() const
464 int wxListItemData::GetWidth() const
469 int wxListItemData::GetHeight() const
474 int wxListItemData::GetImage() const
479 void wxListItemData::GetItem( wxListItem
&info
) const
481 info
.m_text
= m_text
;
482 info
.m_image
= m_image
;
483 info
.m_data
= m_data
;
487 if ( m_attr
->HasTextColour() )
488 info
.SetTextColour(m_attr
->GetTextColour());
489 if ( m_attr
->HasBackgroundColour() )
490 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
491 if ( m_attr
->HasFont() )
492 info
.SetFont(m_attr
->GetFont());
496 //-----------------------------------------------------------------------------
498 //-----------------------------------------------------------------------------
500 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
502 wxListHeaderData::wxListHeaderData()
513 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
521 void wxListHeaderData::SetItem( const wxListItem
&item
)
523 m_mask
= item
.m_mask
;
524 m_text
= item
.m_text
;
525 m_image
= item
.m_image
;
526 m_format
= item
.m_format
;
527 m_width
= item
.m_width
;
528 if (m_width
< 0) m_width
= 80;
529 if (m_width
< 6) m_width
= 6;
532 void wxListHeaderData::SetPosition( int x
, int y
)
538 void wxListHeaderData::SetHeight( int h
)
543 void wxListHeaderData::SetWidth( int w
)
546 if (m_width
< 0) m_width
= 80;
547 if (m_width
< 6) m_width
= 6;
550 void wxListHeaderData::SetFormat( int format
)
555 bool wxListHeaderData::HasImage() const
557 return (m_image
!= 0);
560 bool wxListHeaderData::HasText() const
562 return (m_text
.Length() > 0);
565 bool wxListHeaderData::IsHit( int x
, int y
) const
567 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
570 void wxListHeaderData::GetItem( wxListItem
&item
)
572 item
.m_mask
= m_mask
;
573 item
.m_text
= m_text
;
574 item
.m_image
= m_image
;
575 item
.m_format
= m_format
;
576 item
.m_width
= m_width
;
579 void wxListHeaderData::GetText( wxString
&s
)
584 int wxListHeaderData::GetImage() const
589 int wxListHeaderData::GetWidth() const
594 int wxListHeaderData::GetFormat() const
599 //-----------------------------------------------------------------------------
601 //-----------------------------------------------------------------------------
603 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
605 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
610 m_hilightBrush
= hilightBrush
;
611 m_items
.DeleteContents( TRUE
);
615 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
622 m_bound_all
.width
= m_spacing
;
623 wxNode
*node
= m_items
.First();
626 wxListItemData
*item
= (wxListItemData
*)node
->Data();
627 wxString s
= item
->GetText();
628 if (s
.IsEmpty()) s
= wxT("H");
630 dc
->GetTextExtent( s
, &lw
, &lh
);
631 if (lh
< 15) lh
= 15;
635 m_bound_all
.height
= m_spacing
+lh
;
636 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
637 m_bound_label
.width
= lw
;
638 m_bound_label
.height
= lh
;
640 if (item
->HasImage())
644 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
645 m_bound_icon
.width
= w
+ 8;
646 m_bound_icon
.height
= h
+ 8;
649 if (!item
->HasText())
651 m_bound_hilight
.width
= m_bound_icon
.width
;
652 m_bound_hilight
.height
= m_bound_icon
.height
;
656 m_bound_hilight
.width
= m_bound_label
.width
;
657 m_bound_hilight
.height
= m_bound_label
.height
;
664 wxNode
*node
= m_items
.First();
667 wxListItemData
*item
= (wxListItemData
*)node
->Data();
669 wxString s
= item
->GetText();
670 if (s
.IsEmpty()) s
= wxT("H");
672 dc
->GetTextExtent( s
, &lw
, &lh
);
673 if (lh
< 15) lh
= 15;
676 m_bound_label
.width
= lw
;
677 m_bound_label
.height
= lh
;
679 m_bound_all
.width
= lw
;
680 m_bound_all
.height
= lh
;
682 if (item
->HasImage())
686 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
687 m_bound_icon
.width
= w
;
688 m_bound_icon
.height
= h
;
690 m_bound_all
.width
+= 4 + w
;
691 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
694 m_bound_hilight
.width
= m_bound_all
.width
;
695 m_bound_hilight
.height
= m_bound_all
.height
;
701 m_bound_all
.width
= 0;
702 m_bound_all
.height
= 0;
703 wxNode
*node
= m_items
.First();
706 wxListItemData
*item
= (wxListItemData
*)node
->Data();
707 wxString s
= item
->GetText();
708 if (s
.IsEmpty()) s
= wxT("H");
710 dc
->GetTextExtent( s
, &lw
, &lh
);
711 if (lh
< 15) lh
= 15;
715 item
->SetSize( item
->GetWidth(), lh
);
716 m_bound_all
.width
+= lw
;
717 m_bound_all
.height
= lh
;
725 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
726 int x
, int y
, int window_width
)
734 wxNode
*node
= m_items
.First();
737 wxListItemData
*item
= (wxListItemData
*)node
->Data();
738 if (item
->HasImage())
740 m_bound_icon
.x
= m_bound_all
.x
+ 4 + (m_spacing
/2) - (m_bound_icon
.width
/2);
741 m_bound_icon
.y
= m_bound_all
.y
+ 4;
745 if (m_bound_all
.width
> m_spacing
)
746 m_bound_label
.x
= m_bound_all
.x
+ 2;
748 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
749 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
750 m_bound_hilight
.x
= m_bound_label
.x
- 2;
751 m_bound_hilight
.y
= m_bound_label
.y
- 2;
755 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
756 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
763 m_bound_hilight
.x
= m_bound_all
.x
;
764 m_bound_hilight
.y
= m_bound_all
.y
;
765 m_bound_label
.y
= m_bound_all
.y
+ 2;
766 wxNode
*node
= m_items
.First();
769 wxListItemData
*item
= (wxListItemData
*)node
->Data();
770 if (item
->HasImage())
772 m_bound_icon
.x
= m_bound_all
.x
+ 2;
773 m_bound_icon
.y
= m_bound_all
.y
+ 2;
774 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
778 m_bound_label
.x
= m_bound_all
.x
+ 2;
786 m_bound_all
.width
= window_width
;
787 AssignRect( m_bound_hilight
, m_bound_all
);
788 m_bound_label
.x
= m_bound_all
.x
+ 2;
789 m_bound_label
.y
= m_bound_all
.y
+ 2;
790 wxNode
*node
= m_items
.First();
793 wxListItemData
*item
= (wxListItemData
*)node
->Data();
794 if (item
->HasImage())
796 m_bound_icon
.x
= m_bound_all
.x
+ 2;
797 m_bound_icon
.y
= m_bound_all
.y
+ 2;
798 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
806 void wxListLineData::SetColumnPosition( int index
, int x
)
808 wxNode
*node
= m_items
.Nth( (size_t)index
);
811 wxListItemData
*item
= (wxListItemData
*)node
->Data();
812 item
->SetPosition( x
, m_bound_all
.y
+1 );
816 void wxListLineData::GetSize( int &width
, int &height
)
818 width
= m_bound_all
.width
;
819 height
= m_bound_all
.height
;
822 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
826 width
= m_bound_all
.width
;
827 height
= m_bound_all
.height
;
830 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
834 width
= m_bound_label
.width
;
835 height
= m_bound_label
.height
;
838 void wxListLineData::GetRect( wxRect
&rect
)
840 AssignRect( rect
, m_bound_all
);
843 long wxListLineData::IsHit( int x
, int y
)
845 wxNode
*node
= m_items
.First();
848 wxListItemData
*item
= (wxListItemData
*)node
->Data();
849 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
850 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
851 // if (!(item->HasImage() || item->HasText())) return 0;
853 // if there is no icon or text = empty
854 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
858 void wxListLineData::InitItems( int num
)
860 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
863 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
865 wxNode
*node
= m_items
.Nth( index
);
868 wxListItemData
*item
= (wxListItemData
*)node
->Data();
869 item
->SetItem( info
);
873 void wxListLineData::GetItem( int index
, wxListItem
&info
)
876 wxNode
*node
= m_items
.Nth( i
);
879 wxListItemData
*item
= (wxListItemData
*)node
->Data();
880 item
->GetItem( info
);
884 void wxListLineData::GetText( int index
, wxString
&s
)
887 wxNode
*node
= m_items
.Nth( i
);
891 wxListItemData
*item
= (wxListItemData
*)node
->Data();
896 void wxListLineData::SetText( int index
, const wxString s
)
899 wxNode
*node
= m_items
.Nth( i
);
902 wxListItemData
*item
= (wxListItemData
*)node
->Data();
907 int wxListLineData::GetImage( int index
)
910 wxNode
*node
= m_items
.Nth( i
);
913 wxListItemData
*item
= (wxListItemData
*)node
->Data();
914 return item
->GetImage();
919 void wxListLineData::SetAttributes(wxDC
*dc
,
920 const wxListItemAttr
*attr
,
921 const wxColour
& colText
,
925 // don't use foregroud colour for drawing highlighted items - this might
926 // make them completely invisible (and there is no way to do bit
927 // arithmetics on wxColour, unfortunately)
928 if ( !hilight
&& attr
&& attr
->HasTextColour() )
930 dc
->SetTextForeground(attr
->GetTextColour());
934 dc
->SetTextForeground(colText
);
937 if ( attr
&& attr
->HasFont() )
939 dc
->SetFont(attr
->GetFont());
947 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
951 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
952 wxCoord dev_w
= m_bound_all
.width
;
953 wxCoord dev_h
= m_bound_all
.height
;
955 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
958 wxWindow
*listctrl
= m_owner
->GetParent();
960 // default foreground colour
964 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
968 colText
= listctrl
->GetForegroundColour();
972 wxFont font
= listctrl
->GetFont();
974 // VZ: currently we set the colours/fonts only once, but like this (i.e.
975 // using SetAttributes() inside the loop), it will be trivial to
976 // customize the subitems (in report mode) too.
977 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
978 wxListItemAttr
*attr
= item
->GetAttributes();
979 SetAttributes(dc
, attr
, colText
, font
, hilight
);
981 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
982 if ( paintBG
|| hasBgCol
)
986 dc
->SetBrush( * m_hilightBrush
);
991 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
993 dc
->SetBrush( * wxWHITE_BRUSH
);
996 dc
->SetPen( * wxTRANSPARENT_PEN
);
997 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
998 m_bound_hilight
.width
, m_bound_hilight
.height
);
1001 if (m_mode
== wxLC_REPORT
)
1003 wxNode
*node
= m_items
.First();
1006 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1007 int x
= item
->GetX();
1008 if (item
->HasImage())
1011 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1012 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1013 x
+= item
->GetX() + 5;
1015 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1016 if (item
->HasText())
1018 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1020 dc
->DestroyClippingRegion();
1021 node
= node
->Next();
1026 wxNode
*node
= m_items
.First();
1029 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1030 if (item
->HasImage())
1032 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1034 if (item
->HasText())
1036 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1042 void wxListLineData::Hilight( bool on
)
1044 if (on
== m_hilighted
) return;
1047 m_owner
->SelectLine( this );
1049 m_owner
->DeselectLine( this );
1052 void wxListLineData::ReverseHilight( void )
1054 m_hilighted
= !m_hilighted
;
1056 m_owner
->SelectLine( this );
1058 m_owner
->DeselectLine( this );
1061 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1065 dc
->SetPen( * wxBLACK_PEN
);
1066 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1067 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1068 m_bound_hilight
.width
, m_bound_hilight
.height
);
1072 void wxListLineData::Draw( wxDC
*dc
)
1074 DoDraw( dc
, m_hilighted
, m_hilighted
);
1077 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1079 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1080 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1083 bool wxListLineData::IsHilighted( void )
1088 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1093 dest
.height
= height
;
1096 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1100 dest
.width
= source
.width
;
1101 dest
.height
= source
.height
;
1104 //-----------------------------------------------------------------------------
1105 // wxListHeaderWindow
1106 //-----------------------------------------------------------------------------
1108 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1110 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1111 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1112 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1113 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1116 wxListHeaderWindow::wxListHeaderWindow( void )
1118 m_owner
= (wxListMainWindow
*) NULL
;
1119 m_currentCursor
= (wxCursor
*) NULL
;
1120 m_resizeCursor
= (wxCursor
*) NULL
;
1121 m_isDragging
= FALSE
;
1124 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1125 const wxPoint
&pos
, const wxSize
&size
,
1126 long style
, const wxString
&name
) :
1127 wxWindow( win
, id
, pos
, size
, style
, name
)
1130 // m_currentCursor = wxSTANDARD_CURSOR;
1131 m_currentCursor
= (wxCursor
*) NULL
;
1132 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1133 m_isDragging
= FALSE
;
1134 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1137 wxListHeaderWindow::~wxListHeaderWindow( void )
1139 delete m_resizeCursor
;
1142 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1144 const int m_corner
= 1;
1146 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1148 dc
->SetPen( *wxBLACK_PEN
);
1149 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1150 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1152 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1155 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1156 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1158 dc
->SetPen( *wxWHITE_PEN
);
1159 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1160 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1161 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1162 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1165 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1167 wxPaintDC
dc( this );
1169 #if wxUSE_GENERIC_LIST_EXTENSIONS
1170 if ( m_owner
->GetMode() & wxLC_REPORT
)
1175 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
1176 m_owner
->ViewStart( &x
, &y
) ;
1177 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1182 dc
.SetFont( GetFont() );
1188 GetClientSize( &w
, &h
);
1190 dc
.SetBackgroundMode(wxTRANSPARENT
);
1191 dc
.SetTextForeground( *wxBLACK
);
1193 // do *not* use the listctrl colour for headers - one day we will have a
1194 // function to set it separately
1198 int numColumns
= m_owner
->GetColumnCount();
1200 for (int i
= 0; i
< numColumns
; i
++)
1202 m_owner
->GetColumn( i
, item
);
1203 int cw
= item
.m_width
-2;
1204 #if wxUSE_GENERIC_LIST_EXTENSIONS
1205 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
1206 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
1208 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
1211 dc
.SetPen( *wxWHITE_PEN
);
1213 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1214 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1215 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1216 dc
.DestroyClippingRegion();
1218 #if wxUSE_GENERIC_LIST_EXTENSIONS
1219 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
1227 void wxListHeaderWindow::DrawCurrent()
1229 int x1
= m_currentX
;
1231 int x2
= m_currentX
-1;
1234 m_owner
->GetClientSize( &dummy
, &y2
);
1235 ClientToScreen( &x1
, &y1
);
1236 m_owner
->ClientToScreen( &x2
, &y2
);
1239 dc
.SetLogicalFunction( wxINVERT
);
1240 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1241 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1243 dc
.DrawLine( x1
, y1
, x2
, y2
);
1245 dc
.SetLogicalFunction( wxCOPY
);
1247 dc
.SetPen( wxNullPen
);
1248 dc
.SetBrush( wxNullBrush
);
1251 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1253 wxCoord x
= (wxCoord
)event
.GetX();
1254 wxCoord y
= (wxCoord
)event
.GetY();
1258 if (event
.ButtonUp())
1261 m_isDragging
= FALSE
;
1262 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
1268 GetClientSize( &size_x
, & dummy
);
1272 m_currentX
= m_minX
+7;
1273 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
1280 bool hit_border
= FALSE
;
1282 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
1284 xpos
+= m_owner
->GetColumnWidth( j
);
1286 if ((abs(x
-xpos
) < 3) && (y
< 22) && (m_column
< m_owner
->GetColumnCount()-1))
1298 if (event
.LeftDown())
1302 m_isDragging
= TRUE
;
1310 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
1311 le
.SetEventObject( GetParent() );
1312 le
.m_col
= m_column
;
1313 GetParent()->GetEventHandler()->ProcessEvent( le
);
1322 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
1323 m_currentCursor
= m_resizeCursor
;
1327 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
1328 m_currentCursor
= wxSTANDARD_CURSOR
;
1333 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1335 m_owner
->SetFocus();
1338 //-----------------------------------------------------------------------------
1339 // wxListRenameTimer (internal)
1340 //-----------------------------------------------------------------------------
1342 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1347 void wxListRenameTimer::Notify()
1349 m_owner
->OnRenameTimer();
1352 //-----------------------------------------------------------------------------
1353 // wxListTextCtrl (internal)
1354 //-----------------------------------------------------------------------------
1356 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1358 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1359 EVT_CHAR (wxListTextCtrl::OnChar
)
1360 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1363 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1364 const wxWindowID id
,
1367 wxListMainWindow
*owner
,
1368 const wxString
&value
,
1372 const wxValidator
& validator
,
1373 const wxString
&name
)
1374 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1379 (*m_accept
) = FALSE
;
1381 m_startValue
= value
;
1384 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1386 if (event
.m_keyCode
== WXK_RETURN
)
1389 (*m_res
) = GetValue();
1391 if (!wxPendingDelete
.Member(this))
1392 wxPendingDelete
.Append(this);
1394 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1395 m_owner
->OnRenameAccept();
1399 if (event
.m_keyCode
== WXK_ESCAPE
)
1401 (*m_accept
) = FALSE
;
1404 if (!wxPendingDelete
.Member(this))
1405 wxPendingDelete
.Append(this);
1413 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1415 if (!wxPendingDelete
.Member(this))
1416 wxPendingDelete
.Append(this);
1418 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1419 m_owner
->OnRenameAccept();
1422 //-----------------------------------------------------------------------------
1424 //-----------------------------------------------------------------------------
1426 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1428 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1429 EVT_PAINT (wxListMainWindow::OnPaint
)
1430 EVT_SIZE (wxListMainWindow::OnSize
)
1431 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1432 EVT_CHAR (wxListMainWindow::OnChar
)
1433 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1434 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1435 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1436 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1439 wxListMainWindow::wxListMainWindow()
1442 m_lines
.DeleteContents( TRUE
);
1443 m_columns
.DeleteContents( TRUE
);
1444 m_current
= (wxListLineData
*) NULL
;
1446 m_hilightBrush
= (wxBrush
*) NULL
;
1450 m_small_image_list
= (wxImageList
*) NULL
;
1451 m_normal_image_list
= (wxImageList
*) NULL
;
1452 m_small_spacing
= 30;
1453 m_normal_spacing
= 40;
1456 m_lastOnSame
= FALSE
;
1457 m_renameTimer
= new wxListRenameTimer( this );
1458 m_isCreated
= FALSE
;
1462 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1465 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1466 const wxPoint
&pos
, const wxSize
&size
,
1467 long style
, const wxString
&name
) :
1468 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1471 m_lines
.DeleteContents( TRUE
);
1472 m_columns
.DeleteContents( TRUE
);
1473 m_current
= (wxListLineData
*) NULL
;
1476 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1477 m_small_image_list
= (wxImageList
*) NULL
;
1478 m_normal_image_list
= (wxImageList
*) NULL
;
1479 m_small_spacing
= 30;
1480 m_normal_spacing
= 40;
1483 m_isCreated
= FALSE
;
1487 if (m_mode
& wxLC_REPORT
)
1489 #if wxUSE_GENERIC_LIST_EXTENSIONS
1501 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1504 m_lastOnSame
= FALSE
;
1505 m_renameTimer
= new wxListRenameTimer( this );
1506 m_renameAccept
= FALSE
;
1508 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1511 wxListMainWindow::~wxListMainWindow()
1515 if (m_hilightBrush
) delete m_hilightBrush
;
1517 delete m_renameTimer
;
1520 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1522 if (m_dirty
) return;
1530 line
->GetExtent( x
, y
, w
, h
);
1531 CalcScrolledPosition( x
, y
, &x
, &y
);
1532 wxRect
rect( x
, y
, w
, h
);
1533 Refresh( TRUE
, &rect
);
1536 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1538 // Note: a wxPaintDC must be constructed even if no drawing is
1539 // done (a Windows requirement).
1540 wxPaintDC
dc( this );
1543 if (m_dirty
) return;
1545 if (m_lines
.GetCount() == 0) return;
1549 dc
.SetFont( GetFont() );
1551 if (m_mode
& wxLC_REPORT
)
1553 int lineSpacing
= 0;
1554 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1556 line
->GetSize( dummy
, lineSpacing
);
1559 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1561 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1562 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1566 line
= (wxListLineData
*)node
->Data();
1568 node
= node
->Next();
1573 wxNode
*node
= m_lines
.First();
1576 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1578 node
= node
->Next();
1582 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1587 void wxListMainWindow::HilightAll( bool on
)
1589 wxNode
*node
= m_lines
.First();
1592 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1593 if (line
->IsHilighted() != on
)
1595 line
->Hilight( on
);
1596 RefreshLine( line
);
1598 node
= node
->Next();
1602 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1604 wxListEvent
le( command
, GetParent()->GetId() );
1605 le
.SetEventObject( GetParent() );
1606 le
.m_itemIndex
= GetIndexOfLine( line
);
1607 line
->GetItem( 0, le
.m_item
);
1608 GetParent()->GetEventHandler()->ProcessEvent( le
);
1609 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1612 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1614 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1617 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1619 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1622 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1624 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1627 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1629 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1632 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1634 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1639 void wxListMainWindow::EditLabel( long item
)
1641 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1642 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1644 m_currentEdit
= (wxListLineData
*) node
->Data();
1646 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1647 le
.SetEventObject( GetParent() );
1648 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1649 m_currentEdit
->GetItem( 0, le
.m_item
);
1650 GetParent()->GetEventHandler()->ProcessEvent( le
);
1652 if (!le
.IsAllowed())
1655 // We have to call this here because the label in
1656 // question might just have been added and no screen
1657 // update taken place.
1658 if (m_dirty
) wxYield();
1661 m_currentEdit
->GetText( 0, s
);
1666 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1668 wxClientDC
dc(this);
1670 x
= dc
.LogicalToDeviceX( x
);
1671 y
= dc
.LogicalToDeviceY( y
);
1673 wxListTextCtrl
*text
= new wxListTextCtrl(
1674 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1678 void wxListMainWindow::OnRenameTimer()
1680 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1682 Edit( m_lines
.IndexOf( m_current
) );
1685 void wxListMainWindow::OnRenameAccept()
1687 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1688 le
.SetEventObject( GetParent() );
1689 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1690 m_currentEdit
->GetItem( 0, le
.m_item
);
1691 le
.m_item
.m_text
= m_renameRes
;
1692 GetParent()->GetEventHandler()->ProcessEvent( le
);
1694 if (!le
.IsAllowed()) return;
1697 info
.m_mask
= wxLIST_MASK_TEXT
;
1698 info
.m_itemId
= le
.m_itemIndex
;
1699 info
.m_text
= m_renameRes
;
1700 info
.SetTextColour(le
.m_item
.GetTextColour());
1704 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1706 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1708 if (!m_current
) return;
1709 if (m_dirty
) return;
1710 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1712 wxClientDC
dc(this);
1714 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1715 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1717 /* Did we actually hit an item ? */
1719 wxNode
*node
= m_lines
.First();
1720 wxListLineData
*line
= (wxListLineData
*) NULL
;
1723 line
= (wxListLineData
*)node
->Data();
1724 hitResult
= line
->IsHit( x
, y
);
1725 if (hitResult
) break;
1726 line
= (wxListLineData
*) NULL
;
1727 node
= node
->Next();
1730 if (event
.Dragging())
1732 if (m_dragCount
== 0)
1733 m_dragStart
= wxPoint(x
,y
);
1737 if (m_dragCount
!= 3) return;
1739 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1740 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1742 wxListEvent
le( command
, GetParent()->GetId() );
1743 le
.SetEventObject( GetParent() );
1744 le
.m_pointDrag
= m_dragStart
;
1745 GetParent()->GetEventHandler()->ProcessEvent( le
);
1756 bool forceClick
= FALSE
;
1757 if (event
.ButtonDClick())
1759 m_renameTimer
->Stop();
1760 m_lastOnSame
= FALSE
;
1762 if ( line
== m_lineBeforeLastClicked
)
1766 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1772 // the first click was on another item, so don't interpret this as
1773 // a double click, but as a simple click instead
1778 if (event
.LeftUp() && m_lastOnSame
)
1781 if ((line
== m_current
) &&
1782 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1783 (m_mode
& wxLC_EDIT_LABELS
) )
1785 m_renameTimer
->Start( 100, TRUE
);
1787 m_lastOnSame
= FALSE
;
1791 if (event
.RightDown())
1793 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1797 if (event
.MiddleDown())
1799 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1803 if ( event
.LeftDown() || forceClick
)
1805 m_lineBeforeLastClicked
= m_lineLastClicked
;
1806 m_lineLastClicked
= line
;
1809 wxListLineData
*oldCurrent
= m_current
;
1810 if (m_mode
& wxLC_SINGLE_SEL
)
1813 HilightAll( FALSE
);
1814 m_current
->ReverseHilight();
1815 RefreshLine( m_current
);
1819 if (event
.ControlDown())
1822 m_current
->ReverseHilight();
1823 RefreshLine( m_current
);
1825 else if (event
.ShiftDown())
1829 int numOfCurrent
= -1;
1830 node
= m_lines
.First();
1833 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1835 if (test_line
== oldCurrent
) break;
1836 node
= node
->Next();
1840 node
= m_lines
.First();
1843 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1845 if (test_line
== line
) break;
1846 node
= node
->Next();
1849 if (numOfLine
< numOfCurrent
)
1852 numOfLine
= numOfCurrent
;
1856 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1857 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1859 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1860 test_line
->Hilight(TRUE
);
1861 RefreshLine( test_line
);
1862 node
= node
->Next();
1868 HilightAll( FALSE
);
1869 m_current
->ReverseHilight();
1870 RefreshLine( m_current
);
1873 if (m_current
!= oldCurrent
)
1875 RefreshLine( oldCurrent
);
1876 UnfocusLine( oldCurrent
);
1877 FocusLine( m_current
);
1880 // forceClick is only set if the previous click was on another item
1881 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
1887 void wxListMainWindow::MoveToFocus()
1889 if (!m_current
) return;
1895 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1899 GetClientSize( &client_w
, &client_h
);
1901 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1902 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1904 if (m_mode
& wxLC_REPORT
)
1906 if (item_y
-5 < view_y
)
1907 Scroll( -1, (item_y
-5)/m_yScroll
);
1908 if (item_y
+item_h
+5 > view_y
+client_h
)
1909 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
1913 if (item_x
-view_x
< 5)
1914 Scroll( (item_x
-5)/m_xScroll
, -1 );
1915 if (item_x
+item_w
-5 > view_x
+client_w
)
1916 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
1920 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1922 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1923 wxListLineData
*oldCurrent
= m_current
;
1924 m_current
= newCurrent
;
1925 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1926 RefreshLine( m_current
);
1927 RefreshLine( oldCurrent
);
1928 FocusLine( m_current
);
1929 UnfocusLine( oldCurrent
);
1933 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1935 wxWindow
*parent
= GetParent();
1937 /* we propagate the key event up */
1938 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1939 ke
.m_shiftDown
= event
.m_shiftDown
;
1940 ke
.m_controlDown
= event
.m_controlDown
;
1941 ke
.m_altDown
= event
.m_altDown
;
1942 ke
.m_metaDown
= event
.m_metaDown
;
1943 ke
.m_keyCode
= event
.m_keyCode
;
1946 ke
.SetEventObject( parent
);
1947 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1952 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1954 wxWindow
*parent
= GetParent();
1956 /* we send a list_key event up */
1957 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1958 le
.m_code
= (int)event
.KeyCode();
1959 le
.SetEventObject( parent
);
1960 parent
->GetEventHandler()->ProcessEvent( le
);
1962 /* we propagate the char event up */
1963 wxKeyEvent
ke( wxEVT_CHAR
);
1964 ke
.m_shiftDown
= event
.m_shiftDown
;
1965 ke
.m_controlDown
= event
.m_controlDown
;
1966 ke
.m_altDown
= event
.m_altDown
;
1967 ke
.m_metaDown
= event
.m_metaDown
;
1968 ke
.m_keyCode
= event
.m_keyCode
;
1971 ke
.SetEventObject( parent
);
1972 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1974 if (event
.KeyCode() == WXK_TAB
)
1976 wxNavigationKeyEvent nevent
;
1977 nevent
.SetWindowChange( event
.ControlDown() );
1978 nevent
.SetDirection( !event
.ShiftDown() );
1979 nevent
.SetEventObject( GetParent()->GetParent() );
1980 nevent
.SetCurrentFocus( m_parent
);
1981 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
1984 /* no item -> nothing to do */
1991 switch (event
.KeyCode())
1995 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
1996 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2001 wxNode
*node
= m_lines
.Member( m_current
)->Next();
2002 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2007 wxNode
*node
= m_lines
.Last();
2008 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2013 wxNode
*node
= m_lines
.First();
2014 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2020 if (m_mode
& wxLC_REPORT
)
2022 steps
= m_visibleLines
-1;
2027 wxNode
*node
= m_lines
.First();
2028 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
2029 steps
= pos
% m_visibleLines
;
2031 wxNode
*node
= m_lines
.Member( m_current
);
2032 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
2033 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2039 if (m_mode
& wxLC_REPORT
)
2041 steps
= m_visibleLines
-1;
2045 int pos
= 0; wxNode
*node
= m_lines
.First();
2046 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
2047 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
2049 wxNode
*node
= m_lines
.Member( m_current
);
2050 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
2051 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2056 if (!(m_mode
& wxLC_REPORT
))
2058 wxNode
*node
= m_lines
.Member( m_current
);
2059 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
2060 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2066 if (!(m_mode
& wxLC_REPORT
))
2068 wxNode
*node
= m_lines
.Member( m_current
);
2069 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
2070 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2076 if (m_mode
& wxLC_SINGLE_SEL
)
2078 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2079 le
.SetEventObject( GetParent() );
2080 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2081 m_current
->GetItem( 0, le
.m_item
);
2082 GetParent()->GetEventHandler()->ProcessEvent( le
);
2086 m_current
->ReverseHilight();
2087 RefreshLine( m_current
);
2093 if (!(m_mode
& wxLC_SINGLE_SEL
))
2095 wxListLineData
*oldCurrent
= m_current
;
2096 m_current
->ReverseHilight();
2097 wxNode
*node
= m_lines
.Member( m_current
)->Next();
2098 if (node
) m_current
= (wxListLineData
*)node
->Data();
2099 RefreshLine( oldCurrent
);
2100 RefreshLine( m_current
);
2101 UnfocusLine( oldCurrent
);
2102 FocusLine( m_current
);
2110 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2111 le
.SetEventObject( GetParent() );
2112 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2113 m_current
->GetItem( 0, le
.m_item
);
2114 GetParent()->GetEventHandler()->ProcessEvent( le
);
2127 extern wxWindow
*g_focusWindow
;
2130 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2133 RefreshLine( m_current
);
2135 if (!GetParent()) return;
2138 g_focusWindow
= GetParent();
2141 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2142 event
.SetEventObject( GetParent() );
2143 GetParent()->GetEventHandler()->ProcessEvent( event
);
2146 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2149 RefreshLine( m_current
);
2152 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2155 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2161 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2163 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2165 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2168 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2170 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2172 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2174 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2176 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2178 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2183 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2185 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2187 m_normal_image_list
->GetSize( index
, width
, height
);
2190 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2192 m_small_image_list
->GetSize( index
, width
, height
);
2195 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2197 m_small_image_list
->GetSize( index
, width
, height
);
2200 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2202 m_small_image_list
->GetSize( index
, width
, height
);
2209 int wxListMainWindow::GetTextLength( wxString
&s
)
2211 wxClientDC
dc( this );
2214 dc
.GetTextExtent( s
, &lw
, &lh
);
2218 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2221 wxNode
*node
= m_lines
.First();
2224 if (line
== (wxListLineData
*)node
->Data()) return i
;
2226 node
= node
->Next();
2231 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2234 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
2235 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
2238 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2243 m_small_spacing
= spacing
;
2247 m_normal_spacing
= spacing
;
2251 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2253 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
2256 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2259 wxNode
*node
= m_columns
.Nth( col
);
2262 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2263 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2264 column
->SetItem( item
);
2266 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
2267 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
2270 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2272 if (!(m_mode
& wxLC_REPORT
)) return;
2276 wxNode
*node
= (wxNode
*) NULL
;
2278 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
2279 if (width
== wxLIST_AUTOSIZE
)
2281 wxClientDC
dc(this);
2282 dc
.SetFont( GetFont() );
2284 node
= m_lines
.First();
2287 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2288 wxNode
*n
= line
->m_items
.Nth( col
);
2291 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2292 int current
= 0, ix
= 0, iy
= 0;
2293 wxCoord lx
= 0, ly
= 0;
2294 if (item
->HasImage())
2296 GetImageSize( item
->GetImage(), ix
, iy
);
2299 if (item
->HasText())
2302 item
->GetText( str
);
2303 dc
.GetTextExtent( str
, &lx
, &ly
);
2306 if (current
> max
) max
= current
;
2308 node
= node
->Next();
2313 node
= m_columns
.Nth( col
);
2316 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2317 column
->SetWidth( width
);
2320 node
= m_lines
.First();
2323 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2324 wxNode
*n
= line
->m_items
.Nth( col
);
2327 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2328 item
->SetSize( width
, -1 );
2330 node
= node
->Next();
2333 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
2334 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
2337 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2339 wxNode
*node
= m_columns
.Nth( col
);
2342 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2343 column
->GetItem( item
);
2355 int wxListMainWindow::GetColumnWidth( int col
)
2357 wxNode
*node
= m_columns
.Nth( col
);
2360 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2361 return column
->GetWidth();
2369 int wxListMainWindow::GetColumnCount()
2371 return m_columns
.Number();
2374 int wxListMainWindow::GetCountPerPage()
2376 return m_visibleLines
;
2379 void wxListMainWindow::SetItem( wxListItem
&item
)
2382 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2385 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2386 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2387 line
->SetItem( item
.m_col
, item
);
2391 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2393 // m_dirty = TRUE; no recalcs needed
2395 wxListLineData
*oldCurrent
= m_current
;
2397 if (stateMask
& wxLIST_STATE_FOCUSED
)
2399 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2402 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2403 UnfocusLine( m_current
);
2405 FocusLine( m_current
);
2406 RefreshLine( m_current
);
2407 if (oldCurrent
) RefreshLine( oldCurrent
);
2411 if (stateMask
& wxLIST_STATE_SELECTED
)
2413 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2414 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2416 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2419 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2420 if (m_mode
& wxLC_SINGLE_SEL
)
2422 UnfocusLine( m_current
);
2424 FocusLine( m_current
);
2425 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2426 RefreshLine( m_current
);
2427 if (oldCurrent
) RefreshLine( oldCurrent
);
2429 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2430 if (on
!= line
->IsHilighted())
2432 line
->Hilight( on
);
2433 RefreshLine( line
);
2439 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2441 int ret
= wxLIST_STATE_DONTCARE
;
2442 if (stateMask
& wxLIST_STATE_FOCUSED
)
2444 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2447 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2448 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2451 if (stateMask
& wxLIST_STATE_SELECTED
)
2453 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2456 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2457 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2463 void wxListMainWindow::GetItem( wxListItem
&item
)
2465 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2468 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2469 line
->GetItem( item
.m_col
, item
);
2480 int wxListMainWindow::GetItemCount()
2482 return m_lines
.Number();
2485 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2487 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2490 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2491 line
->GetRect( rect
);
2502 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2504 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2508 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2509 line
->GetRect( rect
);
2521 int wxListMainWindow::GetSelectedItemCount()
2524 wxNode
*node
= m_lines
.First();
2527 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2528 if (line
->IsHilighted()) ret
++;
2529 node
= node
->Next();
2534 void wxListMainWindow::SetMode( long mode
)
2541 if (m_mode
& wxLC_REPORT
)
2543 #if wxUSE_GENERIC_LIST_EXTENSIONS
2557 long wxListMainWindow::GetMode() const
2562 void wxListMainWindow::CalculatePositions()
2564 if (!m_lines
.First()) return;
2566 wxClientDC
dc( this );
2567 dc
.SetFont( GetFont() );
2569 int iconSpacing
= 0;
2570 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2571 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2573 // we take the first line (which also can be an icon or
2574 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2575 // measure the size of the line
2579 int lineSpacing
= 0;
2581 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2582 line
->CalculateSize( &dc
, iconSpacing
);
2584 line
->GetSize( dummy
, lineSpacing
);
2587 int clientWidth
= 0;
2588 int clientHeight
= 0;
2590 if (m_mode
& wxLC_REPORT
)
2594 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2595 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2596 #if wxUSE_GENERIC_LIST_EXTENSIONS
2597 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2599 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2601 GetClientSize( &clientWidth
, &clientHeight
);
2603 wxNode
* node
= m_lines
.First();
2604 int entireWidth
= 0 ;
2607 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2608 line
->CalculateSize( &dc
, iconSpacing
);
2609 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2611 for (int i
= 0; i
< GetColumnCount(); i
++)
2613 line
->SetColumnPosition( i
, col_x
);
2614 col_x
+= GetColumnWidth( i
);
2616 entireWidth
= wxMax( entireWidth
, col_x
) ;
2617 #if wxUSE_GENERIC_LIST_EXTENSIONS
2618 line
->SetPosition( &dc
, x
, y
, col_x
);
2620 y
+= lineSpacing
; // one pixel blank line between items
2621 node
= node
->Next();
2623 m_visibleLines
= clientHeight
/ lineSpacing
;
2624 #if wxUSE_GENERIC_LIST_EXTENSIONS
2625 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2630 // at first we try without any scrollbar. if the items don't
2631 // fit into the window, we recalculate after subtracting an
2632 // approximated 15 pt for the horizontal scrollbar
2634 GetSize( &clientWidth
, &clientHeight
);
2635 clientHeight
-= 4; // sunken frame
2637 int entireWidth
= 0;
2639 for (int tries
= 0; tries
< 2; tries
++)
2646 int m_currentVisibleLines
= 0;
2647 wxNode
*node
= m_lines
.First();
2650 m_currentVisibleLines
++;
2651 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2652 line
->CalculateSize( &dc
, iconSpacing
);
2653 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2654 line
->GetSize( lineWidth
, lineHeight
);
2655 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2657 if (m_currentVisibleLines
> m_visibleLines
)
2658 m_visibleLines
= m_currentVisibleLines
;
2659 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2661 m_currentVisibleLines
= 0;
2664 entireWidth
+= maxWidth
+6;
2667 node
= node
->Next();
2668 if (!node
) entireWidth
+= maxWidth
;
2669 if ((tries
== 0) && (entireWidth
> clientWidth
))
2671 clientHeight
-= 15; // scrollbar height
2673 m_currentVisibleLines
= 0;
2676 if (!node
) tries
= 1; // everything fits, no second try required
2680 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2681 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2685 void wxListMainWindow::RealizeChanges( void )
2689 wxNode
*node
= m_lines
.First();
2690 if (node
) m_current
= (wxListLineData
*)node
->Data();
2694 FocusLine( m_current
);
2695 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2699 long wxListMainWindow::GetNextItem( long item
,
2700 int WXUNUSED(geometry
),
2704 max
= GetItemCount();
2705 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2706 _T("invalid listctrl index in GetNextItem()") );
2708 // notice that we start with the next item (or the first one if item == -1)
2709 // and this is intentional to allow writing a simple loop to iterate over
2710 // all selected items
2714 // this is not an error because the index was ok initially, just no
2719 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2722 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2723 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2725 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2731 node
= node
->Next();
2737 void wxListMainWindow::DeleteItem( long index
)
2740 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2743 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2744 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2746 m_lines
.DeleteNode( node
);
2750 void wxListMainWindow::DeleteColumn( int col
)
2752 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2753 wxT("attempting to delete inexistent column in wxListView") );
2756 wxNode
*node
= m_columns
.Nth( col
);
2757 if (node
) m_columns
.DeleteNode( node
);
2760 void wxListMainWindow::DeleteAllItems()
2763 m_current
= (wxListLineData
*) NULL
;
2765 // to make the deletion of all items faster, we don't send the
2766 // notifications in this case: this is compatible with wxMSW and
2767 // documented in DeleteAllItems() description
2769 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2770 event
.SetEventObject( GetParent() );
2771 GetParent()->GetEventHandler()->ProcessEvent( event
);
2776 void wxListMainWindow::DeleteEverything()
2783 void wxListMainWindow::EnsureVisible( long index
)
2785 // We have to call this here because the label in
2786 // question might just have been added and no screen
2787 // update taken place.
2788 if (m_dirty
) wxYield();
2790 wxListLineData
*oldCurrent
= m_current
;
2791 m_current
= (wxListLineData
*) NULL
;
2792 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2793 if (node
) m_current
= (wxListLineData
*)node
->Data();
2794 if (m_current
) MoveToFocus();
2795 m_current
= oldCurrent
;
2798 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2802 if (pos
< 0) pos
= 0;
2803 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2806 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2808 line
->GetText( 0, s
);
2809 if (s
== tmp
) return pos
;
2810 node
= node
->Next();
2816 long wxListMainWindow::FindItem(long start
, long data
)
2819 if (pos
< 0) pos
= 0;
2820 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2823 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2825 line
->GetItem( 0, item
);
2826 if (item
.m_data
== data
) return pos
;
2827 node
= node
->Next();
2833 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2835 wxNode
*node
= m_lines
.First();
2839 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2840 long ret
= line
->IsHit( x
, y
);
2846 node
= node
->Next();
2852 void wxListMainWindow::InsertItem( wxListItem
&item
)
2856 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2857 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2858 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2859 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2861 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2863 if (m_mode
& wxLC_REPORT
)
2865 line
->InitItems( GetColumnCount() );
2866 item
.m_width
= GetColumnWidth( 0 )-3;
2870 line
->InitItems( 1 );
2873 line
->SetItem( 0, item
);
2874 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2876 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2877 if (node
) m_lines
.Insert( node
, line
);
2881 m_lines
.Append( line
);
2885 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2888 if (m_mode
& wxLC_REPORT
)
2890 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2891 wxListHeaderData
*column
= new wxListHeaderData( item
);
2892 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2894 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2896 m_columns
.Insert( node
, column
);
2900 m_columns
.Append( column
);
2905 wxListCtrlCompare list_ctrl_compare_func_2
;
2906 long list_ctrl_compare_data
;
2908 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2910 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2911 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2913 line1
->GetItem( 0, item
);
2914 long data1
= item
.m_data
;
2915 line2
->GetItem( 0, item
);
2916 long data2
= item
.m_data
;
2917 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2920 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2922 list_ctrl_compare_func_2
= fn
;
2923 list_ctrl_compare_data
= data
;
2924 m_lines
.Sort( list_ctrl_compare_func_1
);
2928 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2930 wxScrolledWindow::OnScroll( event
) ;
2931 #if wxUSE_GENERIC_LIST_EXTENSIONS
2933 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2935 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2938 lc
->m_headerWin
->Refresh() ;
2940 lc
->m_headerWin
->MacUpdateImmediately() ;
2947 // -------------------------------------------------------------------------------------
2949 // -------------------------------------------------------------------------------------
2951 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2953 wxListItem::wxListItem()
2962 m_format
= wxLIST_FORMAT_CENTRE
;
2968 void wxListItem::Clear()
2977 m_format
= wxLIST_FORMAT_CENTRE
;
2979 m_text
= wxEmptyString
;
2981 if (m_attr
) delete m_attr
;
2985 void wxListItem::ClearAttributes()
2987 if (m_attr
) delete m_attr
;
2991 // -------------------------------------------------------------------------------------
2993 // -------------------------------------------------------------------------------------
2995 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
2997 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
2998 wxNotifyEvent( commandType
, id
)
3004 m_cancelled
= FALSE
;
3009 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3011 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3013 wxNotifyEvent::CopyObject(object_dest
);
3015 obj
->m_code
= m_code
;
3016 obj
->m_itemIndex
= m_itemIndex
;
3017 obj
->m_oldItemIndex
= m_oldItemIndex
;
3019 obj
->m_cancelled
= m_cancelled
;
3020 obj
->m_pointDrag
= m_pointDrag
;
3021 obj
->m_item
.m_mask
= m_item
.m_mask
;
3022 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3023 obj
->m_item
.m_col
= m_item
.m_col
;
3024 obj
->m_item
.m_state
= m_item
.m_state
;
3025 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3026 obj
->m_item
.m_text
= m_item
.m_text
;
3027 obj
->m_item
.m_image
= m_item
.m_image
;
3028 obj
->m_item
.m_data
= m_item
.m_data
;
3029 obj
->m_item
.m_format
= m_item
.m_format
;
3030 obj
->m_item
.m_width
= m_item
.m_width
;
3032 if ( m_item
.HasAttributes() )
3034 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3038 // -------------------------------------------------------------------------------------
3040 // -------------------------------------------------------------------------------------
3042 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3044 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3045 EVT_SIZE (wxListCtrl::OnSize
)
3046 EVT_IDLE (wxListCtrl::OnIdle
)
3049 wxListCtrl::wxListCtrl()
3051 m_imageListNormal
= (wxImageList
*) NULL
;
3052 m_imageListSmall
= (wxImageList
*) NULL
;
3053 m_imageListState
= (wxImageList
*) NULL
;
3054 m_mainWin
= (wxListMainWindow
*) NULL
;
3055 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3058 wxListCtrl::~wxListCtrl()
3062 bool wxListCtrl::Create(wxWindow
*parent
,
3067 const wxValidator
&validator
,
3068 const wxString
&name
)
3070 m_imageListNormal
= (wxImageList
*) NULL
;
3071 m_imageListSmall
= (wxImageList
*) NULL
;
3072 m_imageListState
= (wxImageList
*) NULL
;
3073 m_mainWin
= (wxListMainWindow
*) NULL
;
3074 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3076 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3078 style
= style
| wxLC_LIST
;
3081 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3084 if (style
& wxSUNKEN_BORDER
)
3085 style
-= wxSUNKEN_BORDER
;
3087 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3089 if (HasFlag(wxLC_REPORT
))
3091 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3092 if (HasFlag(wxLC_NO_HEADER
))
3093 m_headerWin
->Show( FALSE
);
3097 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3100 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
3105 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3107 /* handled in OnIdle */
3109 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3112 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3114 long flag
= GetWindowStyle();
3118 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3119 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3120 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3129 if (flag
& style
) flag
-= style
;
3132 SetWindowStyleFlag( flag
);
3135 void wxListCtrl::SetWindowStyleFlag( long flag
)
3139 m_mainWin
->DeleteEverything();
3143 GetClientSize( &width
, &height
);
3145 m_mainWin
->SetMode( flag
);
3147 if (flag
& wxLC_REPORT
)
3149 if (!HasFlag(wxLC_REPORT
))
3153 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3154 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3155 if (HasFlag(wxLC_NO_HEADER
))
3156 m_headerWin
->Show( FALSE
);
3160 if (flag
& wxLC_NO_HEADER
)
3161 m_headerWin
->Show( FALSE
);
3163 m_headerWin
->Show( TRUE
);
3169 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3171 m_headerWin
->Show( FALSE
);
3176 wxWindow::SetWindowStyleFlag( flag
);
3179 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3181 m_mainWin
->GetColumn( col
, item
);
3185 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3187 m_mainWin
->SetColumn( col
, item
);
3191 int wxListCtrl::GetColumnWidth( int col
) const
3193 return m_mainWin
->GetColumnWidth( col
);
3196 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3198 m_mainWin
->SetColumnWidth( col
, width
);
3202 int wxListCtrl::GetCountPerPage() const
3204 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3207 bool wxListCtrl::GetItem( wxListItem
&info
) const
3209 m_mainWin
->GetItem( info
);
3213 bool wxListCtrl::SetItem( wxListItem
&info
)
3215 m_mainWin
->SetItem( info
);
3219 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3222 info
.m_text
= label
;
3223 info
.m_mask
= wxLIST_MASK_TEXT
;
3224 info
.m_itemId
= index
;
3228 info
.m_image
= imageId
;
3229 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3231 m_mainWin
->SetItem(info
);
3235 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3237 return m_mainWin
->GetItemState( item
, stateMask
);
3240 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3242 m_mainWin
->SetItemState( item
, state
, stateMask
);
3246 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3249 info
.m_image
= image
;
3250 info
.m_mask
= wxLIST_MASK_IMAGE
;
3251 info
.m_itemId
= item
;
3252 m_mainWin
->SetItem( info
);
3256 wxString
wxListCtrl::GetItemText( long item
) const
3259 info
.m_itemId
= item
;
3260 m_mainWin
->GetItem( info
);
3264 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3267 info
.m_mask
= wxLIST_MASK_TEXT
;
3268 info
.m_itemId
= item
;
3270 m_mainWin
->SetItem( info
);
3273 long wxListCtrl::GetItemData( long item
) const
3276 info
.m_itemId
= item
;
3277 m_mainWin
->GetItem( info
);
3281 bool wxListCtrl::SetItemData( long item
, long data
)
3284 info
.m_mask
= wxLIST_MASK_DATA
;
3285 info
.m_itemId
= item
;
3287 m_mainWin
->SetItem( info
);
3291 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3293 m_mainWin
->GetItemRect( item
, rect
);
3297 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3299 m_mainWin
->GetItemPosition( item
, pos
);
3303 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3308 int wxListCtrl::GetItemCount() const
3310 return m_mainWin
->GetItemCount();
3313 int wxListCtrl::GetColumnCount() const
3315 return m_mainWin
->GetColumnCount();
3318 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3320 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3323 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3325 return m_mainWin
->GetItemSpacing( isSmall
);
3328 int wxListCtrl::GetSelectedItemCount() const
3330 return m_mainWin
->GetSelectedItemCount();
3333 wxColour
wxListCtrl::GetTextColour() const
3335 return GetForegroundColour();
3338 void wxListCtrl::SetTextColour(const wxColour
& col
)
3340 SetForegroundColour(col
);
3343 long wxListCtrl::GetTopItem() const
3348 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3350 return m_mainWin
->GetNextItem( item
, geom
, state
);
3353 wxImageList
*wxListCtrl::GetImageList(int which
) const
3355 if (which
== wxIMAGE_LIST_NORMAL
)
3357 return m_imageListNormal
;
3359 else if (which
== wxIMAGE_LIST_SMALL
)
3361 return m_imageListSmall
;
3363 else if (which
== wxIMAGE_LIST_STATE
)
3365 return m_imageListState
;
3367 return (wxImageList
*) NULL
;
3370 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3372 m_mainWin
->SetImageList( imageList
, which
);
3375 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3380 bool wxListCtrl::DeleteItem( long item
)
3382 m_mainWin
->DeleteItem( item
);
3386 bool wxListCtrl::DeleteAllItems()
3388 m_mainWin
->DeleteAllItems();
3392 bool wxListCtrl::DeleteAllColumns()
3394 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3400 void wxListCtrl::ClearAll()
3402 m_mainWin
->DeleteEverything();
3405 bool wxListCtrl::DeleteColumn( int col
)
3407 m_mainWin
->DeleteColumn( col
);
3411 void wxListCtrl::Edit( long item
)
3413 m_mainWin
->Edit( item
);
3416 bool wxListCtrl::EnsureVisible( long item
)
3418 m_mainWin
->EnsureVisible( item
);
3422 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3424 return m_mainWin
->FindItem( start
, str
, partial
);
3427 long wxListCtrl::FindItem( long start
, long data
)
3429 return m_mainWin
->FindItem( start
, data
);
3432 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3433 int WXUNUSED(direction
))
3438 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3440 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3443 long wxListCtrl::InsertItem( wxListItem
& info
)
3445 m_mainWin
->InsertItem( info
);
3446 return info
.m_itemId
;
3449 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3452 info
.m_text
= label
;
3453 info
.m_mask
= wxLIST_MASK_TEXT
;
3454 info
.m_itemId
= index
;
3455 return InsertItem( info
);
3458 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3461 info
.m_mask
= wxLIST_MASK_IMAGE
;
3462 info
.m_image
= imageIndex
;
3463 info
.m_itemId
= index
;
3464 return InsertItem( info
);
3467 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3470 info
.m_text
= label
;
3471 info
.m_image
= imageIndex
;
3472 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3473 info
.m_itemId
= index
;
3474 return InsertItem( info
);
3477 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3479 wxASSERT( m_headerWin
);
3480 m_mainWin
->InsertColumn( col
, item
);
3481 m_headerWin
->Refresh();
3486 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3487 int format
, int width
)
3490 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3491 item
.m_text
= heading
;
3494 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3495 item
.m_width
= width
;
3497 item
.m_format
= format
;
3499 return InsertColumn( col
, item
);
3502 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3508 // fn is a function which takes 3 long arguments: item1, item2, data.
3509 // item1 is the long data associated with a first item (NOT the index).
3510 // item2 is the long data associated with a second item (NOT the index).
3511 // data is the same value as passed to SortItems.
3512 // The return value is a negative number if the first item should precede the second
3513 // item, a positive number of the second item should precede the first,
3514 // or zero if the two items are equivalent.
3515 // data is arbitrary data to be passed to the sort function.
3517 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3519 m_mainWin
->SortItems( fn
, data
);
3523 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3525 if (!m_mainWin
->m_dirty
) return;
3529 GetClientSize( &cw
, &ch
);
3536 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3538 m_headerWin
->GetPosition( &x
, &y
);
3539 m_headerWin
->GetSize( &w
, &h
);
3540 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3541 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3543 m_mainWin
->GetPosition( &x
, &y
);
3544 m_mainWin
->GetSize( &w
, &h
);
3545 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3546 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3550 m_mainWin
->GetPosition( &x
, &y
);
3551 m_mainWin
->GetSize( &w
, &h
);
3552 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3553 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3556 m_mainWin
->CalculatePositions();
3557 m_mainWin
->RealizeChanges();
3558 m_mainWin
->m_dirty
= FALSE
;
3559 m_mainWin
->Refresh();
3562 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3564 if ( !wxWindow::SetBackgroundColour( colour
) )
3569 m_mainWin
->SetBackgroundColour( colour
);
3570 m_mainWin
->m_dirty
= TRUE
;
3575 // m_headerWin->SetBackgroundColour( colour );
3581 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3583 if ( !wxWindow::SetForegroundColour( colour
) )
3588 m_mainWin
->SetForegroundColour( colour
);
3589 m_mainWin
->m_dirty
= TRUE
;
3594 m_headerWin
->SetForegroundColour( colour
);
3600 bool wxListCtrl::SetFont( const wxFont
&font
)
3602 if ( !wxWindow::SetFont( font
) )
3607 m_mainWin
->SetFont( font
);
3608 m_mainWin
->m_dirty
= TRUE
;
3613 m_headerWin
->SetFont( font
);
3619 #if wxUSE_DRAG_AND_DROP
3621 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3623 m_mainWin
->SetDropTarget( dropTarget
);
3626 wxDropTarget
*wxListCtrl::GetDropTarget() const
3628 return m_mainWin
->GetDropTarget();
3631 #endif // wxUSE_DRAG_AND_DROP
3633 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3635 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3638 wxColour
wxListCtrl::GetBackgroundColour() const
3640 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3643 wxColour
wxListCtrl::GetForegroundColour() const
3645 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3648 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3650 return m_mainWin
->PopupMenu( menu
, x
, y
);
3653 void wxListCtrl::SetFocus()
3655 /* The test in window.cpp fails as we are a composite
3656 window, so it checks against "this", but not m_mainWin. */
3657 if ( FindFocus() != this )
3658 m_mainWin
->SetFocus();