1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dcscreen.h"
24 #include "wx/listctrl.h"
25 #include "wx/generic/imaglist.h"
26 #include "wx/dynarray.h"
28 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
29 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
32 // ============================================================================
34 // ============================================================================
36 //-----------------------------------------------------------------------------
37 // wxListItemData (internal)
38 //-----------------------------------------------------------------------------
40 class WXDLLEXPORT wxListItemData
: public wxObject
49 wxListItemAttr
*m_attr
;
53 ~wxListItemData() { delete m_attr
; }
55 wxListItemData( const wxListItem
&info
);
56 void SetItem( const wxListItem
&info
);
57 void SetText( const wxString
&s
);
58 void SetImage( int image
);
59 void SetData( long data
);
60 void SetPosition( int x
, int y
);
61 void SetSize( int width
, int height
);
62 bool HasImage() const;
64 bool IsHit( int x
, int y
) const;
65 void GetText( wxString
&s
);
66 const wxString
& GetText() { return m_text
; }
67 int GetX( void ) const;
68 int GetY( void ) const;
70 int GetHeight() const;
72 void GetItem( wxListItem
&info
) const;
74 wxListItemAttr
*GetAttributes() const { return m_attr
; }
77 DECLARE_DYNAMIC_CLASS(wxListItemData
);
80 //-----------------------------------------------------------------------------
81 // wxListHeaderData (internal)
82 //-----------------------------------------------------------------------------
84 class WXDLLEXPORT wxListHeaderData
: public wxObject
97 wxListHeaderData( const wxListItem
&info
);
98 void SetItem( const wxListItem
&item
);
99 void SetPosition( int x
, int y
);
100 void SetWidth( int w
);
101 void SetFormat( int format
);
102 void SetHeight( int h
);
103 bool HasImage() const;
104 bool HasText() const;
105 bool IsHit( int x
, int y
) const;
106 void GetItem( wxListItem
&item
);
107 void GetText( wxString
&s
);
108 int GetImage() const;
109 int GetWidth() const;
110 int GetFormat() const;
113 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
116 //-----------------------------------------------------------------------------
117 // wxListLineData (internal)
118 //-----------------------------------------------------------------------------
120 class WXDLLEXPORT wxListLineData
: public wxObject
125 wxRect m_bound_label
;
127 wxRect m_bound_hilight
;
130 wxBrush
*m_hilightBrush
;
132 wxListMainWindow
*m_owner
;
134 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
138 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
139 void CalculateSize( wxDC
*dc
, int spacing
);
140 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
141 void SetColumnPosition( int index
, int x
);
142 void GetSize( int &width
, int &height
);
143 void GetExtent( int &x
, int &y
, int &width
, int &height
);
144 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
145 long IsHit( int x
, int y
);
146 void InitItems( int num
);
147 void SetItem( int index
, const wxListItem
&info
);
148 void GetItem( int index
, wxListItem
&info
);
149 void GetText( int index
, wxString
&s
);
150 void SetText( int index
, const wxString s
);
151 int GetImage( int index
);
152 void GetRect( wxRect
&rect
);
153 void Hilight( bool on
);
154 void ReverseHilight();
155 void DrawRubberBand( wxDC
*dc
, bool on
);
156 void Draw( wxDC
*dc
);
157 bool IsInRect( int x
, int y
, const wxRect
&rect
);
159 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
160 void AssignRect( wxRect
&dest
, const wxRect
&source
);
163 void SetAttributes(wxDC
*dc
,
164 const wxListItemAttr
*attr
,
165 const wxColour
& colText
, const wxFont
& font
,
168 DECLARE_DYNAMIC_CLASS(wxListLineData
);
172 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
173 #include "wx/arrimpl.cpp"
174 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
176 //-----------------------------------------------------------------------------
177 // wxListHeaderWindow (internal)
178 //-----------------------------------------------------------------------------
180 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
183 wxListMainWindow
*m_owner
;
184 wxCursor
*m_currentCursor
;
185 wxCursor
*m_resizeCursor
;
188 // column being resized
191 // divider line position in logical (unscrolled) coords
194 // minimal position beyond which the divider line can't be dragged in
199 wxListHeaderWindow();
200 virtual ~wxListHeaderWindow();
202 wxListHeaderWindow( wxWindow
*win
,
204 wxListMainWindow
*owner
,
205 const wxPoint
&pos
= wxDefaultPosition
,
206 const wxSize
&size
= wxDefaultSize
,
208 const wxString
&name
= "wxlistctrlcolumntitles" );
210 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
212 void AdjustDC(wxDC
& dc
);
214 void OnPaint( wxPaintEvent
&event
);
215 void OnMouse( wxMouseEvent
&event
);
216 void OnSetFocus( wxFocusEvent
&event
);
222 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
223 DECLARE_EVENT_TABLE()
226 //-----------------------------------------------------------------------------
227 // wxListRenameTimer (internal)
228 //-----------------------------------------------------------------------------
230 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
233 wxListMainWindow
*m_owner
;
236 wxListRenameTimer( wxListMainWindow
*owner
);
240 //-----------------------------------------------------------------------------
241 // wxListTextCtrl (internal)
242 //-----------------------------------------------------------------------------
244 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
249 wxListMainWindow
*m_owner
;
250 wxString m_startValue
;
254 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
255 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
256 const wxString
&value
= "",
257 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
259 const wxValidator
& validator
= wxDefaultValidator
,
260 const wxString
&name
= "listctrltextctrl" );
261 void OnChar( wxKeyEvent
&event
);
262 void OnKillFocus( wxFocusEvent
&event
);
265 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
266 DECLARE_EVENT_TABLE()
269 //-----------------------------------------------------------------------------
270 // wxListMainWindow (internal)
271 //-----------------------------------------------------------------------------
273 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
277 wxListLineDataArray m_lines
;
279 wxListLineData
*m_current
;
280 wxListLineData
*m_currentEdit
;
282 wxBrush
*m_hilightBrush
;
283 wxColour
*m_hilightColour
;
284 int m_xScroll
,m_yScroll
;
286 wxImageList
*m_small_image_list
;
287 wxImageList
*m_normal_image_list
;
289 int m_normal_spacing
;
293 wxTimer
*m_renameTimer
;
295 wxString m_renameRes
;
300 // for double click logic
301 wxListLineData
*m_lineLastClicked
,
302 *m_lineBeforeLastClicked
;
306 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
307 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
308 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
310 void RefreshLine( wxListLineData
*line
);
311 void OnPaint( wxPaintEvent
&event
);
312 void HilightAll( bool on
);
313 void SendNotify( wxListLineData
*line
, wxEventType command
);
314 void FocusLine( wxListLineData
*line
);
315 void UnfocusLine( wxListLineData
*line
);
316 void SelectLine( wxListLineData
*line
);
317 void DeselectLine( wxListLineData
*line
);
318 void DeleteLine( wxListLineData
*line
);
320 void EditLabel( long item
);
321 void Edit( long item
) { EditLabel(item
); } // deprecated
322 void OnRenameTimer();
323 void OnRenameAccept();
325 void OnMouse( wxMouseEvent
&event
);
327 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
328 void OnChar( wxKeyEvent
&event
);
329 void OnKeyDown( wxKeyEvent
&event
);
330 void OnSetFocus( wxFocusEvent
&event
);
331 void OnKillFocus( wxFocusEvent
&event
);
332 void OnSize( wxSizeEvent
&event
);
333 void OnScroll(wxScrollWinEvent
& event
) ;
335 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
336 void GetImageSize( int index
, int &width
, int &height
);
337 int GetIndexOfLine( const wxListLineData
*line
);
338 int GetTextLength( wxString
&s
); // should be const
340 void SetImageList( wxImageList
*imageList
, int which
);
341 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
342 int GetItemSpacing( bool isSmall
= FALSE
);
343 void SetColumn( int col
, wxListItem
&item
);
344 void SetColumnWidth( int col
, int width
);
345 void GetColumn( int col
, wxListItem
&item
);
346 int GetColumnWidth( int vol
);
347 int GetColumnCount();
348 int GetCountPerPage();
349 void SetItem( wxListItem
&item
);
350 void GetItem( wxListItem
&item
);
351 void SetItemState( long item
, long state
, long stateMask
);
352 int GetItemState( long item
, long stateMask
);
354 void GetItemRect( long index
, wxRect
&rect
);
355 bool GetItemPosition( long item
, wxPoint
& pos
);
356 int GetSelectedItemCount();
357 void SetMode( long mode
);
358 long GetMode() const;
359 void CalculatePositions();
360 void RealizeChanges();
361 long GetNextItem( long item
, int geometry
, int state
);
362 void DeleteItem( long index
);
363 void DeleteAllItems();
364 void DeleteColumn( int col
);
365 void DeleteEverything();
366 void EnsureVisible( long index
);
367 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
368 long FindItem( long start
, long data
);
369 long HitTest( int x
, int y
, int &flags
);
370 void InsertItem( wxListItem
&item
);
371 // void AddItem( wxListItem &item );
372 void InsertColumn( long col
, wxListItem
&item
);
373 // void AddColumn( wxListItem &item );
374 void SortItems( wxListCtrlCompare fn
, long data
);
377 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
378 DECLARE_EVENT_TABLE()
381 // ============================================================================
383 // ============================================================================
385 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
389 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
391 wxListItemData::wxListItemData()
402 wxListItemData::wxListItemData( const wxListItem
&info
)
411 void wxListItemData::SetItem( const wxListItem
&info
)
413 if (info
.m_mask
& wxLIST_MASK_TEXT
) m_text
= info
.m_text
;
414 if (info
.m_mask
& wxLIST_MASK_IMAGE
) m_image
= info
.m_image
;
415 if (info
.m_mask
& wxLIST_MASK_DATA
) m_data
= info
.m_data
;
417 if ( info
.HasAttributes() )
420 *m_attr
= *info
.GetAttributes();
422 m_attr
= new wxListItemAttr(*info
.GetAttributes());
427 m_width
= info
.m_width
;
431 void wxListItemData::SetText( const wxString
&s
)
436 void wxListItemData::SetImage( int image
)
441 void wxListItemData::SetData( long data
)
446 void wxListItemData::SetPosition( int x
, int y
)
452 void wxListItemData::SetSize( int width
, int height
)
454 if (width
!= -1) m_width
= width
;
455 if (height
!= -1) m_height
= height
;
458 bool wxListItemData::HasImage() const
460 return (m_image
>= 0);
463 bool wxListItemData::HasText() const
465 return (!m_text
.IsNull());
468 bool wxListItemData::IsHit( int x
, int y
) const
470 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
473 void wxListItemData::GetText( wxString
&s
)
478 int wxListItemData::GetX() const
483 int wxListItemData::GetY() const
488 int wxListItemData::GetWidth() const
493 int wxListItemData::GetHeight() const
498 int wxListItemData::GetImage() const
503 void wxListItemData::GetItem( wxListItem
&info
) const
505 info
.m_text
= m_text
;
506 info
.m_image
= m_image
;
507 info
.m_data
= m_data
;
511 if ( m_attr
->HasTextColour() )
512 info
.SetTextColour(m_attr
->GetTextColour());
513 if ( m_attr
->HasBackgroundColour() )
514 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
515 if ( m_attr
->HasFont() )
516 info
.SetFont(m_attr
->GetFont());
520 //-----------------------------------------------------------------------------
522 //-----------------------------------------------------------------------------
524 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
526 wxListHeaderData::wxListHeaderData()
537 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
545 void wxListHeaderData::SetItem( const wxListItem
&item
)
547 m_mask
= item
.m_mask
;
548 m_text
= item
.m_text
;
549 m_image
= item
.m_image
;
550 m_format
= item
.m_format
;
551 m_width
= item
.m_width
;
552 if (m_width
< 0) m_width
= 80;
553 if (m_width
< 6) m_width
= 6;
556 void wxListHeaderData::SetPosition( int x
, int y
)
562 void wxListHeaderData::SetHeight( int h
)
567 void wxListHeaderData::SetWidth( int w
)
570 if (m_width
< 0) m_width
= 80;
571 if (m_width
< 6) m_width
= 6;
574 void wxListHeaderData::SetFormat( int format
)
579 bool wxListHeaderData::HasImage() const
581 return (m_image
!= 0);
584 bool wxListHeaderData::HasText() const
586 return (m_text
.Length() > 0);
589 bool wxListHeaderData::IsHit( int x
, int y
) const
591 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
594 void wxListHeaderData::GetItem( wxListItem
&item
)
596 item
.m_mask
= m_mask
;
597 item
.m_text
= m_text
;
598 item
.m_image
= m_image
;
599 item
.m_format
= m_format
;
600 item
.m_width
= m_width
;
603 void wxListHeaderData::GetText( wxString
&s
)
608 int wxListHeaderData::GetImage() const
613 int wxListHeaderData::GetWidth() const
618 int wxListHeaderData::GetFormat() const
623 //-----------------------------------------------------------------------------
625 //-----------------------------------------------------------------------------
627 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
629 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
634 m_hilightBrush
= hilightBrush
;
635 m_items
.DeleteContents( TRUE
);
639 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
646 m_bound_all
.width
= m_spacing
;
647 wxNode
*node
= m_items
.First();
650 wxListItemData
*item
= (wxListItemData
*)node
->Data();
651 wxString s
= item
->GetText();
652 if (s
.IsEmpty()) s
= wxT("H");
654 dc
->GetTextExtent( s
, &lw
, &lh
);
655 if (lh
< 15) lh
= 15;
659 m_bound_all
.height
= m_spacing
+lh
;
660 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
661 m_bound_label
.width
= lw
;
662 m_bound_label
.height
= lh
;
664 if (item
->HasImage())
668 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
669 m_bound_icon
.width
= w
+ 8;
670 m_bound_icon
.height
= h
+ 8;
672 if ( m_bound_icon
.width
> m_bound_all
.width
)
673 m_bound_all
.width
= m_bound_icon
.width
;
674 if ( h
+ lh
> m_bound_all
.height
- 4 )
675 m_bound_all
.height
= h
+ lh
+ 4;
678 if (!item
->HasText())
680 m_bound_hilight
.width
= m_bound_icon
.width
;
681 m_bound_hilight
.height
= m_bound_icon
.height
;
685 m_bound_hilight
.width
= m_bound_label
.width
;
686 m_bound_hilight
.height
= m_bound_label
.height
;
693 wxNode
*node
= m_items
.First();
696 wxListItemData
*item
= (wxListItemData
*)node
->Data();
698 wxString s
= item
->GetText();
699 if (s
.IsEmpty()) s
= wxT("H");
701 dc
->GetTextExtent( s
, &lw
, &lh
);
702 if (lh
< 15) lh
= 15;
705 m_bound_label
.width
= lw
;
706 m_bound_label
.height
= lh
;
708 m_bound_all
.width
= lw
;
709 m_bound_all
.height
= lh
;
711 if (item
->HasImage())
715 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
716 m_bound_icon
.width
= w
;
717 m_bound_icon
.height
= h
;
719 m_bound_all
.width
+= 4 + w
;
720 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
723 m_bound_hilight
.width
= m_bound_all
.width
;
724 m_bound_hilight
.height
= m_bound_all
.height
;
730 m_bound_all
.width
= 0;
731 m_bound_all
.height
= 0;
732 wxNode
*node
= m_items
.First();
735 wxListItemData
*item
= (wxListItemData
*)node
->Data();
736 wxString s
= item
->GetText();
737 if (s
.IsEmpty()) s
= wxT("H");
739 dc
->GetTextExtent( s
, &lw
, &lh
);
740 if (lh
< 15) lh
= 15;
744 item
->SetSize( item
->GetWidth(), lh
);
745 m_bound_all
.width
+= lw
;
746 m_bound_all
.height
= lh
;
754 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
755 int x
, int y
, int window_width
)
763 wxNode
*node
= m_items
.First();
766 wxListItemData
*item
= (wxListItemData
*)node
->Data();
767 if (item
->HasImage())
769 m_bound_icon
.x
= m_bound_all
.x
+ 4
770 + (m_spacing
- m_bound_icon
.width
)/2;
771 m_bound_icon
.y
= m_bound_all
.y
+ 4;
775 if (m_bound_all
.width
> m_spacing
)
776 m_bound_label
.x
= m_bound_all
.x
+ 2;
778 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
779 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
780 m_bound_hilight
.x
= m_bound_label
.x
- 2;
781 m_bound_hilight
.y
= m_bound_label
.y
- 2;
785 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
786 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
793 m_bound_hilight
.x
= m_bound_all
.x
;
794 m_bound_hilight
.y
= m_bound_all
.y
;
795 m_bound_label
.y
= m_bound_all
.y
+ 2;
796 wxNode
*node
= m_items
.First();
799 wxListItemData
*item
= (wxListItemData
*)node
->Data();
800 if (item
->HasImage())
802 m_bound_icon
.x
= m_bound_all
.x
+ 2;
803 m_bound_icon
.y
= m_bound_all
.y
+ 2;
804 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
808 m_bound_label
.x
= m_bound_all
.x
+ 2;
816 m_bound_all
.width
= window_width
;
817 AssignRect( m_bound_hilight
, m_bound_all
);
818 m_bound_label
.x
= m_bound_all
.x
+ 2;
819 m_bound_label
.y
= m_bound_all
.y
+ 2;
820 wxNode
*node
= m_items
.First();
823 wxListItemData
*item
= (wxListItemData
*)node
->Data();
824 if (item
->HasImage())
826 m_bound_icon
.x
= m_bound_all
.x
+ 2;
827 m_bound_icon
.y
= m_bound_all
.y
+ 2;
828 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
836 void wxListLineData::SetColumnPosition( int index
, int x
)
838 wxNode
*node
= m_items
.Nth( (size_t)index
);
841 wxListItemData
*item
= (wxListItemData
*)node
->Data();
842 item
->SetPosition( x
, m_bound_all
.y
+1 );
846 void wxListLineData::GetSize( int &width
, int &height
)
848 width
= m_bound_all
.width
;
849 height
= m_bound_all
.height
;
852 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
856 width
= m_bound_all
.width
;
857 height
= m_bound_all
.height
;
860 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
864 width
= m_bound_label
.width
;
865 height
= m_bound_label
.height
;
868 void wxListLineData::GetRect( wxRect
&rect
)
870 AssignRect( rect
, m_bound_all
);
873 long wxListLineData::IsHit( int x
, int y
)
875 wxNode
*node
= m_items
.First();
878 wxListItemData
*item
= (wxListItemData
*)node
->Data();
879 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
880 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
881 // if (!(item->HasImage() || item->HasText())) return 0;
883 // if there is no icon or text = empty
884 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
888 void wxListLineData::InitItems( int num
)
890 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
893 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
895 wxNode
*node
= m_items
.Nth( index
);
898 wxListItemData
*item
= (wxListItemData
*)node
->Data();
899 item
->SetItem( info
);
903 void wxListLineData::GetItem( int index
, wxListItem
&info
)
906 wxNode
*node
= m_items
.Nth( i
);
909 wxListItemData
*item
= (wxListItemData
*)node
->Data();
910 item
->GetItem( info
);
914 void wxListLineData::GetText( int index
, wxString
&s
)
917 wxNode
*node
= m_items
.Nth( i
);
921 wxListItemData
*item
= (wxListItemData
*)node
->Data();
926 void wxListLineData::SetText( int index
, const wxString s
)
929 wxNode
*node
= m_items
.Nth( i
);
932 wxListItemData
*item
= (wxListItemData
*)node
->Data();
937 int wxListLineData::GetImage( int index
)
940 wxNode
*node
= m_items
.Nth( i
);
943 wxListItemData
*item
= (wxListItemData
*)node
->Data();
944 return item
->GetImage();
949 void wxListLineData::SetAttributes(wxDC
*dc
,
950 const wxListItemAttr
*attr
,
951 const wxColour
& colText
,
955 // don't use foregroud colour for drawing highlighted items - this might
956 // make them completely invisible (and there is no way to do bit
957 // arithmetics on wxColour, unfortunately)
958 if ( !hilight
&& attr
&& attr
->HasTextColour() )
960 dc
->SetTextForeground(attr
->GetTextColour());
964 dc
->SetTextForeground(colText
);
967 if ( attr
&& attr
->HasFont() )
969 dc
->SetFont(attr
->GetFont());
977 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
981 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
982 wxCoord dev_w
= m_bound_all
.width
;
983 wxCoord dev_h
= m_bound_all
.height
;
985 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
988 wxWindow
*listctrl
= m_owner
->GetParent();
990 // default foreground colour
994 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
998 colText
= listctrl
->GetForegroundColour();
1002 wxFont font
= listctrl
->GetFont();
1004 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1005 // using SetAttributes() inside the loop), it will be trivial to
1006 // customize the subitems (in report mode) too.
1007 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1008 wxListItemAttr
*attr
= item
->GetAttributes();
1009 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1011 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1012 if ( paintBG
|| hasBgCol
)
1016 dc
->SetBrush( * m_hilightBrush
);
1021 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1023 dc
->SetBrush( * wxWHITE_BRUSH
);
1026 dc
->SetPen( * wxTRANSPARENT_PEN
);
1027 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1028 m_bound_hilight
.width
, m_bound_hilight
.height
);
1031 if (m_mode
== wxLC_REPORT
)
1033 wxNode
*node
= m_items
.First();
1036 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1037 int x
= item
->GetX();
1038 if (item
->HasImage())
1041 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1042 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1043 x
+= item
->GetX() + 5;
1045 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1046 if (item
->HasText())
1048 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1050 dc
->DestroyClippingRegion();
1051 node
= node
->Next();
1056 wxNode
*node
= m_items
.First();
1059 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1060 if (item
->HasImage())
1062 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1064 if (item
->HasText())
1066 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1072 void wxListLineData::Hilight( bool on
)
1074 if (on
== m_hilighted
) return;
1077 m_owner
->SelectLine( this );
1079 m_owner
->DeselectLine( this );
1082 void wxListLineData::ReverseHilight( void )
1084 m_hilighted
= !m_hilighted
;
1086 m_owner
->SelectLine( this );
1088 m_owner
->DeselectLine( this );
1091 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1095 dc
->SetPen( * wxBLACK_PEN
);
1096 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1097 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1098 m_bound_hilight
.width
, m_bound_hilight
.height
);
1102 void wxListLineData::Draw( wxDC
*dc
)
1104 DoDraw( dc
, m_hilighted
, m_hilighted
);
1107 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1109 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1110 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1113 bool wxListLineData::IsHilighted( void )
1118 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1123 dest
.height
= height
;
1126 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1130 dest
.width
= source
.width
;
1131 dest
.height
= source
.height
;
1134 //-----------------------------------------------------------------------------
1135 // wxListHeaderWindow
1136 //-----------------------------------------------------------------------------
1138 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1140 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1141 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1142 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1143 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1146 wxListHeaderWindow::wxListHeaderWindow( void )
1148 m_owner
= (wxListMainWindow
*) NULL
;
1149 m_currentCursor
= (wxCursor
*) NULL
;
1150 m_resizeCursor
= (wxCursor
*) NULL
;
1151 m_isDragging
= FALSE
;
1154 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1155 const wxPoint
&pos
, const wxSize
&size
,
1156 long style
, const wxString
&name
) :
1157 wxWindow( win
, id
, pos
, size
, style
, name
)
1160 // m_currentCursor = wxSTANDARD_CURSOR;
1161 m_currentCursor
= (wxCursor
*) NULL
;
1162 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1163 m_isDragging
= FALSE
;
1166 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1169 wxListHeaderWindow::~wxListHeaderWindow( void )
1171 delete m_resizeCursor
;
1174 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1176 const int m_corner
= 1;
1178 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1180 dc
->SetPen( *wxBLACK_PEN
);
1181 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1182 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1184 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1187 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1188 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1190 dc
->SetPen( *wxWHITE_PEN
);
1191 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1192 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1193 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1194 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1197 // shift the DC origin to match the position of the main window horz
1198 // scrollbar: this allows us to always use logical coords
1199 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1201 #if wxUSE_GENERIC_LIST_EXTENSIONS
1203 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1206 m_owner
->GetViewStart( &x
, NULL
);
1208 // account for the horz scrollbar offset
1209 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1210 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1213 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1215 wxPaintDC
dc( this );
1221 dc
.SetFont( GetFont() );
1223 // width and height of the entire header window
1225 GetClientSize( &w
, &h
);
1226 #if wxUSE_GENERIC_LIST_EXTENSIONS
1227 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1228 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1230 dc
.SetBackgroundMode(wxTRANSPARENT
);
1232 // do *not* use the listctrl colour for headers - one day we will have a
1233 // function to set it separately
1234 //dc.SetTextForeground( *wxBLACK );
1235 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1237 int x
= 1; // left of the header rect
1238 const int y
= 1; // top
1239 int numColumns
= m_owner
->GetColumnCount();
1241 for (int i
= 0; i
< numColumns
; i
++)
1243 m_owner
->GetColumn( i
, item
);
1244 int wCol
= item
.m_width
;
1245 int cw
= wCol
- 2; // the width of the rect to draw
1247 int xEnd
= x
+ wCol
;
1249 // VZ: no, draw it normally - this is better now as we allow resizing
1250 // of the last column as well
1252 // let the last column occupy all available space
1253 if ( i
== numColumns
- 1 )
1257 dc
.SetPen( *wxWHITE_PEN
);
1259 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1260 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1261 dc
.DrawText( item
.m_text
, x
+4, y
+3 );
1262 dc
.DestroyClippingRegion();
1271 void wxListHeaderWindow::DrawCurrent()
1273 int x1
= m_currentX
;
1275 ClientToScreen( &x1
, &y1
);
1277 int x2
= m_currentX
-1;
1279 m_owner
->GetClientSize( NULL
, &y2
);
1280 m_owner
->ClientToScreen( &x2
, &y2
);
1283 dc
.SetLogicalFunction( wxINVERT
);
1284 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1285 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1289 dc
.DrawLine( x1
, y1
, x2
, y2
);
1291 dc
.SetLogicalFunction( wxCOPY
);
1293 dc
.SetPen( wxNullPen
);
1294 dc
.SetBrush( wxNullBrush
);
1297 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1299 // we want to work with logical coords
1300 #if wxUSE_GENERIC_LIST_EXTENSIONS
1302 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1303 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1304 int x
= event
.GetX();
1305 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1306 int y
= event
.GetY();
1310 // we don't draw the line beyond our window, but we allow dragging it
1313 GetClientSize( &w
, NULL
);
1314 #if wxUSE_GENERIC_LIST_EXTENSIONS
1315 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1316 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1319 // erase the line if it was drawn
1320 if ( m_currentX
< w
)
1323 if (event
.ButtonUp())
1326 m_isDragging
= FALSE
;
1328 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1335 m_currentX
= m_minX
+ 7;
1337 // draw in the new location
1338 if ( m_currentX
< w
)
1342 else // not dragging
1345 bool hit_border
= FALSE
;
1347 // end of the current column
1350 // find the column where this event occured
1351 int countCol
= m_owner
->GetColumnCount();
1352 for (int j
= 0; j
< countCol
; j
++)
1354 xpos
+= m_owner
->GetColumnWidth( j
);
1357 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1359 // near the column border
1366 // inside the column
1373 if (event
.LeftDown())
1377 m_isDragging
= TRUE
;
1384 wxWindow
*parent
= GetParent();
1385 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1386 le
.SetEventObject( parent
);
1387 le
.m_col
= m_column
;
1388 parent
->GetEventHandler()->ProcessEvent( le
);
1391 else if (event
.Moving())
1396 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1397 m_currentCursor
= m_resizeCursor
;
1401 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1402 m_currentCursor
= wxSTANDARD_CURSOR
;
1406 SetCursor(*m_currentCursor
);
1411 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1413 m_owner
->SetFocus();
1416 //-----------------------------------------------------------------------------
1417 // wxListRenameTimer (internal)
1418 //-----------------------------------------------------------------------------
1420 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1425 void wxListRenameTimer::Notify()
1427 m_owner
->OnRenameTimer();
1430 //-----------------------------------------------------------------------------
1431 // wxListTextCtrl (internal)
1432 //-----------------------------------------------------------------------------
1434 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1436 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1437 EVT_CHAR (wxListTextCtrl::OnChar
)
1438 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1441 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1442 const wxWindowID id
,
1445 wxListMainWindow
*owner
,
1446 const wxString
&value
,
1450 const wxValidator
& validator
,
1451 const wxString
&name
)
1452 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1457 (*m_accept
) = FALSE
;
1459 m_startValue
= value
;
1462 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1464 if (event
.m_keyCode
== WXK_RETURN
)
1467 (*m_res
) = GetValue();
1469 if (!wxPendingDelete
.Member(this))
1470 wxPendingDelete
.Append(this);
1472 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1473 m_owner
->OnRenameAccept();
1477 if (event
.m_keyCode
== WXK_ESCAPE
)
1479 (*m_accept
) = FALSE
;
1482 if (!wxPendingDelete
.Member(this))
1483 wxPendingDelete
.Append(this);
1491 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1493 if (!wxPendingDelete
.Member(this))
1494 wxPendingDelete
.Append(this);
1496 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1497 m_owner
->OnRenameAccept();
1500 //-----------------------------------------------------------------------------
1502 //-----------------------------------------------------------------------------
1504 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1506 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1507 EVT_PAINT (wxListMainWindow::OnPaint
)
1508 EVT_SIZE (wxListMainWindow::OnSize
)
1509 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1510 EVT_CHAR (wxListMainWindow::OnChar
)
1511 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1512 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1513 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1514 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1517 wxListMainWindow::wxListMainWindow()
1520 m_columns
.DeleteContents( TRUE
);
1521 m_current
= (wxListLineData
*) NULL
;
1523 m_hilightBrush
= (wxBrush
*) NULL
;
1527 m_small_image_list
= (wxImageList
*) NULL
;
1528 m_normal_image_list
= (wxImageList
*) NULL
;
1529 m_small_spacing
= 30;
1530 m_normal_spacing
= 40;
1533 m_lastOnSame
= FALSE
;
1534 m_renameTimer
= new wxListRenameTimer( this );
1535 m_isCreated
= FALSE
;
1539 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1542 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1543 const wxPoint
&pos
, const wxSize
&size
,
1544 long style
, const wxString
&name
) :
1545 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1548 m_columns
.DeleteContents( TRUE
);
1549 m_current
= (wxListLineData
*) NULL
;
1552 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1553 m_small_image_list
= (wxImageList
*) NULL
;
1554 m_normal_image_list
= (wxImageList
*) NULL
;
1555 m_small_spacing
= 30;
1556 m_normal_spacing
= 40;
1559 m_isCreated
= FALSE
;
1563 if (m_mode
& wxLC_REPORT
)
1565 #if wxUSE_GENERIC_LIST_EXTENSIONS
1577 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1580 m_lastOnSame
= FALSE
;
1581 m_renameTimer
= new wxListRenameTimer( this );
1582 m_renameAccept
= FALSE
;
1584 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1587 wxListMainWindow::~wxListMainWindow()
1591 if (m_hilightBrush
) delete m_hilightBrush
;
1593 delete m_renameTimer
;
1596 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1598 if (m_dirty
) return;
1606 line
->GetExtent( x
, y
, w
, h
);
1607 CalcScrolledPosition( x
, y
, &x
, &y
);
1608 wxRect
rect( x
, y
, w
, h
);
1609 Refresh( TRUE
, &rect
);
1612 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1614 // Note: a wxPaintDC must be constructed even if no drawing is
1615 // done (a Windows requirement).
1616 wxPaintDC
dc( this );
1619 if (m_dirty
) return;
1621 if (m_lines
.GetCount() == 0) return;
1625 dc
.SetFont( GetFont() );
1627 if (m_mode
& wxLC_REPORT
)
1629 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1631 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1633 wxSize clientSize
= GetClientSize();
1636 int lineSpacing
= 0;
1637 wxListLineData
*line
= &m_lines
[0];
1639 line
->GetSize( dummy
, lineSpacing
);
1642 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1644 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1645 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1647 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1649 m_lines
[i
].Draw( &dc
);
1650 // Draw horizontal rule if required
1651 if (GetWindowStyle() & wxLC_HRULES
)
1652 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1655 // Draw last horizontal rule
1656 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1657 dc
.DrawLine(0, i
*lineSpacing
, clientSize
.x
, i
*lineSpacing
);
1659 // Draw vertical rules if required
1660 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1663 wxRect firstItemRect
;
1664 wxRect lastItemRect
;
1665 GetItemRect(0, firstItemRect
);
1666 GetItemRect(GetItemCount() - 1, lastItemRect
);
1667 int x
= firstItemRect
.GetX();
1668 for (col
= 0; col
< GetColumnCount(); col
++)
1670 int colWidth
= GetColumnWidth(col
);
1672 dc
.DrawLine(x
, firstItemRect
.GetY() - 1, x
, lastItemRect
.GetBottom() + 1);
1678 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1679 m_lines
[i
].Draw( &dc
);
1682 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1687 void wxListMainWindow::HilightAll( bool on
)
1689 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1691 wxListLineData
*line
= &m_lines
[i
];
1692 if (line
->IsHilighted() != on
)
1694 line
->Hilight( on
);
1695 RefreshLine( line
);
1700 void wxListMainWindow::SendNotify( wxListLineData
*line
, wxEventType command
)
1702 wxListEvent
le( command
, GetParent()->GetId() );
1703 le
.SetEventObject( GetParent() );
1704 le
.m_itemIndex
= GetIndexOfLine( line
);
1705 line
->GetItem( 0, le
.m_item
);
1706 GetParent()->GetEventHandler()->ProcessEvent( le
);
1707 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1710 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1712 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1715 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1717 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1720 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1722 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1725 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1727 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1730 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1732 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1737 void wxListMainWindow::EditLabel( long item
)
1739 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1740 wxT("wrong index in wxListCtrl::Edit()") );
1742 m_currentEdit
= &m_lines
[(size_t)item
];
1744 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1745 le
.SetEventObject( GetParent() );
1746 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1747 m_currentEdit
->GetItem( 0, le
.m_item
);
1748 GetParent()->GetEventHandler()->ProcessEvent( le
);
1750 if (!le
.IsAllowed())
1753 // We have to call this here because the label in
1754 // question might just have been added and no screen
1755 // update taken place.
1756 if (m_dirty
) wxYield();
1759 m_currentEdit
->GetText( 0, s
);
1764 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1766 wxClientDC
dc(this);
1768 x
= dc
.LogicalToDeviceX( x
);
1769 y
= dc
.LogicalToDeviceY( y
);
1771 wxListTextCtrl
*text
= new wxListTextCtrl(
1772 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1776 void wxListMainWindow::OnRenameTimer()
1778 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1780 Edit( m_lines
.Index( *m_current
) );
1783 void wxListMainWindow::OnRenameAccept()
1785 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1786 le
.SetEventObject( GetParent() );
1787 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1788 m_currentEdit
->GetItem( 0, le
.m_item
);
1789 le
.m_item
.m_text
= m_renameRes
;
1790 GetParent()->GetEventHandler()->ProcessEvent( le
);
1792 if (!le
.IsAllowed()) return;
1795 info
.m_mask
= wxLIST_MASK_TEXT
;
1796 info
.m_itemId
= le
.m_itemIndex
;
1797 info
.m_text
= m_renameRes
;
1798 info
.SetTextColour(le
.m_item
.GetTextColour());
1802 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1804 event
.SetEventObject( GetParent() );
1805 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1807 if (!m_current
) return;
1808 if (m_dirty
) return;
1809 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1811 int x
= event
.GetX();
1812 int y
= event
.GetY();
1813 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1815 /* Did we actually hit an item ? */
1817 wxListLineData
*line
= (wxListLineData
*) NULL
;
1818 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1821 hitResult
= line
->IsHit( x
, y
);
1822 if (hitResult
) break;
1823 line
= (wxListLineData
*) NULL
;
1826 if (event
.Dragging())
1828 if (m_dragCount
== 0)
1829 m_dragStart
= wxPoint(x
,y
);
1833 if (m_dragCount
!= 3) return;
1835 int command
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1836 if (event
.RightIsDown()) command
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1838 wxListEvent
le( command
, GetParent()->GetId() );
1839 le
.SetEventObject( GetParent() );
1840 le
.m_pointDrag
= m_dragStart
;
1841 GetParent()->GetEventHandler()->ProcessEvent( le
);
1852 bool forceClick
= FALSE
;
1853 if (event
.ButtonDClick())
1855 m_renameTimer
->Stop();
1856 m_lastOnSame
= FALSE
;
1858 if ( line
== m_lineBeforeLastClicked
)
1862 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1868 // the first click was on another item, so don't interpret this as
1869 // a double click, but as a simple click instead
1874 if (event
.LeftUp() && m_lastOnSame
)
1877 if ((line
== m_current
) &&
1878 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1879 (m_mode
& wxLC_EDIT_LABELS
) )
1881 m_renameTimer
->Start( 100, TRUE
);
1883 m_lastOnSame
= FALSE
;
1887 if (event
.RightDown())
1889 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
);
1893 if (event
.MiddleDown())
1895 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1899 if ( event
.LeftDown() || forceClick
)
1901 m_lineBeforeLastClicked
= m_lineLastClicked
;
1902 m_lineLastClicked
= line
;
1905 wxListLineData
*oldCurrent
= m_current
;
1906 if (m_mode
& wxLC_SINGLE_SEL
)
1909 HilightAll( FALSE
);
1910 m_current
->ReverseHilight();
1911 RefreshLine( m_current
);
1915 if (event
.ControlDown())
1918 m_current
->ReverseHilight();
1919 RefreshLine( m_current
);
1921 else if (event
.ShiftDown())
1927 int numOfCurrent
= -1;
1928 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1930 wxListLineData
*test_line
= &m_lines
[j
];
1932 if (test_line
== oldCurrent
) break;
1937 for (j
= 0; j
< m_lines
.GetCount(); j
++)
1939 wxListLineData
*test_line
= &m_lines
[j
];
1941 if (test_line
== line
) break;
1944 if (numOfLine
< numOfCurrent
)
1947 numOfLine
= numOfCurrent
;
1951 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
1953 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
1954 test_line
->Hilight(TRUE
);
1955 RefreshLine( test_line
);
1961 HilightAll( FALSE
);
1962 m_current
->ReverseHilight();
1963 RefreshLine( m_current
);
1966 if (m_current
!= oldCurrent
)
1968 RefreshLine( oldCurrent
);
1969 UnfocusLine( oldCurrent
);
1970 FocusLine( m_current
);
1973 // forceClick is only set if the previous click was on another item
1974 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
1980 void wxListMainWindow::MoveToFocus()
1982 if (!m_current
) return;
1988 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
1992 GetClientSize( &client_w
, &client_h
);
1994 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
1995 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1997 if (m_mode
& wxLC_REPORT
)
1999 if (item_y
-5 < view_y
)
2000 Scroll( -1, (item_y
-5)/m_yScroll
);
2001 if (item_y
+item_h
+5 > view_y
+client_h
)
2002 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2006 if (item_x
-view_x
< 5)
2007 Scroll( (item_x
-5)/m_xScroll
, -1 );
2008 if (item_x
+item_w
-5 > view_x
+client_w
)
2009 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2013 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2015 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2016 wxListLineData
*oldCurrent
= m_current
;
2017 m_current
= newCurrent
;
2018 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2019 RefreshLine( m_current
);
2020 RefreshLine( oldCurrent
);
2021 FocusLine( m_current
);
2022 UnfocusLine( oldCurrent
);
2026 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2028 wxWindow
*parent
= GetParent();
2030 /* we propagate the key event up */
2031 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2032 ke
.m_shiftDown
= event
.m_shiftDown
;
2033 ke
.m_controlDown
= event
.m_controlDown
;
2034 ke
.m_altDown
= event
.m_altDown
;
2035 ke
.m_metaDown
= event
.m_metaDown
;
2036 ke
.m_keyCode
= event
.m_keyCode
;
2039 ke
.SetEventObject( parent
);
2040 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2045 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2047 wxWindow
*parent
= GetParent();
2049 /* we send a list_key event up */
2052 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2053 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2054 m_current
->GetItem( 0, le
.m_item
);
2055 le
.m_code
= (int)event
.KeyCode();
2056 le
.SetEventObject( parent
);
2057 parent
->GetEventHandler()->ProcessEvent( le
);
2060 /* we propagate the char event up */
2061 wxKeyEvent
ke( wxEVT_CHAR
);
2062 ke
.m_shiftDown
= event
.m_shiftDown
;
2063 ke
.m_controlDown
= event
.m_controlDown
;
2064 ke
.m_altDown
= event
.m_altDown
;
2065 ke
.m_metaDown
= event
.m_metaDown
;
2066 ke
.m_keyCode
= event
.m_keyCode
;
2069 ke
.SetEventObject( parent
);
2070 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2072 if (event
.KeyCode() == WXK_TAB
)
2074 wxNavigationKeyEvent nevent
;
2075 nevent
.SetWindowChange( event
.ControlDown() );
2076 nevent
.SetDirection( !event
.ShiftDown() );
2077 nevent
.SetEventObject( GetParent()->GetParent() );
2078 nevent
.SetCurrentFocus( m_parent
);
2079 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2082 /* no item -> nothing to do */
2089 switch (event
.KeyCode())
2093 int index
= m_lines
.Index(*m_current
);
2094 if (index
!= wxNOT_FOUND
&& index
> 0)
2095 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2100 int index
= m_lines
.Index(*m_current
);
2101 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2102 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2107 if (!m_lines
.IsEmpty())
2108 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2113 if (!m_lines
.IsEmpty())
2114 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2120 int index
= m_lines
.Index(*m_current
);
2121 if (m_mode
& wxLC_REPORT
)
2123 steps
= m_visibleLines
-1;
2127 steps
= index
% m_visibleLines
;
2129 if (index
!= wxNOT_FOUND
)
2132 if (index
< 0) index
= 0;
2133 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2140 int index
= m_lines
.Index(*m_current
);
2141 if (m_mode
& wxLC_REPORT
)
2143 steps
= m_visibleLines
-1;
2147 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2150 if (index
!= wxNOT_FOUND
)
2153 if ((size_t)index
>= m_lines
.GetCount())
2154 index
= m_lines
.GetCount()-1;
2155 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2161 if (!(m_mode
& wxLC_REPORT
))
2163 int index
= m_lines
.Index(*m_current
);
2164 if (index
!= wxNOT_FOUND
)
2166 index
-= m_visibleLines
;
2167 if (index
< 0) index
= 0;
2168 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2175 if (!(m_mode
& wxLC_REPORT
))
2177 int index
= m_lines
.Index(*m_current
);
2178 if (index
!= wxNOT_FOUND
)
2180 index
+= m_visibleLines
;
2181 if ((size_t)index
>= m_lines
.GetCount())
2182 index
= m_lines
.GetCount()-1;
2183 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2190 if (m_mode
& wxLC_SINGLE_SEL
)
2192 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2193 le
.SetEventObject( GetParent() );
2194 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2195 m_current
->GetItem( 0, le
.m_item
);
2196 GetParent()->GetEventHandler()->ProcessEvent( le
);
2200 m_current
->ReverseHilight();
2201 RefreshLine( m_current
);
2207 if (!(m_mode
& wxLC_SINGLE_SEL
))
2209 wxListLineData
*oldCurrent
= m_current
;
2210 m_current
->ReverseHilight();
2211 int index
= m_lines
.Index( *m_current
) + 1;
2212 if ( (size_t)index
< m_lines
.GetCount() )
2213 m_current
= &m_lines
[index
];
2214 RefreshLine( oldCurrent
);
2215 RefreshLine( m_current
);
2216 UnfocusLine( oldCurrent
);
2217 FocusLine( m_current
);
2225 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2226 le
.SetEventObject( GetParent() );
2227 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2228 m_current
->GetItem( 0, le
.m_item
);
2229 GetParent()->GetEventHandler()->ProcessEvent( le
);
2242 extern wxWindow
*g_focusWindow
;
2245 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2248 RefreshLine( m_current
);
2250 if (!GetParent()) return;
2253 g_focusWindow
= GetParent();
2256 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2257 event
.SetEventObject( GetParent() );
2258 GetParent()->GetEventHandler()->ProcessEvent( event
);
2261 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2264 RefreshLine( m_current
);
2267 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2270 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2276 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2278 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2280 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2283 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2285 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2287 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2289 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2291 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2293 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2298 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2300 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2302 m_normal_image_list
->GetSize( index
, width
, height
);
2305 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2307 m_small_image_list
->GetSize( index
, width
, height
);
2310 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2312 m_small_image_list
->GetSize( index
, width
, height
);
2315 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2317 m_small_image_list
->GetSize( index
, width
, height
);
2324 int wxListMainWindow::GetTextLength( wxString
&s
)
2326 wxClientDC
dc( this );
2329 dc
.GetTextExtent( s
, &lw
, &lh
);
2333 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2335 int i
= m_lines
.Index(*line
);
2336 if (i
== wxNOT_FOUND
) return -1;
2340 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2344 // calc the spacing from the icon size
2347 if ((imageList
) && (imageList
->GetImageCount()) )
2349 imageList
->GetSize(0, width
, height
);
2352 if (which
== wxIMAGE_LIST_NORMAL
)
2354 m_normal_image_list
= imageList
;
2355 m_normal_spacing
= width
+ 8;
2358 if (which
== wxIMAGE_LIST_SMALL
)
2360 m_small_image_list
= imageList
;
2361 m_small_spacing
= width
+ 14;
2365 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2370 m_small_spacing
= spacing
;
2374 m_normal_spacing
= spacing
;
2378 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2380 return isSmall
? m_small_spacing
: m_normal_spacing
;
2383 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2386 wxNode
*node
= m_columns
.Nth( col
);
2389 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
)+7;
2390 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2391 column
->SetItem( item
);
2394 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2396 headerWin
->m_dirty
= TRUE
;
2399 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2401 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2402 _T("SetColumnWidth() can only be called in report mode.") );
2406 wxNode
*node
= (wxNode
*) NULL
;
2408 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2410 // TODO do use the header
2413 else if (width
== wxLIST_AUTOSIZE
)
2415 wxClientDC
dc(this);
2416 dc
.SetFont( GetFont() );
2419 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2421 wxListLineData
*line
= &m_lines
[i
];
2422 wxNode
*n
= line
->m_items
.Nth( col
);
2425 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2426 int current
= 0, ix
= 0, iy
= 0;
2427 wxCoord lx
= 0, ly
= 0;
2428 if (item
->HasImage())
2430 GetImageSize( item
->GetImage(), ix
, iy
);
2433 if (item
->HasText())
2436 item
->GetText( str
);
2437 dc
.GetTextExtent( str
, &lx
, &ly
);
2440 if (current
> max
) max
= current
;
2446 node
= m_columns
.Nth( col
);
2449 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2450 column
->SetWidth( width
);
2453 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2455 wxListLineData
*line
= &m_lines
[i
];
2456 wxNode
*n
= line
->m_items
.Nth( col
);
2459 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2460 item
->SetSize( width
, -1 );
2464 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2466 headerWin
->m_dirty
= TRUE
;
2469 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2471 wxNode
*node
= m_columns
.Nth( col
);
2474 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2475 column
->GetItem( item
);
2487 int wxListMainWindow::GetColumnWidth( int col
)
2489 wxNode
*node
= m_columns
.Nth( col
);
2492 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2493 return column
->GetWidth();
2501 int wxListMainWindow::GetColumnCount()
2503 return m_columns
.Number();
2506 int wxListMainWindow::GetCountPerPage()
2508 return m_visibleLines
;
2511 void wxListMainWindow::SetItem( wxListItem
&item
)
2514 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2516 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2517 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2518 line
->SetItem( item
.m_col
, item
);
2522 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2524 // m_dirty = TRUE; no recalcs needed
2526 wxListLineData
*oldCurrent
= m_current
;
2528 if (stateMask
& wxLIST_STATE_FOCUSED
)
2530 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2532 wxListLineData
*line
= &m_lines
[(size_t)item
];
2533 UnfocusLine( m_current
);
2535 FocusLine( m_current
);
2536 if ((m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
) oldCurrent
->Hilight( FALSE
);
2537 RefreshLine( m_current
);
2538 if (oldCurrent
) RefreshLine( oldCurrent
);
2542 if (stateMask
& wxLIST_STATE_SELECTED
)
2544 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2545 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
)) return;
2547 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2549 wxListLineData
*line
= &m_lines
[(size_t)item
];
2550 if (m_mode
& wxLC_SINGLE_SEL
)
2552 UnfocusLine( m_current
);
2554 FocusLine( m_current
);
2555 if (oldCurrent
) oldCurrent
->Hilight( FALSE
);
2556 RefreshLine( m_current
);
2557 if (oldCurrent
) RefreshLine( oldCurrent
);
2559 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2560 if (on
!= line
->IsHilighted())
2562 line
->Hilight( on
);
2563 RefreshLine( line
);
2569 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2571 int ret
= wxLIST_STATE_DONTCARE
;
2572 if (stateMask
& wxLIST_STATE_FOCUSED
)
2574 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2576 wxListLineData
*line
= &m_lines
[(size_t)item
];
2577 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2580 if (stateMask
& wxLIST_STATE_SELECTED
)
2582 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2584 wxListLineData
*line
= &m_lines
[(size_t)item
];
2585 if (line
->IsHilighted()) ret
|= wxLIST_STATE_FOCUSED
;
2591 void wxListMainWindow::GetItem( wxListItem
&item
)
2593 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2595 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2596 line
->GetItem( item
.m_col
, item
);
2607 int wxListMainWindow::GetItemCount()
2609 return m_lines
.GetCount();
2612 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2614 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2616 m_lines
[(size_t)index
].GetRect( rect
);
2627 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2629 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2632 m_lines
[(size_t)item
].GetRect( rect
);
2644 int wxListMainWindow::GetSelectedItemCount()
2647 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2649 if (m_lines
[i
].IsHilighted()) ret
++;
2654 void wxListMainWindow::SetMode( long mode
)
2661 if (m_mode
& wxLC_REPORT
)
2663 #if wxUSE_GENERIC_LIST_EXTENSIONS
2677 long wxListMainWindow::GetMode() const
2682 void wxListMainWindow::CalculatePositions()
2684 if (m_lines
.IsEmpty()) return;
2686 wxClientDC
dc( this );
2687 dc
.SetFont( GetFont() );
2689 int iconSpacing
= 0;
2690 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2691 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2693 // we take the first line (which also can be an icon or
2694 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2695 // measure the size of the line
2699 int lineSpacing
= 0;
2701 wxListLineData
*line
= &m_lines
[0];
2702 line
->CalculateSize( &dc
, iconSpacing
);
2704 line
->GetSize( dummy
, lineSpacing
);
2707 int clientWidth
= 0;
2708 int clientHeight
= 0;
2710 if (m_mode
& wxLC_REPORT
)
2714 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2715 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2716 #if wxUSE_GENERIC_LIST_EXTENSIONS
2717 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2719 SetScrollbars( m_xScroll
, m_yScroll
, 0, (entireHeight
+15) / m_yScroll
, 0, scroll_pos
, TRUE
);
2721 GetClientSize( &clientWidth
, &clientHeight
);
2723 int entireWidth
= 0 ;
2724 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2726 wxListLineData
*line
= &m_lines
[j
];
2727 line
->CalculateSize( &dc
, iconSpacing
);
2728 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2730 for (int i
= 0; i
< GetColumnCount(); i
++)
2732 line
->SetColumnPosition( i
, col_x
);
2733 col_x
+= GetColumnWidth( i
);
2735 entireWidth
= wxMax( entireWidth
, col_x
) ;
2736 #if wxUSE_GENERIC_LIST_EXTENSIONS
2737 line
->SetPosition( &dc
, x
, y
, col_x
);
2739 y
+= lineSpacing
; // one pixel blank line between items
2741 m_visibleLines
= clientHeight
/ lineSpacing
;
2742 #if wxUSE_GENERIC_LIST_EXTENSIONS
2743 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/ m_xScroll
, (entireHeight
+15) / m_yScroll
, x_scroll_pos
, scroll_pos
, TRUE
);
2748 // at first we try without any scrollbar. if the items don't
2749 // fit into the window, we recalculate after subtracting an
2750 // approximated 15 pt for the horizontal scrollbar
2752 GetSize( &clientWidth
, &clientHeight
);
2753 clientHeight
-= 4; // sunken frame
2755 int entireWidth
= 0;
2757 for (int tries
= 0; tries
< 2; tries
++)
2764 int m_currentVisibleLines
= 0;
2765 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2767 m_currentVisibleLines
++;
2768 wxListLineData
*line
= &m_lines
[i
];
2769 line
->CalculateSize( &dc
, iconSpacing
);
2770 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2771 line
->GetSize( lineWidth
, lineHeight
);
2772 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2774 if (m_currentVisibleLines
> m_visibleLines
)
2775 m_visibleLines
= m_currentVisibleLines
;
2776 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2778 m_currentVisibleLines
= 0;
2781 entireWidth
+= maxWidth
+6;
2784 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2785 if ((tries
== 0) && (entireWidth
> clientWidth
))
2787 clientHeight
-= 15; // scrollbar height
2789 m_currentVisibleLines
= 0;
2792 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2796 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2797 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2801 void wxListMainWindow::RealizeChanges()
2805 if (!m_lines
.IsEmpty())
2806 m_current
= &m_lines
[0];
2810 FocusLine( m_current
);
2811 // TODO: MSW doesn't automatically hilight the
2813 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2817 long wxListMainWindow::GetNextItem( long item
,
2818 int WXUNUSED(geometry
),
2822 max
= GetItemCount();
2823 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2824 _T("invalid listctrl index in GetNextItem()") );
2826 // notice that we start with the next item (or the first one if item == -1)
2827 // and this is intentional to allow writing a simple loop to iterate over
2828 // all selected items
2832 // this is not an error because the index was ok initially, just no
2837 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2839 wxListLineData
*line
= &m_lines
[i
];
2840 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2842 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2852 void wxListMainWindow::DeleteItem( long index
)
2855 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2857 wxListLineData
*line
= &m_lines
[(size_t)index
];
2858 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2860 m_lines
.RemoveAt( (size_t)index
);
2864 void wxListMainWindow::DeleteColumn( int col
)
2866 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2867 wxT("attempting to delete inexistent column in wxListView") );
2870 wxNode
*node
= m_columns
.Nth( col
);
2871 if (node
) m_columns
.DeleteNode( node
);
2874 void wxListMainWindow::DeleteAllItems()
2877 m_current
= (wxListLineData
*) NULL
;
2879 // to make the deletion of all items faster, we don't send the
2880 // notifications in this case: this is compatible with wxMSW and
2881 // documented in DeleteAllItems() description
2883 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2884 event
.SetEventObject( GetParent() );
2885 GetParent()->GetEventHandler()->ProcessEvent( event
);
2890 void wxListMainWindow::DeleteEverything()
2897 void wxListMainWindow::EnsureVisible( long index
)
2899 // We have to call this here because the label in
2900 // question might just have been added and no screen
2901 // update taken place.
2902 if (m_dirty
) wxYield();
2904 wxListLineData
*oldCurrent
= m_current
;
2905 m_current
= (wxListLineData
*) NULL
;
2906 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2907 m_current
= &m_lines
[(size_t)index
];
2908 if (m_current
) MoveToFocus();
2909 m_current
= oldCurrent
;
2912 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
2916 if (pos
< 0) pos
= 0;
2917 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2919 wxListLineData
*line
= &m_lines
[i
];
2921 line
->GetText( 0, s
);
2922 if (s
== tmp
) return pos
;
2928 long wxListMainWindow::FindItem(long start
, long data
)
2931 if (pos
< 0) pos
= 0;
2932 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
2934 wxListLineData
*line
= &m_lines
[i
];
2936 line
->GetItem( 0, item
);
2937 if (item
.m_data
== data
) return pos
;
2943 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
2945 CalcUnscrolledPosition( x
, y
, &x
, &y
);
2948 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2950 wxListLineData
*line
= &m_lines
[i
];
2951 long ret
= line
->IsHit( x
, y
);
2962 void wxListMainWindow::InsertItem( wxListItem
&item
)
2966 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
2967 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
2968 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
2969 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
2971 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
2973 if (m_mode
& wxLC_REPORT
)
2975 line
->InitItems( GetColumnCount() );
2976 item
.m_width
= GetColumnWidth( 0 )-3;
2980 line
->InitItems( 1 );
2983 line
->SetItem( 0, item
);
2984 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
2986 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
2990 m_lines
.Add( line
);
2991 item
.m_itemId
= m_lines
.GetCount();
2995 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
2998 if (m_mode
& wxLC_REPORT
)
3000 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
) item
.m_width
= GetTextLength( item
.m_text
);
3001 wxListHeaderData
*column
= new wxListHeaderData( item
);
3002 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3004 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3006 m_columns
.Insert( node
, column
);
3010 m_columns
.Append( column
);
3015 wxListCtrlCompare list_ctrl_compare_func_2
;
3016 long list_ctrl_compare_data
;
3018 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3020 wxListLineData
*line1
= *arg1
;
3021 wxListLineData
*line2
= *arg2
;
3023 line1
->GetItem( 0, item
);
3024 long data1
= item
.m_data
;
3025 line2
->GetItem( 0, item
);
3026 long data2
= item
.m_data
;
3027 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3030 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3032 list_ctrl_compare_func_2
= fn
;
3033 list_ctrl_compare_data
= data
;
3034 m_lines
.Sort( list_ctrl_compare_func_1
);
3038 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3040 wxScrolledWindow::OnScroll( event
) ;
3041 #if wxUSE_GENERIC_LIST_EXTENSIONS
3043 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3045 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3048 lc
->m_headerWin
->Refresh() ;
3050 lc
->m_headerWin
->MacUpdateImmediately() ;
3057 // -------------------------------------------------------------------------------------
3059 // -------------------------------------------------------------------------------------
3061 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3063 wxListItem::wxListItem()
3072 m_format
= wxLIST_FORMAT_CENTRE
;
3078 void wxListItem::Clear()
3087 m_format
= wxLIST_FORMAT_CENTRE
;
3089 m_text
= wxEmptyString
;
3091 if (m_attr
) delete m_attr
;
3095 void wxListItem::ClearAttributes()
3097 if (m_attr
) delete m_attr
;
3101 // -------------------------------------------------------------------------------------
3103 // -------------------------------------------------------------------------------------
3105 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3107 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3108 wxNotifyEvent( commandType
, id
)
3114 m_cancelled
= FALSE
;
3119 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3121 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3123 wxNotifyEvent::CopyObject(object_dest
);
3125 obj
->m_code
= m_code
;
3126 obj
->m_itemIndex
= m_itemIndex
;
3127 obj
->m_oldItemIndex
= m_oldItemIndex
;
3129 obj
->m_cancelled
= m_cancelled
;
3130 obj
->m_pointDrag
= m_pointDrag
;
3131 obj
->m_item
.m_mask
= m_item
.m_mask
;
3132 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3133 obj
->m_item
.m_col
= m_item
.m_col
;
3134 obj
->m_item
.m_state
= m_item
.m_state
;
3135 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3136 obj
->m_item
.m_text
= m_item
.m_text
;
3137 obj
->m_item
.m_image
= m_item
.m_image
;
3138 obj
->m_item
.m_data
= m_item
.m_data
;
3139 obj
->m_item
.m_format
= m_item
.m_format
;
3140 obj
->m_item
.m_width
= m_item
.m_width
;
3142 if ( m_item
.HasAttributes() )
3144 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3148 // -------------------------------------------------------------------------------------
3150 // -------------------------------------------------------------------------------------
3152 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3154 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3155 EVT_SIZE (wxListCtrl::OnSize
)
3156 EVT_IDLE (wxListCtrl::OnIdle
)
3159 wxListCtrl::wxListCtrl()
3161 m_imageListNormal
= (wxImageList
*) NULL
;
3162 m_imageListSmall
= (wxImageList
*) NULL
;
3163 m_imageListState
= (wxImageList
*) NULL
;
3164 m_mainWin
= (wxListMainWindow
*) NULL
;
3165 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3168 wxListCtrl::~wxListCtrl()
3172 bool wxListCtrl::Create(wxWindow
*parent
,
3177 const wxValidator
&validator
,
3178 const wxString
&name
)
3180 m_imageListNormal
= (wxImageList
*) NULL
;
3181 m_imageListSmall
= (wxImageList
*) NULL
;
3182 m_imageListState
= (wxImageList
*) NULL
;
3183 m_mainWin
= (wxListMainWindow
*) NULL
;
3184 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3186 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3188 style
= style
| wxLC_LIST
;
3191 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3194 if (style
& wxSUNKEN_BORDER
)
3195 style
-= wxSUNKEN_BORDER
;
3197 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3199 if (HasFlag(wxLC_REPORT
))
3201 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3202 if (HasFlag(wxLC_NO_HEADER
))
3203 m_headerWin
->Show( FALSE
);
3207 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3213 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3215 /* handled in OnIdle */
3217 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3220 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3222 long flag
= GetWindowStyle();
3226 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3227 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3228 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3237 if (flag
& style
) flag
-= style
;
3240 SetWindowStyleFlag( flag
);
3243 void wxListCtrl::SetWindowStyleFlag( long flag
)
3247 m_mainWin
->DeleteEverything();
3251 GetClientSize( &width
, &height
);
3253 m_mainWin
->SetMode( flag
);
3255 if (flag
& wxLC_REPORT
)
3257 if (!HasFlag(wxLC_REPORT
))
3261 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3262 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3263 if (HasFlag(wxLC_NO_HEADER
))
3264 m_headerWin
->Show( FALSE
);
3268 if (flag
& wxLC_NO_HEADER
)
3269 m_headerWin
->Show( FALSE
);
3271 m_headerWin
->Show( TRUE
);
3277 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3279 m_headerWin
->Show( FALSE
);
3284 wxWindow::SetWindowStyleFlag( flag
);
3287 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3289 m_mainWin
->GetColumn( col
, item
);
3293 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3295 m_mainWin
->SetColumn( col
, item
);
3299 int wxListCtrl::GetColumnWidth( int col
) const
3301 return m_mainWin
->GetColumnWidth( col
);
3304 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3306 m_mainWin
->SetColumnWidth( col
, width
);
3310 int wxListCtrl::GetCountPerPage() const
3312 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3315 bool wxListCtrl::GetItem( wxListItem
&info
) const
3317 m_mainWin
->GetItem( info
);
3321 bool wxListCtrl::SetItem( wxListItem
&info
)
3323 m_mainWin
->SetItem( info
);
3327 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3330 info
.m_text
= label
;
3331 info
.m_mask
= wxLIST_MASK_TEXT
;
3332 info
.m_itemId
= index
;
3336 info
.m_image
= imageId
;
3337 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3339 m_mainWin
->SetItem(info
);
3343 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3345 return m_mainWin
->GetItemState( item
, stateMask
);
3348 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3350 m_mainWin
->SetItemState( item
, state
, stateMask
);
3354 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3357 info
.m_image
= image
;
3358 info
.m_mask
= wxLIST_MASK_IMAGE
;
3359 info
.m_itemId
= item
;
3360 m_mainWin
->SetItem( info
);
3364 wxString
wxListCtrl::GetItemText( long item
) const
3367 info
.m_itemId
= item
;
3368 m_mainWin
->GetItem( info
);
3372 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3375 info
.m_mask
= wxLIST_MASK_TEXT
;
3376 info
.m_itemId
= item
;
3378 m_mainWin
->SetItem( info
);
3381 long wxListCtrl::GetItemData( long item
) const
3384 info
.m_itemId
= item
;
3385 m_mainWin
->GetItem( info
);
3389 bool wxListCtrl::SetItemData( long item
, long data
)
3392 info
.m_mask
= wxLIST_MASK_DATA
;
3393 info
.m_itemId
= item
;
3395 m_mainWin
->SetItem( info
);
3399 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3401 m_mainWin
->GetItemRect( item
, rect
);
3405 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3407 m_mainWin
->GetItemPosition( item
, pos
);
3411 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3416 int wxListCtrl::GetItemCount() const
3418 return m_mainWin
->GetItemCount();
3421 int wxListCtrl::GetColumnCount() const
3423 return m_mainWin
->GetColumnCount();
3426 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3428 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3431 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3433 return m_mainWin
->GetItemSpacing( isSmall
);
3436 int wxListCtrl::GetSelectedItemCount() const
3438 return m_mainWin
->GetSelectedItemCount();
3441 wxColour
wxListCtrl::GetTextColour() const
3443 return GetForegroundColour();
3446 void wxListCtrl::SetTextColour(const wxColour
& col
)
3448 SetForegroundColour(col
);
3451 long wxListCtrl::GetTopItem() const
3456 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3458 return m_mainWin
->GetNextItem( item
, geom
, state
);
3461 wxImageList
*wxListCtrl::GetImageList(int which
) const
3463 if (which
== wxIMAGE_LIST_NORMAL
)
3465 return m_imageListNormal
;
3467 else if (which
== wxIMAGE_LIST_SMALL
)
3469 return m_imageListSmall
;
3471 else if (which
== wxIMAGE_LIST_STATE
)
3473 return m_imageListState
;
3475 return (wxImageList
*) NULL
;
3478 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3480 m_mainWin
->SetImageList( imageList
, which
);
3483 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3488 bool wxListCtrl::DeleteItem( long item
)
3490 m_mainWin
->DeleteItem( item
);
3494 bool wxListCtrl::DeleteAllItems()
3496 m_mainWin
->DeleteAllItems();
3500 bool wxListCtrl::DeleteAllColumns()
3502 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3508 void wxListCtrl::ClearAll()
3510 m_mainWin
->DeleteEverything();
3513 bool wxListCtrl::DeleteColumn( int col
)
3515 m_mainWin
->DeleteColumn( col
);
3519 void wxListCtrl::Edit( long item
)
3521 m_mainWin
->Edit( item
);
3524 bool wxListCtrl::EnsureVisible( long item
)
3526 m_mainWin
->EnsureVisible( item
);
3530 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3532 return m_mainWin
->FindItem( start
, str
, partial
);
3535 long wxListCtrl::FindItem( long start
, long data
)
3537 return m_mainWin
->FindItem( start
, data
);
3540 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3541 int WXUNUSED(direction
))
3546 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3548 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3551 long wxListCtrl::InsertItem( wxListItem
& info
)
3553 m_mainWin
->InsertItem( info
);
3554 return info
.m_itemId
;
3557 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3560 info
.m_text
= label
;
3561 info
.m_mask
= wxLIST_MASK_TEXT
;
3562 info
.m_itemId
= index
;
3563 return InsertItem( info
);
3566 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3569 info
.m_mask
= wxLIST_MASK_IMAGE
;
3570 info
.m_image
= imageIndex
;
3571 info
.m_itemId
= index
;
3572 return InsertItem( info
);
3575 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3578 info
.m_text
= label
;
3579 info
.m_image
= imageIndex
;
3580 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3581 info
.m_itemId
= index
;
3582 return InsertItem( info
);
3585 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3587 wxASSERT( m_headerWin
);
3588 m_mainWin
->InsertColumn( col
, item
);
3589 m_headerWin
->Refresh();
3594 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3595 int format
, int width
)
3598 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3599 item
.m_text
= heading
;
3602 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3603 item
.m_width
= width
;
3605 item
.m_format
= format
;
3607 return InsertColumn( col
, item
);
3610 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3616 // fn is a function which takes 3 long arguments: item1, item2, data.
3617 // item1 is the long data associated with a first item (NOT the index).
3618 // item2 is the long data associated with a second item (NOT the index).
3619 // data is the same value as passed to SortItems.
3620 // The return value is a negative number if the first item should precede the second
3621 // item, a positive number of the second item should precede the first,
3622 // or zero if the two items are equivalent.
3623 // data is arbitrary data to be passed to the sort function.
3625 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3627 m_mainWin
->SortItems( fn
, data
);
3631 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3633 if (!m_mainWin
->m_dirty
) return;
3637 GetClientSize( &cw
, &ch
);
3644 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3646 m_headerWin
->GetPosition( &x
, &y
);
3647 m_headerWin
->GetSize( &w
, &h
);
3648 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3649 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3651 m_mainWin
->GetPosition( &x
, &y
);
3652 m_mainWin
->GetSize( &w
, &h
);
3653 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3654 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3658 m_mainWin
->GetPosition( &x
, &y
);
3659 m_mainWin
->GetSize( &w
, &h
);
3660 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3661 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3664 m_mainWin
->CalculatePositions();
3665 m_mainWin
->RealizeChanges();
3666 m_mainWin
->m_dirty
= FALSE
;
3667 m_mainWin
->Refresh();
3669 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3671 m_headerWin
->m_dirty
= FALSE
;
3672 m_headerWin
->Refresh();
3676 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3680 m_mainWin
->SetBackgroundColour( colour
);
3681 m_mainWin
->m_dirty
= TRUE
;
3687 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3689 if ( !wxWindow::SetForegroundColour( colour
) )
3694 m_mainWin
->SetForegroundColour( colour
);
3695 m_mainWin
->m_dirty
= TRUE
;
3700 m_headerWin
->SetForegroundColour( colour
);
3706 bool wxListCtrl::SetFont( const wxFont
&font
)
3708 if ( !wxWindow::SetFont( font
) )
3713 m_mainWin
->SetFont( font
);
3714 m_mainWin
->m_dirty
= TRUE
;
3719 m_headerWin
->SetFont( font
);
3725 #if wxUSE_DRAG_AND_DROP
3727 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3729 m_mainWin
->SetDropTarget( dropTarget
);
3732 wxDropTarget
*wxListCtrl::GetDropTarget() const
3734 return m_mainWin
->GetDropTarget();
3737 #endif // wxUSE_DRAG_AND_DROP
3739 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3741 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3744 wxColour
wxListCtrl::GetBackgroundColour() const
3746 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3749 wxColour
wxListCtrl::GetForegroundColour() const
3751 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3754 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3756 return m_mainWin
->PopupMenu( menu
, x
, y
);
3759 void wxListCtrl::SetFocus()
3761 /* The test in window.cpp fails as we are a composite
3762 window, so it checks against "this", but not m_mainWin. */
3763 if ( FindFocus() != this )
3764 m_mainWin
->SetFocus();