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 0
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 m_bound_all
.height
= m_spacing
+13;
624 wxNode
*node
= m_items
.First();
627 wxListItemData
*item
= (wxListItemData
*)node
->Data();
628 wxString s
= item
->GetText();
630 dc
->GetTextExtent( s
, &lw
, &lh
);
631 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
637 wxNode
*node
= m_items
.First();
640 wxListItemData
*item
= (wxListItemData
*)node
->Data();
641 wxString s
= item
->GetText();
643 dc
->GetTextExtent( s
, &lw
, &lh
);
644 m_bound_all
.width
= lw
;
645 m_bound_all
.height
= lh
;
646 if (item
->HasImage())
655 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
656 m_bound_all
.width
+= 4 + w
;
657 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
664 m_bound_all
.width
= 0;
665 m_bound_all
.height
= 0;
666 wxNode
*node
= m_items
.First();
669 wxListItemData
*item
= (wxListItemData
*)node
->Data();
672 if (s
.IsNull()) s
= "H";
674 dc
->GetTextExtent( s
, &lw
, &lh
);
675 if (lh
< 15) lh
= 15;
676 item
->SetSize( item
->GetWidth(), lh
);
677 m_bound_all
.width
+= lw
;
678 m_bound_all
.height
= lh
;
686 void wxListLineData::SetPosition( wxDC
*dc
, int x
, int y
, int window_width
)
694 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
695 AssignRect( m_bound_label
, 0, 0, 0, 0 );
696 AssignRect( m_bound_hilight
, m_bound_all
);
697 wxNode
*node
= m_items
.First();
700 wxListItemData
*item
= (wxListItemData
*)node
->Data();
701 if (item
->HasImage())
703 wxListItemData
*item
= (wxListItemData
*)node
->Data();
706 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
707 m_bound_icon
.x
= m_bound_all
.x
+ (m_spacing
/2) - (w
/2);
708 m_bound_icon
.y
= m_bound_all
.y
+ m_spacing
- h
- 5;
709 m_bound_icon
.width
= w
;
710 m_bound_icon
.height
= h
;
711 if (!item
->HasText())
713 AssignRect( m_bound_hilight
, m_bound_icon
);
714 m_bound_hilight
.x
-= 5;
715 m_bound_hilight
.y
-= 5;
716 m_bound_hilight
.width
+= 9;
717 m_bound_hilight
.height
+= 9;
725 dc
->GetTextExtent( s
, &lw
, &lh
);
726 if (m_bound_all
.width
> m_spacing
)
727 m_bound_label
.x
= m_bound_all
.x
;
729 m_bound_label
.x
= m_bound_all
.x
+ (m_spacing
/2) - lw
/2;
730 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
- lh
;
731 m_bound_label
.width
= lw
;
732 m_bound_label
.height
= lh
;
733 AssignRect( m_bound_hilight
, m_bound_label
);
734 m_bound_hilight
.x
-= 2;
735 m_bound_hilight
.y
-= 2;
736 m_bound_hilight
.width
+= 4;
737 m_bound_hilight
.height
+= 4;
744 AssignRect( m_bound_label
, m_bound_all
);
747 m_bound_all
.width
+= 4;
748 m_bound_all
.height
+= 3;
749 AssignRect( m_bound_hilight
, m_bound_all
);
750 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
751 wxNode
*node
= m_items
.First();
754 wxListItemData
*item
= (wxListItemData
*)node
->Data();
755 if (item
->HasImage())
757 m_bound_icon
.x
= m_bound_all
.x
+ 2;
758 m_bound_icon
.y
= m_bound_all
.y
+ 2;
761 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
762 m_bound_icon
.width
= w
;
763 m_bound_icon
.height
= h
;
764 m_bound_label
.x
+= 4 + w
;
765 m_bound_label
.width
-= 4 + w
;
773 dc
->GetTextExtent( "H", &lw
, &lh
);
774 if (lh
< 15) lh
= 15;
777 m_bound_all
.height
= lh
+3;
778 m_bound_all
.width
= window_width
;
779 AssignRect( m_bound_hilight
, m_bound_all
);
780 AssignRect( m_bound_label
, m_bound_all
);
781 AssignRect( m_bound_icon
, 0, 0, 0, 0 );
782 wxNode
*node
= m_items
.First();
785 wxListItemData
*item
= (wxListItemData
*)node
->Data();
788 if (s
.IsEmpty()) s
= wxT("H");
790 dc
->GetTextExtent( s
, &lw
, &lh
);
791 if (lh
< 15) lh
= 15;
792 m_bound_label
.width
= lw
;
793 m_bound_label
.height
= lh
;
794 if (item
->HasImage())
796 m_bound_icon
.x
= m_bound_all
.x
+ 2;
797 m_bound_icon
.y
= m_bound_all
.y
+ 2;
800 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
801 m_bound_icon
.width
= w
;
802 m_bound_icon
.height
= h
;
803 m_bound_label
.x
+= 4 + w
;
811 void wxListLineData::SetColumnPosition( int index
, int x
)
813 wxNode
*node
= m_items
.Nth( (size_t)index
);
816 wxListItemData
*item
= (wxListItemData
*)node
->Data();
817 item
->SetPosition( x
, m_bound_all
.y
+1 );
821 void wxListLineData::GetSize( int &width
, int &height
)
823 width
= m_bound_all
.width
;
824 height
= m_bound_all
.height
;
827 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
831 width
= m_bound_all
.width
;
832 height
= m_bound_all
.height
;
835 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
839 width
= m_bound_label
.width
;
840 height
= m_bound_label
.height
;
843 void wxListLineData::GetRect( wxRect
&rect
)
845 AssignRect( rect
, m_bound_all
);
848 long wxListLineData::IsHit( int x
, int y
)
850 wxNode
*node
= m_items
.First();
853 wxListItemData
*item
= (wxListItemData
*)node
->Data();
854 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
855 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
856 // if (!(item->HasImage() || item->HasText())) return 0;
858 // if there is no icon or text = empty
859 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
863 void wxListLineData::InitItems( int num
)
865 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
868 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
870 wxNode
*node
= m_items
.Nth( index
);
873 wxListItemData
*item
= (wxListItemData
*)node
->Data();
874 item
->SetItem( info
);
878 void wxListLineData::GetItem( int index
, wxListItem
&info
)
881 wxNode
*node
= m_items
.Nth( i
);
884 wxListItemData
*item
= (wxListItemData
*)node
->Data();
885 item
->GetItem( info
);
889 void wxListLineData::GetText( int index
, wxString
&s
)
892 wxNode
*node
= m_items
.Nth( i
);
896 wxListItemData
*item
= (wxListItemData
*)node
->Data();
901 void wxListLineData::SetText( int index
, const wxString s
)
904 wxNode
*node
= m_items
.Nth( i
);
907 wxListItemData
*item
= (wxListItemData
*)node
->Data();
912 int wxListLineData::GetImage( int index
)
915 wxNode
*node
= m_items
.Nth( i
);
918 wxListItemData
*item
= (wxListItemData
*)node
->Data();
919 return item
->GetImage();
924 void wxListLineData::SetAttributes(wxDC
*dc
,
925 const wxListItemAttr
*attr
,
926 const wxColour
& colText
,
930 // don't use foregroud colour for drawing highlighted items - this might
931 // make them completely invisible (and there is no way to do bit
932 // arithmetics on wxColour, unfortunately)
933 if ( !hilight
&& attr
&& attr
->HasTextColour() )
935 dc
->SetTextForeground(attr
->GetTextColour());
939 dc
->SetTextForeground(colText
);
942 if ( attr
&& attr
->HasFont() )
944 dc
->SetFont(attr
->GetFont());
952 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
956 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
957 wxCoord dev_w
= m_bound_all
.width
;
958 wxCoord dev_h
= m_bound_all
.height
;
960 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
963 wxWindow
*listctrl
= m_owner
->GetParent();
965 // default foreground colour
969 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
973 colText
= listctrl
->GetForegroundColour();
977 wxFont font
= listctrl
->GetFont();
979 // VZ: currently we set the colours/fonts only once, but like this (i.e.
980 // using SetAttributes() inside the loop), it will be trivial to
981 // customize the subitems (in report mode) too.
982 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
983 wxListItemAttr
*attr
= item
->GetAttributes();
984 SetAttributes(dc
, attr
, colText
, font
, hilight
);
986 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
987 if ( paintBG
|| hasBgCol
)
991 dc
->SetBrush( * m_hilightBrush
);
996 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
998 dc
->SetBrush( * wxWHITE_BRUSH
);
1001 dc
->SetPen( * wxTRANSPARENT_PEN
);
1002 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1003 m_bound_hilight
.width
, m_bound_hilight
.height
);
1006 if (m_mode
== wxLC_REPORT
)
1008 wxNode
*node
= m_items
.First();
1011 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1012 int x
= item
->GetX();
1013 if (item
->HasImage())
1016 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1017 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1018 x
+= item
->GetX() + 5;
1020 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1021 if (item
->HasText())
1023 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1025 dc
->DestroyClippingRegion();
1026 node
= node
->Next();
1031 wxNode
*node
= m_items
.First();
1034 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1035 if (item
->HasImage())
1037 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1039 if (item
->HasText())
1041 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1047 void wxListLineData::Hilight( bool on
)
1049 if (on
== m_hilighted
) return;
1052 m_owner
->SelectLine( this );
1054 m_owner
->DeselectLine( this );
1057 void wxListLineData::ReverseHilight( void )
1059 m_hilighted
= !m_hilighted
;
1061 m_owner
->SelectLine( this );
1063 m_owner
->DeselectLine( this );
1066 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1070 dc
->SetPen( * wxBLACK_PEN
);
1071 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1072 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1073 m_bound_hilight
.width
, m_bound_hilight
.height
);
1077 void wxListLineData::Draw( wxDC
*dc
)
1079 DoDraw( dc
, m_hilighted
, m_hilighted
);
1082 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1084 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1085 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1088 bool wxListLineData::IsHilighted( void )
1093 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1098 dest
.height
= height
;
1101 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1105 dest
.width
= source
.width
;
1106 dest
.height
= source
.height
;
1109 //-----------------------------------------------------------------------------
1110 // wxListHeaderWindow
1111 //-----------------------------------------------------------------------------
1113 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1115 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1116 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1117 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1118 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1121 wxListHeaderWindow::wxListHeaderWindow( void )
1123 m_owner
= (wxListMainWindow
*) NULL
;
1124 m_currentCursor
= (wxCursor
*) NULL
;
1125 m_resizeCursor
= (wxCursor
*) NULL
;
1126 m_isDragging
= FALSE
;
1129 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1130 const wxPoint
&pos
, const wxSize
&size
,
1131 long style
, const wxString
&name
) :
1132 wxWindow( win
, id
, pos
, size
, style
, name
)
1135 // m_currentCursor = wxSTANDARD_CURSOR;
1136 m_currentCursor
= (wxCursor
*) NULL
;
1137 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1138 m_isDragging
= FALSE
;
1139 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1142 wxListHeaderWindow::~wxListHeaderWindow( void )
1144 delete m_resizeCursor
;
1147 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1149 const int m_corner
= 1;
1151 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1153 dc
->SetPen( *wxBLACK_PEN
);
1154 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1155 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1157 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1160 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1161 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1163 dc
->SetPen( *wxWHITE_PEN
);
1164 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1165 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1166 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1167 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1170 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1172 wxPaintDC
dc( this );
1174 #if wxUSE_GENERIC_LIST_EXTENSIONS
1175 if ( m_owner
->GetMode() & wxLC_REPORT
)
1180 m_owner
->GetScrollPixelsPerUnit( &xpix
, &ypix
) ;
1181 m_owner
->ViewStart( &x
, &y
) ;
1182 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1187 dc
.SetFont( GetFont() );
1193 GetClientSize( &w
, &h
);
1195 dc
.SetBackgroundMode(wxTRANSPARENT
);
1196 dc
.SetTextForeground( *wxBLACK
);
1198 // do *not* use the listctrl colour for headers - one day we will have a
1199 // function to set it separately
1203 int numColumns
= m_owner
->GetColumnCount();
1205 for (int i
= 0; i
< numColumns
; i
++)
1207 m_owner
->GetColumn( i
, item
);
1208 int cw
= item
.m_width
-2;
1209 #if wxUSE_GENERIC_LIST_EXTENSIONS
1210 if ((i
+1 == numColumns
) || ( dc
.LogicalToDeviceX(x
+item
.m_width
) > w
-5))
1211 cw
= dc
.DeviceToLogicalX(w
)-x
-1;
1213 if ((i
+1 == numColumns
) || (x
+item
.m_width
> w
-5))
1216 dc
.SetPen( *wxWHITE_PEN
);
1218 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1219 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1220 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1221 dc
.DestroyClippingRegion();
1223 #if wxUSE_GENERIC_LIST_EXTENSIONS
1224 if (dc
.LogicalToDeviceX(x
) > w
+5) break;
1232 void wxListHeaderWindow::DrawCurrent()
1234 int x1
= m_currentX
;
1236 int x2
= m_currentX
-1;
1239 m_owner
->GetClientSize( &dummy
, &y2
);
1240 ClientToScreen( &x1
, &y1
);
1241 m_owner
->ClientToScreen( &x2
, &y2
);
1244 dc
.SetLogicalFunction( wxINVERT
);
1245 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1246 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1248 dc
.DrawLine( x1
, y1
, x2
, y2
);
1250 dc
.SetLogicalFunction( wxCOPY
);
1252 dc
.SetPen( wxNullPen
);
1253 dc
.SetBrush( wxNullBrush
);
1256 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1258 wxCoord x
= (wxCoord
)event
.GetX();
1259 wxCoord y
= (wxCoord
)event
.GetY();
1263 if (event
.ButtonUp())
1266 m_isDragging
= FALSE
;
1267 m_owner
->SetColumnWidth( m_column
, m_currentX
-m_minX
);
1273 GetClientSize( &size_x
, & dummy
);
1277 m_currentX
= m_minX
+7;
1278 if (m_currentX
> size_x
-7) m_currentX
= size_x
-7;
1285 bool hit_border
= FALSE
;
1287 for (int j
= 0; j
< m_owner
->GetColumnCount(); j
++)
1289 xpos
+= m_owner
->GetColumnWidth( j
);
1291 if ((abs(x
-xpos
) < 3) && (y
< 22) && (m_column
< m_owner
->GetColumnCount()-1))
1303 if (event
.LeftDown())
1307 m_isDragging
= TRUE
;
1315 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, GetParent()->GetId() );
1316 le
.SetEventObject( GetParent() );
1317 le
.m_col
= m_column
;
1318 GetParent()->GetEventHandler()->ProcessEvent( le
);
1327 if (m_currentCursor
== wxSTANDARD_CURSOR
) SetCursor( * m_resizeCursor
);
1328 m_currentCursor
= m_resizeCursor
;
1332 if (m_currentCursor
!= wxSTANDARD_CURSOR
) SetCursor( * wxSTANDARD_CURSOR
);
1333 m_currentCursor
= wxSTANDARD_CURSOR
;
1338 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1340 m_owner
->SetFocus();
1343 //-----------------------------------------------------------------------------
1344 // wxListRenameTimer (internal)
1345 //-----------------------------------------------------------------------------
1347 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1352 void wxListRenameTimer::Notify()
1354 m_owner
->OnRenameTimer();
1357 //-----------------------------------------------------------------------------
1358 // wxListTextCtrl (internal)
1359 //-----------------------------------------------------------------------------
1361 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1363 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1364 EVT_CHAR (wxListTextCtrl::OnChar
)
1365 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1368 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1369 const wxWindowID id
,
1372 wxListMainWindow
*owner
,
1373 const wxString
&value
,
1377 const wxValidator
& validator
,
1378 const wxString
&name
)
1379 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1384 (*m_accept
) = FALSE
;
1386 m_startValue
= value
;
1389 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1391 if (event
.m_keyCode
== WXK_RETURN
)
1394 (*m_res
) = GetValue();
1396 if (!wxPendingDelete
.Member(this))
1397 wxPendingDelete
.Append(this);
1399 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1400 m_owner
->OnRenameAccept();
1404 if (event
.m_keyCode
== WXK_ESCAPE
)
1406 (*m_accept
) = FALSE
;
1409 if (!wxPendingDelete
.Member(this))
1410 wxPendingDelete
.Append(this);
1418 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1420 if (!wxPendingDelete
.Member(this))
1421 wxPendingDelete
.Append(this);
1423 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1424 m_owner
->OnRenameAccept();
1427 //-----------------------------------------------------------------------------
1429 //-----------------------------------------------------------------------------
1431 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1433 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1434 EVT_PAINT (wxListMainWindow::OnPaint
)
1435 EVT_SIZE (wxListMainWindow::OnSize
)
1436 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1437 EVT_CHAR (wxListMainWindow::OnChar
)
1438 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1439 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1440 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1441 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1444 wxListMainWindow::wxListMainWindow()
1447 m_lines
.DeleteContents( TRUE
);
1448 m_columns
.DeleteContents( TRUE
);
1449 m_current
= (wxListLineData
*) NULL
;
1451 m_hilightBrush
= (wxBrush
*) NULL
;
1455 m_small_image_list
= (wxImageList
*) NULL
;
1456 m_normal_image_list
= (wxImageList
*) NULL
;
1457 m_small_spacing
= 30;
1458 m_normal_spacing
= 40;
1461 m_lastOnSame
= FALSE
;
1462 m_renameTimer
= new wxListRenameTimer( this );
1463 m_isCreated
= FALSE
;
1467 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1470 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1471 const wxPoint
&pos
, const wxSize
&size
,
1472 long style
, const wxString
&name
) :
1473 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1476 m_lines
.DeleteContents( TRUE
);
1477 m_columns
.DeleteContents( TRUE
);
1478 m_current
= (wxListLineData
*) NULL
;
1481 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1482 m_small_image_list
= (wxImageList
*) NULL
;
1483 m_normal_image_list
= (wxImageList
*) NULL
;
1484 m_small_spacing
= 30;
1485 m_normal_spacing
= 40;
1488 m_isCreated
= FALSE
;
1492 if (m_mode
& wxLC_REPORT
)
1494 #if wxUSE_GENERIC_LIST_EXTENSIONS
1506 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1509 m_lastOnSame
= FALSE
;
1510 m_renameTimer
= new wxListRenameTimer( this );
1511 m_renameAccept
= FALSE
;
1513 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1516 wxListMainWindow::~wxListMainWindow()
1520 if (m_hilightBrush
) delete m_hilightBrush
;
1522 delete m_renameTimer
;
1525 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1527 if (m_dirty
) return;
1535 line
->GetExtent( x
, y
, w
, h
);
1536 CalcScrolledPosition( x
, y
, &x
, &y
);
1537 wxRect
rect( x
, y
, w
, h
);
1538 Refresh( TRUE
, &rect
);
1541 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1543 // Note: a wxPaintDC must be constructed even if no drawing is
1544 // done (a Windows requirement).
1545 wxPaintDC
dc( this );
1548 if (m_dirty
) return;
1550 if (m_lines
.GetCount() == 0) return;
1554 dc
.SetFont( GetFont() );
1556 if (m_mode
& wxLC_REPORT
)
1558 int lineSpacing
= 0;
1559 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
1561 line
->GetSize( dummy
, lineSpacing
);
1564 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1566 wxNode
*node
= m_lines
.Nth( y_s
/ lineSpacing
);
1567 for (int i
= 0; i
< m_visibleLines
+2; i
++)
1571 line
= (wxListLineData
*)node
->Data();
1573 node
= node
->Next();
1578 wxNode
*node
= m_lines
.First();
1581 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1583 node
= node
->Next();
1587 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1592 void wxListMainWindow::HilightAll( bool on
)
1594 wxNode
*node
= m_lines
.First();
1597 wxListLineData
*line
= (wxListLineData
*)node
->Data();
1598 if (line
->IsHilighted() != on
)
1600 line
->Hilight( on
);
1601 RefreshLine( line
);
1603 node
= node
->Next();
1607 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1609 wxListEvent
le( command
, GetParent()->GetId() );
1610 le
.SetEventObject( GetParent() );
1611 le
.m_itemIndex
= GetIndexOfLine( line
);
1612 line
->GetItem( 0, le
.m_item
);
1613 GetParent()->GetEventHandler()->ProcessEvent( le
);
1614 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1617 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1619 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1622 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1624 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1627 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1629 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1632 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1634 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1637 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1639 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1644 void wxListMainWindow::EditLabel( long item
)
1646 wxNode
*node
= m_lines
.Nth( (size_t)item
);
1647 wxCHECK_RET( node
, wxT("wrong index in wxListCtrl::Edit()") );
1649 m_currentEdit
= (wxListLineData
*) node
->Data();
1651 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1652 le
.SetEventObject( GetParent() );
1653 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1654 m_currentEdit
->GetItem( 0, le
.m_item
);
1655 GetParent()->GetEventHandler()->ProcessEvent( le
);
1657 if (!le
.IsAllowed())
1660 // We have to call this here because the label in
1661 // question might just have been added and no screen
1662 // update taken place.
1663 if (m_dirty
) wxYield();
1666 m_currentEdit
->GetText( 0, s
);
1671 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1673 wxClientDC
dc(this);
1675 x
= dc
.LogicalToDeviceX( x
);
1676 y
= dc
.LogicalToDeviceY( y
);
1678 wxListTextCtrl
*text
= new wxListTextCtrl(
1679 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1683 void wxListMainWindow::OnRenameTimer()
1685 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1687 Edit( m_lines
.IndexOf( m_current
) );
1690 void wxListMainWindow::OnRenameAccept()
1692 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1693 le
.SetEventObject( GetParent() );
1694 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1695 m_currentEdit
->GetItem( 0, le
.m_item
);
1696 le
.m_item
.m_text
= m_renameRes
;
1697 GetParent()->GetEventHandler()->ProcessEvent( le
);
1699 if (!le
.IsAllowed()) return;
1702 info
.m_mask
= wxLIST_MASK_TEXT
;
1703 info
.m_itemId
= le
.m_itemIndex
;
1704 info
.m_text
= m_renameRes
;
1705 info
.SetTextColour(le
.m_item
.GetTextColour());
1709 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1711 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1713 if (!m_current
) return;
1714 if (m_dirty
) return;
1715 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1717 wxClientDC
dc(this);
1719 wxCoord x
= dc
.DeviceToLogicalX( (wxCoord
)event
.GetX() );
1720 wxCoord y
= dc
.DeviceToLogicalY( (wxCoord
)event
.GetY() );
1722 /* Did we actually hit an item ? */
1724 wxNode
*node
= m_lines
.First();
1725 wxListLineData
*line
= (wxListLineData
*) NULL
;
1728 line
= (wxListLineData
*)node
->Data();
1729 hitResult
= line
->IsHit( x
, y
);
1730 if (hitResult
) break;
1731 line
= (wxListLineData
*) NULL
;
1732 node
= node
->Next();
1735 if (event
.Dragging())
1737 if (m_dragCount
== 0)
1738 m_dragStart
= wxPoint(x
,y
);
1742 if (m_dragCount
!= 3) return;
1744 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1745 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1747 wxListEvent
le( command
, GetParent()->GetId() );
1748 le
.SetEventObject( GetParent() );
1749 le
.m_pointDrag
= m_dragStart
;
1750 GetParent()->GetEventHandler()->ProcessEvent( le
);
1761 bool forceClick
= FALSE
;
1762 if (event
.ButtonDClick())
1764 m_renameTimer
->Stop();
1765 m_lastOnSame
= FALSE
;
1767 if ( line
== m_lineBeforeLastClicked
)
1771 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1777 // the first click was on another item, so don't interpret this as
1778 // a double click, but as a simple click instead
1783 if (event
.LeftUp() && m_lastOnSame
)
1786 if ((line
== m_current
) &&
1787 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1788 (m_mode
& wxLC_EDIT_LABELS
) )
1790 m_renameTimer
->Start( 100, TRUE
);
1792 m_lastOnSame
= FALSE
;
1796 if (event
.RightDown())
1798 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1802 if (event
.MiddleDown())
1804 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1808 if ( event
.LeftDown() || forceClick
)
1810 m_lineBeforeLastClicked
= m_lineLastClicked
;
1811 m_lineLastClicked
= line
;
1814 wxListLineData
*oldCurrent
= m_current
;
1815 if (m_mode
& wxLC_SINGLE_SEL
)
1818 HilightAll( FALSE
);
1819 m_current
->ReverseHilight();
1820 RefreshLine( m_current
);
1824 if (event
.ControlDown())
1827 m_current
->ReverseHilight();
1828 RefreshLine( m_current
);
1830 else if (event
.ShiftDown())
1834 int numOfCurrent
= -1;
1835 node
= m_lines
.First();
1838 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1840 if (test_line
== oldCurrent
) break;
1841 node
= node
->Next();
1845 node
= m_lines
.First();
1848 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1850 if (test_line
== line
) break;
1851 node
= node
->Next();
1854 if (numOfLine
< numOfCurrent
)
1857 numOfLine
= numOfCurrent
;
1861 wxNode
*node
= m_lines
.Nth( numOfCurrent
);
1862 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1864 wxListLineData
*test_line
= (wxListLineData
*)node
->Data();
1865 test_line
->Hilight(TRUE
);
1866 RefreshLine( test_line
);
1867 node
= node
->Next();
1873 HilightAll( FALSE
);
1874 m_current
->ReverseHilight();
1875 RefreshLine( m_current
);
1878 if (m_current
!= oldCurrent
)
1880 RefreshLine( oldCurrent
);
1881 UnfocusLine( oldCurrent
);
1882 FocusLine( m_current
);
1885 // forceClick is only set if the previous click was on another item
1886 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
1892 void wxListMainWindow::MoveToFocus()
1894 if (!m_current
) return;
1900 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1904 GetClientSize( &client_w
, &client_h
);
1906 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1907 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1909 if (m_mode
& wxLC_REPORT
)
1911 if (item_y
-5 < view_y
)
1912 Scroll( -1, (item_y
-5)/m_yScroll
);
1913 if (item_y
+item_h
+5 > view_y
+client_h
)
1914 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
1918 if (item_x
-view_x
< 5)
1919 Scroll( (item_x
-5)/m_xScroll
, -1 );
1920 if (item_x
+item_w
-5 > view_x
+client_w
)
1921 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
1925 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
1927 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
1928 wxListLineData
*oldCurrent
= m_current
;
1929 m_current
= newCurrent
;
1930 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
1931 RefreshLine( m_current
);
1932 RefreshLine( oldCurrent
);
1933 FocusLine( m_current
);
1934 UnfocusLine( oldCurrent
);
1938 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
1940 wxWindow
*parent
= GetParent();
1942 /* we propagate the key event up */
1943 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
1944 ke
.m_shiftDown
= event
.m_shiftDown
;
1945 ke
.m_controlDown
= event
.m_controlDown
;
1946 ke
.m_altDown
= event
.m_altDown
;
1947 ke
.m_metaDown
= event
.m_metaDown
;
1948 ke
.m_keyCode
= event
.m_keyCode
;
1951 ke
.SetEventObject( parent
);
1952 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1957 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
1959 wxWindow
*parent
= GetParent();
1961 /* we send a list_key event up */
1962 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
1963 le
.m_code
= (int)event
.KeyCode();
1964 le
.SetEventObject( parent
);
1965 parent
->GetEventHandler()->ProcessEvent( le
);
1967 /* we propagate the char event up */
1968 wxKeyEvent
ke( wxEVT_CHAR
);
1969 ke
.m_shiftDown
= event
.m_shiftDown
;
1970 ke
.m_controlDown
= event
.m_controlDown
;
1971 ke
.m_altDown
= event
.m_altDown
;
1972 ke
.m_metaDown
= event
.m_metaDown
;
1973 ke
.m_keyCode
= event
.m_keyCode
;
1976 ke
.SetEventObject( parent
);
1977 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
1979 if (event
.KeyCode() == WXK_TAB
)
1981 wxNavigationKeyEvent nevent
;
1982 nevent
.SetWindowChange( event
.ControlDown() );
1983 nevent
.SetDirection( !event
.ShiftDown() );
1984 nevent
.SetEventObject( GetParent()->GetParent() );
1985 nevent
.SetCurrentFocus( m_parent
);
1986 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
1989 /* no item -> nothing to do */
1996 switch (event
.KeyCode())
2000 wxNode
*node
= m_lines
.Member( m_current
)->Previous();
2001 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2006 wxNode
*node
= m_lines
.Member( m_current
)->Next();
2007 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2012 wxNode
*node
= m_lines
.Last();
2013 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2018 wxNode
*node
= m_lines
.First();
2019 OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2025 if (m_mode
& wxLC_REPORT
)
2027 steps
= m_visibleLines
-1;
2032 wxNode
*node
= m_lines
.First();
2033 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
2034 steps
= pos
% m_visibleLines
;
2036 wxNode
*node
= m_lines
.Member( m_current
);
2037 for (int i
= 0; i
< steps
; i
++) if (node
->Previous()) node
= node
->Previous();
2038 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2044 if (m_mode
& wxLC_REPORT
)
2046 steps
= m_visibleLines
-1;
2050 int pos
= 0; wxNode
*node
= m_lines
.First();
2051 for (;;) { if (m_current
== (wxListLineData
*)node
->Data()) break; pos
++; node
= node
->Next(); }
2052 steps
= m_visibleLines
-(pos
% m_visibleLines
)-1;
2054 wxNode
*node
= m_lines
.Member( m_current
);
2055 for (int i
= 0; i
< steps
; i
++) if (node
->Next()) node
= node
->Next();
2056 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2061 if (!(m_mode
& wxLC_REPORT
))
2063 wxNode
*node
= m_lines
.Member( m_current
);
2064 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Previous()) node
= node
->Previous();
2065 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2071 if (!(m_mode
& wxLC_REPORT
))
2073 wxNode
*node
= m_lines
.Member( m_current
);
2074 for (int i
= 0; i
<m_visibleLines
; i
++) if (node
->Next()) node
= node
->Next();
2075 if (node
) OnArrowChar( (wxListLineData
*)node
->Data(), event
.ShiftDown() );
2081 if (m_mode
& wxLC_SINGLE_SEL
)
2083 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2084 le
.SetEventObject( GetParent() );
2085 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2086 m_current
->GetItem( 0, le
.m_item
);
2087 GetParent()->GetEventHandler()->ProcessEvent( le
);
2091 m_current
->ReverseHilight();
2092 RefreshLine( m_current
);
2098 if (!(m_mode
& wxLC_SINGLE_SEL
))
2100 wxListLineData
*oldCurrent
= m_current
;
2101 m_current
->ReverseHilight();
2102 wxNode
*node
= m_lines
.Member( m_current
)->Next();
2103 if (node
) m_current
= (wxListLineData
*)node
->Data();
2104 RefreshLine( oldCurrent
);
2105 RefreshLine( m_current
);
2106 UnfocusLine( oldCurrent
);
2107 FocusLine( m_current
);
2115 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2116 le
.SetEventObject( GetParent() );
2117 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2118 m_current
->GetItem( 0, le
.m_item
);
2119 GetParent()->GetEventHandler()->ProcessEvent( le
);
2132 extern wxWindow
*g_focusWindow
;
2135 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2138 RefreshLine( m_current
);
2140 if (!GetParent()) return;
2143 g_focusWindow
= GetParent();
2146 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2147 event
.SetEventObject( GetParent() );
2148 GetParent()->GetEventHandler()->ProcessEvent( event
);
2151 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2154 RefreshLine( m_current
);
2157 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2160 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2165 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2167 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2169 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2172 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2174 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2176 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2178 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2180 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2182 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2187 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2189 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2191 m_normal_image_list
->GetSize( index
, width
, height
);
2194 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2196 m_small_image_list
->GetSize( index
, width
, height
);
2199 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2201 m_small_image_list
->GetSize( index
, width
, height
);
2204 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2206 m_small_image_list
->GetSize( index
, width
, height
);
2213 int wxListMainWindow::GetTextLength( wxString
&s
)
2215 wxClientDC
dc( this );
2218 dc
.GetTextExtent( s
, &lw
, &lh
);
2222 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2225 wxNode
*node
= m_lines
.First();
2228 if (line
== (wxListLineData
*)node
->Data()) return i
;
2230 node
= node
->Next();
2235 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2238 if (which
== wxIMAGE_LIST_NORMAL
) m_normal_image_list
= imageList
;
2239 if (which
== wxIMAGE_LIST_SMALL
) m_small_image_list
= imageList
;
2242 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2247 m_small_spacing
= spacing
;
2251 m_normal_spacing
= spacing
;
2255 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2257 if (isSmall
) return m_small_spacing
; else return m_normal_spacing
;
2260 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2263 wxNode
*node
= m_columns
.Nth( col
);
2266 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2267 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2268 column
->SetItem( item
);
2270 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
2271 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
2274 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2276 if (!(m_mode
& wxLC_REPORT
)) return;
2280 wxNode
*node
= (wxNode
*) NULL
;
2282 if (width
== wxLIST_AUTOSIZE_USEHEADER
) width
= 80;
2283 if (width
== wxLIST_AUTOSIZE
)
2285 wxClientDC
dc(this);
2286 dc
.SetFont( GetFont() );
2288 node
= m_lines
.First();
2291 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2292 wxNode
*n
= line
->m_items
.Nth( col
);
2295 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2296 int current
= 0, ix
= 0, iy
= 0;
2297 wxCoord lx
= 0, ly
= 0;
2298 if (item
->HasImage())
2300 GetImageSize( item
->GetImage(), ix
, iy
);
2303 if (item
->HasText())
2306 item
->GetText( str
);
2307 dc
.GetTextExtent( str
, &lx
, &ly
);
2310 if (current
> max
) max
= current
;
2312 node
= node
->Next();
2317 node
= m_columns
.Nth( col
);
2320 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2321 column
->SetWidth( width
);
2324 node
= m_lines
.First();
2327 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2328 wxNode
*n
= line
->m_items
.Nth( col
);
2331 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2332 item
->SetSize( width
, -1 );
2334 node
= node
->Next();
2337 wxListCtrl
*lc
= (wxListCtrl
*) GetParent();
2338 if (lc
->m_headerWin
) lc
->m_headerWin
->Refresh();
2341 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2343 wxNode
*node
= m_columns
.Nth( col
);
2346 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2347 column
->GetItem( item
);
2359 int wxListMainWindow::GetColumnWidth( int col
)
2361 wxNode
*node
= m_columns
.Nth( col
);
2364 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2365 return column
->GetWidth();
2373 int wxListMainWindow::GetColumnCount()
2375 return m_columns
.Number();
2378 int wxListMainWindow::GetCountPerPage()
2380 return m_visibleLines
;
2383 void wxListMainWindow::SetItem( wxListItem
&item
)
2386 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2389 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2390 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2391 line
->SetItem( item
.m_col
, item
);
2395 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2397 // m_dirty = TRUE; no recalcs needed
2399 wxListLineData
*oldCurrent
= m_current
;
2401 if (stateMask
& wxLIST_STATE_FOCUSED
)
2403 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2406 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2407 UnfocusLine( m_current
);
2409 FocusLine( m_current
);
2410 RefreshLine( m_current
);
2411 if (oldCurrent
) RefreshLine( oldCurrent
);
2415 if (stateMask
& wxLIST_STATE_SELECTED
)
2417 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2418 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2420 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2423 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2424 if (m_mode
& wxLC_SINGLE_SEL
)
2426 UnfocusLine( m_current
);
2428 FocusLine( m_current
);
2429 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2430 RefreshLine( m_current
);
2431 if (oldCurrent
) RefreshLine( oldCurrent
);
2433 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2434 if (on
!= line
->IsHilighted())
2436 line
->Hilight( on
);
2437 RefreshLine( line
);
2443 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2445 int ret
= wxLIST_STATE_DONTCARE
;
2446 if (stateMask
& wxLIST_STATE_FOCUSED
)
2448 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2451 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2452 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2455 if (stateMask
& wxLIST_STATE_SELECTED
)
2457 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2460 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2461 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2467 void wxListMainWindow::GetItem( wxListItem
&item
)
2469 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2472 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2473 line
->GetItem( item
.m_col
, item
);
2484 int wxListMainWindow::GetItemCount()
2486 return m_lines
.Number();
2489 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2491 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2494 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2495 line
->GetRect( rect
);
2506 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2508 wxNode
*node
= m_lines
.Nth( (size_t)item
);
2512 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2513 line
->GetRect( rect
);
2525 int wxListMainWindow::GetSelectedItemCount()
2528 wxNode
*node
= m_lines
.First();
2531 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2532 if (line
->IsHilighted()) ret
++;
2533 node
= node
->Next();
2538 void wxListMainWindow::SetMode( long mode
)
2545 if (m_mode
& wxLC_REPORT
)
2547 #if wxUSE_GENERIC_LIST_EXTENSIONS
2561 long wxListMainWindow::GetMode() const
2566 void wxListMainWindow::CalculatePositions()
2568 if (!m_lines
.First()) return;
2570 wxClientDC
dc( this );
2571 dc
.SetFont( GetFont() );
2573 int iconSpacing
= 0;
2574 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2575 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2577 // we take the first line (which also can be an icon or
2578 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2579 // measure the size of the line
2583 int lineSpacing
= 0;
2585 wxListLineData
*line
= (wxListLineData
*)m_lines
.First()->Data();
2586 line
->CalculateSize( &dc
, iconSpacing
);
2588 line
->GetSize( dummy
, lineSpacing
);
2591 int clientWidth
= 0;
2592 int clientHeight
= 0;
2594 if (m_mode
& wxLC_REPORT
)
2598 int entireHeight
= m_lines
.Number() * lineSpacing
+ 2;
2599 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2600 #if wxUSE_GENERIC_LIST_EXTENSIONS
2601 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2603 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2605 GetClientSize( &clientWidth
, &clientHeight
);
2607 wxNode
* node
= m_lines
.First();
2608 int entireWidth
= 0 ;
2611 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2612 line
->CalculateSize( &dc
, iconSpacing
);
2613 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2615 for (int i
= 0; i
< GetColumnCount(); i
++)
2617 line
->SetColumnPosition( i
, col_x
);
2618 col_x
+= GetColumnWidth( i
);
2620 entireWidth
= wxMax( entireWidth
, col_x
) ;
2621 #if wxUSE_GENERIC_LIST_EXTENSIONS
2622 line
->SetPosition( &dc
, x
, y
, col_x
);
2624 y
+= lineSpacing
; // one pixel blank line between items
2625 node
= node
->Next();
2627 m_visibleLines
= clientHeight
/ lineSpacing
;
2628 #if wxUSE_GENERIC_LIST_EXTENSIONS
2629 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2634 // at first we try without any scrollbar. if the items don't
2635 // fit into the window, we recalculate after subtracting an
2636 // approximated 15 pt for the horizontal scrollbar
2638 GetSize( &clientWidth
, &clientHeight
);
2639 clientHeight
-= 4; // sunken frame
2641 int entireWidth
= 0;
2643 for (int tries
= 0; tries
< 2; tries
++)
2646 int x
= 5; // painting is done at x-2
2647 int y
= 5; // painting is done at y-2
2650 int m_currentVisibleLines
= 0;
2651 wxNode
*node
= m_lines
.First();
2654 m_currentVisibleLines
++;
2655 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2656 line
->CalculateSize( &dc
, iconSpacing
);
2657 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2658 line
->GetSize( lineWidth
, lineHeight
);
2659 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2661 if (m_currentVisibleLines
> m_visibleLines
)
2662 m_visibleLines
= m_currentVisibleLines
;
2663 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2665 m_currentVisibleLines
= 0;
2668 entireWidth
+= maxWidth
+6;
2671 node
= node
->Next();
2672 if (!node
) entireWidth
+= maxWidth
;
2673 if ((tries
== 0) && (entireWidth
> clientWidth
))
2675 clientHeight
-= 15; // scrollbar height
2677 m_currentVisibleLines
= 0;
2680 if (!node
) tries
= 1; // everything fits, no second try required
2684 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2685 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2689 void wxListMainWindow::RealizeChanges( void )
2693 wxNode
*node
= m_lines
.First();
2694 if (node
) m_current
= (wxListLineData
*)node
->Data();
2698 FocusLine( m_current
);
2699 if (m_mode
& wxLC_SINGLE_SEL
) m_current
->Hilight( TRUE
);
2703 long wxListMainWindow::GetNextItem( long item
,
2704 int WXUNUSED(geometry
),
2708 max
= GetItemCount();
2709 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2710 _T("invalid listctrl index in GetNextItem()") );
2712 // notice that we start with the next item (or the first one if item == -1)
2713 // and this is intentional to allow writing a simple loop to iterate over
2714 // all selected items
2718 // this is not an error because the index was ok initially, just no
2723 wxNode
*node
= m_lines
.Nth( (size_t)ret
);
2726 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2727 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2729 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2735 node
= node
->Next();
2741 void wxListMainWindow::DeleteItem( long index
)
2744 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2747 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2748 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2750 m_lines
.DeleteNode( node
);
2754 void wxListMainWindow::DeleteColumn( int col
)
2756 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2757 wxT("attempting to delete inexistent column in wxListView") );
2760 wxNode
*node
= m_columns
.Nth( col
);
2761 if (node
) m_columns
.DeleteNode( node
);
2764 void wxListMainWindow::DeleteAllItems()
2767 m_current
= (wxListLineData
*) NULL
;
2769 // to make the deletion of all items faster, we don't send the
2770 // notifications in this case: this is compatible with wxMSW and
2771 // documented in DeleteAllItems() description
2773 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2774 event
.SetEventObject( GetParent() );
2775 GetParent()->GetEventHandler()->ProcessEvent( event
);
2780 void wxListMainWindow::DeleteEverything()
2787 void wxListMainWindow::EnsureVisible( long index
)
2789 // We have to call this here because the label in
2790 // question might just have been added and no screen
2791 // update taken place.
2792 if (m_dirty
) wxYield();
2794 wxListLineData
*oldCurrent
= m_current
;
2795 m_current
= (wxListLineData
*) NULL
;
2796 wxNode
*node
= m_lines
.Nth( (size_t)index
);
2797 if (node
) m_current
= (wxListLineData
*)node
->Data();
2798 if (m_current
) MoveToFocus();
2799 m_current
= oldCurrent
;
2802 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2806 if (pos
< 0) pos
= 0;
2807 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2810 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2812 line
->GetText( 0, s
);
2813 if (s
== tmp
) return pos
;
2814 node
= node
->Next();
2820 long wxListMainWindow::FindItem(long start
, long data
)
2823 if (pos
< 0) pos
= 0;
2824 wxNode
*node
= m_lines
.Nth( (size_t)pos
);
2827 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2829 line
->GetItem( 0, item
);
2830 if (item
.m_data
== data
) return pos
;
2831 node
= node
->Next();
2837 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2839 wxNode
*node
= m_lines
.First();
2843 wxListLineData
*line
= (wxListLineData
*)node
->Data();
2844 long ret
= line
->IsHit( x
, y
);
2850 node
= node
->Next();
2856 void wxListMainWindow::InsertItem( wxListItem
&item
)
2860 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2861 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2862 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2863 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2865 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2867 if (m_mode
& wxLC_REPORT
)
2869 line
->InitItems( GetColumnCount() );
2870 item
.m_width
= GetColumnWidth( 0 )-3;
2874 line
->InitItems( 1 );
2877 line
->SetItem( 0, item
);
2878 if ((item
.m_itemId
>= 0) && (item
.m_itemId
< (int)m_lines
.GetCount()))
2880 wxNode
*node
= m_lines
.Nth( (size_t)item
.m_itemId
);
2881 if (node
) m_lines
.Insert( node
, line
);
2885 m_lines
.Append( line
);
2889 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2892 if (m_mode
& wxLC_REPORT
)
2894 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
2895 wxListHeaderData
*column
= new wxListHeaderData( item
);
2896 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
2898 wxNode
*node
= m_columns
.Nth( (size_t)col
);
2900 m_columns
.Insert( node
, column
);
2904 m_columns
.Append( column
);
2909 wxListCtrlCompare list_ctrl_compare_func_2
;
2910 long list_ctrl_compare_data
;
2912 int LINKAGEMODE
list_ctrl_compare_func_1( const void *arg1
, const void *arg2
)
2914 wxListLineData
*line1
= *((wxListLineData
**)arg1
);
2915 wxListLineData
*line2
= *((wxListLineData
**)arg2
);
2917 line1
->GetItem( 0, item
);
2918 long data1
= item
.m_data
;
2919 line2
->GetItem( 0, item
);
2920 long data2
= item
.m_data
;
2921 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
2924 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
2926 list_ctrl_compare_func_2
= fn
;
2927 list_ctrl_compare_data
= data
;
2928 m_lines
.Sort( list_ctrl_compare_func_1
);
2932 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
2934 wxScrolledWindow::OnScroll( event
) ;
2935 #if wxUSE_GENERIC_LIST_EXTENSIONS
2937 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
2939 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
2942 lc
->m_headerWin
->Refresh() ;
2944 lc
->m_headerWin
->MacUpdateImmediately() ;
2951 // -------------------------------------------------------------------------------------
2953 // -------------------------------------------------------------------------------------
2955 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
2957 wxListItem::wxListItem()
2966 m_format
= wxLIST_FORMAT_CENTRE
;
2972 void wxListItem::Clear()
2981 m_format
= wxLIST_FORMAT_CENTRE
;
2983 m_text
= wxEmptyString
;
2985 if (m_attr
) delete m_attr
;
2989 void wxListItem::ClearAttributes()
2991 if (m_attr
) delete m_attr
;
2995 // -------------------------------------------------------------------------------------
2997 // -------------------------------------------------------------------------------------
2999 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3001 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3002 wxNotifyEvent( commandType
, id
)
3008 m_cancelled
= FALSE
;
3013 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3015 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3017 wxNotifyEvent::CopyObject(object_dest
);
3019 obj
->m_code
= m_code
;
3020 obj
->m_itemIndex
= m_itemIndex
;
3021 obj
->m_oldItemIndex
= m_oldItemIndex
;
3023 obj
->m_cancelled
= m_cancelled
;
3024 obj
->m_pointDrag
= m_pointDrag
;
3025 obj
->m_item
.m_mask
= m_item
.m_mask
;
3026 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3027 obj
->m_item
.m_col
= m_item
.m_col
;
3028 obj
->m_item
.m_state
= m_item
.m_state
;
3029 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3030 obj
->m_item
.m_text
= m_item
.m_text
;
3031 obj
->m_item
.m_image
= m_item
.m_image
;
3032 obj
->m_item
.m_data
= m_item
.m_data
;
3033 obj
->m_item
.m_format
= m_item
.m_format
;
3034 obj
->m_item
.m_width
= m_item
.m_width
;
3036 if ( m_item
.HasAttributes() )
3038 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3042 // -------------------------------------------------------------------------------------
3044 // -------------------------------------------------------------------------------------
3046 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3048 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3049 EVT_SIZE (wxListCtrl::OnSize
)
3050 EVT_IDLE (wxListCtrl::OnIdle
)
3053 wxListCtrl::wxListCtrl()
3055 m_imageListNormal
= (wxImageList
*) NULL
;
3056 m_imageListSmall
= (wxImageList
*) NULL
;
3057 m_imageListState
= (wxImageList
*) NULL
;
3058 m_mainWin
= (wxListMainWindow
*) NULL
;
3059 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3062 wxListCtrl::~wxListCtrl()
3066 bool wxListCtrl::Create(wxWindow
*parent
,
3071 const wxValidator
&validator
,
3072 const wxString
&name
)
3074 m_imageListNormal
= (wxImageList
*) NULL
;
3075 m_imageListSmall
= (wxImageList
*) NULL
;
3076 m_imageListState
= (wxImageList
*) NULL
;
3077 m_mainWin
= (wxListMainWindow
*) NULL
;
3078 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3080 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3082 style
= style
| wxLC_LIST
;
3085 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3088 if (style
& wxSUNKEN_BORDER
)
3089 style
-= wxSUNKEN_BORDER
;
3091 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3093 if (HasFlag(wxLC_REPORT
))
3095 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3096 if (HasFlag(wxLC_NO_HEADER
))
3097 m_headerWin
->Show( FALSE
);
3101 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3104 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
3109 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3111 /* handled in OnIdle */
3113 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3116 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3118 long flag
= GetWindowStyle();
3122 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3123 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3124 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3133 if (flag
& style
) flag
-= style
;
3136 SetWindowStyleFlag( flag
);
3139 void wxListCtrl::SetWindowStyleFlag( long flag
)
3143 m_mainWin
->DeleteEverything();
3147 GetClientSize( &width
, &height
);
3149 m_mainWin
->SetMode( flag
);
3151 if (flag
& wxLC_REPORT
)
3153 if (!HasFlag(wxLC_REPORT
))
3157 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3158 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3159 if (HasFlag(wxLC_NO_HEADER
))
3160 m_headerWin
->Show( FALSE
);
3164 if (flag
& wxLC_NO_HEADER
)
3165 m_headerWin
->Show( FALSE
);
3167 m_headerWin
->Show( TRUE
);
3173 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3175 m_headerWin
->Show( FALSE
);
3180 wxWindow::SetWindowStyleFlag( flag
);
3183 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3185 m_mainWin
->GetColumn( col
, item
);
3189 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3191 m_mainWin
->SetColumn( col
, item
);
3195 int wxListCtrl::GetColumnWidth( int col
) const
3197 return m_mainWin
->GetColumnWidth( col
);
3200 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3202 m_mainWin
->SetColumnWidth( col
, width
);
3206 int wxListCtrl::GetCountPerPage() const
3208 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3211 bool wxListCtrl::GetItem( wxListItem
&info
) const
3213 m_mainWin
->GetItem( info
);
3217 bool wxListCtrl::SetItem( wxListItem
&info
)
3219 m_mainWin
->SetItem( info
);
3223 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3226 info
.m_text
= label
;
3227 info
.m_mask
= wxLIST_MASK_TEXT
;
3228 info
.m_itemId
= index
;
3232 info
.m_image
= imageId
;
3233 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3235 m_mainWin
->SetItem(info
);
3239 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3241 return m_mainWin
->GetItemState( item
, stateMask
);
3244 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3246 m_mainWin
->SetItemState( item
, state
, stateMask
);
3250 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3253 info
.m_image
= image
;
3254 info
.m_mask
= wxLIST_MASK_IMAGE
;
3255 info
.m_itemId
= item
;
3256 m_mainWin
->SetItem( info
);
3260 wxString
wxListCtrl::GetItemText( long item
) const
3263 info
.m_itemId
= item
;
3264 m_mainWin
->GetItem( info
);
3268 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3271 info
.m_mask
= wxLIST_MASK_TEXT
;
3272 info
.m_itemId
= item
;
3274 m_mainWin
->SetItem( info
);
3277 long wxListCtrl::GetItemData( long item
) const
3280 info
.m_itemId
= item
;
3281 m_mainWin
->GetItem( info
);
3285 bool wxListCtrl::SetItemData( long item
, long data
)
3288 info
.m_mask
= wxLIST_MASK_DATA
;
3289 info
.m_itemId
= item
;
3291 m_mainWin
->SetItem( info
);
3295 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3297 m_mainWin
->GetItemRect( item
, rect
);
3301 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3303 m_mainWin
->GetItemPosition( item
, pos
);
3307 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3312 int wxListCtrl::GetItemCount() const
3314 return m_mainWin
->GetItemCount();
3317 int wxListCtrl::GetColumnCount() const
3319 return m_mainWin
->GetColumnCount();
3322 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3324 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3327 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3329 return m_mainWin
->GetItemSpacing( isSmall
);
3332 int wxListCtrl::GetSelectedItemCount() const
3334 return m_mainWin
->GetSelectedItemCount();
3337 wxColour
wxListCtrl::GetTextColour() const
3339 return GetForegroundColour();
3342 void wxListCtrl::SetTextColour(const wxColour
& col
)
3344 SetForegroundColour(col
);
3347 long wxListCtrl::GetTopItem() const
3352 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3354 return m_mainWin
->GetNextItem( item
, geom
, state
);
3357 wxImageList
*wxListCtrl::GetImageList(int which
) const
3359 if (which
== wxIMAGE_LIST_NORMAL
)
3361 return m_imageListNormal
;
3363 else if (which
== wxIMAGE_LIST_SMALL
)
3365 return m_imageListSmall
;
3367 else if (which
== wxIMAGE_LIST_STATE
)
3369 return m_imageListState
;
3371 return (wxImageList
*) NULL
;
3374 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3376 m_mainWin
->SetImageList( imageList
, which
);
3379 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3384 bool wxListCtrl::DeleteItem( long item
)
3386 m_mainWin
->DeleteItem( item
);
3390 bool wxListCtrl::DeleteAllItems()
3392 m_mainWin
->DeleteAllItems();
3396 bool wxListCtrl::DeleteAllColumns()
3398 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3404 void wxListCtrl::ClearAll()
3406 m_mainWin
->DeleteEverything();
3409 bool wxListCtrl::DeleteColumn( int col
)
3411 m_mainWin
->DeleteColumn( col
);
3415 void wxListCtrl::Edit( long item
)
3417 m_mainWin
->Edit( item
);
3420 bool wxListCtrl::EnsureVisible( long item
)
3422 m_mainWin
->EnsureVisible( item
);
3426 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3428 return m_mainWin
->FindItem( start
, str
, partial
);
3431 long wxListCtrl::FindItem( long start
, long data
)
3433 return m_mainWin
->FindItem( start
, data
);
3436 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3437 int WXUNUSED(direction
))
3442 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3444 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3447 long wxListCtrl::InsertItem( wxListItem
& info
)
3449 m_mainWin
->InsertItem( info
);
3450 return info
.m_itemId
;
3453 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3456 info
.m_text
= label
;
3457 info
.m_mask
= wxLIST_MASK_TEXT
;
3458 info
.m_itemId
= index
;
3459 return InsertItem( info
);
3462 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3465 info
.m_mask
= wxLIST_MASK_IMAGE
;
3466 info
.m_image
= imageIndex
;
3467 info
.m_itemId
= index
;
3468 return InsertItem( info
);
3471 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3474 info
.m_text
= label
;
3475 info
.m_image
= imageIndex
;
3476 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3477 info
.m_itemId
= index
;
3478 return InsertItem( info
);
3481 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3483 wxASSERT( m_headerWin
);
3484 m_mainWin
->InsertColumn( col
, item
);
3485 m_headerWin
->Refresh();
3490 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3491 int format
, int width
)
3494 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3495 item
.m_text
= heading
;
3498 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3499 item
.m_width
= width
;
3501 item
.m_format
= format
;
3503 return InsertColumn( col
, item
);
3506 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3512 // fn is a function which takes 3 long arguments: item1, item2, data.
3513 // item1 is the long data associated with a first item (NOT the index).
3514 // item2 is the long data associated with a second item (NOT the index).
3515 // data is the same value as passed to SortItems.
3516 // The return value is a negative number if the first item should precede the second
3517 // item, a positive number of the second item should precede the first,
3518 // or zero if the two items are equivalent.
3519 // data is arbitrary data to be passed to the sort function.
3521 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3523 m_mainWin
->SortItems( fn
, data
);
3527 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3529 if (!m_mainWin
->m_dirty
) return;
3533 GetClientSize( &cw
, &ch
);
3540 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3542 m_headerWin
->GetPosition( &x
, &y
);
3543 m_headerWin
->GetSize( &w
, &h
);
3544 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3545 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3547 m_mainWin
->GetPosition( &x
, &y
);
3548 m_mainWin
->GetSize( &w
, &h
);
3549 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3550 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3554 m_mainWin
->GetPosition( &x
, &y
);
3555 m_mainWin
->GetSize( &w
, &h
);
3556 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3557 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3560 m_mainWin
->CalculatePositions();
3561 m_mainWin
->RealizeChanges();
3562 m_mainWin
->m_dirty
= FALSE
;
3563 m_mainWin
->Refresh();
3566 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3568 if ( !wxWindow::SetBackgroundColour( colour
) )
3573 m_mainWin
->SetBackgroundColour( colour
);
3574 m_mainWin
->m_dirty
= TRUE
;
3579 // m_headerWin->SetBackgroundColour( colour );
3585 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3587 if ( !wxWindow::SetForegroundColour( colour
) )
3592 m_mainWin
->SetForegroundColour( colour
);
3593 m_mainWin
->m_dirty
= TRUE
;
3598 m_headerWin
->SetForegroundColour( colour
);
3604 bool wxListCtrl::SetFont( const wxFont
&font
)
3606 if ( !wxWindow::SetFont( font
) )
3611 m_mainWin
->SetFont( font
);
3612 m_mainWin
->m_dirty
= TRUE
;
3617 m_headerWin
->SetFont( font
);
3623 #if wxUSE_DRAG_AND_DROP
3625 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3627 m_mainWin
->SetDropTarget( dropTarget
);
3630 wxDropTarget
*wxListCtrl::GetDropTarget() const
3632 return m_mainWin
->GetDropTarget();
3635 #endif // wxUSE_DRAG_AND_DROP
3637 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3639 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3642 wxColour
wxListCtrl::GetBackgroundColour() const
3644 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3647 wxColour
wxListCtrl::GetForegroundColour() const
3649 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3652 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3654 return m_mainWin
->PopupMenu( menu
, x
, y
);
3657 void wxListCtrl::SetFocus()
3659 /* The test in window.cpp fails as we are a composite
3660 window, so it checks against "this", but not m_mainWin. */
3661 if ( FindFocus() != this )
3662 m_mainWin
->SetFocus();