1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
39 #include "wx/stockitem.h"
40 #include "wx/calctrl.h"
41 #include "wx/popupwin.h"
42 #include "wx/renderer.h"
43 #include "wx/dcbuffer.h"
46 #include "wx/listimpl.cpp"
47 #include "wx/imaglist.h"
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
55 static const int SCROLL_UNIT_X
= 15;
57 // the cell padding on the left/right
58 static const int PADDING_RIGHTLEFT
= 3;
60 // the expander space margin
61 static const int EXPANDER_MARGIN
= 4;
64 static const int EXPANDER_OFFSET
= 4;
66 static const int EXPANDER_OFFSET
= 1;
69 //-----------------------------------------------------------------------------
70 // wxDataViewHeaderWindow
71 //-----------------------------------------------------------------------------
73 // on wxMSW the header window (only that part however) can be made native!
74 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
75 #define USE_NATIVE_HEADER_WINDOW
78 //Below is the compare stuff
79 //For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed
80 static wxDataViewModel
* g_model
;
81 static int g_column
= -2;
82 static bool g_asending
= true;
84 // NB: for some reason, this class must be dllexport'ed or we get warnings from
86 class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase
: public wxControl
89 wxDataViewHeaderWindowBase()
92 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
93 const wxPoint
&pos
, const wxSize
&size
,
96 return wxWindow::Create(parent
, id
, pos
, size
, wxNO_BORDER
, name
);
99 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
100 wxDataViewCtrl
*GetOwner() { return m_owner
; }
102 // called on column addition/removal
103 virtual void UpdateDisplay() { /* by default, do nothing */ }
105 // returns the n-th column
106 virtual wxDataViewColumn
*GetColumn(unsigned int n
)
109 wxDataViewColumn
*ret
= m_owner
->GetColumn(n
);
116 wxDataViewCtrl
*m_owner
;
118 // sends an event generated from the n-th wxDataViewColumn
119 void SendEvent(wxEventType type
, unsigned int n
);
122 #ifdef USE_NATIVE_HEADER_WINDOW
124 #define COLUMN_WIDTH_OFFSET 2
125 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow
127 class wxDataViewHeaderWindowMSW
: public wxDataViewHeaderWindowBase
131 wxDataViewHeaderWindowMSW( wxDataViewCtrl
*parent
,
133 const wxPoint
&pos
= wxDefaultPosition
,
134 const wxSize
&size
= wxDefaultSize
,
135 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
137 Create(parent
, id
, pos
, size
, name
);
140 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
141 const wxPoint
&pos
, const wxSize
&size
,
142 const wxString
&name
);
144 ~wxDataViewHeaderWindowMSW();
146 // called when any column setting is changed and/or changed
148 virtual void UpdateDisplay();
150 virtual void OnInternalIdle();
152 // called Refresh afterwards
153 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
155 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
158 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
160 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
162 wxSize
DoGetBestSize() const;
164 unsigned int GetColumnIdxFromHeader(NMHEADER
*nmHDR
);
166 wxDataViewColumn
*GetColumnFromHeader(NMHEADER
*nmHDR
)
167 { return GetColumn(GetColumnIdxFromHeader(nmHDR
)); }
171 bool m_vetoColumnDrag
;
172 bool m_delayedUpdate
;
173 wxImageList
*m_imageList
;
176 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW
)
179 #else // !defined(__WXMSW__)
181 #define HEADER_WINDOW_HEIGHT 25
182 #define HEADER_HORIZ_BORDER 5
183 #define HEADER_VERT_BORDER 3
184 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
186 class wxGenericDataViewHeaderWindow
: public wxDataViewHeaderWindowBase
189 wxGenericDataViewHeaderWindow( wxDataViewCtrl
*parent
,
191 const wxPoint
&pos
= wxDefaultPosition
,
192 const wxSize
&size
= wxDefaultSize
,
193 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
196 Create(parent
, id
, pos
, size
, name
);
199 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
200 const wxPoint
&pos
, const wxSize
&size
,
201 const wxString
&name
);
203 ~wxGenericDataViewHeaderWindow()
205 delete m_resizeCursor
;
208 virtual void UpdateDisplay() { Refresh(); }
212 void OnPaint( wxPaintEvent
&event
);
213 void OnMouse( wxMouseEvent
&event
);
214 void OnSetFocus( wxFocusEvent
&event
);
219 // vars used for column resizing:
221 wxCursor
*m_resizeCursor
;
222 const wxCursor
*m_currentCursor
;
225 bool m_dirty
; // needs refresh?
226 int m_hover
; // index of the column under the mouse
227 int m_column
; // index of the column being resized
228 int m_currentX
; // divider line position in logical (unscrolled) coords
229 int m_minX
; // minimal position beyond which the divider line
230 // can't be dragged in logical coords
232 // the pen used to draw the current column width drag line
233 // when resizing the columsn
237 // internal utilities:
241 m_currentCursor
= (wxCursor
*) NULL
;
242 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
244 m_isDragging
= false;
247 m_hover
= wxNOT_FOUND
;
248 m_column
= wxNOT_FOUND
;
252 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
253 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
256 void AdjustDC(wxDC
& dc
);
259 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
260 DECLARE_EVENT_TABLE()
263 #endif // defined(__WXMSW__)
265 //-----------------------------------------------------------------------------
266 // wxDataViewRenameTimer
267 //-----------------------------------------------------------------------------
269 class wxDataViewRenameTimer
: public wxTimer
272 wxDataViewMainWindow
*m_owner
;
275 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
279 //-----------------------------------------------------------------------------
280 // wxDataViewTreeNode
281 //-----------------------------------------------------------------------------
282 class wxDataViewTreeNode
;
283 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
284 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
286 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
);
287 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
289 class wxDataViewTreeNode
292 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
299 m_hasChildren
= false;
303 ~wxDataViewTreeNode()
307 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
308 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
309 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
310 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
312 void AddNode( wxDataViewTreeNode
* node
)
314 m_leaves
.Add( node
->GetItem().GetID() );
316 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
319 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
321 void AddLeaf( void * leaf
)
323 m_leaves
.Add( leaf
);
325 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
328 wxDataViewItem
& GetItem() { return m_item
; }
329 const wxDataViewItem
& GetItem() const { return m_item
; }
330 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
332 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
333 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
334 int GetIndentLevel() const
337 const wxDataViewTreeNode
* node
= this;
338 while( node
->GetParent()->GetParent() != NULL
)
340 node
= node
->GetParent();
353 int len
= m_nodes
.GetCount();
355 for ( int i
= 0 ;i
< len
; i
++)
356 sum
+= m_nodes
[i
]->GetSubTreeCount();
358 sum
+= m_leaves
.GetCount();
361 ChangeSubTreeCount(-sum
);
367 ChangeSubTreeCount(sum
);
370 bool HasChildren() const { return m_hasChildren
; }
371 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
373 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
374 int GetSubTreeCount() const { return m_subTreeCount
; }
375 void ChangeSubTreeCount( int num
)
379 m_subTreeCount
+= num
;
381 m_parent
->ChangeSubTreeCount(num
);
388 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
389 int len
= m_nodes
.GetCount();
390 for (int i
= 0; i
< len
; i
++)
391 m_nodes
[i
]->Resort();
392 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
397 wxDataViewTreeNode
*m_parent
;
398 wxDataViewTreeNodes m_nodes
;
399 wxDataViewTreeLeaves m_leaves
;
400 wxDataViewItem m_item
;
406 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
)
408 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
411 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
413 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
418 //-----------------------------------------------------------------------------
419 // wxDataViewMainWindow
420 //-----------------------------------------------------------------------------
422 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
424 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
425 WX_DEFINE_LIST(ItemList
)
427 class wxDataViewMainWindow
: public wxWindow
430 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
432 const wxPoint
&pos
= wxDefaultPosition
,
433 const wxSize
&size
= wxDefaultSize
,
434 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
435 virtual ~wxDataViewMainWindow();
437 bool IsVirtualList() const { return m_root
== NULL
; }
439 // notifications from wxDataViewModel
440 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
441 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
442 bool ItemChanged( const wxDataViewItem
&item
);
443 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
447 if (!IsVirtualList())
457 g_model
= GetOwner()->GetModel();
458 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
461 if (g_model
->HasDefaultCompare())
469 g_column
= col
->GetModelColumn();
470 g_asending
= col
->IsSortOrderAscending();
473 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
474 wxDataViewCtrl
*GetOwner() { return m_owner
; }
475 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
477 void OnPaint( wxPaintEvent
&event
);
478 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
479 void OnChar( wxKeyEvent
&event
);
480 void OnMouse( wxMouseEvent
&event
);
481 void OnSetFocus( wxFocusEvent
&event
);
482 void OnKillFocus( wxFocusEvent
&event
);
484 void UpdateDisplay();
485 void RecalculateDisplay();
486 void OnInternalIdle();
488 void OnRenameTimer();
490 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
491 void ScrollTo( int rows
, int column
);
493 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
494 void ChangeCurrentRow( unsigned int row
);
496 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
497 bool IsEmpty() { return GetRowCount() == 0; }
499 int GetCountPerPage() const;
500 int GetEndOfLastCol() const;
501 unsigned int GetFirstVisibleRow() const;
502 //I change this method to un const because in the tree view, the displaying number of the tree are changing along with the expanding/collapsing of the tree nodes
503 unsigned int GetLastVisibleRow();
504 unsigned int GetRowCount() ;
506 wxDataViewItem
GetSelection() const;
507 wxDataViewSelection
GetSelections(){ return m_selection
; }
508 void SetSelections( const wxDataViewSelection
& sel
) { m_selection
= sel
; UpdateDisplay(); }
509 void Select( const wxArrayInt
& aSelections
);
510 void SelectAllRows( bool on
);
511 void SelectRow( unsigned int row
, bool on
);
512 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
513 void ReverseRowSelection( unsigned int row
);
514 bool IsRowSelected( unsigned int row
);
515 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
517 void RefreshRow( unsigned int row
);
518 void RefreshRows( unsigned int from
, unsigned int to
);
519 void RefreshRowsAfter( unsigned int firstRow
);
521 // returns the colour to be used for drawing the rules
522 wxColour
GetRuleColour() const
524 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
527 wxRect
GetLineRect( unsigned int row
) const;
529 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
530 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
531 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
533 //Some useful functions for row and item mapping
534 wxDataViewItem
GetItemByRow( unsigned int row
) const;
535 int GetRowByItem( const wxDataViewItem
& item
) const;
537 //Methods for building the mapping tree
538 void BuildTree( wxDataViewModel
* model
);
540 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
541 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
543 void Expand( unsigned int row
) { OnExpanding( row
); }
544 void Collapse( unsigned int row
) { OnCollapsing( row
); }
546 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
547 //We did not need this temporarily
548 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
550 int RecalculateCount() ;
552 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
553 void OnExpanding( unsigned int row
);
554 void OnCollapsing( unsigned int row
);
556 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
559 wxDataViewCtrl
*m_owner
;
563 wxDataViewColumn
*m_currentCol
;
564 unsigned int m_currentRow
;
565 wxDataViewSelection m_selection
;
567 wxDataViewRenameTimer
*m_renameTimer
;
575 // for double click logic
576 unsigned int m_lineLastClicked
,
577 m_lineBeforeLastClicked
,
578 m_lineSelectSingleOnUp
;
580 // the pen used to draw horiz/vertical rules
583 // the pen used to draw the expander and the lines
586 //This is the tree structure of the model
587 wxDataViewTreeNode
* m_root
;
589 //This is the tree node under the cursor
590 wxDataViewTreeNode
* m_underMouse
;
592 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
593 DECLARE_EVENT_TABLE()
596 // ---------------------------------------------------------
597 // wxGenericDataViewModelNotifier
598 // ---------------------------------------------------------
600 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
603 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
604 { m_mainWindow
= mainWindow
; }
606 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
607 { return m_mainWindow
->ItemAdded( parent
, item
); }
608 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
609 { return m_mainWindow
->ItemDeleted( parent
, item
); }
610 virtual bool ItemChanged( const wxDataViewItem
& item
)
611 { return m_mainWindow
->ItemChanged(item
); }
612 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
613 { return m_mainWindow
->ValueChanged( item
, col
); }
614 virtual bool Cleared()
615 { return m_mainWindow
->Cleared(); }
616 virtual void Resort()
617 { m_mainWindow
->Resort(); }
619 wxDataViewMainWindow
*m_mainWindow
;
622 // ---------------------------------------------------------
623 // wxDataViewRenderer
624 // ---------------------------------------------------------
626 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
628 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
629 wxDataViewCellMode mode
,
631 wxDataViewRendererBase( varianttype
, mode
, align
)
640 wxDataViewRenderer::~wxDataViewRenderer()
646 wxDC
*wxDataViewRenderer::GetDC()
650 if (GetOwner() == NULL
)
652 if (GetOwner()->GetOwner() == NULL
)
654 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
660 void wxDataViewRenderer::SetAlignment( int align
)
665 int wxDataViewRenderer::GetAlignment() const
670 int wxDataViewRenderer::CalculateAlignment() const
672 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
674 if (GetOwner() == NULL
)
675 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
677 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
683 // ---------------------------------------------------------
684 // wxDataViewCustomRenderer
685 // ---------------------------------------------------------
687 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
689 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
690 wxDataViewCellMode mode
, int align
) :
691 wxDataViewRenderer( varianttype
, mode
, align
)
695 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
697 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
698 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
699 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
700 view
->GetForegroundColour();
701 dc
->SetTextForeground(col
);
702 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
705 // ---------------------------------------------------------
706 // wxDataViewTextRenderer
707 // ---------------------------------------------------------
709 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
711 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
712 wxDataViewCellMode mode
, int align
) :
713 wxDataViewCustomRenderer( varianttype
, mode
, align
)
717 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
719 m_text
= value
.GetString();
724 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
729 bool wxDataViewTextRenderer::HasEditorCtrl()
734 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
735 wxRect labelRect
, const wxVariant
&value
)
737 return new wxTextCtrl( parent
, wxID_ANY
, value
,
738 wxPoint(labelRect
.x
,labelRect
.y
),
739 wxSize(labelRect
.width
,labelRect
.height
) );
742 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
744 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
745 value
= text
->GetValue();
749 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
751 RenderText( m_text
, 0, cell
, dc
, state
);
755 wxSize
wxDataViewTextRenderer::GetSize() const
757 const wxDataViewCtrl
*view
= GetView();
761 view
->GetTextExtent( m_text
, &x
, &y
);
762 return wxSize( x
, y
);
764 return wxSize(80,20);
767 // ---------------------------------------------------------
768 // wxDataViewTextRendererAttr
769 // ---------------------------------------------------------
771 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
773 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
774 wxDataViewCellMode mode
, int align
) :
775 wxDataViewTextRenderer( varianttype
, mode
, align
)
780 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
787 if (m_attr
.HasColour())
789 colour
= dc
->GetTextForeground();
790 dc
->SetTextForeground( m_attr
.GetColour() );
793 if (m_attr
.GetBold() || m_attr
.GetItalic())
795 font
= dc
->GetFont();
796 wxFont myfont
= font
;
797 if (m_attr
.GetBold())
798 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
799 if (m_attr
.GetItalic())
800 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
801 dc
->SetFont( myfont
);
805 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
810 if (m_attr
.HasColour())
811 dc
->SetTextForeground( colour
);
813 if (m_attr
.GetBold() || m_attr
.GetItalic())
821 // ---------------------------------------------------------
822 // wxDataViewBitmapRenderer
823 // ---------------------------------------------------------
825 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
827 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
828 wxDataViewCellMode mode
, int align
) :
829 wxDataViewCustomRenderer( varianttype
, mode
, align
)
833 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
835 if (value
.GetType() == wxT("wxBitmap"))
837 if (value
.GetType() == wxT("wxIcon"))
843 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
848 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
851 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
852 else if (m_icon
.Ok())
853 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
858 wxSize
wxDataViewBitmapRenderer::GetSize() const
861 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
862 else if (m_icon
.Ok())
863 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
865 return wxSize(16,16);
868 // ---------------------------------------------------------
869 // wxDataViewToggleRenderer
870 // ---------------------------------------------------------
872 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
874 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
875 wxDataViewCellMode mode
, int align
) :
876 wxDataViewCustomRenderer( varianttype
, mode
, align
)
881 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
883 m_toggle
= value
.GetBool();
888 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
893 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
895 // User wxRenderer here
898 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
900 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
905 flags
|= wxCONTROL_CHECKED
;
906 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
907 flags
|= wxCONTROL_DISABLED
;
909 wxRendererNative::Get().DrawCheckBox(
910 GetOwner()->GetOwner(),
918 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
919 wxDataViewModel
*model
,
920 const wxDataViewItem
& item
, unsigned int col
)
922 bool value
= !m_toggle
;
923 wxVariant variant
= value
;
924 model
->SetValue( variant
, item
, col
);
925 model
->ValueChanged( item
, col
);
929 wxSize
wxDataViewToggleRenderer::GetSize() const
931 return wxSize(20,20);
934 // ---------------------------------------------------------
935 // wxDataViewProgressRenderer
936 // ---------------------------------------------------------
938 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
940 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
941 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
942 wxDataViewCustomRenderer( varianttype
, mode
, align
)
948 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
952 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
954 m_value
= (long) value
;
956 if (m_value
< 0) m_value
= 0;
957 if (m_value
> 100) m_value
= 100;
962 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
964 value
= (long) m_value
;
968 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
970 double pct
= (double)m_value
/ 100.0;
972 bar
.width
= (int)(cell
.width
* pct
);
973 dc
->SetPen( *wxTRANSPARENT_PEN
);
974 dc
->SetBrush( *wxBLUE_BRUSH
);
975 dc
->DrawRectangle( bar
);
977 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
978 dc
->SetPen( *wxBLACK_PEN
);
979 dc
->DrawRectangle( cell
);
984 wxSize
wxDataViewProgressRenderer::GetSize() const
986 return wxSize(40,12);
989 // ---------------------------------------------------------
990 // wxDataViewDateRenderer
991 // ---------------------------------------------------------
993 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
995 #if wxUSE_DATE_RENDERER_POPUP
997 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1000 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1001 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
1002 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
1007 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
1008 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1009 sizer
->Add( m_cal
, 1, wxGROW
);
1014 void OnCalendar( wxCalendarEvent
&event
);
1016 wxCalendarCtrl
*m_cal
;
1017 wxDataViewModel
*m_model
;
1019 const wxDataViewItem
& m_item
;
1022 virtual void OnDismiss()
1027 DECLARE_EVENT_TABLE()
1030 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1031 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1034 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1036 wxDateTime date
= event
.GetDate();
1037 wxVariant value
= date
;
1038 m_model
->SetValue( value
, m_item
, m_col
);
1039 m_model
->ValueChanged( m_item
, m_col
);
1043 #endif // wxUSE_DATE_RENDERER_POPUP
1045 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1047 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1048 wxDataViewCellMode mode
, int align
) :
1049 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1053 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1055 m_date
= value
.GetDateTime();
1060 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1066 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1068 wxString tmp
= m_date
.FormatDate();
1069 RenderText( tmp
, 0, cell
, dc
, state
);
1073 wxSize
wxDataViewDateRenderer::GetSize() const
1075 const wxDataViewCtrl
* view
= GetView();
1076 wxString tmp
= m_date
.FormatDate();
1078 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1079 return wxSize(x
,y
+d
);
1082 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1083 const wxDataViewItem
& item
, unsigned int col
)
1086 model
->GetValue( variant
, item
, col
);
1087 wxDateTime value
= variant
.GetDateTime();
1089 #if wxUSE_DATE_RENDERER_POPUP
1090 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1091 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1092 wxPoint pos
= wxGetMousePosition();
1095 popup
->Popup( popup
->m_cal
);
1096 #else // !wxUSE_DATE_RENDERER_POPUP
1097 wxMessageBox(value
.Format());
1098 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1102 // ---------------------------------------------------------
1103 // wxDataViewIconTextRenderer
1104 // ---------------------------------------------------------
1106 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1108 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1109 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1110 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1113 SetAlignment(align
);
1116 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1120 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1126 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1131 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1134 const wxIcon
&icon
= m_value
.GetIcon();
1137 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1138 xoffset
= icon
.GetWidth()+4;
1141 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1146 wxSize
wxDataViewIconTextRenderer::GetSize() const
1148 const wxDataViewCtrl
*view
= GetView();
1149 if (!m_value
.GetText().empty())
1152 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1154 if (m_value
.GetIcon().IsOk())
1155 x
+= m_value
.GetIcon().GetWidth() + 4;
1156 return wxSize( x
, y
);
1158 return wxSize(80,20);
1162 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
1163 wxRect
WXUNUSED(labelRect
),
1164 const wxVariant
& WXUNUSED(value
))
1170 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
1171 wxVariant
& WXUNUSED(value
))
1176 // ---------------------------------------------------------
1178 // ---------------------------------------------------------
1180 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1182 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1183 unsigned int model_column
,
1184 int width
, wxAlignment align
, int flags
) :
1185 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1187 SetAlignment(align
);
1191 m_autosize
= width
< 0; // TODO
1193 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1196 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1197 unsigned int model_column
,
1198 int width
, wxAlignment align
, int flags
) :
1199 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1201 SetAlignment(align
);
1204 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1207 wxDataViewColumn::~wxDataViewColumn()
1211 void wxDataViewColumn::Init( int width
)
1214 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
1218 void wxDataViewColumn::SetResizeable( bool resizeable
)
1221 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
1223 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
1226 void wxDataViewColumn::SetHidden( bool hidden
)
1229 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
1231 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
1233 // tell our owner to e.g. update its scrollbars:
1235 GetOwner()->OnColumnChange();
1238 void wxDataViewColumn::SetSortable( bool sortable
)
1241 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
1243 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
1245 // Update header button
1247 GetOwner()->OnColumnChange();
1250 void wxDataViewColumn::SetReorderable( bool reorderable
)
1253 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
1255 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
1258 void wxDataViewColumn::SetSortOrder( bool ascending
)
1260 m_ascending
= ascending
;
1262 // Update header button
1264 GetOwner()->OnColumnChange();
1267 bool wxDataViewColumn::IsSortOrderAscending() const
1272 void wxDataViewColumn::SetInternalWidth( int width
)
1276 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
1277 if (m_owner
&& m_owner
->m_clientArea
)
1278 m_owner
->m_clientArea
->RecalculateDisplay();
1281 void wxDataViewColumn::SetWidth( int width
)
1283 if (m_owner
->m_headerArea
) m_owner
->m_headerArea
->UpdateDisplay();
1285 SetInternalWidth(width
);
1289 //-----------------------------------------------------------------------------
1290 // wxDataViewHeaderWindowBase
1291 //-----------------------------------------------------------------------------
1293 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
1295 wxWindow
*parent
= GetParent();
1296 wxDataViewEvent
le(type
, parent
->GetId());
1298 le
.SetEventObject(parent
);
1300 le
.SetDataViewColumn(GetColumn(n
));
1301 le
.SetModel(GetOwner()->GetModel());
1303 // for events created by wxDataViewHeaderWindow the
1304 // row / value fields are not valid
1306 parent
->GetEventHandler()->ProcessEvent(le
);
1309 #ifdef USE_NATIVE_HEADER_WINDOW
1311 #ifndef HDS_DRAGDROP
1312 #define HDS_DRAGDROP 0x0040
1314 #ifndef HDS_FULLDRAG
1315 #define HDS_FULLDRAG 0x0080
1318 // implemented in msw/listctrl.cpp:
1319 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
1321 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
1323 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
1324 const wxPoint
&pos
, const wxSize
&size
,
1325 const wxString
&name
)
1329 m_scrollOffsetX
= 0;
1330 m_delayedUpdate
= false;
1331 m_vetoColumnDrag
= false;
1332 m_buttonHeight
= wxRendererNative::Get().GetHeaderButtonHeight( this );
1334 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
1335 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
1336 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
1339 wxSize
new_size(w
,h
);
1341 if ( !CreateControl(parent
, id
, pos
, new_size
, 0, wxDefaultValidator
, name
) )
1344 // create the native WC_HEADER window:
1345 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
1346 WXDWORD msStyle
= WS_CHILD
| HDS_DRAGDROP
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
1349 msStyle
|= WS_VISIBLE
;
1351 m_hWnd
= CreateWindowEx(0,
1362 wxLogLastError(_T("CreateWindowEx"));
1366 m_imageList
= new wxImageList( 16, 16 );
1367 Header_SetImageList( (HWND
) m_hWnd
, m_imageList
->GetHIMAGELIST() );
1369 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
1370 // to call wxDataViewHeaderWindow::MSWOnNotify
1371 SubclassWin(m_hWnd
);
1373 // the following is required to get the default win's font for
1374 // header windows and must be done befor sending the HDM_LAYOUT msg
1380 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
1386 wxSize
wxDataViewHeaderWindowMSW::DoGetBestSize() const
1388 return wxSize( 80, m_buttonHeight
+2 );
1391 void wxDataViewHeaderWindowMSW::OnInternalIdle()
1393 if (m_delayedUpdate
)
1395 m_delayedUpdate
= false;
1400 void wxDataViewHeaderWindowMSW::UpdateDisplay()
1402 // remove old columns
1403 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
1404 Header_DeleteItem((HWND
)m_hWnd
, 0);
1406 m_imageList
->RemoveAll();
1408 // add the updated array of columns to the header control
1409 unsigned int cols
= GetOwner()->GetColumnCount();
1410 unsigned int added
= 0;
1411 for (unsigned int i
= 0; i
< cols
; i
++)
1413 wxDataViewColumn
*col
= GetColumn( i
);
1414 if (col
->IsHidden())
1415 continue; // don't add it!
1417 wxString
title( col
->GetTitle() );
1419 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1420 if (col
->GetBitmap().IsOk())
1422 m_imageList
->Add( col
->GetBitmap() );
1423 hdi
.mask
|= HDI_IMAGE
;
1424 hdi
.iImage
= m_imageList
->GetImageCount()-1;
1426 hdi
.pszText
= (wxChar
*) title
.wx_str();
1427 hdi
.cxy
= col
->GetWidth();
1428 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1429 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1430 if (col
->GetBitmap().IsOk())
1431 hdi
.fmt
|= HDF_IMAGE
;
1433 //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
1435 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1437 //The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default
1438 //see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail
1439 // VZ: works with 5.81
1440 hdi
.fmt
|= col
->IsSortOrderAscending() ? HDF_SORTUP
: HDF_SORTDOWN
;
1443 // lParam is reserved for application's use:
1444 // we store there the column index to use it later in MSWOnNotify
1445 // (since columns may have been hidden)
1446 hdi
.lParam
= (LPARAM
)i
;
1448 // the native wxMSW implementation of the header window
1449 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1450 // on the right: to correct this effect we make the column
1451 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1453 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1455 switch (col
->GetAlignment())
1458 hdi
.fmt
|= HDF_LEFT
;
1460 case wxALIGN_CENTER
:
1461 case wxALIGN_CENTER_HORIZONTAL
:
1462 hdi
.fmt
|= HDF_CENTER
;
1465 hdi
.fmt
|= HDF_RIGHT
;
1469 // such alignment is not allowed for the column header!
1473 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1474 (WPARAM
)added
, (LPARAM
)&hdi
);
1479 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1483 // NOTE: we don't just return nmHDR->iItem because when there are
1484 // hidden columns, nmHDR->iItem may be different from
1485 // nmHDR->pitem->lParam
1487 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1489 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1494 item
.mask
= HDI_LPARAM
;
1495 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1497 return (unsigned int)item
.lParam
;
1500 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1502 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1504 // is it a message from the header?
1505 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1506 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1508 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1509 switch ( nmhdr
->code
)
1511 case NM_RELEASEDCAPTURE
:
1513 // user has released the mouse
1514 m_vetoColumnDrag
= false;
1518 case HDN_BEGINTRACK
:
1519 // user has started to resize a column:
1520 // do we need to veto it?
1521 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1530 if (nmHDR
->iItem
!= -1)
1532 // user has started to reorder a valid column
1533 if ((m_vetoColumnDrag
== true) || (!GetColumn(nmHDR
->iItem
)->IsReorderable()))
1537 m_vetoColumnDrag
= true;
1543 m_vetoColumnDrag
= true;
1547 case HDN_ENDDRAG
: // user has finished reordering a column
1549 wxDataViewColumn
*col
= GetColumn(nmHDR
->iItem
);
1550 unsigned int new_pos
= nmHDR
->pitem
->iOrder
;
1551 m_owner
->ColumnMoved( col
, new_pos
);
1552 m_delayedUpdate
= true;
1556 case HDN_ITEMCHANGING
:
1557 if (nmHDR
->pitem
!= NULL
&&
1558 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1560 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1561 if (nmHDR
->pitem
->cxy
< minWidth
)
1563 // do not allow the user to resize this column under
1564 // its minimal width:
1570 case HDN_ITEMCHANGED
: // user is resizing a column
1571 case HDN_ENDTRACK
: // user has finished resizing a column
1573 // update the width of the modified column:
1574 if (nmHDR
->pitem
!= NULL
&&
1575 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1577 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1578 unsigned int w
= nmHDR
->pitem
->cxy
;
1579 wxDataViewColumn
*col
= GetColumn(idx
);
1581 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1582 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1583 w
-= COLUMN_WIDTH_OFFSET
;
1585 if (w
>= (unsigned)col
->GetMinWidth())
1586 col
->SetInternalWidth(w
);
1592 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1593 wxDataViewModel
* model
= GetOwner()->GetModel();
1595 if(nmHDR
->iButton
== 0)
1597 wxDataViewColumn
*col
= GetColumn(idx
);
1598 if(col
->IsSortable())
1600 if(model
&& m_owner
->GetSortingColumn() == col
)
1602 bool order
= col
->IsSortOrderAscending();
1603 col
->SetSortOrder(!order
);
1607 m_owner
->SetSortingColumn(col
);
1615 wxEventType evt
= nmHDR
->iButton
== 0 ?
1616 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1617 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1618 SendEvent(evt
, idx
);
1624 // NOTE: for some reason (i.e. for a bug in Windows)
1625 // the HDN_ITEMCLICK notification is not sent on
1626 // right clicks, so we need to handle NM_RCLICK
1629 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1630 if (column
!= wxNOT_FOUND
)
1633 item
.mask
= HDI_LPARAM
;
1634 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1636 // 'idx' may be different from 'column' if there are
1637 // hidden columns...
1638 unsigned int idx
= (unsigned int)item
.lParam
;
1639 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1645 case HDN_GETDISPINFOW
:
1646 // see wxListCtrl::MSWOnNotify for more info!
1649 case HDN_ITEMDBLCLICK
:
1651 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1652 int w
= GetOwner()->GetBestColumnWidth(idx
);
1654 // update the native control:
1656 ZeroMemory(&hd
, sizeof(hd
));
1657 hd
.mask
= HDI_WIDTH
;
1659 Header_SetItem(GetHwnd(),
1660 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1663 // update the wxDataViewColumn class:
1664 GetColumn(idx
)->SetInternalWidth(w
);
1669 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1675 void wxDataViewHeaderWindowMSW::ScrollWindow(int dx
, int WXUNUSED(dy
),
1676 const wxRect
* WXUNUSED(rect
))
1678 m_scrollOffsetX
+= dx
;
1680 GetParent()->Layout();
1683 void wxDataViewHeaderWindowMSW::DoSetSize(int x
, int y
,
1687 // TODO: why is there a border + 2px around it?
1688 wxControl::DoSetSize( x
+m_scrollOffsetX
+1, y
+1, w
-m_scrollOffsetX
-2, h
-2, f
);
1691 #else // !defined(__WXMSW__)
1693 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1694 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1695 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1696 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1697 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1700 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1701 const wxPoint
&pos
, const wxSize
&size
,
1702 const wxString
&name
)
1706 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1709 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1710 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1711 SetOwnForegroundColour( attr
.colFg
);
1712 SetOwnBackgroundColour( attr
.colBg
);
1714 SetOwnFont( attr
.font
);
1716 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1717 // a wxBoxSizer and in order to avoid super-big header windows,
1718 // we need to set our height as fixed
1719 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1720 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1725 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1728 GetClientSize( &w
, &h
);
1730 wxAutoBufferedPaintDC
dc( this );
1732 dc
.SetBackground(GetBackgroundColour());
1736 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1739 m_owner
->GetViewStart( &x
, NULL
);
1741 // account for the horz scrollbar offset
1742 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1744 dc
.SetFont( GetFont() );
1746 unsigned int cols
= GetOwner()->GetColumnCount();
1749 for (i
= 0; i
< cols
; i
++)
1751 wxDataViewColumn
*col
= GetColumn( i
);
1752 if (col
->IsHidden())
1753 continue; // skip it!
1755 int cw
= col
->GetWidth();
1758 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
;
1759 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1761 if (col
->IsSortOrderAscending())
1762 sortArrow
= wxHDR_SORT_ICON_UP
;
1764 sortArrow
= wxHDR_SORT_ICON_DOWN
;
1768 if (m_parent
->IsEnabled())
1770 if ((int) i
== m_hover
)
1771 state
= wxCONTROL_CURRENT
;
1775 state
= (int) wxCONTROL_DISABLED
;
1778 wxRendererNative::Get().DrawHeaderButton
1782 wxRect(xpos
, 0, cw
, ch
-1),
1787 // align as required the column title:
1789 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1790 switch (col
->GetAlignment())
1793 x
+= HEADER_HORIZ_BORDER
;
1796 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1799 case wxALIGN_CENTER
:
1800 case wxALIGN_CENTER_HORIZONTAL
:
1801 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1805 // always center the title vertically:
1806 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1808 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1810 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1811 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1812 dc
.DrawText( col
->GetTitle(), x
, y
);
1813 dc
.DestroyClippingRegion();
1819 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1821 GetParent()->SetFocus();
1825 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1827 // we want to work with logical coords
1829 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1830 int y
= event
.GetY();
1834 // we don't draw the line beyond our window,
1835 // but we allow dragging it there
1837 GetClientSize( &w
, NULL
);
1838 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1841 if (event
.ButtonUp())
1843 m_isDragging
= false;
1849 m_currentX
= wxMax(m_minX
+ 7, x
);
1853 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1855 GetOwner()->Refresh();
1859 else // not dragging
1862 m_column
= wxNOT_FOUND
;
1864 bool hit_border
= false;
1866 // end of the current column
1869 // find the column where this event occured
1870 int countCol
= m_owner
->GetColumnCount();
1871 for (int column
= 0; column
< countCol
; column
++)
1873 wxDataViewColumn
*p
= GetColumn(column
);
1876 continue; // skip if not shown
1878 xpos
+= p
->GetWidth();
1880 if ((abs(x
-xpos
) < 3) && (y
< 22))
1888 // inside the column
1895 int old_hover
= m_hover
;
1897 if (event
.Leaving())
1898 m_hover
= wxNOT_FOUND
;
1899 if (old_hover
!= m_hover
)
1902 if (m_column
== wxNOT_FOUND
)
1905 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1906 if (event
.LeftDClick() && resizeable
)
1908 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1911 else if (event
.LeftDown() || event
.RightUp())
1913 if (hit_border
&& event
.LeftDown() && resizeable
)
1915 m_isDragging
= true;
1919 else // click on a column
1921 wxDataViewModel
* model
= GetOwner()->GetModel();
1922 wxEventType evt
= event
.LeftDown() ?
1923 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1924 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1925 SendEvent(evt
, m_column
);
1927 //Left click the header
1928 if(event
.LeftDown())
1930 wxDataViewColumn
*col
= GetColumn(m_column
);
1931 if(col
->IsSortable())
1933 wxDataViewColumn
* sortCol
= m_owner
->GetSortingColumn();
1934 if(model
&& sortCol
== col
)
1936 bool order
= col
->IsSortOrderAscending();
1937 col
->SetSortOrder(!order
);
1941 m_owner
->SetSortingColumn(col
);
1947 //Send the column sorted event
1948 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, m_column
);
1952 else if (event
.Moving())
1954 if (hit_border
&& resizeable
)
1955 m_currentCursor
= m_resizeCursor
;
1957 m_currentCursor
= wxSTANDARD_CURSOR
;
1959 SetCursor(*m_currentCursor
);
1964 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1968 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1969 m_owner
->GetViewStart( &x
, NULL
);
1971 // shift the DC origin to match the position of the main window horizontal
1972 // scrollbar: this allows us to always use logical coords
1973 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1976 #endif // defined(__WXMSW__)
1978 //-----------------------------------------------------------------------------
1979 // wxDataViewRenameTimer
1980 //-----------------------------------------------------------------------------
1982 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1987 void wxDataViewRenameTimer::Notify()
1989 m_owner
->OnRenameTimer();
1992 //-----------------------------------------------------------------------------
1993 // wxDataViewMainWindow
1994 //-----------------------------------------------------------------------------
1996 //The tree building helper, declared firstly
1997 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
);
1999 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
2001 if (row1
> row2
) return 1;
2002 if (row1
== row2
) return 0;
2007 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
2009 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
2010 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
2011 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
2012 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
2013 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
2014 EVT_CHAR (wxDataViewMainWindow::OnChar
)
2017 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
2018 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
2019 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
2020 m_selection( wxDataViewSelectionCmp
)
2025 m_lastOnSame
= false;
2026 m_renameTimer
= new wxDataViewRenameTimer( this );
2028 // TODO: user better initial values/nothing selected
2029 m_currentCol
= NULL
;
2032 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
2035 m_dragStart
= wxPoint(0,0);
2036 m_lineLastClicked
= (unsigned int) -1;
2037 m_lineBeforeLastClicked
= (unsigned int) -1;
2038 m_lineSelectSingleOnUp
= (unsigned int) -1;
2042 SetBackgroundColour( *wxWHITE
);
2044 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
2046 m_penRule
= wxPen(GetRuleColour());
2048 //Here I compose a pen can draw black lines, maybe there are something system colour to use
2049 m_penExpander
= wxPen(wxColour(0,0,0));
2050 //Some new added code to deal with the tree structure
2051 m_root
= new wxDataViewTreeNode( NULL
);
2052 m_root
->SetHasChildren(true);
2054 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
2056 m_underMouse
= NULL
;
2060 wxDataViewMainWindow::~wxDataViewMainWindow()
2063 delete m_renameTimer
;
2066 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2068 wxDataViewModel
*model
= GetOwner()->GetModel();
2069 wxAutoBufferedPaintDC
dc( this );
2072 dc
.SetPen( *wxTRANSPARENT_PEN
);
2073 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
2074 dc
.SetBrush( *wxWHITE_BRUSH
);
2075 wxSize
size( GetClientSize() );
2076 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
2080 GetOwner()->PrepareDC( dc
);
2081 dc
.SetFont( GetFont() );
2083 wxRect update
= GetUpdateRegion().GetBox();
2084 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
2086 // compute which items needs to be redrawn
2087 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
2088 unsigned int item_count
=
2089 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
2090 (int)(GetRowCount( ) - item_start
));
2091 unsigned int item_last
= item_start
+ item_count
;
2093 // compute which columns needs to be redrawn
2094 unsigned int cols
= GetOwner()->GetColumnCount();
2095 unsigned int col_start
= 0;
2096 unsigned int x_start
= 0;
2097 for (x_start
= 0; col_start
< cols
; col_start
++)
2099 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
2100 if (col
->IsHidden())
2101 continue; // skip it!
2103 unsigned int w
= col
->GetWidth();
2104 if (x_start
+w
>= (unsigned int)update
.x
)
2110 unsigned int col_last
= col_start
;
2111 unsigned int x_last
= x_start
;
2112 for (; col_last
< cols
; col_last
++)
2114 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
2115 if (col
->IsHidden())
2116 continue; // skip it!
2118 if (x_last
> (unsigned int)update
.GetRight())
2121 x_last
+= col
->GetWidth();
2124 // Draw horizontal rules if required
2125 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
2127 dc
.SetPen(m_penRule
);
2128 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2130 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
2132 int y
= GetLineStart( i
);
2133 dc
.DrawLine(x_start
, y
, x_last
, y
);
2137 // Draw vertical rules if required
2138 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
2140 dc
.SetPen(m_penRule
);
2141 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2144 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2146 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
2147 if (col
->IsHidden())
2148 continue; // skip it
2150 dc
.DrawLine(x
, GetLineStart( item_start
),
2151 x
, GetLineStart( item_last
) );
2153 x
+= col
->GetWidth();
2156 // Draw last vertical rule
2157 dc
.DrawLine(x
, GetLineStart( item_start
),
2158 x
, GetLineStart( item_last
) );
2161 // redraw the background for the items which are selected/current
2162 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2164 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
2165 if (selected
|| item
== m_currentRow
)
2167 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
2168 if (item
== m_currentRow
)
2169 flags
|= wxCONTROL_CURRENT
;
2171 flags
|= wxCONTROL_FOCUSED
;
2173 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
2174 wxRendererNative::Get().DrawItemSelectionRect
2184 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
2187 // TODO: last column for RTL support
2188 expander
= GetOwner()->GetColumn( 0 );
2189 GetOwner()->SetExpanderColumn(expander
);
2192 // redraw all cells for all rows which must be repainted and all columns
2194 cell_rect
.x
= x_start
;
2195 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2198 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
2199 wxDataViewRenderer
*cell
= col
->GetRenderer();
2200 cell_rect
.width
= col
->GetWidth();
2202 if (col
->IsHidden())
2203 continue; // skip it!
2205 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2207 // get the cell value and set it into the renderer
2209 wxDataViewTreeNode
*node
= NULL
;
2210 wxDataViewItem dataitem
;
2212 if (!IsVirtualList())
2214 node
= GetTreeNodeByRow(item
);
2218 dataitem
= node
->GetItem();
2220 if ((i
> 0) && model
->IsContainer(dataitem
) && !model
->HasContainerColumns(dataitem
))
2225 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
2228 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
2229 cell
->SetValue( value
);
2231 if (cell
->GetWantsAttr())
2233 wxDataViewItemAttr attr
;
2234 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
2236 cell
->SetAttr( attr
);
2237 cell
->SetHasAttr( ret
);
2241 cell_rect
.y
= GetLineStart( item
);
2242 cell_rect
.height
= GetLineHeight( item
); // -1 is for the horizontal rules (?)
2244 //Draw the expander here.
2246 if ((!IsVirtualList()) && (col
== expander
))
2248 indent
= node
->GetIndentLevel();
2250 //Calculate the indent first
2251 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
2253 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
2254 // change the cell_rect.x to the appropriate pos
2255 int expander_x
= indent
+ EXPANDER_MARGIN
;
2256 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2) - (expander_width
/2) - EXPANDER_OFFSET
;
2257 indent
= indent
+ m_lineHeight
; //try to use the m_lineHeight as the expander space
2258 dc
.SetPen( m_penExpander
);
2259 dc
.SetBrush( wxNullBrush
);
2260 if( node
->HasChildren() )
2262 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
2264 if (m_underMouse
== node
)
2266 flag
|= wxCONTROL_CURRENT
;
2268 if( node
->IsOpen() )
2269 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
|wxCONTROL_EXPANDED
);
2271 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
2273 //force the expander column to left-center align
2274 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
2276 if (node
&& !node
->HasChildren())
2278 // Yes, if the node does not have any child, it must be a leaf which
2279 // mean that it is a temporarily created by GetTreeNodeByRow
2283 // cannot be bigger than allocated space
2284 wxSize size
= cell
->GetSize();
2285 // Because of the tree structure indent, here we should minus the width of the cell for drawing
2286 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
2287 // size.y = wxMin( size.y, cell_rect.height );
2288 size
.y
= cell_rect
.height
;
2290 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
2291 int align
= cell
->CalculateAlignment();
2293 // horizontal alignment:
2294 item_rect
.x
= cell_rect
.x
;
2295 if (align
& wxALIGN_CENTER_HORIZONTAL
)
2296 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
2297 else if (align
& wxALIGN_RIGHT
)
2298 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
2299 //else: wxALIGN_LEFT is the default
2301 // vertical alignment:
2302 item_rect
.y
= cell_rect
.y
;
2303 if (align
& wxALIGN_CENTER_VERTICAL
)
2304 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
2305 else if (align
& wxALIGN_BOTTOM
)
2306 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
2307 //else: wxALIGN_TOP is the default
2310 item_rect
.x
+= PADDING_RIGHTLEFT
;
2311 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
2313 //Here we add the tree indent
2314 item_rect
.x
+= indent
;
2317 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
2318 state
|= wxDATAVIEW_CELL_SELECTED
;
2320 // TODO: it would be much more efficient to create a clipping
2321 // region for the entire column being rendered (in the OnPaint
2322 // of wxDataViewMainWindow) instead of a single clip region for
2323 // each cell. However it would mean that each renderer should
2324 // respect the given wxRect's top & bottom coords, eventually
2325 // violating only the left & right coords - however the user can
2326 // make its own renderer and thus we cannot be sure of that.
2327 dc
.SetClippingRegion( item_rect
);
2328 cell
->Render( item_rect
, &dc
, state
);
2329 dc
.DestroyClippingRegion();
2332 cell_rect
.x
+= cell_rect
.width
;
2336 void wxDataViewMainWindow::OnRenameTimer()
2338 // We have to call this here because changes may just have
2339 // been made and no screen update taken place.
2344 unsigned int cols
= GetOwner()->GetColumnCount();
2346 for (i
= 0; i
< cols
; i
++)
2348 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2350 continue; // skip it!
2352 if (c
== m_currentCol
)
2354 xpos
+= c
->GetWidth();
2356 wxRect
labelRect( xpos
,
2357 GetLineStart( m_currentRow
),
2358 m_currentCol
->GetWidth(),
2359 GetLineHeight( m_currentRow
) );
2361 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
2362 &labelRect
.x
, &labelRect
.y
);
2364 wxDataViewItem item
= GetItemByRow( m_currentRow
);
2365 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
2369 //------------------------------------------------------------------
2370 // Helper class for do operation on the tree node
2371 //------------------------------------------------------------------
2378 //The return value control how the tree-walker tranverse the tree
2379 // 0: Job done, stop tranverse and return
2380 // 1: Ignore the current node's subtree and continue
2381 // 2: Job not done, continue
2382 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
2383 virtual int operator() ( wxDataViewTreeNode
* node
) = 0 ;
2384 virtual int operator() ( void * n
) = 0;
2387 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2392 switch( func( node
) )
2403 wxDataViewTreeNodes nodes
= node
->GetNodes();
2404 wxDataViewTreeLeaves leaves
= node
->GetChildren();
2406 int len_nodes
= nodes
.GetCount();
2407 int len
= leaves
.GetCount();
2408 int i
= 0, nodes_i
= 0;
2410 for( ; i
< len
; i
++ )
2412 void * n
= leaves
[i
];
2413 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
2415 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
2418 if( Walker( nd
, func
) )
2437 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2448 wxDataViewTreeNode
* node
;
2449 node
= FindNode(parent
);
2454 node
->SetHasChildren( true );
2456 if( g_model
->IsContainer( item
) )
2458 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2459 newnode
->SetItem(item
);
2460 newnode
->SetHasChildren( true );
2461 node
->AddNode( newnode
);
2464 node
->AddLeaf( item
.GetID() );
2466 node
->ChangeSubTreeCount(1);
2474 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2476 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2477 const wxDataViewItem
& item
)
2482 if( m_currentRow
> GetRowCount() )
2483 m_currentRow
= m_count
- 1;
2485 m_selection
.Empty();
2492 wxDataViewTreeNode
* node
= FindNode(parent
);
2494 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2495 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
, false, "item not found" );
2498 node
->GetChildren().Remove( item
.GetID() );
2499 //Manuplate selection
2500 if( m_selection
.GetCount() > 1 )
2502 m_selection
.Empty();
2504 bool isContainer
= false;
2505 wxDataViewTreeNodes nds
= node
->GetNodes();
2506 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2508 if (nds
[i
]->GetItem() == item
)
2516 wxDataViewTreeNode
* n
= NULL
;
2517 wxDataViewTreeNodes nodes
= node
->GetNodes();
2518 int len
= nodes
.GetCount();
2519 for( int i
= 0 ; i
< len
; i
++)
2521 if( nodes
[i
]->GetItem() == item
)
2528 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2530 node
->GetNodes().Remove( n
);
2531 sub
-= n
->GetSubTreeCount();
2532 ::DestroyTreeHelper(n
);
2534 //Make the row number invalid and get a new valid one when user call GetRowCount
2536 node
->ChangeSubTreeCount(sub
);
2538 //Change the current row to the last row if the current exceed the max row number
2539 if( m_currentRow
> GetRowCount() )
2540 m_currentRow
= m_count
- 1;
2547 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2553 wxWindow
*parent
= GetParent();
2554 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2555 le
.SetEventObject(parent
);
2556 le
.SetModel(GetOwner()->GetModel());
2558 parent
->GetEventHandler()->ProcessEvent(le
);
2563 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2565 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2566 /*#define MAX_VIRTUAL_WIDTH 100000
2568 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2569 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2570 Refresh( true, &rect );
2578 wxWindow
*parent
= GetParent();
2579 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2580 le
.SetEventObject(parent
);
2581 le
.SetModel(GetOwner()->GetModel());
2584 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2585 parent
->GetEventHandler()->ProcessEvent(le
);
2590 bool wxDataViewMainWindow::Cleared()
2595 BuildTree( GetOwner()->GetModel() );
2602 void wxDataViewMainWindow::UpdateDisplay()
2607 void wxDataViewMainWindow::OnInternalIdle()
2609 wxWindow::OnInternalIdle();
2613 RecalculateDisplay();
2618 void wxDataViewMainWindow::RecalculateDisplay()
2620 wxDataViewModel
*model
= GetOwner()->GetModel();
2627 int width
= GetEndOfLastCol();
2628 int height
= GetLineStart( GetRowCount() );
2630 SetVirtualSize( width
, height
);
2631 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2636 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2638 wxWindow::ScrollWindow( dx
, dy
, rect
);
2640 if (GetOwner()->m_headerArea
)
2641 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2644 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2647 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2648 int sy
= GetLineStart( rows
)/y
;
2652 wxRect rect
= GetClientRect();
2654 int x_start
= 0, x_end
= 0, w
= 0;
2656 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2657 for (x_start
= 0; colnum
< column
; colnum
++)
2659 wxDataViewColumn
*col
= GetOwner()->GetColumn(colnum
);
2660 if (col
->IsHidden())
2661 continue; // skip it!
2663 w
= col
->GetWidth();
2667 x_end
= x_start
+ w
;
2668 xe
= xx
+ rect
.width
;
2671 sx
= ( xx
+ x_end
- xe
)/x
;
2678 m_owner
->Scroll( sx
, sy
);
2681 int wxDataViewMainWindow::GetCountPerPage() const
2683 wxSize size
= GetClientSize();
2684 return size
.y
/ m_lineHeight
;
2687 int wxDataViewMainWindow::GetEndOfLastCol() const
2691 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2693 const wxDataViewColumn
*c
=
2694 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
2697 width
+= c
->GetWidth();
2702 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2706 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2708 return GetLineAt( y
);
2711 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2713 wxSize client_size
= GetClientSize();
2714 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2715 &client_size
.x
, &client_size
.y
);
2717 //we should deal with the pixel here
2718 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2720 return wxMin( GetRowCount()-1, row
);
2723 unsigned int wxDataViewMainWindow::GetRowCount()
2725 if ( m_count
== -1 )
2727 m_count
= RecalculateCount();
2733 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2740 void wxDataViewMainWindow::SelectAllRows( bool on
)
2747 m_selection
.Clear();
2748 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2749 m_selection
.Add( i
);
2754 unsigned int first_visible
= GetFirstVisibleRow();
2755 unsigned int last_visible
= GetLastVisibleRow();
2757 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2759 unsigned int row
= m_selection
[i
];
2760 if ((row
>= first_visible
) && (row
<= last_visible
))
2763 m_selection
.Clear();
2767 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2769 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2773 m_selection
.Add( row
);
2781 m_selection
.Remove( row
);
2787 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2791 unsigned int tmp
= from
;
2797 for (i
= from
; i
<= to
; i
++)
2799 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2802 m_selection
.Add( i
);
2807 m_selection
.Remove( i
);
2810 RefreshRows( from
, to
);
2813 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2815 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2817 int n
= aSelections
[i
];
2819 m_selection
.Add( n
);
2824 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2826 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2827 m_selection
.Add( row
);
2829 m_selection
.Remove( row
);
2833 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2835 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2838 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2840 wxWindow
*parent
= GetParent();
2841 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2843 le
.SetEventObject(parent
);
2844 le
.SetModel(GetOwner()->GetModel());
2847 parent
->GetEventHandler()->ProcessEvent(le
);
2850 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2852 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2853 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2855 wxSize client_size
= GetClientSize();
2856 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2857 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2858 if (intersect_rect
.width
> 0)
2859 Refresh( true, &intersect_rect
);
2862 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2866 unsigned int tmp
= to
;
2871 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2872 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2874 wxSize client_size
= GetClientSize();
2875 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2876 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2877 if (intersect_rect
.width
> 0)
2878 Refresh( true, &intersect_rect
);
2881 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2883 wxSize client_size
= GetClientSize();
2884 int start
= GetLineStart( firstRow
);
2885 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2886 if (start
> client_size
.y
) return;
2888 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2890 Refresh( true, &rect
);
2893 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2895 wxCHECK_RET( newCurrent
< GetRowCount(),
2896 _T("invalid item index in OnArrowChar()") );
2898 // if there is no selection, we cannot move it anywhere
2899 if (!HasCurrentRow())
2902 unsigned int oldCurrent
= m_currentRow
;
2904 // in single selection we just ignore Shift as we can't select several
2906 if ( event
.ShiftDown() && !IsSingleSel() )
2908 RefreshRow( oldCurrent
);
2910 ChangeCurrentRow( newCurrent
);
2912 // select all the items between the old and the new one
2913 if ( oldCurrent
> newCurrent
)
2915 newCurrent
= oldCurrent
;
2916 oldCurrent
= m_currentRow
;
2919 SelectRows( oldCurrent
, newCurrent
, true );
2920 if (oldCurrent
!=newCurrent
)
2921 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2925 RefreshRow( oldCurrent
);
2927 // all previously selected items are unselected unless ctrl is held
2928 if ( !event
.ControlDown() )
2929 SelectAllRows(false);
2931 ChangeCurrentRow( newCurrent
);
2933 if ( !event
.ControlDown() )
2935 SelectRow( m_currentRow
, true );
2936 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2939 RefreshRow( m_currentRow
);
2942 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2945 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2949 rect
.y
= GetLineStart( row
);
2950 rect
.width
= GetEndOfLastCol();
2951 rect
.height
= GetLineHeight( row
);
2956 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2958 const wxDataViewModel
*model
= GetOwner()->GetModel();
2960 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2962 // TODO make more efficient
2967 for (r
= 0; r
< row
; r
++)
2969 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2970 if (!node
) return start
;
2972 wxDataViewItem item
= node
->GetItem();
2974 if (node
&& !node
->HasChildren())
2976 // Yes, if the node does not have any child, it must be a leaf which
2977 // mean that it is a temporarily created by GetTreeNodeByRow
2981 unsigned int cols
= GetOwner()->GetColumnCount();
2983 int height
= m_lineHeight
;
2984 for (col
= 0; col
< cols
; col
++)
2986 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2987 if (column
->IsHidden())
2988 continue; // skip it!
2990 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2991 continue; // skip it!
2993 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2995 model
->GetValue( value
, item
, column
->GetModelColumn() );
2996 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2997 renderer2
->SetValue( value
);
2998 height
= wxMax( height
, renderer
->GetSize().y
);
3009 return row
* m_lineHeight
;
3013 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
3015 const wxDataViewModel
*model
= GetOwner()->GetModel();
3017 // check for the easy case first
3018 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
3019 return y
/ m_lineHeight
;
3021 // TODO make more efficient
3022 unsigned int row
= 0;
3023 unsigned int yy
= 0;
3026 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3029 // not really correct...
3030 return row
+ ((y
-yy
) / m_lineHeight
);
3033 wxDataViewItem item
= node
->GetItem();
3035 if (node
&& !node
->HasChildren())
3037 // Yes, if the node does not have any child, it must be a leaf which
3038 // mean that it is a temporarily created by GetTreeNodeByRow
3042 unsigned int cols
= GetOwner()->GetColumnCount();
3044 int height
= m_lineHeight
;
3045 for (col
= 0; col
< cols
; col
++)
3047 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3048 if (column
->IsHidden())
3049 continue; // skip it!
3051 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3052 continue; // skip it!
3054 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3056 model
->GetValue( value
, item
, column
->GetModelColumn() );
3057 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3058 renderer2
->SetValue( value
);
3059 height
= wxMax( height
, renderer
->GetSize().y
);
3070 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
3072 const wxDataViewModel
*model
= GetOwner()->GetModel();
3074 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
3076 wxASSERT( !IsVirtualList() );
3078 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3079 // wxASSERT( node );
3080 if (!node
) return m_lineHeight
;
3082 wxDataViewItem item
= node
->GetItem();
3084 if (node
&& !node
->HasChildren())
3086 // Yes, if the node does not have any child, it must be a leaf which
3087 // mean that it is a temporarily created by GetTreeNodeByRow
3091 int height
= m_lineHeight
;
3093 unsigned int cols
= GetOwner()->GetColumnCount();
3095 for (col
= 0; col
< cols
; col
++)
3097 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3098 if (column
->IsHidden())
3099 continue; // skip it!
3101 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3102 continue; // skip it!
3104 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3106 model
->GetValue( value
, item
, column
->GetModelColumn() );
3107 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3108 renderer2
->SetValue( value
);
3109 height
= wxMax( height
, renderer
->GetSize().y
);
3116 return m_lineHeight
;
3120 class RowToItemJob
: public DoJob
3123 RowToItemJob( unsigned int row
, int current
) { this->row
= row
; this->current
= current
;}
3124 virtual ~RowToItemJob(){};
3126 virtual int operator() ( wxDataViewTreeNode
* node
)
3129 if( current
== static_cast<int>(row
))
3131 ret
= node
->GetItem() ;
3135 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3137 current
+= node
->GetSubTreeCount();
3142 //If the current has no child node, we can find the desired item of the row number directly.
3143 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3144 if( node
->GetNodes().GetCount() == 0)
3146 int index
= static_cast<int>(row
) - current
- 1;
3147 ret
= node
->GetChildren().Item( index
);
3154 virtual int operator() ( void * n
)
3157 if( current
== static_cast<int>(row
))
3159 ret
= wxDataViewItem( n
) ;
3164 wxDataViewItem
GetResult(){ return ret
; }
3171 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
3175 return wxDataViewItem( wxUIntToPtr(row
) );
3179 RowToItemJob
job( row
, -2 );
3180 Walker( m_root
, job
);
3181 return job
.GetResult();
3185 class RowToTreeNodeJob
: public DoJob
3188 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
3191 this->current
= current
;
3195 virtual ~RowToTreeNodeJob(){};
3197 virtual int operator() ( wxDataViewTreeNode
* node
)
3200 if( current
== static_cast<int>(row
))
3206 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3208 current
+= node
->GetSubTreeCount();
3214 //If the current has no child node, we can find the desired item of the row number directly.
3215 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3216 if( node
->GetNodes().GetCount() == 0)
3218 int index
= static_cast<int>(row
) - current
- 1;
3219 void * n
= node
->GetChildren().Item( index
);
3220 ret
= new wxDataViewTreeNode( parent
) ;
3221 ret
->SetItem( wxDataViewItem( n
));
3222 ret
->SetHasChildren(false);
3231 virtual int operator() ( void * n
)
3234 if( current
== static_cast<int>(row
))
3236 ret
= new wxDataViewTreeNode( parent
) ;
3237 ret
->SetItem( wxDataViewItem( n
));
3238 ret
->SetHasChildren(false);
3244 wxDataViewTreeNode
* GetResult(){ return ret
; }
3248 wxDataViewTreeNode
* ret
;
3249 wxDataViewTreeNode
* parent
;
3253 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
3255 wxASSERT( !IsVirtualList() );
3257 RowToTreeNodeJob
job( row
, -2, m_root
);
3258 Walker( m_root
, job
);
3259 return job
.GetResult();
3262 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
)
3264 wxWindow
*parent
= GetParent();
3265 wxDataViewEvent
le(type
, parent
->GetId());
3267 le
.SetEventObject(parent
);
3268 le
.SetModel(GetOwner()->GetModel());
3271 parent
->GetEventHandler()->ProcessEvent(le
);
3275 void wxDataViewMainWindow::OnExpanding( unsigned int row
)
3277 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3280 if( node
->HasChildren())
3282 if( !node
->IsOpen())
3284 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,node
->GetItem());
3285 //Check if the user prevent expanding
3286 if( e
.GetSkipped() )
3290 //Here I build the children of current node
3291 if( node
->GetChildrenNumber() == 0 )
3294 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
3298 //Send the expanded event
3299 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
3303 SelectRow( row
, false );
3304 SelectRow( row
+ 1, true );
3305 ChangeCurrentRow( row
+ 1 );
3306 SendSelectionChangedEvent( GetItemByRow(row
+1));
3314 void wxDataViewMainWindow::OnCollapsing(unsigned int row
)
3316 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3319 wxDataViewTreeNode
* nd
= node
;
3321 if( node
->HasChildren() && node
->IsOpen() )
3323 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
3324 if( e
.GetSkipped() )
3329 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,nd
->GetItem());
3333 node
= node
->GetParent();
3336 int parent
= GetRowByItem( node
->GetItem() ) ;
3339 SelectRow( row
, false);
3340 SelectRow(parent
, true );
3341 ChangeCurrentRow( parent
);
3342 SendSelectionChangedEvent( node
->GetItem() );
3346 if( !nd
->HasChildren())
3351 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3353 wxDataViewModel
* model
= GetOwner()->GetModel();
3357 //Compose the a parent-chain of the finding item
3359 list
.DeleteContents( true );
3360 wxDataViewItem
it( item
);
3363 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3364 list
.Insert( pItem
);
3365 it
= model
->GetParent( it
);
3368 //Find the item along the parent-chain.
3369 //This algorithm is designed to speed up the node-finding method
3370 wxDataViewTreeNode
* node
= m_root
;
3371 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end() ; iter
++ )
3373 if( node
->HasChildren() )
3375 if( node
->GetChildrenNumber() == 0 )
3378 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3381 wxDataViewTreeNodes nodes
= node
->GetNodes();
3385 for (i
= 0; i
< nodes
.GetCount(); i
++)
3387 if (nodes
[i
]->GetItem() == (**iter
))
3389 if (nodes
[i
]->GetItem() == item
)
3406 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
)
3408 wxDataViewColumn
*col
= NULL
;
3409 unsigned int cols
= GetOwner()->GetColumnCount();
3410 unsigned int colnum
= 0;
3411 unsigned int x_start
= 0;
3413 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3414 for (x_start
= 0; colnum
< cols
; colnum
++)
3416 col
= GetOwner()->GetColumn(colnum
);
3417 if (col
->IsHidden())
3418 continue; // skip it!
3420 unsigned int w
= col
->GetWidth();
3421 if (x_start
+w
>= (unsigned int)x
)
3428 item
= GetItemByRow( GetLineAt( y
) );
3431 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
3433 int row
= GetRowByItem(item
);
3434 int y
= GetLineStart( row
);
3435 int h
= GetLineHeight( m_lineHeight
);
3437 wxDataViewColumn
*col
= NULL
;
3438 for( int i
= 0, cols
= GetOwner()->GetColumnCount(); i
< cols
; i
++ )
3440 col
= GetOwner()->GetColumn( i
);
3441 x
+= col
->GetWidth();
3442 if( GetOwner()->GetColumn(i
+1) == column
)
3445 int w
= col
->GetWidth();
3446 m_owner
->CalcScrolledPosition( x
, y
, &x
, &y
);
3447 return wxRect(x
, y
, w
, h
);
3450 int wxDataViewMainWindow::RecalculateCount()
3454 wxDataViewIndexListModel
*list_model
= (wxDataViewIndexListModel
*) GetOwner()->GetModel();
3456 return list_model
->GetLastIndex() + 1;
3458 return list_model
->GetLastIndex() - 1;
3463 return m_root
->GetSubTreeCount();
3467 class ItemToRowJob
: public DoJob
3470 ItemToRowJob(const wxDataViewItem
& item
, ItemList::const_iterator iter
)
3471 { this->item
= item
; ret
= -1 ; m_iter
= iter
; }
3472 virtual ~ItemToRowJob(){};
3474 //Maybe binary search will help to speed up this process
3475 virtual int operator() ( wxDataViewTreeNode
* node
)
3478 if( node
->GetItem() == item
)
3483 if( node
->GetItem() == **m_iter
)
3490 ret
+= node
->GetSubTreeCount();
3496 virtual int operator() ( void * n
)
3499 if( n
== item
.GetID() )
3503 //the row number is begin from zero
3504 int GetResult(){ return ret
-1 ; }
3506 ItemList::const_iterator m_iter
;
3507 wxDataViewItem item
;
3512 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3514 const wxDataViewModel
* model
= GetOwner()->GetModel();
3520 return wxPtrToUInt( item
.GetID() );
3527 //Compose the a parent-chain of the finding item
3529 wxDataViewItem
* pItem
= NULL
;
3530 list
.DeleteContents( true );
3531 wxDataViewItem
it( item
);
3534 pItem
= new wxDataViewItem( it
);
3535 list
.Insert( pItem
);
3536 it
= model
->GetParent( it
);
3538 pItem
= new wxDataViewItem( );
3539 list
.Insert( pItem
);
3541 ItemToRowJob
job( item
, list
.begin() );
3542 Walker(m_root
, job
);
3543 return job
.GetResult();
3547 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
)
3549 if( !model
->IsContainer( item
) )
3552 wxDataViewItemArray children
;
3553 unsigned int num
= model
->GetChildren( item
, children
);
3554 unsigned int index
= 0;
3555 while( index
< num
)
3557 if( model
->IsContainer( children
[index
] ) )
3559 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3560 n
->SetItem(children
[index
]);
3561 n
->SetHasChildren( true ) ;
3566 node
->AddLeaf( children
[index
].GetID() );
3570 node
->SetSubTreeCount( num
);
3571 wxDataViewTreeNode
* n
= node
->GetParent();
3573 n
->ChangeSubTreeCount(num
);
3577 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3581 if (GetOwner()->GetModel()->IsVirtualListModel())
3587 m_root
= new wxDataViewTreeNode( NULL
);
3588 m_root
->SetHasChildren(true);
3590 //First we define a invalid item to fetch the top-level elements
3591 wxDataViewItem item
;
3593 BuildTreeHelper( model
, item
, m_root
);
3597 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3599 if( node
->GetNodeNumber() != 0 )
3601 int len
= node
->GetNodeNumber();
3603 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3604 for( ; i
< len
; i
++ )
3606 DestroyTreeHelper(nodes
[i
]);
3612 void wxDataViewMainWindow::DestroyTree()
3614 if (!IsVirtualList())
3616 ::DestroyTreeHelper(m_root
);
3622 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3624 if ( HandleAsNavigationKey(event
) )
3627 // no item -> nothing to do
3628 if (!HasCurrentRow())
3634 // don't use m_linesPerPage directly as it might not be computed yet
3635 const int pageSize
= GetCountPerPage();
3636 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3638 switch ( event
.GetKeyCode() )
3642 if (m_currentRow
> 0)
3644 wxWindow
*parent
= GetParent();
3645 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3646 le
.SetItem( GetItemByRow(m_currentRow
) );
3647 le
.SetEventObject(parent
);
3648 le
.SetModel(GetOwner()->GetModel());
3650 parent
->GetEventHandler()->ProcessEvent(le
);
3655 if ( m_currentRow
> 0 )
3656 OnArrowChar( m_currentRow
- 1, event
);
3660 if ( m_currentRow
< GetRowCount() - 1 )
3661 OnArrowChar( m_currentRow
+ 1, event
);
3663 //Add the process for tree expanding/collapsing
3665 OnCollapsing(m_currentRow
);
3668 OnExpanding( m_currentRow
);
3672 OnArrowChar( GetRowCount() - 1, event
);
3677 OnArrowChar( 0, event
);
3682 int steps
= pageSize
- 1;
3683 int index
= m_currentRow
- steps
;
3687 OnArrowChar( index
, event
);
3693 int steps
= pageSize
- 1;
3694 unsigned int index
= m_currentRow
+ steps
;
3695 unsigned int count
= GetRowCount();
3696 if ( index
>= count
)
3699 OnArrowChar( index
, event
);
3708 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3710 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3712 // let the base handle mouse wheel events.
3717 int x
= event
.GetX();
3718 int y
= event
.GetY();
3719 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3720 wxDataViewColumn
*col
= NULL
;
3723 unsigned int cols
= GetOwner()->GetColumnCount();
3725 for (i
= 0; i
< cols
; i
++)
3727 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
3729 continue; // skip it!
3731 if (x
< xpos
+ c
->GetWidth())
3736 xpos
+= c
->GetWidth();
3741 wxDataViewRenderer
*cell
= col
->GetRenderer();
3742 unsigned int current
= GetLineAt( y
);
3743 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
3745 // Unselect all if below the last row ?
3749 //Test whether the mouse is hovered on the tree item button
3751 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3753 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3754 if( node
!=NULL
&& node
->HasChildren() )
3756 int indent
= node
->GetIndentLevel();
3757 indent
= GetOwner()->GetIndent()*indent
;
3758 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3759 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3760 m_lineHeight
-2*EXPANDER_MARGIN
,
3761 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3762 if( rect
.Contains( x
, y
) )
3764 //So the mouse is over the expander
3766 if (m_underMouse
&& m_underMouse
!= node
)
3768 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3769 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3771 if (m_underMouse
!= node
)
3773 //wxLogMessage("Do the row: %d", current);
3774 RefreshRow(current
);
3776 m_underMouse
= node
;
3779 if (node
!=NULL
&& !node
->HasChildren())
3784 if (m_underMouse
!= NULL
)
3786 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3787 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3788 m_underMouse
= NULL
;
3792 wxDataViewModel
*model
= GetOwner()->GetModel();
3794 if (event
.Dragging())
3796 if (m_dragCount
== 0)
3798 // we have to report the raw, physical coords as we want to be
3799 // able to call HitTest(event.m_pointDrag) from the user code to
3800 // get the item being dragged
3801 m_dragStart
= event
.GetPosition();
3806 if (m_dragCount
!= 3)
3809 if (event
.LeftIsDown())
3811 // Notify cell about drag
3820 bool forceClick
= false;
3822 if (event
.ButtonDClick())
3824 m_renameTimer
->Stop();
3825 m_lastOnSame
= false;
3828 wxDataViewItem item
= GetItemByRow(current
);
3829 bool ignore_other_columns
=
3830 ((GetOwner()->GetExpanderColumn() != col
) &&
3831 (model
->IsContainer(item
)) &&
3832 (!model
->HasContainerColumns(item
)));
3834 if (event
.LeftDClick())
3836 if ( current
== m_lineLastClicked
)
3838 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3841 model
->GetValue( value
, item
, col
->GetModelColumn() );
3842 cell
->SetValue( value
);
3843 wxRect
cell_rect( xpos
, GetLineStart( current
),
3844 col
->GetWidth(), GetLineHeight( current
) );
3845 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3850 wxWindow
*parent
= GetParent();
3851 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3853 le
.SetEventObject(parent
);
3854 le
.SetModel(GetOwner()->GetModel());
3856 parent
->GetEventHandler()->ProcessEvent(le
);
3862 // The first click was on another item, so don't interpret this as
3863 // a double click, but as a simple click instead
3870 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3872 // select single line
3873 SelectAllRows( false );
3874 SelectRow( m_lineSelectSingleOnUp
, true );
3877 //Process the event of user clicking the expander
3878 bool expander
= false;
3879 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3881 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3882 if( node
!=NULL
&& node
->HasChildren() )
3884 int indent
= node
->GetIndentLevel();
3885 indent
= GetOwner()->GetIndent()*indent
;
3886 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3887 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3888 m_lineHeight
-2*EXPANDER_MARGIN
,
3889 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3891 if( rect
.Contains( x
, y
) )
3894 if( node
->IsOpen() )
3895 OnCollapsing(current
);
3897 OnExpanding( current
);
3900 if (node
&& !node
->HasChildren())
3903 //If the user click the expander, we do not do editing even if the column with expander are editable
3904 if (m_lastOnSame
&& !expander
&& !ignore_other_columns
)
3906 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3907 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3909 m_renameTimer
->Start( 100, true );
3913 m_lastOnSame
= false;
3914 m_lineSelectSingleOnUp
= (unsigned int)-1;
3918 // This is necessary, because after a DnD operation in
3919 // from and to ourself, the up event is swallowed by the
3920 // DnD code. So on next non-up event (which means here and
3921 // now) m_lineSelectSingleOnUp should be reset.
3922 m_lineSelectSingleOnUp
= (unsigned int)-1;
3925 if (event
.RightDown())
3927 m_lineBeforeLastClicked
= m_lineLastClicked
;
3928 m_lineLastClicked
= current
;
3930 // If the item is already selected, do not update the selection.
3931 // Multi-selections should not be cleared if a selected item is clicked.
3932 if (!IsRowSelected(current
))
3934 SelectAllRows(false);
3935 ChangeCurrentRow(current
);
3936 SelectRow(m_currentRow
,true);
3937 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3941 model
->GetValue( value
, item
, col
->GetModelColumn() );
3942 wxWindow
*parent
= GetParent();
3943 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3945 le
.SetEventObject(parent
);
3946 le
.SetModel(GetOwner()->GetModel());
3948 parent
->GetEventHandler()->ProcessEvent(le
);
3950 else if (event
.MiddleDown())
3953 if (event
.LeftDown() || forceClick
)
3957 m_lineBeforeLastClicked
= m_lineLastClicked
;
3958 m_lineLastClicked
= current
;
3960 unsigned int oldCurrentRow
= m_currentRow
;
3961 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3963 bool cmdModifierDown
= event
.CmdDown();
3964 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3966 if ( IsSingleSel() || !IsRowSelected(current
) )
3968 SelectAllRows( false );
3969 ChangeCurrentRow(current
);
3970 SelectRow(m_currentRow
,true);
3971 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3973 else // multi sel & current is highlighted & no mod keys
3975 m_lineSelectSingleOnUp
= current
;
3976 ChangeCurrentRow(current
); // change focus
3979 else // multi sel & either ctrl or shift is down
3981 if (cmdModifierDown
)
3983 ChangeCurrentRow(current
);
3984 ReverseRowSelection(m_currentRow
);
3985 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3987 else if (event
.ShiftDown())
3989 ChangeCurrentRow(current
);
3991 unsigned int lineFrom
= oldCurrentRow
,
3994 if ( lineTo
< lineFrom
)
3997 lineFrom
= m_currentRow
;
4000 SelectRows(lineFrom
, lineTo
, true);
4001 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
4003 else // !ctrl, !shift
4005 // test in the enclosing if should make it impossible
4006 wxFAIL_MSG( _T("how did we get here?") );
4010 if (m_currentRow
!= oldCurrentRow
)
4011 RefreshRow( oldCurrentRow
);
4013 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
4015 // Update selection here...
4018 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
4019 (current
== oldCurrentRow
)) && oldWasSelected
;
4021 // Call LeftClick after everything else as under GTK+
4022 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
4024 // notify cell about right click
4026 model
->GetValue( value
, item
, col
->GetModelColumn() );
4027 cell
->SetValue( value
);
4028 wxRect
cell_rect( xpos
, GetLineStart( current
),
4029 col
->GetWidth(), GetLineHeight( current
) );
4030 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
, model
, item
, col
->GetModelColumn());
4035 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
4039 if (HasCurrentRow())
4045 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
4049 if (HasCurrentRow())
4055 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
4057 if( m_selection
.GetCount() != 1 )
4058 return wxDataViewItem();
4060 return GetItemByRow( m_selection
.Item(0));
4063 //-----------------------------------------------------------------------------
4065 //-----------------------------------------------------------------------------
4066 WX_DEFINE_LIST(wxDataViewColumnList
)
4068 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4070 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
4071 EVT_SIZE(wxDataViewCtrl::OnSize
)
4074 wxDataViewCtrl::~wxDataViewCtrl()
4077 GetModel()->RemoveNotifier( m_notifier
);
4082 void wxDataViewCtrl::Init()
4084 m_cols
.DeleteContents(true);
4088 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4089 const wxPoint
& pos
, const wxSize
& size
,
4090 long style
, const wxValidator
& validator
)
4092 if ( (style
& wxBORDER_MASK
) == 0)
4093 style
|= wxBORDER_SUNKEN
;
4095 if (!wxControl::Create( parent
, id
, pos
, size
,
4096 style
| wxScrolledWindowStyle
, validator
))
4099 SetInitialSize(size
);
4104 MacSetClipChildren( true ) ;
4107 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
4109 if (HasFlag(wxDV_NO_HEADER
))
4110 m_headerArea
= NULL
;
4112 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
4114 SetTargetWindow( m_clientArea
);
4116 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4118 sizer
->Add( m_headerArea
, 0, wxGROW
);
4119 sizer
->Add( m_clientArea
, 1, wxGROW
);
4126 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
4130 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4133 // we need to process arrows ourselves for scrolling
4134 if ( nMsg
== WM_GETDLGCODE
)
4136 rc
|= DLGC_WANTARROWS
;
4144 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4146 // We need to override OnSize so that our scrolled
4147 // window a) does call Layout() to use sizers for
4148 // positioning the controls but b) does not query
4149 // the sizer for their size and use that for setting
4150 // the scrollable area as set that ourselves by
4151 // calling SetScrollbar() further down.
4158 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4160 if (!wxDataViewCtrlBase::AssociateModel( model
))
4163 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4165 model
->AddNotifier( m_notifier
);
4167 m_clientArea
->DestroyTree();
4169 m_clientArea
->BuildTree(model
);
4171 m_clientArea
->UpdateDisplay();
4176 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4178 if (!wxDataViewCtrlBase::AppendColumn(col
))
4181 m_cols
.Append( col
);
4186 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4188 if (!wxDataViewCtrlBase::PrependColumn(col
))
4191 m_cols
.Insert( col
);
4196 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4198 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4201 m_cols
.Insert( pos
, col
);
4206 void wxDataViewCtrl::OnColumnChange()
4209 m_headerArea
->UpdateDisplay();
4211 m_clientArea
->UpdateDisplay();
4214 void wxDataViewCtrl::DoSetExpanderColumn()
4216 m_clientArea
->UpdateDisplay();
4219 void wxDataViewCtrl::DoSetIndent()
4221 m_clientArea
->UpdateDisplay();
4224 unsigned int wxDataViewCtrl::GetColumnCount() const
4226 return m_cols
.GetCount();
4229 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4231 wxDataViewColumnList::const_iterator iter
;
4233 for (iter
= m_cols
.begin(); iter
!=m_cols
.end(); iter
++)
4238 if ((*iter
)->IsHidden())
4245 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
)
4247 if (new_pos
> m_cols
.GetCount()) return;
4249 // Exchange position
4250 m_cols
.DeleteContents(false);
4251 m_cols
.DeleteObject( col
);
4252 m_cols
.Insert( new_pos
, col
);
4253 m_cols
.DeleteContents(true);
4255 m_clientArea
->UpdateDisplay();
4258 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4260 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4270 bool wxDataViewCtrl::ClearColumns()
4277 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4279 int ret
= 0, dead
= 0;
4280 int len
= GetColumnCount();
4281 for (int i
=0; i
<len
; i
++)
4283 wxDataViewColumn
* col
= GetColumn(i
);
4284 if (col
->IsHidden())
4286 ret
+= col
->GetWidth();
4289 CalcScrolledPosition( ret
, dead
, &ret
, &dead
);
4296 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4301 //Selection code with wxDataViewItem as parameters
4302 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4304 return m_clientArea
->GetSelection();
4307 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4310 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4311 int len
= selection
.GetCount();
4312 for( int i
= 0; i
< len
; i
++)
4314 unsigned int row
= selection
[i
];
4315 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4320 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4322 wxDataViewSelection
selection(wxDataViewSelectionCmp
) ;
4323 int len
= sel
.GetCount();
4324 for( int i
= 0; i
< len
; i
++ )
4326 int row
= m_clientArea
->GetRowByItem( sel
[i
] );
4328 selection
.Add( static_cast<unsigned int>(row
) );
4330 m_clientArea
->SetSelections( selection
);
4333 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4335 int row
= m_clientArea
->GetRowByItem( item
);
4338 //Unselect all rows before select another in the single select mode
4339 if (m_clientArea
->IsSingleSel())
4340 m_clientArea
->SelectAllRows(false);
4341 m_clientArea
->SelectRow(row
, true);
4345 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4347 int row
= m_clientArea
->GetRowByItem( item
);
4349 m_clientArea
->SelectRow(row
, false);
4352 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4354 int row
= m_clientArea
->GetRowByItem( item
);
4357 return m_clientArea
->IsRowSelected(row
);
4362 //Selection code with row number as parameter
4363 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4366 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4367 int len
= selection
.GetCount();
4368 for( int i
= 0; i
< len
; i
++)
4370 unsigned int row
= selection
[i
];
4376 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4378 wxDataViewSelection
selection(wxDataViewSelectionCmp
) ;
4379 int len
= sel
.GetCount();
4380 for( int i
= 0; i
< len
; i
++ )
4384 selection
.Add( static_cast<unsigned int>(row
) );
4386 m_clientArea
->SetSelections( selection
);
4389 void wxDataViewCtrl::Select( int row
)
4393 if (m_clientArea
->IsSingleSel())
4394 m_clientArea
->SelectAllRows(false);
4395 m_clientArea
->SelectRow( row
, true );
4399 void wxDataViewCtrl::Unselect( int row
)
4402 m_clientArea
->SelectRow(row
, false);
4405 bool wxDataViewCtrl::IsSelected( int row
) const
4408 return m_clientArea
->IsRowSelected(row
);
4412 void wxDataViewCtrl::SelectRange( int from
, int to
)
4415 for( int i
= from
; i
< to
; i
++ )
4417 m_clientArea
->Select(sel
);
4420 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4422 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4423 for( int i
= from
; i
< to
; i
++ )
4424 if( sel
.Index( i
) != wxNOT_FOUND
)
4426 m_clientArea
->SetSelections(sel
);
4429 void wxDataViewCtrl::SelectAll()
4431 m_clientArea
->SelectAllRows(true);
4434 void wxDataViewCtrl::UnselectAll()
4436 m_clientArea
->SelectAllRows(false);
4439 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4443 if( row
> (int) m_clientArea
->GetRowCount() )
4444 row
= m_clientArea
->GetRowCount();
4446 int first
= m_clientArea
->GetFirstVisibleRow();
4447 int last
= m_clientArea
->GetLastVisibleRow();
4449 m_clientArea
->ScrollTo( row
, column
);
4450 else if( row
> last
)
4451 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4453 m_clientArea
->ScrollTo( first
, column
);
4456 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4458 int row
= m_clientArea
->GetRowByItem(item
);
4461 if( column
== NULL
)
4462 EnsureVisible(row
, -1);
4466 int len
= GetColumnCount();
4467 for( int i
= 0; i
< len
; i
++ )
4468 if( GetColumn(i
) == column
)
4473 EnsureVisible( row
, col
);
4479 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const
4481 m_clientArea
->HitTest(point
, item
, column
);
4484 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
) const
4486 return m_clientArea
->GetItemRect(item
, column
);
4489 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4491 return m_clientArea
->GetItemByRow( row
);
4494 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4496 return m_clientArea
->GetRowByItem( item
);
4499 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4501 int row
= m_clientArea
->GetRowByItem( item
);
4503 m_clientArea
->Expand(row
);
4506 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4508 int row
= m_clientArea
->GetRowByItem( item
);
4510 m_clientArea
->Collapse(row
);
4514 // !wxUSE_GENERICDATAVIEWCTRL
4517 // wxUSE_DATAVIEWCTRL