1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/listctrl.cpp
3 // Purpose: generic implementation of wxListCtrl
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "listctrl.h"
12 #pragma implementation "listctrlbase.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
24 #include "wx/dcscreen.h"
26 #include "wx/listctrl.h"
27 #include "wx/generic/imaglist.h"
28 #include "wx/dynarray.h"
32 #include "wx/gtk/win_gtk.h"
35 #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
36 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
47 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
52 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
58 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
60 // ============================================================================
62 // ============================================================================
64 //-----------------------------------------------------------------------------
65 // wxListItemData (internal)
66 //-----------------------------------------------------------------------------
68 class WXDLLEXPORT wxListItemData
: public wxObject
72 ~wxListItemData() { delete m_attr
; }
74 wxListItemData( const wxListItem
&info
);
75 void SetItem( const wxListItem
&info
);
76 void SetImage( int image
);
77 void SetData( long data
);
78 void SetPosition( int x
, int y
);
79 void SetSize( int width
, int height
);
80 bool HasImage() const;
82 bool HasText() const { return !m_text
.empty(); }
83 const wxString
& GetText() const { return m_text
; }
84 void SetText(const wxString
& text
) { m_text
= text
; }
86 bool IsHit( int x
, int y
) const;
88 int GetX( void ) const;
89 int GetY( void ) const;
91 int GetHeight() const;
93 void GetItem( wxListItem
&info
) const;
95 wxListItemAttr
*GetAttributes() const { return m_attr
; }
105 wxListItemAttr
*m_attr
;
111 DECLARE_DYNAMIC_CLASS(wxListItemData
);
114 //-----------------------------------------------------------------------------
115 // wxListHeaderData (internal)
116 //-----------------------------------------------------------------------------
118 class WXDLLEXPORT wxListHeaderData
: public wxObject
131 wxListHeaderData( const wxListItem
&info
);
132 void SetItem( const wxListItem
&item
);
133 void SetPosition( int x
, int y
);
134 void SetWidth( int w
);
135 void SetFormat( int format
);
136 void SetHeight( int h
);
137 bool HasImage() const;
139 bool HasText() const { return !m_text
.empty(); }
140 const wxString
& GetText() const { return m_text
; }
141 void SetText(const wxString
& text
) { m_text
= text
; }
143 void GetItem( wxListItem
&item
);
145 bool IsHit( int x
, int y
) const;
146 int GetImage() const;
147 int GetWidth() const;
148 int GetFormat() const;
151 DECLARE_DYNAMIC_CLASS(wxListHeaderData
);
154 //-----------------------------------------------------------------------------
155 // wxListLineData (internal)
156 //-----------------------------------------------------------------------------
158 class WXDLLEXPORT wxListLineData
: public wxObject
163 wxRect m_bound_label
;
165 wxRect m_bound_hilight
;
168 wxBrush
*m_hilightBrush
;
170 wxListMainWindow
*m_owner
;
172 void DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
);
176 wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
);
177 void CalculateSize( wxDC
*dc
, int spacing
);
178 void SetPosition( wxDC
*dc
, int x
, int y
, int window_width
);
179 void SetColumnPosition( int index
, int x
);
180 void GetSize( int &width
, int &height
);
181 void GetExtent( int &x
, int &y
, int &width
, int &height
);
182 void GetLabelExtent( int &x
, int &y
, int &width
, int &height
);
183 long IsHit( int x
, int y
);
184 void InitItems( int num
);
185 void SetItem( int index
, const wxListItem
&info
);
186 void GetItem( int index
, wxListItem
&info
);
187 wxString
GetText(int index
) const;
188 void SetText( int index
, const wxString s
);
189 int GetImage( int index
);
190 void GetRect( wxRect
&rect
);
191 void Hilight( bool on
);
192 void ReverseHilight();
193 void DrawRubberBand( wxDC
*dc
, bool on
);
194 void Draw( wxDC
*dc
);
195 bool IsInRect( int x
, int y
, const wxRect
&rect
);
197 void AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
);
198 void AssignRect( wxRect
&dest
, const wxRect
&source
);
201 void SetAttributes(wxDC
*dc
,
202 const wxListItemAttr
*attr
,
203 const wxColour
& colText
, const wxFont
& font
,
206 DECLARE_DYNAMIC_CLASS(wxListLineData
);
210 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData
, wxListLineDataArray
);
211 #include "wx/arrimpl.cpp"
212 WX_DEFINE_OBJARRAY(wxListLineDataArray
);
214 //-----------------------------------------------------------------------------
215 // wxListHeaderWindow (internal)
216 //-----------------------------------------------------------------------------
218 class WXDLLEXPORT wxListHeaderWindow
: public wxWindow
221 wxListMainWindow
*m_owner
;
222 wxCursor
*m_currentCursor
;
223 wxCursor
*m_resizeCursor
;
226 // column being resized
229 // divider line position in logical (unscrolled) coords
232 // minimal position beyond which the divider line can't be dragged in
237 wxListHeaderWindow();
238 virtual ~wxListHeaderWindow();
240 wxListHeaderWindow( wxWindow
*win
,
242 wxListMainWindow
*owner
,
243 const wxPoint
&pos
= wxDefaultPosition
,
244 const wxSize
&size
= wxDefaultSize
,
246 const wxString
&name
= "wxlistctrlcolumntitles" );
248 void DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
);
250 void AdjustDC(wxDC
& dc
);
252 void OnPaint( wxPaintEvent
&event
);
253 void OnMouse( wxMouseEvent
&event
);
254 void OnSetFocus( wxFocusEvent
&event
);
260 DECLARE_DYNAMIC_CLASS(wxListHeaderWindow
)
261 DECLARE_EVENT_TABLE()
264 //-----------------------------------------------------------------------------
265 // wxListRenameTimer (internal)
266 //-----------------------------------------------------------------------------
268 class WXDLLEXPORT wxListRenameTimer
: public wxTimer
271 wxListMainWindow
*m_owner
;
274 wxListRenameTimer( wxListMainWindow
*owner
);
278 //-----------------------------------------------------------------------------
279 // wxListTextCtrl (internal)
280 //-----------------------------------------------------------------------------
282 class WXDLLEXPORT wxListTextCtrl
: public wxTextCtrl
287 wxListMainWindow
*m_owner
;
288 wxString m_startValue
;
292 wxListTextCtrl( wxWindow
*parent
, const wxWindowID id
,
293 bool *accept
, wxString
*res
, wxListMainWindow
*owner
,
294 const wxString
&value
= "",
295 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
297 const wxValidator
& validator
= wxDefaultValidator
,
298 const wxString
&name
= "listctrltextctrl" );
299 void OnChar( wxKeyEvent
&event
);
300 void OnKeyUp( wxKeyEvent
&event
);
301 void OnKillFocus( wxFocusEvent
&event
);
304 DECLARE_DYNAMIC_CLASS(wxListTextCtrl
);
305 DECLARE_EVENT_TABLE()
308 //-----------------------------------------------------------------------------
309 // wxListMainWindow (internal)
310 //-----------------------------------------------------------------------------
312 class WXDLLEXPORT wxListMainWindow
: public wxScrolledWindow
316 wxListLineDataArray m_lines
;
318 wxListLineData
*m_current
;
319 wxListLineData
*m_currentEdit
;
321 wxBrush
*m_hilightBrush
;
322 wxColour
*m_hilightColour
;
323 int m_xScroll
,m_yScroll
;
325 wxImageList
*m_small_image_list
;
326 wxImageList
*m_normal_image_list
;
328 int m_normal_spacing
;
332 wxTimer
*m_renameTimer
;
334 wxString m_renameRes
;
339 // for double click logic
340 wxListLineData
*m_lineLastClicked
,
341 *m_lineBeforeLastClicked
;
345 wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
346 const wxPoint
&pos
= wxDefaultPosition
, const wxSize
&size
= wxDefaultSize
,
347 long style
= 0, const wxString
&name
= "listctrlmainwindow" );
349 void RefreshLine( wxListLineData
*line
);
350 void OnPaint( wxPaintEvent
&event
);
351 void HilightAll( bool on
);
352 void SendNotify( wxListLineData
*line
,
354 wxPoint point
= wxDefaultPosition
);
355 void FocusLine( wxListLineData
*line
);
356 void UnfocusLine( wxListLineData
*line
);
357 void SelectLine( wxListLineData
*line
);
358 void DeselectLine( wxListLineData
*line
);
359 void DeleteLine( wxListLineData
*line
);
361 void EditLabel( long item
);
362 void Edit( long item
) { EditLabel(item
); } // deprecated
363 void OnRenameTimer();
364 void OnRenameAccept();
366 void OnMouse( wxMouseEvent
&event
);
368 void OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
);
369 void OnChar( wxKeyEvent
&event
);
370 void OnKeyDown( wxKeyEvent
&event
);
371 void OnSetFocus( wxFocusEvent
&event
);
372 void OnKillFocus( wxFocusEvent
&event
);
373 void OnSize( wxSizeEvent
&event
);
374 void OnScroll(wxScrollWinEvent
& event
) ;
376 void DrawImage( int index
, wxDC
*dc
, int x
, int y
);
377 void GetImageSize( int index
, int &width
, int &height
);
378 int GetIndexOfLine( const wxListLineData
*line
);
379 int GetTextLength( wxString
&s
); // should be const
381 void SetImageList( wxImageList
*imageList
, int which
);
382 void SetItemSpacing( int spacing
, bool isSmall
= FALSE
);
383 int GetItemSpacing( bool isSmall
= FALSE
);
384 void SetColumn( int col
, wxListItem
&item
);
385 void SetColumnWidth( int col
, int width
);
386 void GetColumn( int col
, wxListItem
&item
);
387 int GetColumnWidth( int vol
);
388 int GetColumnCount();
389 int GetCountPerPage();
390 void SetItem( wxListItem
&item
);
391 void GetItem( wxListItem
&item
);
392 void SetItemState( long item
, long state
, long stateMask
);
393 int GetItemState( long item
, long stateMask
);
395 void GetItemRect( long index
, wxRect
&rect
);
396 bool GetItemPosition( long item
, wxPoint
& pos
);
397 int GetSelectedItemCount();
398 void SetMode( long mode
);
399 long GetMode() const;
400 void CalculatePositions();
401 void RealizeChanges();
402 long GetNextItem( long item
, int geometry
, int state
);
403 void DeleteItem( long index
);
404 void DeleteAllItems();
405 void DeleteColumn( int col
);
406 void DeleteEverything();
407 void EnsureVisible( long index
);
408 long FindItem( long start
, const wxString
& str
, bool partial
= FALSE
);
409 long FindItem( long start
, long data
);
410 long HitTest( int x
, int y
, int &flags
);
411 void InsertItem( wxListItem
&item
);
412 // void AddItem( wxListItem &item );
413 void InsertColumn( long col
, wxListItem
&item
);
414 // void AddColumn( wxListItem &item );
415 void SortItems( wxListCtrlCompare fn
, long data
);
418 DECLARE_DYNAMIC_CLASS(wxListMainWindow
);
419 DECLARE_EVENT_TABLE()
422 // ============================================================================
424 // ============================================================================
426 //-----------------------------------------------------------------------------
428 //-----------------------------------------------------------------------------
430 IMPLEMENT_DYNAMIC_CLASS(wxListItemData
,wxObject
);
432 wxListItemData::wxListItemData()
443 wxListItemData::wxListItemData( const wxListItem
&info
)
452 void wxListItemData::SetItem( const wxListItem
&info
)
454 if (info
.m_mask
& wxLIST_MASK_TEXT
)
455 SetText(info
.m_text
);
456 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
457 m_image
= info
.m_image
;
458 if (info
.m_mask
& wxLIST_MASK_DATA
)
459 m_data
= info
.m_data
;
461 if ( info
.HasAttributes() )
464 *m_attr
= *info
.GetAttributes();
466 m_attr
= new wxListItemAttr(*info
.GetAttributes());
471 m_width
= info
.m_width
;
475 void wxListItemData::SetImage( int image
)
480 void wxListItemData::SetData( long data
)
485 void wxListItemData::SetPosition( int x
, int y
)
491 void wxListItemData::SetSize( int width
, int height
)
493 if (width
!= -1) m_width
= width
;
494 if (height
!= -1) m_height
= height
;
497 bool wxListItemData::HasImage() const
499 return (m_image
>= 0);
502 bool wxListItemData::IsHit( int x
, int y
) const
504 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
507 int wxListItemData::GetX() const
512 int wxListItemData::GetY() const
517 int wxListItemData::GetWidth() const
522 int wxListItemData::GetHeight() const
527 int wxListItemData::GetImage() const
532 void wxListItemData::GetItem( wxListItem
&info
) const
534 info
.m_text
= m_text
;
535 info
.m_image
= m_image
;
536 info
.m_data
= m_data
;
540 if ( m_attr
->HasTextColour() )
541 info
.SetTextColour(m_attr
->GetTextColour());
542 if ( m_attr
->HasBackgroundColour() )
543 info
.SetBackgroundColour(m_attr
->GetBackgroundColour());
544 if ( m_attr
->HasFont() )
545 info
.SetFont(m_attr
->GetFont());
549 //-----------------------------------------------------------------------------
551 //-----------------------------------------------------------------------------
553 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData
,wxObject
);
555 wxListHeaderData::wxListHeaderData()
566 wxListHeaderData::wxListHeaderData( const wxListItem
&item
)
574 void wxListHeaderData::SetItem( const wxListItem
&item
)
576 m_mask
= item
.m_mask
;
577 m_text
= item
.m_text
;
578 m_image
= item
.m_image
;
579 m_format
= item
.m_format
;
580 m_width
= item
.m_width
;
581 if (m_width
< 0) m_width
= 80;
582 if (m_width
< 6) m_width
= 6;
585 void wxListHeaderData::SetPosition( int x
, int y
)
591 void wxListHeaderData::SetHeight( int h
)
596 void wxListHeaderData::SetWidth( int w
)
599 if (m_width
< 0) m_width
= 80;
600 if (m_width
< 6) m_width
= 6;
603 void wxListHeaderData::SetFormat( int format
)
608 bool wxListHeaderData::HasImage() const
610 return (m_image
!= 0);
613 bool wxListHeaderData::IsHit( int x
, int y
) const
615 return ((x
>= m_xpos
) && (x
<= m_xpos
+m_width
) && (y
>= m_ypos
) && (y
<= m_ypos
+m_height
));
618 void wxListHeaderData::GetItem( wxListItem
&item
)
620 item
.m_mask
= m_mask
;
621 item
.m_text
= m_text
;
622 item
.m_image
= m_image
;
623 item
.m_format
= m_format
;
624 item
.m_width
= m_width
;
627 int wxListHeaderData::GetImage() const
632 int wxListHeaderData::GetWidth() const
637 int wxListHeaderData::GetFormat() const
642 //-----------------------------------------------------------------------------
644 //-----------------------------------------------------------------------------
646 IMPLEMENT_DYNAMIC_CLASS(wxListLineData
,wxObject
);
648 wxListLineData::wxListLineData( wxListMainWindow
*owner
, int mode
, wxBrush
*hilightBrush
)
653 m_hilightBrush
= hilightBrush
;
654 m_items
.DeleteContents( TRUE
);
658 void wxListLineData::CalculateSize( wxDC
*dc
, int spacing
)
665 m_bound_all
.width
= m_spacing
;
666 wxNode
*node
= m_items
.First();
669 wxListItemData
*item
= (wxListItemData
*)node
->Data();
670 wxString s
= item
->GetText();
671 if (s
.IsEmpty()) s
= wxT("H");
673 dc
->GetTextExtent( s
, &lw
, &lh
);
674 if (lh
< 15) lh
= 15;
678 m_bound_all
.height
= m_spacing
+lh
;
679 if (lw
> m_spacing
) m_bound_all
.width
= lw
;
680 m_bound_label
.width
= lw
;
681 m_bound_label
.height
= lh
;
683 if (item
->HasImage())
687 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
688 m_bound_icon
.width
= w
+ 8;
689 m_bound_icon
.height
= h
+ 8;
691 if ( m_bound_icon
.width
> m_bound_all
.width
)
692 m_bound_all
.width
= m_bound_icon
.width
;
693 if ( h
+ lh
> m_bound_all
.height
- 4 )
694 m_bound_all
.height
= h
+ lh
+ 4;
697 if (!item
->HasText())
699 m_bound_hilight
.width
= m_bound_icon
.width
;
700 m_bound_hilight
.height
= m_bound_icon
.height
;
704 m_bound_hilight
.width
= m_bound_label
.width
;
705 m_bound_hilight
.height
= m_bound_label
.height
;
712 wxNode
*node
= m_items
.First();
715 wxListItemData
*item
= (wxListItemData
*)node
->Data();
717 wxString s
= item
->GetText();
718 if (s
.IsEmpty()) s
= wxT("H");
720 dc
->GetTextExtent( s
, &lw
, &lh
);
721 if (lh
< 15) lh
= 15;
724 m_bound_label
.width
= lw
;
725 m_bound_label
.height
= lh
;
727 m_bound_all
.width
= lw
;
728 m_bound_all
.height
= lh
;
730 if (item
->HasImage())
734 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
735 m_bound_icon
.width
= w
;
736 m_bound_icon
.height
= h
;
738 m_bound_all
.width
+= 4 + w
;
739 if (h
> m_bound_all
.height
) m_bound_all
.height
= h
;
742 m_bound_hilight
.width
= m_bound_all
.width
;
743 m_bound_hilight
.height
= m_bound_all
.height
;
749 m_bound_all
.width
= 0;
750 m_bound_all
.height
= 0;
751 wxNode
*node
= m_items
.First();
754 wxListItemData
*item
= (wxListItemData
*)node
->Data();
755 if (item
->HasImage())
759 m_owner
->GetImageSize( item
->GetImage(), w
, h
);
760 m_bound_icon
.width
= w
;
761 m_bound_icon
.height
= h
;
765 m_bound_icon
.width
= 0;
766 m_bound_icon
.height
= 0;
771 wxListItemData
*item
= (wxListItemData
*)node
->Data();
772 wxString s
= item
->GetText();
773 if (s
.IsEmpty()) s
= wxT("H");
775 dc
->GetTextExtent( s
, &lw
, &lh
);
776 if (lh
< 15) lh
= 15;
780 item
->SetSize( item
->GetWidth(), lh
);
781 m_bound_all
.width
+= lw
;
782 m_bound_all
.height
= lh
;
785 m_bound_label
.width
= m_bound_all
.width
;
786 m_bound_label
.height
= m_bound_all
.height
;
792 void wxListLineData::SetPosition( wxDC
* WXUNUSED(dc
),
793 int x
, int y
, int window_width
)
801 wxNode
*node
= m_items
.First();
804 wxListItemData
*item
= (wxListItemData
*)node
->Data();
805 if (item
->HasImage())
807 m_bound_icon
.x
= m_bound_all
.x
+ 4
808 + (m_spacing
- m_bound_icon
.width
)/2;
809 m_bound_icon
.y
= m_bound_all
.y
+ 4;
813 if (m_bound_all
.width
> m_spacing
)
814 m_bound_label
.x
= m_bound_all
.x
+ 2;
816 m_bound_label
.x
= m_bound_all
.x
+ 2 + (m_spacing
/2) - (m_bound_label
.width
/2);
817 m_bound_label
.y
= m_bound_all
.y
+ m_bound_all
.height
+ 2 - m_bound_label
.height
;
818 m_bound_hilight
.x
= m_bound_label
.x
- 2;
819 m_bound_hilight
.y
= m_bound_label
.y
- 2;
823 m_bound_hilight
.x
= m_bound_icon
.x
- 4;
824 m_bound_hilight
.y
= m_bound_icon
.y
- 4;
831 m_bound_hilight
.x
= m_bound_all
.x
;
832 m_bound_hilight
.y
= m_bound_all
.y
;
833 m_bound_label
.y
= m_bound_all
.y
+ 2;
834 wxNode
*node
= m_items
.First();
837 wxListItemData
*item
= (wxListItemData
*)node
->Data();
838 if (item
->HasImage())
840 m_bound_icon
.x
= m_bound_all
.x
+ 2;
841 m_bound_icon
.y
= m_bound_all
.y
+ 2;
842 m_bound_label
.x
= m_bound_all
.x
+ 6 + m_bound_icon
.width
;
846 m_bound_label
.x
= m_bound_all
.x
+ 2;
854 m_bound_all
.width
= window_width
;
855 AssignRect( m_bound_hilight
, m_bound_all
);
856 m_bound_label
.x
= m_bound_all
.x
+ 2;
857 m_bound_label
.y
= m_bound_all
.y
+ 2;
858 wxNode
*node
= m_items
.First();
861 wxListItemData
*item
= (wxListItemData
*)node
->Data();
862 if (item
->HasImage())
864 m_bound_icon
.x
= m_bound_all
.x
+ 2;
865 m_bound_icon
.y
= m_bound_all
.y
+ 2;
866 m_bound_label
.x
+= 4 + m_bound_icon
.width
;
874 void wxListLineData::SetColumnPosition( int index
, int x
)
876 wxNode
*node
= m_items
.Nth( (size_t)index
);
879 wxListItemData
*item
= (wxListItemData
*)node
->Data();
880 item
->SetPosition( x
, m_bound_all
.y
+1 );
884 void wxListLineData::GetSize( int &width
, int &height
)
886 width
= m_bound_all
.width
;
887 height
= m_bound_all
.height
;
890 void wxListLineData::GetExtent( int &x
, int &y
, int &width
, int &height
)
894 width
= m_bound_all
.width
;
895 height
= m_bound_all
.height
;
898 void wxListLineData::GetLabelExtent( int &x
, int &y
, int &width
, int &height
)
902 width
= m_bound_label
.width
;
903 height
= m_bound_label
.height
;
906 void wxListLineData::GetRect( wxRect
&rect
)
908 AssignRect( rect
, m_bound_all
);
911 long wxListLineData::IsHit( int x
, int y
)
913 wxNode
*node
= m_items
.First();
916 wxListItemData
*item
= (wxListItemData
*)node
->Data();
917 if (item
->HasImage() && IsInRect( x
, y
, m_bound_icon
)) return wxLIST_HITTEST_ONITEMICON
;
918 if (item
->HasText() && IsInRect( x
, y
, m_bound_label
)) return wxLIST_HITTEST_ONITEMLABEL
;
919 // if (!(item->HasImage() || item->HasText())) return 0;
921 // if there is no icon or text = empty
922 if (IsInRect( x
, y
, m_bound_all
)) return wxLIST_HITTEST_ONITEMICON
;
926 void wxListLineData::InitItems( int num
)
928 for (int i
= 0; i
< num
; i
++) m_items
.Append( new wxListItemData() );
931 void wxListLineData::SetItem( int index
, const wxListItem
&info
)
933 wxNode
*node
= m_items
.Nth( index
);
936 wxListItemData
*item
= (wxListItemData
*)node
->Data();
937 item
->SetItem( info
);
941 void wxListLineData::GetItem( int index
, wxListItem
&info
)
944 wxNode
*node
= m_items
.Nth( i
);
947 wxListItemData
*item
= (wxListItemData
*)node
->Data();
948 item
->GetItem( info
);
952 wxString
wxListLineData::GetText(int index
) const
956 wxNode
*node
= m_items
.Nth( index
);
959 wxListItemData
*item
= (wxListItemData
*)node
->Data();
966 void wxListLineData::SetText( int index
, const wxString s
)
969 wxNode
*node
= m_items
.Nth( i
);
972 wxListItemData
*item
= (wxListItemData
*)node
->Data();
977 int wxListLineData::GetImage( int index
)
980 wxNode
*node
= m_items
.Nth( i
);
983 wxListItemData
*item
= (wxListItemData
*)node
->Data();
984 return item
->GetImage();
989 void wxListLineData::SetAttributes(wxDC
*dc
,
990 const wxListItemAttr
*attr
,
991 const wxColour
& colText
,
995 // don't use foregroud colour for drawing highlighted items - this might
996 // make them completely invisible (and there is no way to do bit
997 // arithmetics on wxColour, unfortunately)
998 if ( !hilight
&& attr
&& attr
->HasTextColour() )
1000 dc
->SetTextForeground(attr
->GetTextColour());
1004 dc
->SetTextForeground(colText
);
1007 if ( attr
&& attr
->HasFont() )
1009 dc
->SetFont(attr
->GetFont());
1017 void wxListLineData::DoDraw( wxDC
*dc
, bool hilight
, bool paintBG
)
1021 m_owner
->CalcScrolledPosition( m_bound_all
.x
, m_bound_all
.y
, &dev_x
, &dev_y
);
1022 wxCoord dev_w
= m_bound_all
.width
;
1023 wxCoord dev_h
= m_bound_all
.height
;
1025 if (!m_owner
->IsExposed( dev_x
, dev_y
, dev_w
, dev_h
))
1028 wxWindow
*listctrl
= m_owner
->GetParent();
1030 // default foreground colour
1034 colText
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT
);
1038 colText
= listctrl
->GetForegroundColour();
1042 wxFont font
= listctrl
->GetFont();
1044 // VZ: currently we set the colours/fonts only once, but like this (i.e.
1045 // using SetAttributes() inside the loop), it will be trivial to
1046 // customize the subitems (in report mode) too.
1047 wxListItemData
*item
= (wxListItemData
*)m_items
.First()->Data();
1048 wxListItemAttr
*attr
= item
->GetAttributes();
1049 SetAttributes(dc
, attr
, colText
, font
, hilight
);
1051 bool hasBgCol
= attr
&& attr
->HasBackgroundColour();
1052 if ( paintBG
|| hasBgCol
)
1056 dc
->SetBrush( * m_hilightBrush
);
1061 dc
->SetBrush(wxBrush(attr
->GetBackgroundColour(), wxSOLID
));
1063 dc
->SetBrush( * wxWHITE_BRUSH
);
1066 dc
->SetPen( * wxTRANSPARENT_PEN
);
1067 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1068 m_bound_hilight
.width
, m_bound_hilight
.height
);
1071 if (m_mode
== wxLC_REPORT
)
1073 wxNode
*node
= m_items
.First();
1076 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1077 int x
= item
->GetX();
1078 if (item
->HasImage())
1081 m_owner
->DrawImage( item
->GetImage(), dc
, x
, item
->GetY() );
1082 m_owner
->GetImageSize( item
->GetImage(), x
, y
);
1083 x
+= item
->GetX() + 5;
1085 dc
->SetClippingRegion( item
->GetX(), item
->GetY(), item
->GetWidth()-3, item
->GetHeight() );
1086 if (item
->HasText())
1088 dc
->DrawText( item
->GetText(), x
, item
->GetY()+1 );
1090 dc
->DestroyClippingRegion();
1091 node
= node
->Next();
1096 wxNode
*node
= m_items
.First();
1099 wxListItemData
*item
= (wxListItemData
*)node
->Data();
1100 if (item
->HasImage())
1102 m_owner
->DrawImage( item
->GetImage(), dc
, m_bound_icon
.x
, m_bound_icon
.y
);
1104 if (item
->HasText())
1106 dc
->DrawText( item
->GetText(), m_bound_label
.x
, m_bound_label
.y
);
1112 void wxListLineData::Hilight( bool on
)
1114 if (on
== m_hilighted
) return;
1117 m_owner
->SelectLine( this );
1119 m_owner
->DeselectLine( this );
1122 void wxListLineData::ReverseHilight( void )
1124 m_hilighted
= !m_hilighted
;
1126 m_owner
->SelectLine( this );
1128 m_owner
->DeselectLine( this );
1131 void wxListLineData::DrawRubberBand( wxDC
*dc
, bool on
)
1135 dc
->SetPen( * wxBLACK_PEN
);
1136 dc
->SetBrush( * wxTRANSPARENT_BRUSH
);
1137 dc
->DrawRectangle( m_bound_hilight
.x
, m_bound_hilight
.y
,
1138 m_bound_hilight
.width
, m_bound_hilight
.height
);
1142 void wxListLineData::Draw( wxDC
*dc
)
1144 DoDraw( dc
, m_hilighted
, m_hilighted
);
1147 bool wxListLineData::IsInRect( int x
, int y
, const wxRect
&rect
)
1149 return ((x
>= rect
.x
) && (x
<= rect
.x
+rect
.width
) &&
1150 (y
>= rect
.y
) && (y
<= rect
.y
+rect
.height
));
1153 bool wxListLineData::IsHilighted( void )
1158 void wxListLineData::AssignRect( wxRect
&dest
, int x
, int y
, int width
, int height
)
1163 dest
.height
= height
;
1166 void wxListLineData::AssignRect( wxRect
&dest
, const wxRect
&source
)
1170 dest
.width
= source
.width
;
1171 dest
.height
= source
.height
;
1174 //-----------------------------------------------------------------------------
1175 // wxListHeaderWindow
1176 //-----------------------------------------------------------------------------
1178 IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow
,wxWindow
);
1180 BEGIN_EVENT_TABLE(wxListHeaderWindow
,wxWindow
)
1181 EVT_PAINT (wxListHeaderWindow::OnPaint
)
1182 EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse
)
1183 EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus
)
1186 wxListHeaderWindow::wxListHeaderWindow( void )
1188 m_owner
= (wxListMainWindow
*) NULL
;
1189 m_currentCursor
= (wxCursor
*) NULL
;
1190 m_resizeCursor
= (wxCursor
*) NULL
;
1191 m_isDragging
= FALSE
;
1194 wxListHeaderWindow::wxListHeaderWindow( wxWindow
*win
, wxWindowID id
, wxListMainWindow
*owner
,
1195 const wxPoint
&pos
, const wxSize
&size
,
1196 long style
, const wxString
&name
) :
1197 wxWindow( win
, id
, pos
, size
, style
, name
)
1200 // m_currentCursor = wxSTANDARD_CURSOR;
1201 m_currentCursor
= (wxCursor
*) NULL
;
1202 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
1203 m_isDragging
= FALSE
;
1206 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
) );
1209 wxListHeaderWindow::~wxListHeaderWindow( void )
1211 delete m_resizeCursor
;
1214 void wxListHeaderWindow::DoDrawRect( wxDC
*dc
, int x
, int y
, int w
, int h
)
1217 GtkStateType state
= GTK_STATE_NORMAL
;
1218 if (!m_parent
->IsEnabled()) state
= GTK_STATE_INSENSITIVE
;
1220 x
= dc
->XLOG2DEV( x
);
1222 gtk_paint_box (m_wxwindow
->style
, GTK_PIZZA(m_wxwindow
)->bin_window
, state
, GTK_SHADOW_OUT
,
1223 (GdkRectangle
*) NULL
, m_wxwindow
, "button", x
-1, y
-1, w
+2, h
+2);
1225 const int m_corner
= 1;
1227 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
1229 dc
->SetPen( *wxBLACK_PEN
);
1230 dc
->DrawLine( x
+w
-m_corner
+1, y
, x
+w
, y
+h
); // right (outer)
1231 dc
->DrawRectangle( x
, y
+h
, w
+1, 1 ); // bottom (outer)
1233 wxPen
pen( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNSHADOW
), 1, wxSOLID
);
1236 dc
->DrawLine( x
+w
-m_corner
, y
, x
+w
-1, y
+h
); // right (inner)
1237 dc
->DrawRectangle( x
+1, y
+h
-1, w
-2, 1 ); // bottom (inner)
1239 dc
->SetPen( *wxWHITE_PEN
);
1240 dc
->DrawRectangle( x
, y
, w
-m_corner
+1, 1 ); // top (outer)
1241 dc
->DrawRectangle( x
, y
, 1, h
); // left (outer)
1242 dc
->DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 );
1243 dc
->DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 );
1247 // shift the DC origin to match the position of the main window horz
1248 // scrollbar: this allows us to always use logical coords
1249 void wxListHeaderWindow::AdjustDC(wxDC
& dc
)
1251 #if wxUSE_GENERIC_LIST_EXTENSIONS
1253 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1256 m_owner
->GetViewStart( &x
, NULL
);
1258 // account for the horz scrollbar offset
1259 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1260 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1263 void wxListHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1266 wxClientDC
dc( this );
1268 wxPaintDC
dc( this );
1276 dc
.SetFont( GetFont() );
1278 // width and height of the entire header window
1280 GetClientSize( &w
, &h
);
1281 #if wxUSE_GENERIC_LIST_EXTENSIONS
1282 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1283 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1285 dc
.SetBackgroundMode(wxTRANSPARENT
);
1287 // do *not* use the listctrl colour for headers - one day we will have a
1288 // function to set it separately
1289 //dc.SetTextForeground( *wxBLACK );
1290 dc
.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT
));
1292 int x
= 1; // left of the header rect
1293 const int y
= 1; // top
1294 int numColumns
= m_owner
->GetColumnCount();
1296 for (int i
= 0; i
< numColumns
; i
++)
1298 m_owner
->GetColumn( i
, item
);
1299 int wCol
= item
.m_width
;
1300 int cw
= wCol
- 2; // the width of the rect to draw
1302 int xEnd
= x
+ wCol
;
1304 // VZ: no, draw it normally - this is better now as we allow resizing
1305 // of the last column as well
1307 // let the last column occupy all available space
1308 if ( i
== numColumns
- 1 )
1312 dc
.SetPen( *wxWHITE_PEN
);
1314 DoDrawRect( &dc
, x
, y
, cw
, h
-2 );
1315 dc
.SetClippingRegion( x
, y
, cw
-5, h
-4 );
1316 dc
.DrawText( item
.GetText(), x
+4, y
+3 );
1317 dc
.DestroyClippingRegion();
1326 void wxListHeaderWindow::DrawCurrent()
1328 int x1
= m_currentX
;
1330 ClientToScreen( &x1
, &y1
);
1332 int x2
= m_currentX
-1;
1334 m_owner
->GetClientSize( NULL
, &y2
);
1335 m_owner
->ClientToScreen( &x2
, &y2
);
1338 dc
.SetLogicalFunction( wxINVERT
);
1339 dc
.SetPen( wxPen( *wxBLACK
, 2, wxSOLID
) );
1340 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
1344 dc
.DrawLine( x1
, y1
, x2
, y2
);
1346 dc
.SetLogicalFunction( wxCOPY
);
1348 dc
.SetPen( wxNullPen
);
1349 dc
.SetBrush( wxNullBrush
);
1352 void wxListHeaderWindow::OnMouse( wxMouseEvent
&event
)
1354 // we want to work with logical coords
1355 #if wxUSE_GENERIC_LIST_EXTENSIONS
1357 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1358 #else // !wxUSE_GENERIC_LIST_EXTENSIONS
1359 int x
= event
.GetX();
1360 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1361 int y
= event
.GetY();
1365 // we don't draw the line beyond our window, but we allow dragging it
1368 GetClientSize( &w
, NULL
);
1369 #if wxUSE_GENERIC_LIST_EXTENSIONS
1370 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1371 #endif // wxUSE_GENERIC_LIST_EXTENSIONS
1374 // erase the line if it was drawn
1375 if ( m_currentX
< w
)
1378 if (event
.ButtonUp())
1381 m_isDragging
= FALSE
;
1383 m_owner
->SetColumnWidth( m_column
, m_currentX
- m_minX
);
1390 m_currentX
= m_minX
+ 7;
1392 // draw in the new location
1393 if ( m_currentX
< w
)
1397 else // not dragging
1400 bool hit_border
= FALSE
;
1402 // end of the current column
1405 // find the column where this event occured
1406 int countCol
= m_owner
->GetColumnCount();
1407 for (int j
= 0; j
< countCol
; j
++)
1409 xpos
+= m_owner
->GetColumnWidth( j
);
1412 if ( (abs(x
-xpos
) < 3) && (y
< 22) )
1414 // near the column border
1421 // inside the column
1428 if (event
.LeftDown())
1432 m_isDragging
= TRUE
;
1439 wxWindow
*parent
= GetParent();
1440 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, parent
->GetId() );
1441 le
.SetEventObject( parent
);
1442 le
.m_col
= m_column
;
1443 parent
->GetEventHandler()->ProcessEvent( le
);
1446 else if (event
.Moving())
1451 setCursor
= m_currentCursor
== wxSTANDARD_CURSOR
;
1452 m_currentCursor
= m_resizeCursor
;
1456 setCursor
= m_currentCursor
!= wxSTANDARD_CURSOR
;
1457 m_currentCursor
= wxSTANDARD_CURSOR
;
1461 SetCursor(*m_currentCursor
);
1466 void wxListHeaderWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
1468 m_owner
->SetFocus();
1471 //-----------------------------------------------------------------------------
1472 // wxListRenameTimer (internal)
1473 //-----------------------------------------------------------------------------
1475 wxListRenameTimer::wxListRenameTimer( wxListMainWindow
*owner
)
1480 void wxListRenameTimer::Notify()
1482 m_owner
->OnRenameTimer();
1485 //-----------------------------------------------------------------------------
1486 // wxListTextCtrl (internal)
1487 //-----------------------------------------------------------------------------
1489 IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl
,wxTextCtrl
);
1491 BEGIN_EVENT_TABLE(wxListTextCtrl
,wxTextCtrl
)
1492 EVT_CHAR (wxListTextCtrl::OnChar
)
1493 EVT_KEY_UP (wxListTextCtrl::OnKeyUp
)
1494 EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus
)
1497 wxListTextCtrl::wxListTextCtrl( wxWindow
*parent
,
1498 const wxWindowID id
,
1501 wxListMainWindow
*owner
,
1502 const wxString
&value
,
1506 const wxValidator
& validator
,
1507 const wxString
&name
)
1508 : wxTextCtrl( parent
, id
, value
, pos
, size
, style
, validator
, name
)
1513 (*m_accept
) = FALSE
;
1515 m_startValue
= value
;
1518 void wxListTextCtrl::OnChar( wxKeyEvent
&event
)
1520 if (event
.m_keyCode
== WXK_RETURN
)
1523 (*m_res
) = GetValue();
1525 if (!wxPendingDelete
.Member(this))
1526 wxPendingDelete
.Append(this);
1528 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1529 m_owner
->OnRenameAccept();
1533 if (event
.m_keyCode
== WXK_ESCAPE
)
1535 (*m_accept
) = FALSE
;
1538 if (!wxPendingDelete
.Member(this))
1539 wxPendingDelete
.Append(this);
1547 void wxListTextCtrl::OnKeyUp( wxKeyEvent
&event
)
1549 // auto-grow the textctrl:
1550 wxSize parentSize
= m_owner
->GetSize();
1551 wxPoint myPos
= GetPosition();
1552 wxSize mySize
= GetSize();
1554 GetTextExtent(GetValue() + _T("MM"), &sx
, &sy
);
1555 if (myPos
.x
+ sx
> parentSize
.x
) sx
= parentSize
.x
- myPos
.x
;
1556 if (mySize
.x
> sx
) sx
= mySize
.x
;
1562 void wxListTextCtrl::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
1564 if (!wxPendingDelete
.Member(this))
1565 wxPendingDelete
.Append(this);
1567 if ((*m_accept
) && ((*m_res
) != m_startValue
))
1568 m_owner
->OnRenameAccept();
1571 //-----------------------------------------------------------------------------
1573 //-----------------------------------------------------------------------------
1575 IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow
,wxScrolledWindow
);
1577 BEGIN_EVENT_TABLE(wxListMainWindow
,wxScrolledWindow
)
1578 EVT_PAINT (wxListMainWindow::OnPaint
)
1579 EVT_SIZE (wxListMainWindow::OnSize
)
1580 EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse
)
1581 EVT_CHAR (wxListMainWindow::OnChar
)
1582 EVT_KEY_DOWN (wxListMainWindow::OnKeyDown
)
1583 EVT_SET_FOCUS (wxListMainWindow::OnSetFocus
)
1584 EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus
)
1585 EVT_SCROLLWIN (wxListMainWindow::OnScroll
)
1588 wxListMainWindow::wxListMainWindow()
1591 m_columns
.DeleteContents( TRUE
);
1592 m_current
= (wxListLineData
*) NULL
;
1594 m_hilightBrush
= (wxBrush
*) NULL
;
1598 m_small_image_list
= (wxImageList
*) NULL
;
1599 m_normal_image_list
= (wxImageList
*) NULL
;
1600 m_small_spacing
= 30;
1601 m_normal_spacing
= 40;
1604 m_lastOnSame
= FALSE
;
1605 m_renameTimer
= new wxListRenameTimer( this );
1606 m_isCreated
= FALSE
;
1610 m_lineBeforeLastClicked
= (wxListLineData
*)NULL
;
1613 wxListMainWindow::wxListMainWindow( wxWindow
*parent
, wxWindowID id
,
1614 const wxPoint
&pos
, const wxSize
&size
,
1615 long style
, const wxString
&name
) :
1616 wxScrolledWindow( parent
, id
, pos
, size
, style
|wxHSCROLL
|wxVSCROLL
, name
)
1619 m_columns
.DeleteContents( TRUE
);
1620 m_current
= (wxListLineData
*) NULL
;
1623 m_hilightBrush
= new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT
), wxSOLID
);
1624 m_small_image_list
= (wxImageList
*) NULL
;
1625 m_normal_image_list
= (wxImageList
*) NULL
;
1626 m_small_spacing
= 30;
1627 m_normal_spacing
= 40;
1630 m_isCreated
= FALSE
;
1634 if (m_mode
& wxLC_REPORT
)
1636 #if wxUSE_GENERIC_LIST_EXTENSIONS
1648 SetScrollbars( m_xScroll
, m_yScroll
, 0, 0, 0, 0 );
1651 m_lastOnSame
= FALSE
;
1652 m_renameTimer
= new wxListRenameTimer( this );
1653 m_renameAccept
= FALSE
;
1655 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX
) );
1658 wxListMainWindow::~wxListMainWindow()
1662 if (m_hilightBrush
) delete m_hilightBrush
;
1664 delete m_renameTimer
;
1667 void wxListMainWindow::RefreshLine( wxListLineData
*line
)
1669 if (m_dirty
) return;
1677 line
->GetExtent( x
, y
, w
, h
);
1678 CalcScrolledPosition( x
, y
, &x
, &y
);
1679 wxRect
rect( x
, y
, w
, h
);
1680 Refresh( TRUE
, &rect
);
1683 void wxListMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1685 // Note: a wxPaintDC must be constructed even if no drawing is
1686 // done (a Windows requirement).
1687 wxPaintDC
dc( this );
1692 CalcScrolledPosition( 0, 0, &dev_x
, &dev_y
);
1694 if (m_dirty
) return;
1696 if (m_lines
.GetCount() == 0) return;
1700 dc
.SetFont( GetFont() );
1702 if (m_mode
& wxLC_REPORT
)
1704 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1705 wxSize clientSize
= GetClientSize();
1707 int lineSpacing
= 0;
1708 wxListLineData
*line
= &m_lines
[0];
1710 line
->GetSize( dummy
, lineSpacing
);
1713 int y_s
= m_yScroll
*GetScrollPos( wxVERTICAL
);
1715 size_t i_to
= y_s
/ lineSpacing
+ m_visibleLines
+2;
1716 if (i_to
>= m_lines
.GetCount()) i_to
= m_lines
.GetCount();
1718 for (i
= y_s
/ lineSpacing
; i
< i_to
; i
++)
1720 m_lines
[i
].Draw( &dc
);
1721 // Draw horizontal rule if required
1722 if (GetWindowStyle() & wxLC_HRULES
)
1725 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1726 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1730 // Draw last horizontal rule
1731 if ((i
> (size_t) (y_s
/ lineSpacing
)) && (GetWindowStyle() & wxLC_HRULES
))
1734 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1735 dc
.DrawLine(0 - dev_x
, i
*lineSpacing
, clientSize
.x
- dev_x
, i
*lineSpacing
);
1738 // Draw vertical rules if required
1739 if ((GetWindowStyle() & wxLC_VRULES
) && (GetItemCount() > 0))
1742 wxRect firstItemRect
;
1743 wxRect lastItemRect
;
1744 GetItemRect(0, firstItemRect
);
1745 GetItemRect(GetItemCount() - 1, lastItemRect
);
1746 int x
= firstItemRect
.GetX();
1748 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1749 for (col
= 0; col
< GetColumnCount(); col
++)
1751 int colWidth
= GetColumnWidth(col
);
1753 dc
.DrawLine(x
- dev_x
, firstItemRect
.GetY() - 1 - dev_y
, x
- dev_x
, lastItemRect
.GetBottom() + 1 - dev_y
);
1759 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1760 m_lines
[i
].Draw( &dc
);
1763 if (m_current
) m_current
->DrawRubberBand( &dc
, m_hasFocus
);
1768 void wxListMainWindow::HilightAll( bool on
)
1770 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1772 wxListLineData
*line
= &m_lines
[i
];
1773 if (line
->IsHilighted() != on
)
1775 line
->Hilight( on
);
1776 RefreshLine( line
);
1781 void wxListMainWindow::SendNotify( wxListLineData
*line
,
1782 wxEventType command
,
1785 wxListEvent
le( command
, GetParent()->GetId() );
1786 le
.SetEventObject( GetParent() );
1787 le
.m_itemIndex
= GetIndexOfLine( line
);
1789 // set only for events which have position
1790 if ( point
!= wxDefaultPosition
)
1791 le
.m_pointDrag
= point
;
1793 line
->GetItem( 0, le
.m_item
);
1794 GetParent()->GetEventHandler()->ProcessEvent( le
);
1795 // GetParent()->GetEventHandler()->AddPendingEvent( le );
1798 void wxListMainWindow::FocusLine( wxListLineData
*WXUNUSED(line
) )
1800 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
1803 void wxListMainWindow::UnfocusLine( wxListLineData
*WXUNUSED(line
) )
1805 // SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
1808 void wxListMainWindow::SelectLine( wxListLineData
*line
)
1810 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_SELECTED
);
1813 void wxListMainWindow::DeselectLine( wxListLineData
*line
)
1815 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1818 void wxListMainWindow::DeleteLine( wxListLineData
*line
)
1820 SendNotify( line
, wxEVT_COMMAND_LIST_DELETE_ITEM
);
1825 void wxListMainWindow::EditLabel( long item
)
1827 wxCHECK_RET( ((size_t)item
< m_lines
.GetCount()),
1828 wxT("wrong index in wxListCtrl::Edit()") );
1830 m_currentEdit
= &m_lines
[(size_t)item
];
1832 wxListEvent
le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, GetParent()->GetId() );
1833 le
.SetEventObject( GetParent() );
1834 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1835 m_currentEdit
->GetItem( 0, le
.m_item
);
1836 GetParent()->GetEventHandler()->ProcessEvent( le
);
1838 if (!le
.IsAllowed())
1841 // We have to call this here because the label in
1842 // question might just have been added and no screen
1843 // update taken place.
1844 if (m_dirty
) wxYield();
1846 wxString s
= m_currentEdit
->GetText(0);
1851 m_currentEdit
->GetLabelExtent( x
, y
, w
, h
);
1853 wxClientDC
dc(this);
1855 x
= dc
.LogicalToDeviceX( x
);
1856 y
= dc
.LogicalToDeviceY( y
);
1858 wxListTextCtrl
*text
= new wxListTextCtrl(
1859 this, -1, &m_renameAccept
, &m_renameRes
, this, s
, wxPoint(x
-4,y
-4), wxSize(w
+11,h
+8) );
1863 void wxListMainWindow::OnRenameTimer()
1865 wxCHECK_RET( m_current
, wxT("invalid m_current") );
1867 Edit( m_lines
.Index( *m_current
) );
1870 void wxListMainWindow::OnRenameAccept()
1872 wxListEvent
le( wxEVT_COMMAND_LIST_END_LABEL_EDIT
, GetParent()->GetId() );
1873 le
.SetEventObject( GetParent() );
1874 le
.m_itemIndex
= GetIndexOfLine( m_currentEdit
);
1875 m_currentEdit
->GetItem( 0, le
.m_item
);
1876 le
.m_item
.m_text
= m_renameRes
;
1877 GetParent()->GetEventHandler()->ProcessEvent( le
);
1879 if (!le
.IsAllowed()) return;
1882 info
.m_mask
= wxLIST_MASK_TEXT
;
1883 info
.m_itemId
= le
.m_itemIndex
;
1884 info
.m_text
= m_renameRes
;
1885 info
.SetTextColour(le
.m_item
.GetTextColour());
1889 void wxListMainWindow::OnMouse( wxMouseEvent
&event
)
1891 event
.SetEventObject( GetParent() );
1892 if (GetParent()->GetEventHandler()->ProcessEvent( event
)) return;
1894 if (!m_current
) return;
1895 if (m_dirty
) return;
1896 if ( !(event
.Dragging() || event
.ButtonDown() || event
.LeftUp() || event
.ButtonDClick()) ) return;
1898 int x
= event
.GetX();
1899 int y
= event
.GetY();
1900 CalcUnscrolledPosition( x
, y
, &x
, &y
);
1902 /* Did we actually hit an item ? */
1904 wxListLineData
*line
= (wxListLineData
*) NULL
;
1905 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
1908 hitResult
= line
->IsHit( x
, y
);
1909 if (hitResult
) break;
1910 line
= (wxListLineData
*) NULL
;
1913 if (event
.Dragging())
1915 if (m_dragCount
== 0)
1916 m_dragStart
= wxPoint(x
,y
);
1920 if (m_dragCount
!= 3) return;
1922 int command
= event
.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
1923 : wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1925 wxListEvent
le( command
, GetParent()->GetId() );
1926 le
.SetEventObject( GetParent() );
1927 le
.m_pointDrag
= m_dragStart
;
1928 GetParent()->GetEventHandler()->ProcessEvent( le
);
1939 bool forceClick
= FALSE
;
1940 if (event
.ButtonDClick())
1942 m_renameTimer
->Stop();
1943 m_lastOnSame
= FALSE
;
1945 if ( line
== m_lineBeforeLastClicked
)
1949 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1955 // the first click was on another item, so don't interpret this as
1956 // a double click, but as a simple click instead
1961 if (event
.LeftUp() && m_lastOnSame
)
1964 if ((line
== m_current
) &&
1965 (hitResult
== wxLIST_HITTEST_ONITEMLABEL
) &&
1966 (m_mode
& wxLC_EDIT_LABELS
) )
1968 m_renameTimer
->Start( 100, TRUE
);
1970 m_lastOnSame
= FALSE
;
1974 if (event
.RightDown())
1976 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
,
1977 event
.GetPosition() );
1981 if (event
.MiddleDown())
1983 SendNotify( line
, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
);
1987 if ( event
.LeftDown() || forceClick
)
1989 m_lineBeforeLastClicked
= m_lineLastClicked
;
1990 m_lineLastClicked
= line
;
1993 wxListLineData
*oldCurrent
= m_current
;
1994 if (m_mode
& wxLC_SINGLE_SEL
)
1997 HilightAll( FALSE
);
1998 m_current
->ReverseHilight();
1999 RefreshLine( m_current
);
2003 if (event
.ControlDown())
2006 m_current
->ReverseHilight();
2007 RefreshLine( m_current
);
2009 else if (event
.ShiftDown())
2015 int numOfCurrent
= -1;
2016 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2018 wxListLineData
*test_line
= &m_lines
[j
];
2020 if (test_line
== oldCurrent
) break;
2025 for (j
= 0; j
< m_lines
.GetCount(); j
++)
2027 wxListLineData
*test_line
= &m_lines
[j
];
2029 if (test_line
== line
) break;
2032 if (numOfLine
< numOfCurrent
)
2035 numOfLine
= numOfCurrent
;
2039 for (int i
= 0; i
<= numOfLine
-numOfCurrent
; i
++)
2041 wxListLineData
*test_line
= &m_lines
[numOfCurrent
+ i
];
2042 test_line
->Hilight(TRUE
);
2043 RefreshLine( test_line
);
2049 HilightAll( FALSE
);
2050 m_current
->ReverseHilight();
2051 RefreshLine( m_current
);
2054 if (m_current
!= oldCurrent
)
2056 RefreshLine( oldCurrent
);
2057 UnfocusLine( oldCurrent
);
2058 FocusLine( m_current
);
2061 // forceClick is only set if the previous click was on another item
2062 m_lastOnSame
= !forceClick
&& (m_current
== oldCurrent
);
2068 void wxListMainWindow::MoveToFocus()
2070 if (!m_current
) return;
2076 m_current
->GetExtent( item_x
, item_y
, item_w
, item_h
);
2080 GetClientSize( &client_w
, &client_h
);
2082 int view_x
= m_xScroll
*GetScrollPos( wxHORIZONTAL
);
2083 int view_y
= m_yScroll
*GetScrollPos( wxVERTICAL
);
2085 if (m_mode
& wxLC_REPORT
)
2087 if (item_y
< view_y
)
2088 Scroll( -1, (item_y
)/m_yScroll
);
2089 if (item_y
+item_h
+5 > view_y
+client_h
)
2090 Scroll( -1, (item_y
+item_h
-client_h
+15)/m_yScroll
);
2094 if (item_x
-view_x
< 5)
2095 Scroll( (item_x
-5)/m_xScroll
, -1 );
2096 if (item_x
+item_w
-5 > view_x
+client_w
)
2097 Scroll( (item_x
+item_w
-client_w
+15)/m_xScroll
, -1 );
2101 void wxListMainWindow::OnArrowChar( wxListLineData
*newCurrent
, bool shiftDown
)
2103 if ((m_mode
& wxLC_SINGLE_SEL
) || (m_usedKeys
== FALSE
)) m_current
->Hilight( FALSE
);
2104 wxListLineData
*oldCurrent
= m_current
;
2105 m_current
= newCurrent
;
2106 if (shiftDown
|| (m_mode
& wxLC_SINGLE_SEL
)) m_current
->Hilight( TRUE
);
2107 RefreshLine( m_current
);
2108 RefreshLine( oldCurrent
);
2109 FocusLine( m_current
);
2110 UnfocusLine( oldCurrent
);
2114 void wxListMainWindow::OnKeyDown( wxKeyEvent
&event
)
2116 wxWindow
*parent
= GetParent();
2118 /* we propagate the key event up */
2119 wxKeyEvent
ke( wxEVT_KEY_DOWN
);
2120 ke
.m_shiftDown
= event
.m_shiftDown
;
2121 ke
.m_controlDown
= event
.m_controlDown
;
2122 ke
.m_altDown
= event
.m_altDown
;
2123 ke
.m_metaDown
= event
.m_metaDown
;
2124 ke
.m_keyCode
= event
.m_keyCode
;
2127 ke
.SetEventObject( parent
);
2128 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2133 void wxListMainWindow::OnChar( wxKeyEvent
&event
)
2135 wxWindow
*parent
= GetParent();
2137 /* we send a list_key event up */
2140 wxListEvent
le( wxEVT_COMMAND_LIST_KEY_DOWN
, GetParent()->GetId() );
2141 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2142 m_current
->GetItem( 0, le
.m_item
);
2143 le
.m_code
= (int)event
.KeyCode();
2144 le
.SetEventObject( parent
);
2145 parent
->GetEventHandler()->ProcessEvent( le
);
2148 /* we propagate the char event up */
2149 wxKeyEvent
ke( wxEVT_CHAR
);
2150 ke
.m_shiftDown
= event
.m_shiftDown
;
2151 ke
.m_controlDown
= event
.m_controlDown
;
2152 ke
.m_altDown
= event
.m_altDown
;
2153 ke
.m_metaDown
= event
.m_metaDown
;
2154 ke
.m_keyCode
= event
.m_keyCode
;
2157 ke
.SetEventObject( parent
);
2158 if (parent
->GetEventHandler()->ProcessEvent( ke
)) return;
2160 if (event
.KeyCode() == WXK_TAB
)
2162 wxNavigationKeyEvent nevent
;
2163 nevent
.SetWindowChange( event
.ControlDown() );
2164 nevent
.SetDirection( !event
.ShiftDown() );
2165 nevent
.SetEventObject( GetParent()->GetParent() );
2166 nevent
.SetCurrentFocus( m_parent
);
2167 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent
)) return;
2170 /* no item -> nothing to do */
2177 switch (event
.KeyCode())
2181 int index
= m_lines
.Index(*m_current
);
2182 if (index
!= wxNOT_FOUND
&& index
> 0)
2183 OnArrowChar( &m_lines
[index
-1], event
.ShiftDown() );
2188 int index
= m_lines
.Index(*m_current
);
2189 if (index
!= wxNOT_FOUND
&& (size_t)index
< m_lines
.GetCount()-1)
2190 OnArrowChar( &m_lines
[index
+1], event
.ShiftDown() );
2195 if (!m_lines
.IsEmpty())
2196 OnArrowChar( &m_lines
.Last(), event
.ShiftDown() );
2201 if (!m_lines
.IsEmpty())
2202 OnArrowChar( &m_lines
[0], event
.ShiftDown() );
2208 int index
= m_lines
.Index(*m_current
);
2209 if (m_mode
& wxLC_REPORT
)
2211 steps
= m_visibleLines
-1;
2215 steps
= index
% m_visibleLines
;
2217 if (index
!= wxNOT_FOUND
)
2220 if (index
< 0) index
= 0;
2221 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2228 int index
= m_lines
.Index(*m_current
);
2229 if (m_mode
& wxLC_REPORT
)
2231 steps
= m_visibleLines
-1;
2235 steps
= m_visibleLines
-(index
% m_visibleLines
)-1;
2238 if (index
!= wxNOT_FOUND
)
2241 if ((size_t)index
>= m_lines
.GetCount())
2242 index
= m_lines
.GetCount()-1;
2243 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2249 if (!(m_mode
& wxLC_REPORT
))
2251 int index
= m_lines
.Index(*m_current
);
2252 if (index
!= wxNOT_FOUND
)
2254 index
-= m_visibleLines
;
2255 if (index
< 0) index
= 0;
2256 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2263 if (!(m_mode
& wxLC_REPORT
))
2265 int index
= m_lines
.Index(*m_current
);
2266 if (index
!= wxNOT_FOUND
)
2268 index
+= m_visibleLines
;
2269 if ((size_t)index
>= m_lines
.GetCount())
2270 index
= m_lines
.GetCount()-1;
2271 OnArrowChar( &m_lines
[index
], event
.ShiftDown() );
2278 if (m_mode
& wxLC_SINGLE_SEL
)
2280 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2281 le
.SetEventObject( GetParent() );
2282 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2283 m_current
->GetItem( 0, le
.m_item
);
2284 GetParent()->GetEventHandler()->ProcessEvent( le
);
2288 m_current
->ReverseHilight();
2289 RefreshLine( m_current
);
2295 if (!(m_mode
& wxLC_SINGLE_SEL
))
2297 wxListLineData
*oldCurrent
= m_current
;
2298 m_current
->ReverseHilight();
2299 int index
= m_lines
.Index( *m_current
) + 1;
2300 if ( (size_t)index
< m_lines
.GetCount() )
2301 m_current
= &m_lines
[index
];
2302 RefreshLine( oldCurrent
);
2303 RefreshLine( m_current
);
2304 UnfocusLine( oldCurrent
);
2305 FocusLine( m_current
);
2313 wxListEvent
le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, GetParent()->GetId() );
2314 le
.SetEventObject( GetParent() );
2315 le
.m_itemIndex
= GetIndexOfLine( m_current
);
2316 m_current
->GetItem( 0, le
.m_item
);
2317 GetParent()->GetEventHandler()->ProcessEvent( le
);
2330 extern wxWindow
*g_focusWindow
;
2333 void wxListMainWindow::OnSetFocus( wxFocusEvent
&WXUNUSED(event
) )
2336 RefreshLine( m_current
);
2338 if (!GetParent()) return;
2341 g_focusWindow
= GetParent();
2344 wxFocusEvent
event( wxEVT_SET_FOCUS
, GetParent()->GetId() );
2345 event
.SetEventObject( GetParent() );
2346 GetParent()->GetEventHandler()->ProcessEvent( event
);
2349 void wxListMainWindow::OnKillFocus( wxFocusEvent
&WXUNUSED(event
) )
2352 RefreshLine( m_current
);
2355 void wxListMainWindow::OnSize( wxSizeEvent
&WXUNUSED(event
) )
2358 We don't even allow the wxScrolledWindow::AdjustScrollbars() call
2364 void wxListMainWindow::DrawImage( int index
, wxDC
*dc
, int x
, int y
)
2366 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2368 m_normal_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2371 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2373 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2375 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2377 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2379 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2381 m_small_image_list
->Draw( index
, *dc
, x
, y
, wxIMAGELIST_DRAW_TRANSPARENT
);
2386 void wxListMainWindow::GetImageSize( int index
, int &width
, int &height
)
2388 if ((m_mode
& wxLC_ICON
) && (m_normal_image_list
))
2390 m_normal_image_list
->GetSize( index
, width
, height
);
2393 if ((m_mode
& wxLC_SMALL_ICON
) && (m_small_image_list
))
2395 m_small_image_list
->GetSize( index
, width
, height
);
2398 if ((m_mode
& wxLC_LIST
) && (m_small_image_list
))
2400 m_small_image_list
->GetSize( index
, width
, height
);
2403 if ((m_mode
& wxLC_REPORT
) && (m_small_image_list
))
2405 m_small_image_list
->GetSize( index
, width
, height
);
2412 int wxListMainWindow::GetTextLength( wxString
&s
)
2414 wxClientDC
dc( this );
2417 dc
.GetTextExtent( s
, &lw
, &lh
);
2421 int wxListMainWindow::GetIndexOfLine( const wxListLineData
*line
)
2423 int i
= m_lines
.Index(*line
);
2424 if (i
== wxNOT_FOUND
) return -1;
2428 void wxListMainWindow::SetImageList( wxImageList
*imageList
, int which
)
2432 // calc the spacing from the icon size
2435 if ((imageList
) && (imageList
->GetImageCount()) )
2437 imageList
->GetSize(0, width
, height
);
2440 if (which
== wxIMAGE_LIST_NORMAL
)
2442 m_normal_image_list
= imageList
;
2443 m_normal_spacing
= width
+ 8;
2446 if (which
== wxIMAGE_LIST_SMALL
)
2448 m_small_image_list
= imageList
;
2449 m_small_spacing
= width
+ 14;
2453 void wxListMainWindow::SetItemSpacing( int spacing
, bool isSmall
)
2458 m_small_spacing
= spacing
;
2462 m_normal_spacing
= spacing
;
2466 int wxListMainWindow::GetItemSpacing( bool isSmall
)
2468 return isSmall
? m_small_spacing
: m_normal_spacing
;
2471 void wxListMainWindow::SetColumn( int col
, wxListItem
&item
)
2474 wxNode
*node
= m_columns
.Nth( col
);
2477 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2478 item
.m_width
= GetTextLength( item
.m_text
)+7;
2479 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2480 column
->SetItem( item
);
2483 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2485 headerWin
->m_dirty
= TRUE
;
2488 void wxListMainWindow::SetColumnWidth( int col
, int width
)
2490 wxCHECK_RET( m_mode
& wxLC_REPORT
,
2491 _T("SetColumnWidth() can only be called in report mode.") );
2495 wxNode
*node
= (wxNode
*) NULL
;
2497 if (width
== wxLIST_AUTOSIZE_USEHEADER
)
2499 // TODO do use the header
2502 else if (width
== wxLIST_AUTOSIZE
)
2504 wxClientDC
dc(this);
2505 dc
.SetFont( GetFont() );
2508 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2510 wxListLineData
*line
= &m_lines
[i
];
2511 wxNode
*n
= line
->m_items
.Nth( col
);
2514 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2515 int current
= 0, ix
= 0, iy
= 0;
2516 wxCoord lx
= 0, ly
= 0;
2517 if (item
->HasImage())
2519 GetImageSize( item
->GetImage(), ix
, iy
);
2522 if (item
->HasText())
2524 wxString str
= item
->GetText();
2525 dc
.GetTextExtent( str
, &lx
, &ly
);
2528 if (current
> max
) max
= current
;
2534 node
= m_columns
.Nth( col
);
2537 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2538 column
->SetWidth( width
);
2541 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2543 wxListLineData
*line
= &m_lines
[i
];
2544 wxNode
*n
= line
->m_items
.Nth( col
);
2547 wxListItemData
*item
= (wxListItemData
*)n
->Data();
2548 item
->SetSize( width
, -1 );
2552 wxListHeaderWindow
*headerWin
= ((wxListCtrl
*) GetParent())->m_headerWin
;
2554 headerWin
->m_dirty
= TRUE
;
2557 void wxListMainWindow::GetColumn( int col
, wxListItem
&item
)
2559 wxNode
*node
= m_columns
.Nth( col
);
2562 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2563 column
->GetItem( item
);
2569 item
.m_text
= _T("");
2575 int wxListMainWindow::GetColumnWidth( int col
)
2577 wxNode
*node
= m_columns
.Nth( col
);
2580 wxListHeaderData
*column
= (wxListHeaderData
*)node
->Data();
2581 return column
->GetWidth();
2589 int wxListMainWindow::GetColumnCount()
2591 return m_columns
.Number();
2594 int wxListMainWindow::GetCountPerPage()
2596 return m_visibleLines
;
2599 void wxListMainWindow::SetItem( wxListItem
&item
)
2602 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2604 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2605 if (m_mode
& wxLC_REPORT
) item
.m_width
= GetColumnWidth( item
.m_col
)-3;
2606 line
->SetItem( item
.m_col
, item
);
2610 void wxListMainWindow::SetItemState( long item
, long state
, long stateMask
)
2612 wxCHECK_RET( item
>= 0 && (size_t)item
< m_lines
.GetCount(),
2613 _T("invalid list ctrl item index in SetItem") );
2615 // m_dirty = TRUE; no recalcs needed
2617 wxListLineData
*oldCurrent
= m_current
;
2619 if ( stateMask
& wxLIST_STATE_FOCUSED
)
2621 wxListLineData
*line
= &m_lines
[(size_t)item
];
2622 if ( state
& wxLIST_STATE_FOCUSED
)
2624 // don't do anything if this item is already focused
2625 if ( line
!= m_current
)
2627 UnfocusLine( m_current
);
2629 FocusLine( m_current
);
2630 if ( (m_mode
& wxLC_SINGLE_SEL
) && oldCurrent
)
2631 oldCurrent
->Hilight( FALSE
);
2633 RefreshLine( m_current
);
2635 RefreshLine( oldCurrent
);
2640 // don't do anything if this item is not focused
2641 if ( line
== m_current
)
2643 UnfocusLine( m_current
);
2649 if ( stateMask
& wxLIST_STATE_SELECTED
)
2651 bool on
= (state
& wxLIST_STATE_SELECTED
) != 0;
2652 if (!on
&& (m_mode
& wxLC_SINGLE_SEL
))
2655 wxListLineData
*line
= &m_lines
[(size_t)item
];
2656 if (m_mode
& wxLC_SINGLE_SEL
)
2658 UnfocusLine( m_current
);
2660 FocusLine( m_current
);
2662 oldCurrent
->Hilight( FALSE
);
2663 RefreshLine( m_current
);
2665 RefreshLine( oldCurrent
);
2668 if (on
!= line
->IsHilighted())
2670 line
->Hilight( on
);
2671 RefreshLine( line
);
2676 int wxListMainWindow::GetItemState( long item
, long stateMask
)
2678 int ret
= wxLIST_STATE_DONTCARE
;
2679 if (stateMask
& wxLIST_STATE_FOCUSED
)
2681 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2683 wxListLineData
*line
= &m_lines
[(size_t)item
];
2684 if (line
== m_current
) ret
|= wxLIST_STATE_FOCUSED
;
2687 if (stateMask
& wxLIST_STATE_SELECTED
)
2689 if (item
>= 0 && (size_t)item
< m_lines
.GetCount())
2691 wxListLineData
*line
= &m_lines
[(size_t)item
];
2692 if (line
->IsHilighted()) ret
|= wxLIST_STATE_SELECTED
;
2698 void wxListMainWindow::GetItem( wxListItem
&item
)
2700 if (item
.m_itemId
>= 0 && (size_t)item
.m_itemId
< m_lines
.GetCount())
2702 wxListLineData
*line
= &m_lines
[(size_t)item
.m_itemId
];
2703 line
->GetItem( item
.m_col
, item
);
2708 item
.m_text
= _T("");
2714 int wxListMainWindow::GetItemCount()
2716 return m_lines
.GetCount();
2719 void wxListMainWindow::GetItemRect( long index
, wxRect
&rect
)
2721 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2723 m_lines
[(size_t)index
].GetRect( rect
);
2724 this->CalcScrolledPosition(rect
.x
,rect
.y
,&rect
.x
,&rect
.y
);
2735 bool wxListMainWindow::GetItemPosition(long item
, wxPoint
& pos
)
2738 this->GetItemRect(item
,rect
);
2739 pos
.x
=rect
.x
; pos
.y
=rect
.y
;
2743 int wxListMainWindow::GetSelectedItemCount()
2746 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2748 if (m_lines
[i
].IsHilighted()) ret
++;
2753 void wxListMainWindow::SetMode( long mode
)
2760 if (m_mode
& wxLC_REPORT
)
2762 #if wxUSE_GENERIC_LIST_EXTENSIONS
2776 long wxListMainWindow::GetMode() const
2781 void wxListMainWindow::CalculatePositions()
2783 if (m_lines
.IsEmpty()) return;
2785 wxClientDC
dc( this );
2786 dc
.SetFont( GetFont() );
2788 int iconSpacing
= 0;
2789 if (m_mode
& wxLC_ICON
) iconSpacing
= m_normal_spacing
;
2790 if (m_mode
& wxLC_SMALL_ICON
) iconSpacing
= m_small_spacing
;
2792 // we take the first line (which also can be an icon or
2793 // an a text item in wxLC_ICON and wxLC_LIST modes) to
2794 // measure the size of the line
2798 int lineSpacing
= 0;
2800 wxListLineData
*line
= &m_lines
[0];
2801 line
->CalculateSize( &dc
, iconSpacing
);
2803 line
->GetSize( dummy
, lineSpacing
);
2806 int clientWidth
= 0;
2807 int clientHeight
= 0;
2809 if (m_mode
& wxLC_REPORT
)
2811 // scroll one line per step
2812 m_yScroll
= lineSpacing
;
2816 int entireHeight
= m_lines
.GetCount() * lineSpacing
+ 2;
2817 int scroll_pos
= GetScrollPos( wxVERTICAL
);
2818 #if wxUSE_GENERIC_LIST_EXTENSIONS
2819 int x_scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2821 SetScrollbars( m_xScroll
, m_yScroll
, 0, entireHeight
/m_yScroll
+1, 0, scroll_pos
, TRUE
);
2823 GetClientSize( &clientWidth
, &clientHeight
);
2825 int entireWidth
= 0 ;
2826 for (size_t j
= 0; j
< m_lines
.GetCount(); j
++)
2828 wxListLineData
*line
= &m_lines
[j
];
2829 line
->CalculateSize( &dc
, iconSpacing
);
2830 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2832 for (int i
= 0; i
< GetColumnCount(); i
++)
2834 line
->SetColumnPosition( i
, col_x
);
2835 col_x
+= GetColumnWidth( i
);
2837 entireWidth
= wxMax( entireWidth
, col_x
) ;
2838 #if wxUSE_GENERIC_LIST_EXTENSIONS
2839 line
->SetPosition( &dc
, x
, y
, col_x
);
2841 y
+= lineSpacing
; // one pixel blank line between items
2843 m_visibleLines
= clientHeight
/ lineSpacing
;
2844 #if wxUSE_GENERIC_LIST_EXTENSIONS
2845 SetScrollbars( m_xScroll
, m_yScroll
, entireWidth
/m_xScroll
+1, entireHeight
/m_yScroll
+1, x_scroll_pos
, scroll_pos
, TRUE
);
2850 // at first we try without any scrollbar. if the items don't
2851 // fit into the window, we recalculate after subtracting an
2852 // approximated 15 pt for the horizontal scrollbar
2854 GetSize( &clientWidth
, &clientHeight
);
2855 clientHeight
-= 4; // sunken frame
2857 int entireWidth
= 0;
2859 for (int tries
= 0; tries
< 2; tries
++)
2866 int m_currentVisibleLines
= 0;
2867 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2869 m_currentVisibleLines
++;
2870 wxListLineData
*line
= &m_lines
[i
];
2871 line
->CalculateSize( &dc
, iconSpacing
);
2872 line
->SetPosition( &dc
, x
, y
, clientWidth
);
2873 line
->GetSize( lineWidth
, lineHeight
);
2874 if (lineWidth
> maxWidth
) maxWidth
= lineWidth
;
2876 if (m_currentVisibleLines
> m_visibleLines
)
2877 m_visibleLines
= m_currentVisibleLines
;
2878 if (y
+lineSpacing
-6 >= clientHeight
) // -6 for earlier "line breaking"
2880 m_currentVisibleLines
= 0;
2883 entireWidth
+= maxWidth
+6;
2886 if (i
== m_lines
.GetCount()-1) entireWidth
+= maxWidth
;
2887 if ((tries
== 0) && (entireWidth
> clientWidth
))
2889 clientHeight
-= 15; // scrollbar height
2891 m_currentVisibleLines
= 0;
2894 if (i
== m_lines
.GetCount()-1) tries
= 1; // everything fits, no second try required
2898 int scroll_pos
= GetScrollPos( wxHORIZONTAL
);
2899 SetScrollbars( m_xScroll
, m_yScroll
, (entireWidth
+15) / m_xScroll
, 0, scroll_pos
, 0, TRUE
);
2903 void wxListMainWindow::RealizeChanges()
2907 if (!m_lines
.IsEmpty())
2908 m_current
= &m_lines
[0];
2912 FocusLine( m_current
);
2913 // TODO: MSW doesn't automatically hilight the
2915 // if (m_mode & wxLC_SINGLE_SEL) m_current->Hilight( TRUE );
2919 long wxListMainWindow::GetNextItem( long item
,
2920 int WXUNUSED(geometry
),
2924 max
= GetItemCount();
2925 wxCHECK_MSG( (ret
== -1) || (ret
< max
), -1,
2926 _T("invalid listctrl index in GetNextItem()") );
2928 // notice that we start with the next item (or the first one if item == -1)
2929 // and this is intentional to allow writing a simple loop to iterate over
2930 // all selected items
2934 // this is not an error because the index was ok initially, just no
2939 for (size_t i
= (size_t)ret
; i
< m_lines
.GetCount(); i
++)
2941 wxListLineData
*line
= &m_lines
[i
];
2942 if ((state
& wxLIST_STATE_FOCUSED
) && (line
== m_current
))
2944 if ((state
& wxLIST_STATE_SELECTED
) && (line
->IsHilighted()))
2954 void wxListMainWindow::DeleteItem( long index
)
2957 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
2959 wxListLineData
*line
= &m_lines
[(size_t)index
];
2960 if (m_current
== line
) m_current
= (wxListLineData
*) NULL
;
2962 m_lines
.RemoveAt( (size_t)index
);
2966 void wxListMainWindow::DeleteColumn( int col
)
2968 wxCHECK_RET( col
< (int)m_columns
.GetCount(),
2969 wxT("attempting to delete inexistent column in wxListView") );
2972 wxNode
*node
= m_columns
.Nth( col
);
2973 if (node
) m_columns
.DeleteNode( node
);
2976 void wxListMainWindow::DeleteAllItems()
2979 m_current
= (wxListLineData
*) NULL
;
2981 // to make the deletion of all items faster, we don't send the
2982 // notifications in this case: this is compatible with wxMSW and
2983 // documented in DeleteAllItems() description
2985 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetParent()->GetId() );
2986 event
.SetEventObject( GetParent() );
2987 GetParent()->GetEventHandler()->ProcessEvent( event
);
2992 void wxListMainWindow::DeleteEverything()
2999 void wxListMainWindow::EnsureVisible( long index
)
3001 // We have to call this here because the label in
3002 // question might just have been added and no screen
3003 // update taken place.
3004 if (m_dirty
) wxYield();
3006 wxListLineData
*oldCurrent
= m_current
;
3007 m_current
= (wxListLineData
*) NULL
;
3008 if (index
>= 0 && (size_t)index
< m_lines
.GetCount())
3009 m_current
= &m_lines
[(size_t)index
];
3010 if (m_current
) MoveToFocus();
3011 m_current
= oldCurrent
;
3014 long wxListMainWindow::FindItem(long start
, const wxString
& str
, bool WXUNUSED(partial
) )
3018 if (pos
< 0) pos
= 0;
3019 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3021 wxListLineData
*line
= &m_lines
[i
];
3022 wxString s
= line
->GetText(0);
3031 long wxListMainWindow::FindItem(long start
, long data
)
3034 if (pos
< 0) pos
= 0;
3035 for (size_t i
= (size_t)pos
; i
< m_lines
.GetCount(); i
++)
3037 wxListLineData
*line
= &m_lines
[i
];
3039 line
->GetItem( 0, item
);
3040 if (item
.m_data
== data
) return pos
;
3046 long wxListMainWindow::HitTest( int x
, int y
, int &flags
)
3048 CalcUnscrolledPosition( x
, y
, &x
, &y
);
3051 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
3053 wxListLineData
*line
= &m_lines
[i
];
3054 long ret
= line
->IsHit( x
, y
);
3055 if (ret
) // & flags) // No: flags is output-only so may be garbage at this point
3065 void wxListMainWindow::InsertItem( wxListItem
&item
)
3069 if (m_mode
& wxLC_REPORT
) mode
= wxLC_REPORT
;
3070 else if (m_mode
& wxLC_LIST
) mode
= wxLC_LIST
;
3071 else if (m_mode
& wxLC_ICON
) mode
= wxLC_ICON
;
3072 else if (m_mode
& wxLC_SMALL_ICON
) mode
= wxLC_ICON
; // no typo
3074 wxListLineData
*line
= new wxListLineData( this, mode
, m_hilightBrush
);
3076 if (m_mode
& wxLC_REPORT
)
3078 line
->InitItems( GetColumnCount() );
3079 item
.m_width
= GetColumnWidth( 0 )-3;
3083 line
->InitItems( 1 );
3086 line
->SetItem( 0, item
);
3087 if ((item
.m_itemId
>= 0) && ((size_t)item
.m_itemId
< m_lines
.GetCount()))
3089 m_lines
.Insert( line
, (size_t)item
.m_itemId
);
3093 m_lines
.Add( line
);
3094 item
.m_itemId
= m_lines
.GetCount()-1;
3098 void wxListMainWindow::InsertColumn( long col
, wxListItem
&item
)
3101 if (m_mode
& wxLC_REPORT
)
3103 if (item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
3104 item
.m_width
= GetTextLength( item
.m_text
);
3105 wxListHeaderData
*column
= new wxListHeaderData( item
);
3106 if ((col
>= 0) && (col
< (int)m_columns
.GetCount()))
3108 wxNode
*node
= m_columns
.Nth( (size_t)col
);
3110 m_columns
.Insert( node
, column
);
3114 m_columns
.Append( column
);
3119 wxListCtrlCompare list_ctrl_compare_func_2
;
3120 long list_ctrl_compare_data
;
3122 int LINKAGEMODE
list_ctrl_compare_func_1( wxListLineData
**arg1
, wxListLineData
**arg2
)
3124 wxListLineData
*line1
= *arg1
;
3125 wxListLineData
*line2
= *arg2
;
3127 line1
->GetItem( 0, item
);
3128 long data1
= item
.m_data
;
3129 line2
->GetItem( 0, item
);
3130 long data2
= item
.m_data
;
3131 return list_ctrl_compare_func_2( data1
, data2
, list_ctrl_compare_data
);
3134 void wxListMainWindow::SortItems( wxListCtrlCompare fn
, long data
)
3136 list_ctrl_compare_func_2
= fn
;
3137 list_ctrl_compare_data
= data
;
3138 m_lines
.Sort( list_ctrl_compare_func_1
);
3142 void wxListMainWindow::OnScroll(wxScrollWinEvent
& event
)
3146 wxScrolledWindow::OnScroll(event
);
3148 HandleOnScroll( event
);
3151 #if wxUSE_GENERIC_LIST_EXTENSIONS
3153 if (event
.GetOrientation() == wxHORIZONTAL
&& ( m_mode
& wxLC_REPORT
))
3155 wxListCtrl
* lc
= wxDynamicCast( GetParent() , wxListCtrl
) ;
3158 lc
->m_headerWin
->Refresh() ;
3160 lc
->m_headerWin
->MacUpdateImmediately() ;
3167 // -------------------------------------------------------------------------------------
3169 // -------------------------------------------------------------------------------------
3171 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
3173 wxListItem::wxListItem()
3182 m_format
= wxLIST_FORMAT_CENTRE
;
3188 void wxListItem::Clear()
3197 m_format
= wxLIST_FORMAT_CENTRE
;
3201 if (m_attr
) delete m_attr
;
3205 void wxListItem::ClearAttributes()
3207 if (m_attr
) delete m_attr
;
3211 // -------------------------------------------------------------------------------------
3213 // -------------------------------------------------------------------------------------
3215 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
3217 wxListEvent::wxListEvent( wxEventType commandType
, int id
):
3218 wxNotifyEvent( commandType
, id
)
3224 m_cancelled
= FALSE
;
3229 void wxListEvent::CopyObject(wxObject
& object_dest
) const
3231 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
3233 wxNotifyEvent::CopyObject(object_dest
);
3235 obj
->m_code
= m_code
;
3236 obj
->m_itemIndex
= m_itemIndex
;
3237 obj
->m_oldItemIndex
= m_oldItemIndex
;
3239 obj
->m_cancelled
= m_cancelled
;
3240 obj
->m_pointDrag
= m_pointDrag
;
3241 obj
->m_item
.m_mask
= m_item
.m_mask
;
3242 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
3243 obj
->m_item
.m_col
= m_item
.m_col
;
3244 obj
->m_item
.m_state
= m_item
.m_state
;
3245 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
3246 obj
->m_item
.m_text
= m_item
.m_text
;
3247 obj
->m_item
.m_image
= m_item
.m_image
;
3248 obj
->m_item
.m_data
= m_item
.m_data
;
3249 obj
->m_item
.m_format
= m_item
.m_format
;
3250 obj
->m_item
.m_width
= m_item
.m_width
;
3252 if ( m_item
.HasAttributes() )
3254 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
3258 // -------------------------------------------------------------------------------------
3260 // -------------------------------------------------------------------------------------
3262 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
3264 BEGIN_EVENT_TABLE(wxListCtrl
,wxControl
)
3265 EVT_SIZE (wxListCtrl::OnSize
)
3266 EVT_IDLE (wxListCtrl::OnIdle
)
3269 wxListCtrl::wxListCtrl()
3271 m_imageListNormal
= (wxImageList
*) NULL
;
3272 m_imageListSmall
= (wxImageList
*) NULL
;
3273 m_imageListState
= (wxImageList
*) NULL
;
3274 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3275 m_mainWin
= (wxListMainWindow
*) NULL
;
3276 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3279 wxListCtrl::~wxListCtrl()
3281 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3282 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3283 if (m_ownsImageListState
) delete m_imageListState
;
3286 bool wxListCtrl::Create(wxWindow
*parent
,
3291 const wxValidator
&validator
,
3292 const wxString
&name
)
3294 m_imageListNormal
= (wxImageList
*) NULL
;
3295 m_imageListSmall
= (wxImageList
*) NULL
;
3296 m_imageListState
= (wxImageList
*) NULL
;
3297 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
3298 m_mainWin
= (wxListMainWindow
*) NULL
;
3299 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3301 if ( !(style
& (wxLC_REPORT
| wxLC_LIST
| wxLC_ICON
)) )
3303 style
= style
| wxLC_LIST
;
3306 bool ret
= wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
);
3309 if (style
& wxSUNKEN_BORDER
)
3310 style
-= wxSUNKEN_BORDER
;
3312 m_mainWin
= new wxListMainWindow( this, -1, wxPoint(0,0), size
, style
);
3314 if (HasFlag(wxLC_REPORT
))
3316 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
, wxPoint(0,0), wxSize(size
.x
,23), wxTAB_TRAVERSAL
);
3317 if (HasFlag(wxLC_NO_HEADER
))
3318 m_headerWin
->Show( FALSE
);
3322 m_headerWin
= (wxListHeaderWindow
*) NULL
;
3328 void wxListCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
3330 /* handled in OnIdle */
3332 if (m_mainWin
) m_mainWin
->m_dirty
= TRUE
;
3335 void wxListCtrl::SetSingleStyle( long style
, bool add
)
3337 long flag
= GetWindowStyle();
3341 if (style
& wxLC_MASK_TYPE
) flag
= flag
& ~wxLC_MASK_TYPE
;
3342 if (style
& wxLC_MASK_ALIGN
) flag
= flag
& ~wxLC_MASK_ALIGN
;
3343 if (style
& wxLC_MASK_SORT
) flag
= flag
& ~wxLC_MASK_SORT
;
3352 if (flag
& style
) flag
-= style
;
3355 SetWindowStyleFlag( flag
);
3358 void wxListCtrl::SetWindowStyleFlag( long flag
)
3362 m_mainWin
->DeleteEverything();
3366 GetClientSize( &width
, &height
);
3368 m_mainWin
->SetMode( flag
);
3370 if (flag
& wxLC_REPORT
)
3372 if (!HasFlag(wxLC_REPORT
))
3376 m_headerWin
= new wxListHeaderWindow( this, -1, m_mainWin
,
3377 wxPoint(0,0), wxSize(width
,23), wxTAB_TRAVERSAL
);
3378 if (HasFlag(wxLC_NO_HEADER
))
3379 m_headerWin
->Show( FALSE
);
3383 if (flag
& wxLC_NO_HEADER
)
3384 m_headerWin
->Show( FALSE
);
3386 m_headerWin
->Show( TRUE
);
3392 if (HasFlag(wxLC_REPORT
) && !(HasFlag(wxLC_NO_HEADER
)))
3394 m_headerWin
->Show( FALSE
);
3399 wxWindow::SetWindowStyleFlag( flag
);
3402 bool wxListCtrl::GetColumn(int col
, wxListItem
&item
) const
3404 m_mainWin
->GetColumn( col
, item
);
3408 bool wxListCtrl::SetColumn( int col
, wxListItem
& item
)
3410 m_mainWin
->SetColumn( col
, item
);
3414 int wxListCtrl::GetColumnWidth( int col
) const
3416 return m_mainWin
->GetColumnWidth( col
);
3419 bool wxListCtrl::SetColumnWidth( int col
, int width
)
3421 m_mainWin
->SetColumnWidth( col
, width
);
3425 int wxListCtrl::GetCountPerPage() const
3427 return m_mainWin
->GetCountPerPage(); // different from Windows ?
3430 bool wxListCtrl::GetItem( wxListItem
&info
) const
3432 m_mainWin
->GetItem( info
);
3436 bool wxListCtrl::SetItem( wxListItem
&info
)
3438 m_mainWin
->SetItem( info
);
3442 long wxListCtrl::SetItem( long index
, int col
, const wxString
& label
, int imageId
)
3445 info
.m_text
= label
;
3446 info
.m_mask
= wxLIST_MASK_TEXT
;
3447 info
.m_itemId
= index
;
3451 info
.m_image
= imageId
;
3452 info
.m_mask
|= wxLIST_MASK_IMAGE
;
3454 m_mainWin
->SetItem(info
);
3458 int wxListCtrl::GetItemState( long item
, long stateMask
) const
3460 return m_mainWin
->GetItemState( item
, stateMask
);
3463 bool wxListCtrl::SetItemState( long item
, long state
, long stateMask
)
3465 m_mainWin
->SetItemState( item
, state
, stateMask
);
3469 bool wxListCtrl::SetItemImage( long item
, int image
, int WXUNUSED(selImage
) )
3472 info
.m_image
= image
;
3473 info
.m_mask
= wxLIST_MASK_IMAGE
;
3474 info
.m_itemId
= item
;
3475 m_mainWin
->SetItem( info
);
3479 wxString
wxListCtrl::GetItemText( long item
) const
3482 info
.m_itemId
= item
;
3483 m_mainWin
->GetItem( info
);
3487 void wxListCtrl::SetItemText( long item
, const wxString
&str
)
3490 info
.m_mask
= wxLIST_MASK_TEXT
;
3491 info
.m_itemId
= item
;
3493 m_mainWin
->SetItem( info
);
3496 long wxListCtrl::GetItemData( long item
) const
3499 info
.m_itemId
= item
;
3500 m_mainWin
->GetItem( info
);
3504 bool wxListCtrl::SetItemData( long item
, long data
)
3507 info
.m_mask
= wxLIST_MASK_DATA
;
3508 info
.m_itemId
= item
;
3510 m_mainWin
->SetItem( info
);
3514 bool wxListCtrl::GetItemRect( long item
, wxRect
&rect
, int WXUNUSED(code
) ) const
3516 m_mainWin
->GetItemRect( item
, rect
);
3520 bool wxListCtrl::GetItemPosition( long item
, wxPoint
& pos
) const
3522 m_mainWin
->GetItemPosition( item
, pos
);
3526 bool wxListCtrl::SetItemPosition( long WXUNUSED(item
), const wxPoint
& WXUNUSED(pos
) )
3531 int wxListCtrl::GetItemCount() const
3533 return m_mainWin
->GetItemCount();
3536 int wxListCtrl::GetColumnCount() const
3538 return m_mainWin
->GetColumnCount();
3541 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
3543 m_mainWin
->SetItemSpacing( spacing
, isSmall
);
3546 int wxListCtrl::GetItemSpacing( bool isSmall
) const
3548 return m_mainWin
->GetItemSpacing( isSmall
);
3551 int wxListCtrl::GetSelectedItemCount() const
3553 return m_mainWin
->GetSelectedItemCount();
3556 wxColour
wxListCtrl::GetTextColour() const
3558 return GetForegroundColour();
3561 void wxListCtrl::SetTextColour(const wxColour
& col
)
3563 SetForegroundColour(col
);
3566 long wxListCtrl::GetTopItem() const
3571 long wxListCtrl::GetNextItem( long item
, int geom
, int state
) const
3573 return m_mainWin
->GetNextItem( item
, geom
, state
);
3576 wxImageList
*wxListCtrl::GetImageList(int which
) const
3578 if (which
== wxIMAGE_LIST_NORMAL
)
3580 return m_imageListNormal
;
3582 else if (which
== wxIMAGE_LIST_SMALL
)
3584 return m_imageListSmall
;
3586 else if (which
== wxIMAGE_LIST_STATE
)
3588 return m_imageListState
;
3590 return (wxImageList
*) NULL
;
3593 void wxListCtrl::SetImageList( wxImageList
*imageList
, int which
)
3595 if ( which
== wxIMAGE_LIST_NORMAL
)
3597 if (m_ownsImageListNormal
) delete m_imageListNormal
;
3598 m_imageListNormal
= imageList
;
3599 m_ownsImageListNormal
= FALSE
;
3601 else if ( which
== wxIMAGE_LIST_SMALL
)
3603 if (m_ownsImageListSmall
) delete m_imageListSmall
;
3604 m_imageListSmall
= imageList
;
3605 m_ownsImageListSmall
= FALSE
;
3607 else if ( which
== wxIMAGE_LIST_STATE
)
3609 if (m_ownsImageListState
) delete m_imageListState
;
3610 m_imageListState
= imageList
;
3611 m_ownsImageListState
= FALSE
;
3614 m_mainWin
->SetImageList( imageList
, which
);
3617 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
3619 SetImageList(imageList
, which
);
3620 if ( which
== wxIMAGE_LIST_NORMAL
)
3621 m_ownsImageListNormal
= TRUE
;
3622 else if ( which
== wxIMAGE_LIST_SMALL
)
3623 m_ownsImageListSmall
= TRUE
;
3624 else if ( which
== wxIMAGE_LIST_STATE
)
3625 m_ownsImageListState
= TRUE
;
3628 bool wxListCtrl::Arrange( int WXUNUSED(flag
) )
3633 bool wxListCtrl::DeleteItem( long item
)
3635 m_mainWin
->DeleteItem( item
);
3639 bool wxListCtrl::DeleteAllItems()
3641 m_mainWin
->DeleteAllItems();
3645 bool wxListCtrl::DeleteAllColumns()
3647 for ( size_t n
= 0; n
< m_mainWin
->m_columns
.GetCount(); n
++ )
3653 void wxListCtrl::ClearAll()
3655 m_mainWin
->DeleteEverything();
3658 bool wxListCtrl::DeleteColumn( int col
)
3660 m_mainWin
->DeleteColumn( col
);
3664 void wxListCtrl::Edit( long item
)
3666 m_mainWin
->Edit( item
);
3669 bool wxListCtrl::EnsureVisible( long item
)
3671 m_mainWin
->EnsureVisible( item
);
3675 long wxListCtrl::FindItem( long start
, const wxString
& str
, bool partial
)
3677 return m_mainWin
->FindItem( start
, str
, partial
);
3680 long wxListCtrl::FindItem( long start
, long data
)
3682 return m_mainWin
->FindItem( start
, data
);
3685 long wxListCtrl::FindItem( long WXUNUSED(start
), const wxPoint
& WXUNUSED(pt
),
3686 int WXUNUSED(direction
))
3691 long wxListCtrl::HitTest( const wxPoint
&point
, int &flags
)
3693 return m_mainWin
->HitTest( (int)point
.x
, (int)point
.y
, flags
);
3696 long wxListCtrl::InsertItem( wxListItem
& info
)
3698 m_mainWin
->InsertItem( info
);
3699 return info
.m_itemId
;
3702 long wxListCtrl::InsertItem( long index
, const wxString
&label
)
3705 info
.m_text
= label
;
3706 info
.m_mask
= wxLIST_MASK_TEXT
;
3707 info
.m_itemId
= index
;
3708 return InsertItem( info
);
3711 long wxListCtrl::InsertItem( long index
, int imageIndex
)
3714 info
.m_mask
= wxLIST_MASK_IMAGE
;
3715 info
.m_image
= imageIndex
;
3716 info
.m_itemId
= index
;
3717 return InsertItem( info
);
3720 long wxListCtrl::InsertItem( long index
, const wxString
&label
, int imageIndex
)
3723 info
.m_text
= label
;
3724 info
.m_image
= imageIndex
;
3725 info
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_IMAGE
;
3726 info
.m_itemId
= index
;
3727 return InsertItem( info
);
3730 long wxListCtrl::InsertColumn( long col
, wxListItem
&item
)
3732 wxASSERT( m_headerWin
);
3733 m_mainWin
->InsertColumn( col
, item
);
3734 m_headerWin
->Refresh();
3739 long wxListCtrl::InsertColumn( long col
, const wxString
&heading
,
3740 int format
, int width
)
3743 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
3744 item
.m_text
= heading
;
3747 item
.m_mask
|= wxLIST_MASK_WIDTH
;
3748 item
.m_width
= width
;
3750 item
.m_format
= format
;
3752 return InsertColumn( col
, item
);
3755 bool wxListCtrl::ScrollList( int WXUNUSED(dx
), int WXUNUSED(dy
) )
3761 // fn is a function which takes 3 long arguments: item1, item2, data.
3762 // item1 is the long data associated with a first item (NOT the index).
3763 // item2 is the long data associated with a second item (NOT the index).
3764 // data is the same value as passed to SortItems.
3765 // The return value is a negative number if the first item should precede the second
3766 // item, a positive number of the second item should precede the first,
3767 // or zero if the two items are equivalent.
3768 // data is arbitrary data to be passed to the sort function.
3770 bool wxListCtrl::SortItems( wxListCtrlCompare fn
, long data
)
3772 m_mainWin
->SortItems( fn
, data
);
3776 void wxListCtrl::OnIdle( wxIdleEvent
&WXUNUSED(event
) )
3778 if (!m_mainWin
->m_dirty
) return;
3782 GetClientSize( &cw
, &ch
);
3789 if (HasFlag(wxLC_REPORT
) && !HasFlag(wxLC_NO_HEADER
))
3791 m_headerWin
->GetPosition( &x
, &y
);
3792 m_headerWin
->GetSize( &w
, &h
);
3793 if ((x
!= 0) || (y
!= 0) || (w
!= cw
) || (h
!= 23))
3794 m_headerWin
->SetSize( 0, 0, cw
, 23 );
3796 m_mainWin
->GetPosition( &x
, &y
);
3797 m_mainWin
->GetSize( &w
, &h
);
3798 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
-24))
3799 m_mainWin
->SetSize( 0, 24, cw
, ch
-24 );
3803 m_mainWin
->GetPosition( &x
, &y
);
3804 m_mainWin
->GetSize( &w
, &h
);
3805 if ((x
!= 0) || (y
!= 24) || (w
!= cw
) || (h
!= ch
))
3806 m_mainWin
->SetSize( 0, 0, cw
, ch
);
3809 m_mainWin
->CalculatePositions();
3810 m_mainWin
->RealizeChanges();
3811 m_mainWin
->m_dirty
= FALSE
;
3812 m_mainWin
->Refresh();
3814 if ( m_headerWin
&& m_headerWin
->m_dirty
)
3816 m_headerWin
->m_dirty
= FALSE
;
3817 m_headerWin
->Refresh();
3821 bool wxListCtrl::SetBackgroundColour( const wxColour
&colour
)
3825 m_mainWin
->SetBackgroundColour( colour
);
3826 m_mainWin
->m_dirty
= TRUE
;
3832 bool wxListCtrl::SetForegroundColour( const wxColour
&colour
)
3834 if ( !wxWindow::SetForegroundColour( colour
) )
3839 m_mainWin
->SetForegroundColour( colour
);
3840 m_mainWin
->m_dirty
= TRUE
;
3845 m_headerWin
->SetForegroundColour( colour
);
3851 bool wxListCtrl::SetFont( const wxFont
&font
)
3853 if ( !wxWindow::SetFont( font
) )
3858 m_mainWin
->SetFont( font
);
3859 m_mainWin
->m_dirty
= TRUE
;
3864 m_headerWin
->SetFont( font
);
3870 #if wxUSE_DRAG_AND_DROP
3872 void wxListCtrl::SetDropTarget( wxDropTarget
*dropTarget
)
3874 m_mainWin
->SetDropTarget( dropTarget
);
3877 wxDropTarget
*wxListCtrl::GetDropTarget() const
3879 return m_mainWin
->GetDropTarget();
3882 #endif // wxUSE_DRAG_AND_DROP
3884 bool wxListCtrl::SetCursor( const wxCursor
&cursor
)
3886 return m_mainWin
? m_mainWin
->wxWindow::SetCursor(cursor
) : FALSE
;
3889 wxColour
wxListCtrl::GetBackgroundColour() const
3891 return m_mainWin
? m_mainWin
->GetBackgroundColour() : wxColour();
3894 wxColour
wxListCtrl::GetForegroundColour() const
3896 return m_mainWin
? m_mainWin
->GetForegroundColour() : wxColour();
3899 bool wxListCtrl::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
3901 return m_mainWin
->PopupMenu( menu
, x
, y
);
3904 void wxListCtrl::SetFocus()
3906 /* The test in window.cpp fails as we are a composite
3907 window, so it checks against "this", but not m_mainWin. */
3908 if ( FindFocus() != this )
3909 m_mainWin
->SetFocus();
3912 #endif // wxUSE_LISTCTRL