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
; }
157 virtual bool AcceptsFocusFromKeyboard() const { return false; }
160 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
162 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
164 wxSize
DoGetBestSize() const;
166 unsigned int GetColumnIdxFromHeader(NMHEADER
*nmHDR
);
168 wxDataViewColumn
*GetColumnFromHeader(NMHEADER
*nmHDR
)
169 { return GetColumn(GetColumnIdxFromHeader(nmHDR
)); }
173 bool m_vetoColumnDrag
;
174 bool m_delayedUpdate
;
175 wxImageList
*m_imageList
;
178 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW
)
181 #else // !defined(__WXMSW__)
183 #define HEADER_WINDOW_HEIGHT 25
184 #define HEADER_HORIZ_BORDER 5
185 #define HEADER_VERT_BORDER 3
186 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
188 class wxGenericDataViewHeaderWindow
: public wxDataViewHeaderWindowBase
191 wxGenericDataViewHeaderWindow( wxDataViewCtrl
*parent
,
193 const wxPoint
&pos
= wxDefaultPosition
,
194 const wxSize
&size
= wxDefaultSize
,
195 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
198 Create(parent
, id
, pos
, size
, name
);
201 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
202 const wxPoint
&pos
, const wxSize
&size
,
203 const wxString
&name
);
205 ~wxGenericDataViewHeaderWindow()
207 delete m_resizeCursor
;
210 virtual void UpdateDisplay() { Refresh(); }
214 void OnPaint( wxPaintEvent
&event
);
215 void OnMouse( wxMouseEvent
&event
);
216 void OnSetFocus( wxFocusEvent
&event
);
221 // vars used for column resizing:
223 wxCursor
*m_resizeCursor
;
224 const wxCursor
*m_currentCursor
;
227 bool m_dirty
; // needs refresh?
228 int m_hover
; // index of the column under the mouse
229 int m_column
; // index of the column being resized
230 int m_currentX
; // divider line position in logical (unscrolled) coords
231 int m_minX
; // minimal position beyond which the divider line
232 // can't be dragged in logical coords
234 // the pen used to draw the current column width drag line
235 // when resizing the columsn
239 // internal utilities:
243 m_currentCursor
= (wxCursor
*) NULL
;
244 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
246 m_isDragging
= false;
249 m_hover
= wxNOT_FOUND
;
250 m_column
= wxNOT_FOUND
;
254 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
255 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
258 void AdjustDC(wxDC
& dc
);
261 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
262 DECLARE_EVENT_TABLE()
265 #endif // defined(__WXMSW__)
267 //-----------------------------------------------------------------------------
268 // wxDataViewRenameTimer
269 //-----------------------------------------------------------------------------
271 class wxDataViewRenameTimer
: public wxTimer
274 wxDataViewMainWindow
*m_owner
;
277 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
281 //-----------------------------------------------------------------------------
282 // wxDataViewTreeNode
283 //-----------------------------------------------------------------------------
284 class wxDataViewTreeNode
;
285 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
286 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
288 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
);
289 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
291 class wxDataViewTreeNode
294 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
301 m_hasChildren
= false;
305 ~wxDataViewTreeNode()
309 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
310 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
311 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
312 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
314 void AddNode( wxDataViewTreeNode
* node
)
316 m_leaves
.Add( node
->GetItem().GetID() );
318 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
321 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
323 void AddLeaf( void * leaf
)
325 m_leaves
.Add( leaf
);
327 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
330 wxDataViewItem
& GetItem() { return m_item
; }
331 const wxDataViewItem
& GetItem() const { return m_item
; }
332 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
334 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
335 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
336 int GetIndentLevel() const
339 const wxDataViewTreeNode
* node
= this;
340 while( node
->GetParent()->GetParent() != NULL
)
342 node
= node
->GetParent();
355 int len
= m_nodes
.GetCount();
357 for ( int i
= 0;i
< len
; i
++)
358 sum
+= m_nodes
[i
]->GetSubTreeCount();
360 sum
+= m_leaves
.GetCount();
363 ChangeSubTreeCount(-sum
);
369 ChangeSubTreeCount(sum
);
372 bool HasChildren() const { return m_hasChildren
; }
373 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
375 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
376 int GetSubTreeCount() const { return m_subTreeCount
; }
377 void ChangeSubTreeCount( int num
)
381 m_subTreeCount
+= num
;
383 m_parent
->ChangeSubTreeCount(num
);
390 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
391 int len
= m_nodes
.GetCount();
392 for (int i
= 0; i
< len
; i
++)
393 m_nodes
[i
]->Resort();
394 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
399 wxDataViewTreeNode
*m_parent
;
400 wxDataViewTreeNodes m_nodes
;
401 wxDataViewTreeLeaves m_leaves
;
402 wxDataViewItem m_item
;
408 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
)
410 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
413 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
415 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
420 //-----------------------------------------------------------------------------
421 // wxDataViewMainWindow
422 //-----------------------------------------------------------------------------
424 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
426 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
427 WX_DEFINE_LIST(ItemList
)
429 class wxDataViewMainWindow
: public wxWindow
432 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
434 const wxPoint
&pos
= wxDefaultPosition
,
435 const wxSize
&size
= wxDefaultSize
,
436 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
437 virtual ~wxDataViewMainWindow();
439 bool IsVirtualList() const { return m_root
== NULL
; }
441 // notifications from wxDataViewModel
442 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
443 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
444 bool ItemChanged( const wxDataViewItem
&item
);
445 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
449 if (!IsVirtualList())
459 g_model
= GetOwner()->GetModel();
460 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
463 if (g_model
->HasDefaultCompare())
471 g_column
= col
->GetModelColumn();
472 g_asending
= col
->IsSortOrderAscending();
475 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
476 wxDataViewCtrl
*GetOwner() { return m_owner
; }
477 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
479 void OnPaint( wxPaintEvent
&event
);
480 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
481 void OnChar( wxKeyEvent
&event
);
482 void OnMouse( wxMouseEvent
&event
);
483 void OnSetFocus( wxFocusEvent
&event
);
484 void OnKillFocus( wxFocusEvent
&event
);
486 void UpdateDisplay();
487 void RecalculateDisplay();
488 void OnInternalIdle();
490 void OnRenameTimer();
492 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
493 void ScrollTo( int rows
, int column
);
495 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
496 void ChangeCurrentRow( unsigned int row
);
498 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
499 bool IsEmpty() { return GetRowCount() == 0; }
501 int GetCountPerPage() const;
502 int GetEndOfLastCol() const;
503 unsigned int GetFirstVisibleRow() const;
504 //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
505 unsigned int GetLastVisibleRow();
506 unsigned int GetRowCount();
508 wxDataViewItem
GetSelection() const;
509 wxDataViewSelection
GetSelections(){ return m_selection
; }
510 void SetSelections( const wxDataViewSelection
& sel
) { m_selection
= sel
; UpdateDisplay(); }
511 void Select( const wxArrayInt
& aSelections
);
512 void SelectAllRows( bool on
);
513 void SelectRow( unsigned int row
, bool on
);
514 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
515 void ReverseRowSelection( unsigned int row
);
516 bool IsRowSelected( unsigned int row
);
517 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
519 void RefreshRow( unsigned int row
);
520 void RefreshRows( unsigned int from
, unsigned int to
);
521 void RefreshRowsAfter( unsigned int firstRow
);
523 // returns the colour to be used for drawing the rules
524 wxColour
GetRuleColour() const
526 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
529 wxRect
GetLineRect( unsigned int row
) const;
531 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
532 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
533 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
535 //Some useful functions for row and item mapping
536 wxDataViewItem
GetItemByRow( unsigned int row
) const;
537 int GetRowByItem( const wxDataViewItem
& item
) const;
539 //Methods for building the mapping tree
540 void BuildTree( wxDataViewModel
* model
);
542 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
543 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
545 void Expand( unsigned int row
) { OnExpanding( row
); }
546 void Collapse( unsigned int row
) { OnCollapsing( row
); }
548 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
549 //We did not need this temporarily
550 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
552 int RecalculateCount();
554 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
555 void OnExpanding( unsigned int row
);
556 void OnCollapsing( unsigned int row
);
558 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
561 wxDataViewCtrl
*m_owner
;
565 wxDataViewColumn
*m_currentCol
;
566 unsigned int m_currentRow
;
567 wxDataViewSelection m_selection
;
569 wxDataViewRenameTimer
*m_renameTimer
;
577 // for double click logic
578 unsigned int m_lineLastClicked
,
579 m_lineBeforeLastClicked
,
580 m_lineSelectSingleOnUp
;
582 // the pen used to draw horiz/vertical rules
585 // the pen used to draw the expander and the lines
588 //This is the tree structure of the model
589 wxDataViewTreeNode
* m_root
;
591 //This is the tree node under the cursor
592 wxDataViewTreeNode
* m_underMouse
;
594 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
595 DECLARE_EVENT_TABLE()
598 // ---------------------------------------------------------
599 // wxGenericDataViewModelNotifier
600 // ---------------------------------------------------------
602 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
605 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
606 { m_mainWindow
= mainWindow
; }
608 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
609 { return m_mainWindow
->ItemAdded( parent
, item
); }
610 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
611 { return m_mainWindow
->ItemDeleted( parent
, item
); }
612 virtual bool ItemChanged( const wxDataViewItem
& item
)
613 { return m_mainWindow
->ItemChanged(item
); }
614 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
615 { return m_mainWindow
->ValueChanged( item
, col
); }
616 virtual bool Cleared()
617 { return m_mainWindow
->Cleared(); }
618 virtual void Resort()
619 { m_mainWindow
->Resort(); }
621 wxDataViewMainWindow
*m_mainWindow
;
624 // ---------------------------------------------------------
625 // wxDataViewRenderer
626 // ---------------------------------------------------------
628 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
630 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
631 wxDataViewCellMode mode
,
633 wxDataViewRendererBase( varianttype
, mode
, align
)
642 wxDataViewRenderer::~wxDataViewRenderer()
648 wxDC
*wxDataViewRenderer::GetDC()
652 if (GetOwner() == NULL
)
654 if (GetOwner()->GetOwner() == NULL
)
656 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
662 void wxDataViewRenderer::SetAlignment( int align
)
667 int wxDataViewRenderer::GetAlignment() const
672 int wxDataViewRenderer::CalculateAlignment() const
674 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
676 if (GetOwner() == NULL
)
677 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
679 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
685 // ---------------------------------------------------------
686 // wxDataViewCustomRenderer
687 // ---------------------------------------------------------
689 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
691 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
692 wxDataViewCellMode mode
, int align
) :
693 wxDataViewRenderer( varianttype
, mode
, align
)
697 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
699 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
700 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
701 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
702 view
->GetForegroundColour();
703 dc
->SetTextForeground(col
);
704 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
707 // ---------------------------------------------------------
708 // wxDataViewTextRenderer
709 // ---------------------------------------------------------
711 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
713 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
714 wxDataViewCellMode mode
, int align
) :
715 wxDataViewCustomRenderer( varianttype
, mode
, align
)
719 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
721 m_text
= value
.GetString();
726 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
731 bool wxDataViewTextRenderer::HasEditorCtrl()
736 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
737 wxRect labelRect
, const wxVariant
&value
)
739 return new wxTextCtrl( parent
, wxID_ANY
, value
,
740 wxPoint(labelRect
.x
,labelRect
.y
),
741 wxSize(labelRect
.width
,labelRect
.height
) );
744 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
746 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
747 value
= text
->GetValue();
751 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
753 RenderText( m_text
, 0, cell
, dc
, state
);
757 wxSize
wxDataViewTextRenderer::GetSize() const
759 const wxDataViewCtrl
*view
= GetView();
763 view
->GetTextExtent( m_text
, &x
, &y
);
764 return wxSize( x
, y
);
766 return wxSize(80,20);
769 // ---------------------------------------------------------
770 // wxDataViewTextRendererAttr
771 // ---------------------------------------------------------
773 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
775 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
776 wxDataViewCellMode mode
, int align
) :
777 wxDataViewTextRenderer( varianttype
, mode
, align
)
782 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
789 if (m_attr
.HasColour())
791 colour
= dc
->GetTextForeground();
792 dc
->SetTextForeground( m_attr
.GetColour() );
795 if (m_attr
.GetBold() || m_attr
.GetItalic())
797 font
= dc
->GetFont();
798 wxFont myfont
= font
;
799 if (m_attr
.GetBold())
800 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
801 if (m_attr
.GetItalic())
802 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
803 dc
->SetFont( myfont
);
807 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
812 if (m_attr
.HasColour())
813 dc
->SetTextForeground( colour
);
815 if (m_attr
.GetBold() || m_attr
.GetItalic())
823 // ---------------------------------------------------------
824 // wxDataViewBitmapRenderer
825 // ---------------------------------------------------------
827 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
829 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
830 wxDataViewCellMode mode
, int align
) :
831 wxDataViewCustomRenderer( varianttype
, mode
, align
)
835 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
837 if (value
.GetType() == wxT("wxBitmap"))
839 if (value
.GetType() == wxT("wxIcon"))
845 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
850 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
853 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
854 else if (m_icon
.Ok())
855 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
860 wxSize
wxDataViewBitmapRenderer::GetSize() const
863 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
864 else if (m_icon
.Ok())
865 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
867 return wxSize(16,16);
870 // ---------------------------------------------------------
871 // wxDataViewToggleRenderer
872 // ---------------------------------------------------------
874 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
876 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
877 wxDataViewCellMode mode
, int align
) :
878 wxDataViewCustomRenderer( varianttype
, mode
, align
)
883 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
885 m_toggle
= value
.GetBool();
890 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
895 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
897 // User wxRenderer here
900 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
902 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
907 flags
|= wxCONTROL_CHECKED
;
908 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
909 flags
|= wxCONTROL_DISABLED
;
911 wxRendererNative::Get().DrawCheckBox(
912 GetOwner()->GetOwner(),
920 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
921 wxDataViewModel
*model
,
922 const wxDataViewItem
& item
, unsigned int col
)
924 bool value
= !m_toggle
;
925 wxVariant variant
= value
;
926 model
->SetValue( variant
, item
, col
);
927 model
->ValueChanged( item
, col
);
931 wxSize
wxDataViewToggleRenderer::GetSize() const
933 return wxSize(20,20);
936 // ---------------------------------------------------------
937 // wxDataViewProgressRenderer
938 // ---------------------------------------------------------
940 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
942 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
943 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
944 wxDataViewCustomRenderer( varianttype
, mode
, align
)
950 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
954 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
956 m_value
= (long) value
;
958 if (m_value
< 0) m_value
= 0;
959 if (m_value
> 100) m_value
= 100;
964 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
966 value
= (long) m_value
;
970 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
972 double pct
= (double)m_value
/ 100.0;
974 bar
.width
= (int)(cell
.width
* pct
);
975 dc
->SetPen( *wxTRANSPARENT_PEN
);
976 dc
->SetBrush( *wxBLUE_BRUSH
);
977 dc
->DrawRectangle( bar
);
979 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
980 dc
->SetPen( *wxBLACK_PEN
);
981 dc
->DrawRectangle( cell
);
986 wxSize
wxDataViewProgressRenderer::GetSize() const
988 return wxSize(40,12);
991 // ---------------------------------------------------------
992 // wxDataViewDateRenderer
993 // ---------------------------------------------------------
995 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
997 #if wxUSE_DATE_RENDERER_POPUP
999 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
1002 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1003 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
1004 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
1009 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
1010 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1011 sizer
->Add( m_cal
, 1, wxGROW
);
1016 void OnCalendar( wxCalendarEvent
&event
);
1018 wxCalendarCtrl
*m_cal
;
1019 wxDataViewModel
*m_model
;
1021 const wxDataViewItem
& m_item
;
1024 virtual void OnDismiss()
1029 DECLARE_EVENT_TABLE()
1032 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1033 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1036 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1038 wxDateTime date
= event
.GetDate();
1039 wxVariant value
= date
;
1040 m_model
->SetValue( value
, m_item
, m_col
);
1041 m_model
->ValueChanged( m_item
, m_col
);
1045 #endif // wxUSE_DATE_RENDERER_POPUP
1047 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1049 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1050 wxDataViewCellMode mode
, int align
) :
1051 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1055 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1057 m_date
= value
.GetDateTime();
1062 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1068 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1070 wxString tmp
= m_date
.FormatDate();
1071 RenderText( tmp
, 0, cell
, dc
, state
);
1075 wxSize
wxDataViewDateRenderer::GetSize() const
1077 const wxDataViewCtrl
* view
= GetView();
1078 wxString tmp
= m_date
.FormatDate();
1080 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1081 return wxSize(x
,y
+d
);
1084 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1085 const wxDataViewItem
& item
, unsigned int col
)
1088 model
->GetValue( variant
, item
, col
);
1089 wxDateTime value
= variant
.GetDateTime();
1091 #if wxUSE_DATE_RENDERER_POPUP
1092 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1093 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1094 wxPoint pos
= wxGetMousePosition();
1097 popup
->Popup( popup
->m_cal
);
1098 #else // !wxUSE_DATE_RENDERER_POPUP
1099 wxMessageBox(value
.Format());
1100 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1104 // ---------------------------------------------------------
1105 // wxDataViewIconTextRenderer
1106 // ---------------------------------------------------------
1108 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1110 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1111 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1112 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1115 SetAlignment(align
);
1118 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1122 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1128 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1133 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1136 const wxIcon
&icon
= m_value
.GetIcon();
1139 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1140 xoffset
= icon
.GetWidth()+4;
1143 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1148 wxSize
wxDataViewIconTextRenderer::GetSize() const
1150 const wxDataViewCtrl
*view
= GetView();
1151 if (!m_value
.GetText().empty())
1154 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1156 if (m_value
.GetIcon().IsOk())
1157 x
+= m_value
.GetIcon().GetWidth() + 4;
1158 return wxSize( x
, y
);
1160 return wxSize(80,20);
1164 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
1165 wxRect
WXUNUSED(labelRect
),
1166 const wxVariant
& WXUNUSED(value
))
1172 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
1173 wxVariant
& WXUNUSED(value
))
1178 // ---------------------------------------------------------
1180 // ---------------------------------------------------------
1182 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1184 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1185 unsigned int model_column
,
1186 int width
, wxAlignment align
, int flags
) :
1187 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1189 SetAlignment(align
);
1193 m_autosize
= width
< 0; // TODO
1195 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1198 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1199 unsigned int model_column
,
1200 int width
, wxAlignment align
, int flags
) :
1201 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1203 SetAlignment(align
);
1206 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1209 wxDataViewColumn::~wxDataViewColumn()
1213 void wxDataViewColumn::Init( int width
)
1216 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
1220 void wxDataViewColumn::SetResizeable( bool resizeable
)
1223 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
1225 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
1228 void wxDataViewColumn::SetHidden( bool hidden
)
1231 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
1233 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
1235 // tell our owner to e.g. update its scrollbars:
1237 GetOwner()->OnColumnChange();
1240 void wxDataViewColumn::SetSortable( bool sortable
)
1243 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
1245 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
1247 // Update header button
1249 GetOwner()->OnColumnChange();
1252 void wxDataViewColumn::SetReorderable( bool reorderable
)
1255 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
1257 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
1260 void wxDataViewColumn::SetSortOrder( bool ascending
)
1262 m_ascending
= ascending
;
1264 // Update header button
1266 GetOwner()->OnColumnChange();
1269 bool wxDataViewColumn::IsSortOrderAscending() const
1274 void wxDataViewColumn::SetInternalWidth( int width
)
1278 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
1279 if (m_owner
&& m_owner
->m_clientArea
)
1280 m_owner
->m_clientArea
->RecalculateDisplay();
1283 void wxDataViewColumn::SetWidth( int width
)
1285 if (m_owner
->m_headerArea
) m_owner
->m_headerArea
->UpdateDisplay();
1287 SetInternalWidth(width
);
1291 //-----------------------------------------------------------------------------
1292 // wxDataViewHeaderWindowBase
1293 //-----------------------------------------------------------------------------
1295 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
1297 wxWindow
*parent
= GetParent();
1298 wxDataViewEvent
le(type
, parent
->GetId());
1300 le
.SetEventObject(parent
);
1302 le
.SetDataViewColumn(GetColumn(n
));
1303 le
.SetModel(GetOwner()->GetModel());
1305 // for events created by wxDataViewHeaderWindow the
1306 // row / value fields are not valid
1308 parent
->GetEventHandler()->ProcessEvent(le
);
1311 #ifdef USE_NATIVE_HEADER_WINDOW
1313 #ifndef HDS_DRAGDROP
1314 #define HDS_DRAGDROP 0x0040
1316 #ifndef HDS_FULLDRAG
1317 #define HDS_FULLDRAG 0x0080
1320 // implemented in msw/listctrl.cpp:
1321 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
1323 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
1325 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
1326 const wxPoint
&pos
, const wxSize
&size
,
1327 const wxString
&name
)
1331 m_scrollOffsetX
= 0;
1332 m_delayedUpdate
= false;
1333 m_vetoColumnDrag
= false;
1334 m_buttonHeight
= wxRendererNative::Get().GetHeaderButtonHeight( this );
1336 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
1337 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
1338 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
1341 wxSize
new_size(w
,h
);
1343 if ( !CreateControl(parent
, id
, pos
, new_size
, 0, wxDefaultValidator
, name
) )
1346 // create the native WC_HEADER window:
1347 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
1348 WXDWORD msStyle
= WS_CHILD
| HDS_DRAGDROP
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
1351 msStyle
|= WS_VISIBLE
;
1353 m_hWnd
= CreateWindowEx(0,
1364 wxLogLastError(_T("CreateWindowEx"));
1368 m_imageList
= new wxImageList( 16, 16 );
1369 (void)Header_SetImageList((HWND
) m_hWnd
, m_imageList
->GetHIMAGELIST());
1371 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
1372 // to call wxDataViewHeaderWindow::MSWOnNotify
1373 SubclassWin(m_hWnd
);
1375 // the following is required to get the default win's font for
1376 // header windows and must be done befor sending the HDM_LAYOUT msg
1382 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
1388 wxSize
wxDataViewHeaderWindowMSW::DoGetBestSize() const
1390 return wxSize( 80, m_buttonHeight
+2 );
1393 void wxDataViewHeaderWindowMSW::OnInternalIdle()
1395 if (m_delayedUpdate
)
1397 m_delayedUpdate
= false;
1402 void wxDataViewHeaderWindowMSW::UpdateDisplay()
1404 // remove old columns
1405 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
1406 Header_DeleteItem((HWND
)m_hWnd
, 0);
1408 m_imageList
->RemoveAll();
1410 // add the updated array of columns to the header control
1411 unsigned int cols
= GetOwner()->GetColumnCount();
1412 unsigned int added
= 0;
1413 for (unsigned int i
= 0; i
< cols
; i
++)
1415 wxDataViewColumn
*col
= GetColumn( i
);
1416 if (col
->IsHidden())
1417 continue; // don't add it!
1419 wxString
title( col
->GetTitle() );
1421 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1422 if (col
->GetBitmap().IsOk())
1424 m_imageList
->Add( col
->GetBitmap() );
1425 hdi
.mask
|= HDI_IMAGE
;
1426 hdi
.iImage
= m_imageList
->GetImageCount()-1;
1428 hdi
.pszText
= (wxChar
*) title
.wx_str();
1429 hdi
.cxy
= col
->GetWidth();
1430 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1431 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1432 if (col
->GetBitmap().IsOk())
1433 hdi
.fmt
|= HDF_IMAGE
;
1435 //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
1437 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1439 //The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default
1440 //see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail
1441 // VZ: works with 5.81
1442 hdi
.fmt
|= col
->IsSortOrderAscending() ? HDF_SORTUP
: HDF_SORTDOWN
;
1445 // lParam is reserved for application's use:
1446 // we store there the column index to use it later in MSWOnNotify
1447 // (since columns may have been hidden)
1448 hdi
.lParam
= (LPARAM
)i
;
1450 // the native wxMSW implementation of the header window
1451 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1452 // on the right: to correct this effect we make the column
1453 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1455 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1457 switch (col
->GetAlignment())
1460 hdi
.fmt
|= HDF_LEFT
;
1462 case wxALIGN_CENTER
:
1463 case wxALIGN_CENTER_HORIZONTAL
:
1464 hdi
.fmt
|= HDF_CENTER
;
1467 hdi
.fmt
|= HDF_RIGHT
;
1471 // such alignment is not allowed for the column header!
1475 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1476 (WPARAM
)added
, (LPARAM
)&hdi
);
1481 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1485 // NOTE: we don't just return nmHDR->iItem because when there are
1486 // hidden columns, nmHDR->iItem may be different from
1487 // nmHDR->pitem->lParam
1489 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1491 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1496 item
.mask
= HDI_LPARAM
;
1497 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1499 return (unsigned int)item
.lParam
;
1502 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1504 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1506 // is it a message from the header?
1507 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1508 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1510 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1511 switch ( nmhdr
->code
)
1513 case NM_RELEASEDCAPTURE
:
1515 // user has released the mouse
1516 m_vetoColumnDrag
= false;
1520 case HDN_BEGINTRACK
:
1521 // user has started to resize a column:
1522 // do we need to veto it?
1523 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1532 if (nmHDR
->iItem
!= -1)
1534 // user has started to reorder a valid column
1535 if ((m_vetoColumnDrag
== true) || (!GetColumn(nmHDR
->iItem
)->IsReorderable()))
1539 m_vetoColumnDrag
= true;
1545 m_vetoColumnDrag
= true;
1549 case HDN_ENDDRAG
: // user has finished reordering a column
1551 wxDataViewColumn
*col
= GetColumn(nmHDR
->iItem
);
1552 unsigned int new_pos
= nmHDR
->pitem
->iOrder
;
1553 m_owner
->ColumnMoved( col
, new_pos
);
1554 m_delayedUpdate
= true;
1558 case HDN_ITEMCHANGING
:
1559 if (nmHDR
->pitem
!= NULL
&&
1560 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1562 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1563 if (nmHDR
->pitem
->cxy
< minWidth
)
1565 // do not allow the user to resize this column under
1566 // its minimal width:
1572 case HDN_ITEMCHANGED
: // user is resizing a column
1573 case HDN_ENDTRACK
: // user has finished resizing a column
1575 // update the width of the modified column:
1576 if (nmHDR
->pitem
!= NULL
&&
1577 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1579 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1580 unsigned int w
= nmHDR
->pitem
->cxy
;
1581 wxDataViewColumn
*col
= GetColumn(idx
);
1583 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1584 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1585 w
-= COLUMN_WIDTH_OFFSET
;
1587 if (w
>= (unsigned)col
->GetMinWidth())
1588 col
->SetInternalWidth(w
);
1594 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1595 wxDataViewModel
* model
= GetOwner()->GetModel();
1597 if(nmHDR
->iButton
== 0)
1599 wxDataViewColumn
*col
= GetColumn(idx
);
1600 if(col
->IsSortable())
1602 if(model
&& m_owner
->GetSortingColumn() == col
)
1604 bool order
= col
->IsSortOrderAscending();
1605 col
->SetSortOrder(!order
);
1609 m_owner
->SetSortingColumn(col
);
1617 wxEventType evt
= nmHDR
->iButton
== 0 ?
1618 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1619 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1620 SendEvent(evt
, idx
);
1626 // NOTE: for some reason (i.e. for a bug in Windows)
1627 // the HDN_ITEMCLICK notification is not sent on
1628 // right clicks, so we need to handle NM_RCLICK
1631 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1632 if (column
!= wxNOT_FOUND
)
1635 item
.mask
= HDI_LPARAM
;
1636 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1638 // 'idx' may be different from 'column' if there are
1639 // hidden columns...
1640 unsigned int idx
= (unsigned int)item
.lParam
;
1641 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1647 case HDN_GETDISPINFOW
:
1648 // see wxListCtrl::MSWOnNotify for more info!
1651 case HDN_ITEMDBLCLICK
:
1653 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1654 int w
= GetOwner()->GetBestColumnWidth(idx
);
1656 // update the native control:
1658 ZeroMemory(&hd
, sizeof(hd
));
1659 hd
.mask
= HDI_WIDTH
;
1661 Header_SetItem(GetHwnd(),
1662 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1665 // update the wxDataViewColumn class:
1666 GetColumn(idx
)->SetInternalWidth(w
);
1671 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1677 void wxDataViewHeaderWindowMSW::ScrollWindow(int dx
, int WXUNUSED(dy
),
1678 const wxRect
* WXUNUSED(rect
))
1680 m_scrollOffsetX
+= dx
;
1682 GetParent()->Layout();
1685 void wxDataViewHeaderWindowMSW::DoSetSize(int x
, int y
,
1689 // TODO: why is there a border + 2px around it?
1690 wxControl::DoSetSize( x
+m_scrollOffsetX
+1, y
+1, w
-m_scrollOffsetX
-2, h
-2, f
);
1693 #else // !defined(__WXMSW__)
1695 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1696 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1697 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1698 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1699 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1702 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1703 const wxPoint
&pos
, const wxSize
&size
,
1704 const wxString
&name
)
1708 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1711 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1712 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1713 SetOwnForegroundColour( attr
.colFg
);
1714 SetOwnBackgroundColour( attr
.colBg
);
1716 SetOwnFont( attr
.font
);
1718 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1719 // a wxBoxSizer and in order to avoid super-big header windows,
1720 // we need to set our height as fixed
1721 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1722 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1727 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1730 GetClientSize( &w
, &h
);
1732 wxAutoBufferedPaintDC
dc( this );
1734 dc
.SetBackground(GetBackgroundColour());
1738 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1741 m_owner
->GetViewStart( &x
, NULL
);
1743 // account for the horz scrollbar offset
1744 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1746 dc
.SetFont( GetFont() );
1748 unsigned int cols
= GetOwner()->GetColumnCount();
1751 for (i
= 0; i
< cols
; i
++)
1753 wxDataViewColumn
*col
= GetColumn( i
);
1754 if (col
->IsHidden())
1755 continue; // skip it!
1757 int cw
= col
->GetWidth();
1760 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
;
1761 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1763 if (col
->IsSortOrderAscending())
1764 sortArrow
= wxHDR_SORT_ICON_UP
;
1766 sortArrow
= wxHDR_SORT_ICON_DOWN
;
1770 if (m_parent
->IsEnabled())
1772 if ((int) i
== m_hover
)
1773 state
= wxCONTROL_CURRENT
;
1777 state
= (int) wxCONTROL_DISABLED
;
1780 wxRendererNative::Get().DrawHeaderButton
1784 wxRect(xpos
, 0, cw
, ch
-1),
1789 // align as required the column title:
1791 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1792 switch (col
->GetAlignment())
1795 x
+= HEADER_HORIZ_BORDER
;
1798 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1801 case wxALIGN_CENTER
:
1802 case wxALIGN_CENTER_HORIZONTAL
:
1803 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1807 // always center the title vertically:
1808 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1810 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1812 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1813 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1814 dc
.DrawText( col
->GetTitle(), x
, y
);
1815 dc
.DestroyClippingRegion();
1821 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1823 GetParent()->SetFocus();
1827 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1829 // we want to work with logical coords
1831 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1832 int y
= event
.GetY();
1836 // we don't draw the line beyond our window,
1837 // but we allow dragging it there
1839 GetClientSize( &w
, NULL
);
1840 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1843 if (event
.ButtonUp())
1845 m_isDragging
= false;
1851 m_currentX
= wxMax(m_minX
+ 7, x
);
1855 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1857 GetOwner()->Refresh();
1861 else // not dragging
1864 m_column
= wxNOT_FOUND
;
1866 bool hit_border
= false;
1868 // end of the current column
1871 // find the column where this event occured
1872 int countCol
= m_owner
->GetColumnCount();
1873 for (int column
= 0; column
< countCol
; column
++)
1875 wxDataViewColumn
*p
= GetColumn(column
);
1878 continue; // skip if not shown
1880 xpos
+= p
->GetWidth();
1882 if ((abs(x
-xpos
) < 3) && (y
< 22))
1890 // inside the column
1897 int old_hover
= m_hover
;
1899 if (event
.Leaving())
1900 m_hover
= wxNOT_FOUND
;
1901 if (old_hover
!= m_hover
)
1904 if (m_column
== wxNOT_FOUND
)
1907 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1908 if (event
.LeftDClick() && resizeable
)
1910 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1913 else if (event
.LeftDown() || event
.RightUp())
1915 if (hit_border
&& event
.LeftDown() && resizeable
)
1917 m_isDragging
= true;
1921 else // click on a column
1923 wxDataViewModel
* model
= GetOwner()->GetModel();
1924 wxEventType evt
= event
.LeftDown() ?
1925 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1926 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1927 SendEvent(evt
, m_column
);
1929 //Left click the header
1930 if(event
.LeftDown())
1932 wxDataViewColumn
*col
= GetColumn(m_column
);
1933 if(col
->IsSortable())
1935 wxDataViewColumn
* sortCol
= m_owner
->GetSortingColumn();
1936 if(model
&& sortCol
== col
)
1938 bool order
= col
->IsSortOrderAscending();
1939 col
->SetSortOrder(!order
);
1943 m_owner
->SetSortingColumn(col
);
1949 //Send the column sorted event
1950 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, m_column
);
1954 else if (event
.Moving())
1956 if (hit_border
&& resizeable
)
1957 m_currentCursor
= m_resizeCursor
;
1959 m_currentCursor
= wxSTANDARD_CURSOR
;
1961 SetCursor(*m_currentCursor
);
1966 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1970 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1971 m_owner
->GetViewStart( &x
, NULL
);
1973 // shift the DC origin to match the position of the main window horizontal
1974 // scrollbar: this allows us to always use logical coords
1975 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1978 #endif // defined(__WXMSW__)
1980 //-----------------------------------------------------------------------------
1981 // wxDataViewRenameTimer
1982 //-----------------------------------------------------------------------------
1984 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1989 void wxDataViewRenameTimer::Notify()
1991 m_owner
->OnRenameTimer();
1994 //-----------------------------------------------------------------------------
1995 // wxDataViewMainWindow
1996 //-----------------------------------------------------------------------------
1998 //The tree building helper, declared firstly
1999 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
);
2001 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
2003 if (row1
> row2
) return 1;
2004 if (row1
== row2
) return 0;
2009 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
2011 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
2012 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
2013 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
2014 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
2015 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
2016 EVT_CHAR (wxDataViewMainWindow::OnChar
)
2019 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
2020 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
2021 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
2022 m_selection( wxDataViewSelectionCmp
)
2027 m_lastOnSame
= false;
2028 m_renameTimer
= new wxDataViewRenameTimer( this );
2030 // TODO: user better initial values/nothing selected
2031 m_currentCol
= NULL
;
2034 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
2037 m_dragStart
= wxPoint(0,0);
2038 m_lineLastClicked
= (unsigned int) -1;
2039 m_lineBeforeLastClicked
= (unsigned int) -1;
2040 m_lineSelectSingleOnUp
= (unsigned int) -1;
2044 SetBackgroundColour( *wxWHITE
);
2046 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
2048 m_penRule
= wxPen(GetRuleColour());
2050 //Here I compose a pen can draw black lines, maybe there are something system colour to use
2051 m_penExpander
= wxPen(wxColour(0,0,0));
2052 //Some new added code to deal with the tree structure
2053 m_root
= new wxDataViewTreeNode( NULL
);
2054 m_root
->SetHasChildren(true);
2056 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
2058 m_underMouse
= NULL
;
2062 wxDataViewMainWindow::~wxDataViewMainWindow()
2065 delete m_renameTimer
;
2068 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2070 wxDataViewModel
*model
= GetOwner()->GetModel();
2071 wxAutoBufferedPaintDC
dc( this );
2074 dc
.SetPen( *wxTRANSPARENT_PEN
);
2075 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
2076 dc
.SetBrush( *wxWHITE_BRUSH
);
2077 wxSize
size( GetClientSize() );
2078 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
2082 GetOwner()->PrepareDC( dc
);
2083 dc
.SetFont( GetFont() );
2085 wxRect update
= GetUpdateRegion().GetBox();
2086 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
2088 // compute which items needs to be redrawn
2089 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
2090 unsigned int item_count
=
2091 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
2092 (int)(GetRowCount( ) - item_start
));
2093 unsigned int item_last
= item_start
+ item_count
;
2095 // compute which columns needs to be redrawn
2096 unsigned int cols
= GetOwner()->GetColumnCount();
2097 unsigned int col_start
= 0;
2098 unsigned int x_start
;
2099 for (x_start
= 0; col_start
< cols
; col_start
++)
2101 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
2102 if (col
->IsHidden())
2103 continue; // skip it!
2105 unsigned int w
= col
->GetWidth();
2106 if (x_start
+w
>= (unsigned int)update
.x
)
2112 unsigned int col_last
= col_start
;
2113 unsigned int x_last
= x_start
;
2114 for (; col_last
< cols
; col_last
++)
2116 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
2117 if (col
->IsHidden())
2118 continue; // skip it!
2120 if (x_last
> (unsigned int)update
.GetRight())
2123 x_last
+= col
->GetWidth();
2126 // Draw horizontal rules if required
2127 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
2129 dc
.SetPen(m_penRule
);
2130 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2132 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
2134 int y
= GetLineStart( i
);
2135 dc
.DrawLine(x_start
, y
, x_last
, y
);
2139 // Draw vertical rules if required
2140 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
2142 dc
.SetPen(m_penRule
);
2143 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2146 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2148 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
2149 if (col
->IsHidden())
2150 continue; // skip it
2152 dc
.DrawLine(x
, GetLineStart( item_start
),
2153 x
, GetLineStart( item_last
) );
2155 x
+= col
->GetWidth();
2158 // Draw last vertical rule
2159 dc
.DrawLine(x
, GetLineStart( item_start
),
2160 x
, GetLineStart( item_last
) );
2163 // redraw the background for the items which are selected/current
2164 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2166 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
2167 if (selected
|| item
== m_currentRow
)
2169 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
2170 if (item
== m_currentRow
)
2171 flags
|= wxCONTROL_CURRENT
;
2173 flags
|= wxCONTROL_FOCUSED
;
2175 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
2176 wxRendererNative::Get().DrawItemSelectionRect
2186 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
2189 // TODO: last column for RTL support
2190 expander
= GetOwner()->GetColumn( 0 );
2191 GetOwner()->SetExpanderColumn(expander
);
2194 // redraw all cells for all rows which must be repainted and all columns
2196 cell_rect
.x
= x_start
;
2197 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2200 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
2201 wxDataViewRenderer
*cell
= col
->GetRenderer();
2202 cell_rect
.width
= col
->GetWidth();
2204 if (col
->IsHidden())
2205 continue; // skip it!
2207 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2209 // get the cell value and set it into the renderer
2211 wxDataViewTreeNode
*node
= NULL
;
2212 wxDataViewItem dataitem
;
2214 if (!IsVirtualList())
2216 node
= GetTreeNodeByRow(item
);
2220 dataitem
= node
->GetItem();
2222 if ((i
> 0) && model
->IsContainer(dataitem
) && !model
->HasContainerColumns(dataitem
))
2227 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
2230 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
2231 cell
->SetValue( value
);
2233 if (cell
->GetWantsAttr())
2235 wxDataViewItemAttr attr
;
2236 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
2238 cell
->SetAttr( attr
);
2239 cell
->SetHasAttr( ret
);
2243 cell_rect
.y
= GetLineStart( item
);
2244 cell_rect
.height
= GetLineHeight( item
); // -1 is for the horizontal rules (?)
2246 //Draw the expander here.
2248 if ((!IsVirtualList()) && (col
== expander
))
2250 indent
= node
->GetIndentLevel();
2252 //Calculate the indent first
2253 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
2255 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
2256 // change the cell_rect.x to the appropriate pos
2257 int expander_x
= indent
+ EXPANDER_MARGIN
;
2258 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2) - (expander_width
/2) - EXPANDER_OFFSET
;
2259 indent
= indent
+ m_lineHeight
; //try to use the m_lineHeight as the expander space
2260 dc
.SetPen( m_penExpander
);
2261 dc
.SetBrush( wxNullBrush
);
2262 if( node
->HasChildren() )
2264 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
2266 if (m_underMouse
== node
)
2268 flag
|= wxCONTROL_CURRENT
;
2270 if( node
->IsOpen() )
2271 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
|wxCONTROL_EXPANDED
);
2273 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
2275 //force the expander column to left-center align
2276 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
2278 if (node
&& !node
->HasChildren())
2280 // Yes, if the node does not have any child, it must be a leaf which
2281 // mean that it is a temporarily created by GetTreeNodeByRow
2285 // cannot be bigger than allocated space
2286 wxSize size
= cell
->GetSize();
2287 // Because of the tree structure indent, here we should minus the width of the cell for drawing
2288 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
2289 // size.y = wxMin( size.y, cell_rect.height );
2290 size
.y
= cell_rect
.height
;
2292 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
2293 int align
= cell
->CalculateAlignment();
2295 // horizontal alignment:
2296 item_rect
.x
= cell_rect
.x
;
2297 if (align
& wxALIGN_CENTER_HORIZONTAL
)
2298 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
2299 else if (align
& wxALIGN_RIGHT
)
2300 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
2301 //else: wxALIGN_LEFT is the default
2303 // vertical alignment:
2304 item_rect
.y
= cell_rect
.y
;
2305 if (align
& wxALIGN_CENTER_VERTICAL
)
2306 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
2307 else if (align
& wxALIGN_BOTTOM
)
2308 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
2309 //else: wxALIGN_TOP is the default
2312 item_rect
.x
+= PADDING_RIGHTLEFT
;
2313 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
2315 //Here we add the tree indent
2316 item_rect
.x
+= indent
;
2319 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
2320 state
|= wxDATAVIEW_CELL_SELECTED
;
2322 // TODO: it would be much more efficient to create a clipping
2323 // region for the entire column being rendered (in the OnPaint
2324 // of wxDataViewMainWindow) instead of a single clip region for
2325 // each cell. However it would mean that each renderer should
2326 // respect the given wxRect's top & bottom coords, eventually
2327 // violating only the left & right coords - however the user can
2328 // make its own renderer and thus we cannot be sure of that.
2329 dc
.SetClippingRegion( item_rect
);
2330 cell
->Render( item_rect
, &dc
, state
);
2331 dc
.DestroyClippingRegion();
2334 cell_rect
.x
+= cell_rect
.width
;
2338 void wxDataViewMainWindow::OnRenameTimer()
2340 // We have to call this here because changes may just have
2341 // been made and no screen update taken place.
2346 unsigned int cols
= GetOwner()->GetColumnCount();
2348 for (i
= 0; i
< cols
; i
++)
2350 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2352 continue; // skip it!
2354 if (c
== m_currentCol
)
2356 xpos
+= c
->GetWidth();
2358 wxRect
labelRect( xpos
,
2359 GetLineStart( m_currentRow
),
2360 m_currentCol
->GetWidth(),
2361 GetLineHeight( m_currentRow
) );
2363 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
2364 &labelRect
.x
, &labelRect
.y
);
2366 wxDataViewItem item
= GetItemByRow( m_currentRow
);
2367 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
2371 //------------------------------------------------------------------
2372 // Helper class for do operation on the tree node
2373 //------------------------------------------------------------------
2378 virtual ~DoJob() { }
2380 //The return value control how the tree-walker tranverse the tree
2381 // 0: Job done, stop tranverse and return
2382 // 1: Ignore the current node's subtree and continue
2383 // 2: Job not done, continue
2384 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
2385 virtual int operator() ( wxDataViewTreeNode
* node
) = 0;
2386 virtual int operator() ( void * n
) = 0;
2389 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2394 switch( func( node
) )
2405 wxDataViewTreeNodes nodes
= node
->GetNodes();
2406 wxDataViewTreeLeaves leaves
= node
->GetChildren();
2408 int len_nodes
= nodes
.GetCount();
2409 int len
= leaves
.GetCount();
2410 int i
= 0, nodes_i
= 0;
2412 for(; i
< len
; i
++ )
2414 void * n
= leaves
[i
];
2415 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
2417 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
2420 if( Walker( nd
, func
) )
2439 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2450 wxDataViewTreeNode
* node
;
2451 node
= FindNode(parent
);
2456 node
->SetHasChildren( true );
2458 if( g_model
->IsContainer( item
) )
2460 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2461 newnode
->SetItem(item
);
2462 newnode
->SetHasChildren( true );
2463 node
->AddNode( newnode
);
2466 node
->AddLeaf( item
.GetID() );
2468 node
->ChangeSubTreeCount(1);
2476 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2478 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2479 const wxDataViewItem
& item
)
2484 if( m_currentRow
> GetRowCount() )
2485 m_currentRow
= m_count
- 1;
2487 m_selection
.Empty();
2494 wxDataViewTreeNode
* node
= FindNode(parent
);
2496 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2497 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
, false, "item not found" );
2500 node
->GetChildren().Remove( item
.GetID() );
2501 //Manuplate selection
2502 if( m_selection
.GetCount() > 1 )
2504 m_selection
.Empty();
2506 bool isContainer
= false;
2507 wxDataViewTreeNodes nds
= node
->GetNodes();
2508 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2510 if (nds
[i
]->GetItem() == item
)
2518 wxDataViewTreeNode
* n
= NULL
;
2519 wxDataViewTreeNodes nodes
= node
->GetNodes();
2520 int len
= nodes
.GetCount();
2521 for( int i
= 0; i
< len
; i
++)
2523 if( nodes
[i
]->GetItem() == item
)
2530 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2532 node
->GetNodes().Remove( n
);
2533 sub
-= n
->GetSubTreeCount();
2534 ::DestroyTreeHelper(n
);
2536 //Make the row number invalid and get a new valid one when user call GetRowCount
2538 node
->ChangeSubTreeCount(sub
);
2540 //Change the current row to the last row if the current exceed the max row number
2541 if( m_currentRow
> GetRowCount() )
2542 m_currentRow
= m_count
- 1;
2549 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2555 wxWindow
*parent
= GetParent();
2556 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2557 le
.SetEventObject(parent
);
2558 le
.SetModel(GetOwner()->GetModel());
2560 parent
->GetEventHandler()->ProcessEvent(le
);
2565 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2567 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2568 /*#define MAX_VIRTUAL_WIDTH 100000
2570 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2571 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2572 Refresh( true, &rect );
2580 wxWindow
*parent
= GetParent();
2581 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2582 le
.SetEventObject(parent
);
2583 le
.SetModel(GetOwner()->GetModel());
2586 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2587 parent
->GetEventHandler()->ProcessEvent(le
);
2592 bool wxDataViewMainWindow::Cleared()
2597 BuildTree( GetOwner()->GetModel() );
2604 void wxDataViewMainWindow::UpdateDisplay()
2609 void wxDataViewMainWindow::OnInternalIdle()
2611 wxWindow::OnInternalIdle();
2615 RecalculateDisplay();
2620 void wxDataViewMainWindow::RecalculateDisplay()
2622 wxDataViewModel
*model
= GetOwner()->GetModel();
2629 int width
= GetEndOfLastCol();
2630 int height
= GetLineStart( GetRowCount() );
2632 SetVirtualSize( width
, height
);
2633 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2638 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2640 wxWindow::ScrollWindow( dx
, dy
, rect
);
2642 if (GetOwner()->m_headerArea
)
2643 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2646 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2649 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2650 int sy
= GetLineStart( rows
)/y
;
2654 wxRect rect
= GetClientRect();
2658 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2659 for (x_start
= 0; colnum
< column
; colnum
++)
2661 wxDataViewColumn
*col
= GetOwner()->GetColumn(colnum
);
2662 if (col
->IsHidden())
2663 continue; // skip it!
2665 w
= col
->GetWidth();
2669 int x_end
= x_start
+ w
;
2670 xe
= xx
+ rect
.width
;
2673 sx
= ( xx
+ x_end
- xe
)/x
;
2680 m_owner
->Scroll( sx
, sy
);
2683 int wxDataViewMainWindow::GetCountPerPage() const
2685 wxSize size
= GetClientSize();
2686 return size
.y
/ m_lineHeight
;
2689 int wxDataViewMainWindow::GetEndOfLastCol() const
2693 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2695 const wxDataViewColumn
*c
=
2696 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
2699 width
+= c
->GetWidth();
2704 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2708 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2710 return GetLineAt( y
);
2713 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2715 wxSize client_size
= GetClientSize();
2716 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2717 &client_size
.x
, &client_size
.y
);
2719 //we should deal with the pixel here
2720 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2722 return wxMin( GetRowCount()-1, row
);
2725 unsigned int wxDataViewMainWindow::GetRowCount()
2727 if ( m_count
== -1 )
2729 m_count
= RecalculateCount();
2735 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2742 void wxDataViewMainWindow::SelectAllRows( bool on
)
2749 m_selection
.Clear();
2750 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2751 m_selection
.Add( i
);
2756 unsigned int first_visible
= GetFirstVisibleRow();
2757 unsigned int last_visible
= GetLastVisibleRow();
2759 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2761 unsigned int row
= m_selection
[i
];
2762 if ((row
>= first_visible
) && (row
<= last_visible
))
2765 m_selection
.Clear();
2769 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2771 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2775 m_selection
.Add( row
);
2783 m_selection
.Remove( row
);
2789 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2793 unsigned int tmp
= from
;
2799 for (i
= from
; i
<= to
; i
++)
2801 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2804 m_selection
.Add( i
);
2809 m_selection
.Remove( i
);
2812 RefreshRows( from
, to
);
2815 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2817 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2819 int n
= aSelections
[i
];
2821 m_selection
.Add( n
);
2826 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2828 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2829 m_selection
.Add( row
);
2831 m_selection
.Remove( row
);
2835 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2837 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2840 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2842 wxWindow
*parent
= GetParent();
2843 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2845 le
.SetEventObject(parent
);
2846 le
.SetModel(GetOwner()->GetModel());
2849 parent
->GetEventHandler()->ProcessEvent(le
);
2852 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2854 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2855 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2857 wxSize client_size
= GetClientSize();
2858 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2859 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2860 if (intersect_rect
.width
> 0)
2861 Refresh( true, &intersect_rect
);
2864 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2868 unsigned int tmp
= to
;
2873 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2874 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2876 wxSize client_size
= GetClientSize();
2877 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2878 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2879 if (intersect_rect
.width
> 0)
2880 Refresh( true, &intersect_rect
);
2883 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2885 wxSize client_size
= GetClientSize();
2886 int start
= GetLineStart( firstRow
);
2887 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2888 if (start
> client_size
.y
) return;
2890 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2892 Refresh( true, &rect
);
2895 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2897 wxCHECK_RET( newCurrent
< GetRowCount(),
2898 _T("invalid item index in OnArrowChar()") );
2900 // if there is no selection, we cannot move it anywhere
2901 if (!HasCurrentRow())
2904 unsigned int oldCurrent
= m_currentRow
;
2906 // in single selection we just ignore Shift as we can't select several
2908 if ( event
.ShiftDown() && !IsSingleSel() )
2910 RefreshRow( oldCurrent
);
2912 ChangeCurrentRow( newCurrent
);
2914 // select all the items between the old and the new one
2915 if ( oldCurrent
> newCurrent
)
2917 newCurrent
= oldCurrent
;
2918 oldCurrent
= m_currentRow
;
2921 SelectRows( oldCurrent
, newCurrent
, true );
2922 if (oldCurrent
!=newCurrent
)
2923 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2927 RefreshRow( oldCurrent
);
2929 // all previously selected items are unselected unless ctrl is held
2930 if ( !event
.ControlDown() )
2931 SelectAllRows(false);
2933 ChangeCurrentRow( newCurrent
);
2935 if ( !event
.ControlDown() )
2937 SelectRow( m_currentRow
, true );
2938 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2941 RefreshRow( m_currentRow
);
2944 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2947 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2951 rect
.y
= GetLineStart( row
);
2952 rect
.width
= GetEndOfLastCol();
2953 rect
.height
= GetLineHeight( row
);
2958 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2960 const wxDataViewModel
*model
= GetOwner()->GetModel();
2962 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2964 // TODO make more efficient
2969 for (r
= 0; r
< row
; r
++)
2971 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2972 if (!node
) return start
;
2974 wxDataViewItem item
= node
->GetItem();
2976 if (node
&& !node
->HasChildren())
2978 // Yes, if the node does not have any child, it must be a leaf which
2979 // mean that it is a temporarily created by GetTreeNodeByRow
2983 unsigned int cols
= GetOwner()->GetColumnCount();
2985 int height
= m_lineHeight
;
2986 for (col
= 0; col
< cols
; col
++)
2988 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2989 if (column
->IsHidden())
2990 continue; // skip it!
2992 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2993 continue; // skip it!
2995 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2997 model
->GetValue( value
, item
, column
->GetModelColumn() );
2998 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2999 renderer2
->SetValue( value
);
3000 height
= wxMax( height
, renderer
->GetSize().y
);
3011 return row
* m_lineHeight
;
3015 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
3017 const wxDataViewModel
*model
= GetOwner()->GetModel();
3019 // check for the easy case first
3020 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
3021 return y
/ m_lineHeight
;
3023 // TODO make more efficient
3024 unsigned int row
= 0;
3025 unsigned int yy
= 0;
3028 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3031 // not really correct...
3032 return row
+ ((y
-yy
) / m_lineHeight
);
3035 wxDataViewItem item
= node
->GetItem();
3037 if (node
&& !node
->HasChildren())
3039 // Yes, if the node does not have any child, it must be a leaf which
3040 // mean that it is a temporarily created by GetTreeNodeByRow
3044 unsigned int cols
= GetOwner()->GetColumnCount();
3046 int height
= m_lineHeight
;
3047 for (col
= 0; col
< cols
; col
++)
3049 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3050 if (column
->IsHidden())
3051 continue; // skip it!
3053 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3054 continue; // skip it!
3056 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3058 model
->GetValue( value
, item
, column
->GetModelColumn() );
3059 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3060 renderer2
->SetValue( value
);
3061 height
= wxMax( height
, renderer
->GetSize().y
);
3072 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
3074 const wxDataViewModel
*model
= GetOwner()->GetModel();
3076 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
3078 wxASSERT( !IsVirtualList() );
3080 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3081 // wxASSERT( node );
3082 if (!node
) return m_lineHeight
;
3084 wxDataViewItem item
= node
->GetItem();
3086 if (node
&& !node
->HasChildren())
3088 // Yes, if the node does not have any child, it must be a leaf which
3089 // mean that it is a temporarily created by GetTreeNodeByRow
3093 int height
= m_lineHeight
;
3095 unsigned int cols
= GetOwner()->GetColumnCount();
3097 for (col
= 0; col
< cols
; col
++)
3099 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3100 if (column
->IsHidden())
3101 continue; // skip it!
3103 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3104 continue; // skip it!
3106 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3108 model
->GetValue( value
, item
, column
->GetModelColumn() );
3109 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3110 renderer2
->SetValue( value
);
3111 height
= wxMax( height
, renderer
->GetSize().y
);
3118 return m_lineHeight
;
3122 class RowToItemJob
: public DoJob
3125 RowToItemJob( unsigned int row
, int current
) { this->row
= row
; this->current
= current
;}
3126 virtual ~RowToItemJob() { }
3128 virtual int operator() ( wxDataViewTreeNode
* node
)
3131 if( current
== static_cast<int>(row
))
3133 ret
= node
->GetItem();
3137 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3139 current
+= node
->GetSubTreeCount();
3144 //If the current has no child node, we can find the desired item of the row number directly.
3145 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3146 if( node
->GetNodes().GetCount() == 0)
3148 int index
= static_cast<int>(row
) - current
- 1;
3149 ret
= node
->GetChildren().Item( index
);
3156 virtual int operator() ( void * n
)
3159 if( current
== static_cast<int>(row
))
3161 ret
= wxDataViewItem( n
);
3166 wxDataViewItem
GetResult(){ return ret
; }
3173 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
3177 return wxDataViewItem( wxUIntToPtr(row
) );
3181 RowToItemJob
job( row
, -2 );
3182 Walker( m_root
, job
);
3183 return job
.GetResult();
3187 class RowToTreeNodeJob
: public DoJob
3190 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
3193 this->current
= current
;
3197 virtual ~RowToTreeNodeJob(){ }
3199 virtual int operator() ( wxDataViewTreeNode
* node
)
3202 if( current
== static_cast<int>(row
))
3208 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3210 current
+= node
->GetSubTreeCount();
3216 //If the current has no child node, we can find the desired item of the row number directly.
3217 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3218 if( node
->GetNodes().GetCount() == 0)
3220 int index
= static_cast<int>(row
) - current
- 1;
3221 void * n
= node
->GetChildren().Item( index
);
3222 ret
= new wxDataViewTreeNode( parent
);
3223 ret
->SetItem( wxDataViewItem( n
));
3224 ret
->SetHasChildren(false);
3233 virtual int operator() ( void * n
)
3236 if( current
== static_cast<int>(row
))
3238 ret
= new wxDataViewTreeNode( parent
);
3239 ret
->SetItem( wxDataViewItem( n
));
3240 ret
->SetHasChildren(false);
3246 wxDataViewTreeNode
* GetResult(){ return ret
; }
3250 wxDataViewTreeNode
* ret
;
3251 wxDataViewTreeNode
* parent
;
3255 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
3257 wxASSERT( !IsVirtualList() );
3259 RowToTreeNodeJob
job( row
, -2, m_root
);
3260 Walker( m_root
, job
);
3261 return job
.GetResult();
3264 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
)
3266 wxWindow
*parent
= GetParent();
3267 wxDataViewEvent
le(type
, parent
->GetId());
3269 le
.SetEventObject(parent
);
3270 le
.SetModel(GetOwner()->GetModel());
3273 parent
->GetEventHandler()->ProcessEvent(le
);
3277 void wxDataViewMainWindow::OnExpanding( unsigned int row
)
3279 if (IsVirtualList())
3282 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3285 if( node
->HasChildren())
3287 if( !node
->IsOpen())
3289 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,node
->GetItem());
3290 //Check if the user prevent expanding
3291 if( e
.GetSkipped() )
3295 //Here I build the children of current node
3296 if( node
->GetChildrenNumber() == 0 )
3299 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
3303 //Send the expanded event
3304 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
3308 SelectRow( row
, false );
3309 SelectRow( row
+ 1, true );
3310 ChangeCurrentRow( row
+ 1 );
3311 SendSelectionChangedEvent( GetItemByRow(row
+1));
3319 void wxDataViewMainWindow::OnCollapsing(unsigned int row
)
3321 if (IsVirtualList())
3324 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3327 wxDataViewTreeNode
* nd
= node
;
3329 if( node
->HasChildren() && node
->IsOpen() )
3331 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
3332 if( e
.GetSkipped() )
3337 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,nd
->GetItem());
3341 node
= node
->GetParent();
3344 int parent
= GetRowByItem( node
->GetItem() );
3347 SelectRow( row
, false);
3348 SelectRow(parent
, true );
3349 ChangeCurrentRow( parent
);
3350 SendSelectionChangedEvent( node
->GetItem() );
3354 if( !nd
->HasChildren())
3359 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3361 wxDataViewModel
* model
= GetOwner()->GetModel();
3365 //Compose the a parent-chain of the finding item
3367 list
.DeleteContents( true );
3368 wxDataViewItem
it( item
);
3371 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3372 list
.Insert( pItem
);
3373 it
= model
->GetParent( it
);
3376 //Find the item along the parent-chain.
3377 //This algorithm is designed to speed up the node-finding method
3378 wxDataViewTreeNode
* node
= m_root
;
3379 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end(); iter
++ )
3381 if( node
->HasChildren() )
3383 if( node
->GetChildrenNumber() == 0 )
3386 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3389 wxDataViewTreeNodes nodes
= node
->GetNodes();
3393 for (i
= 0; i
< nodes
.GetCount(); i
++)
3395 if (nodes
[i
]->GetItem() == (**iter
))
3397 if (nodes
[i
]->GetItem() == item
)
3414 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
)
3416 wxDataViewColumn
*col
= NULL
;
3417 unsigned int cols
= GetOwner()->GetColumnCount();
3418 unsigned int colnum
= 0;
3420 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3421 for (unsigned x_start
= 0; colnum
< cols
; colnum
++)
3423 col
= GetOwner()->GetColumn(colnum
);
3424 if (col
->IsHidden())
3425 continue; // skip it!
3427 unsigned int w
= col
->GetWidth();
3428 if (x_start
+w
>= (unsigned int)x
)
3435 item
= GetItemByRow( GetLineAt( y
) );
3438 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
3440 int row
= GetRowByItem(item
);
3441 int y
= GetLineStart( row
);
3442 int h
= GetLineHeight( m_lineHeight
);
3444 wxDataViewColumn
*col
= NULL
;
3445 for( int i
= 0, cols
= GetOwner()->GetColumnCount(); i
< cols
; i
++ )
3447 col
= GetOwner()->GetColumn( i
);
3448 x
+= col
->GetWidth();
3449 if( GetOwner()->GetColumn(i
+1) == column
)
3452 int w
= col
->GetWidth();
3453 m_owner
->CalcScrolledPosition( x
, y
, &x
, &y
);
3454 return wxRect(x
, y
, w
, h
);
3457 int wxDataViewMainWindow::RecalculateCount()
3461 wxDataViewIndexListModel
*list_model
= (wxDataViewIndexListModel
*) GetOwner()->GetModel();
3463 return list_model
->GetLastIndex() + 1;
3465 return list_model
->GetLastIndex() - 1;
3470 return m_root
->GetSubTreeCount();
3474 class ItemToRowJob
: public DoJob
3477 ItemToRowJob(const wxDataViewItem
& item_
, ItemList::const_iterator iter
)
3484 //Maybe binary search will help to speed up this process
3485 virtual int operator() ( wxDataViewTreeNode
* node
)
3488 if( node
->GetItem() == item
)
3493 if( node
->GetItem() == **m_iter
)
3500 ret
+= node
->GetSubTreeCount();
3506 virtual int operator() ( void * n
)
3509 if( n
== item
.GetID() )
3513 //the row number is begin from zero
3514 int GetResult() { return ret
-1; }
3517 ItemList::const_iterator m_iter
;
3518 wxDataViewItem item
;
3523 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3525 const wxDataViewModel
* model
= GetOwner()->GetModel();
3531 return wxPtrToUInt( item
.GetID() );
3538 //Compose the a parent-chain of the finding item
3540 wxDataViewItem
* pItem
;
3541 list
.DeleteContents( true );
3542 wxDataViewItem
it( item
);
3545 pItem
= new wxDataViewItem( it
);
3546 list
.Insert( pItem
);
3547 it
= model
->GetParent( it
);
3549 pItem
= new wxDataViewItem( );
3550 list
.Insert( pItem
);
3552 ItemToRowJob
job( item
, list
.begin() );
3553 Walker(m_root
, job
);
3554 return job
.GetResult();
3558 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
)
3560 if( !model
->IsContainer( item
) )
3563 wxDataViewItemArray children
;
3564 unsigned int num
= model
->GetChildren( item
, children
);
3565 unsigned int index
= 0;
3566 while( index
< num
)
3568 if( model
->IsContainer( children
[index
] ) )
3570 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3571 n
->SetItem(children
[index
]);
3572 n
->SetHasChildren( true );
3577 node
->AddLeaf( children
[index
].GetID() );
3581 node
->SetSubTreeCount( num
);
3582 wxDataViewTreeNode
* n
= node
->GetParent();
3584 n
->ChangeSubTreeCount(num
);
3588 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3592 if (GetOwner()->GetModel()->IsVirtualListModel())
3598 m_root
= new wxDataViewTreeNode( NULL
);
3599 m_root
->SetHasChildren(true);
3601 //First we define a invalid item to fetch the top-level elements
3602 wxDataViewItem item
;
3604 BuildTreeHelper( model
, item
, m_root
);
3608 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3610 if( node
->GetNodeNumber() != 0 )
3612 int len
= node
->GetNodeNumber();
3614 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3615 for(; i
< len
; i
++ )
3617 DestroyTreeHelper(nodes
[i
]);
3623 void wxDataViewMainWindow::DestroyTree()
3625 if (!IsVirtualList())
3627 ::DestroyTreeHelper(m_root
);
3633 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3635 if ( GetParent()->HandleAsNavigationKey(event
) )
3638 // no item -> nothing to do
3639 if (!HasCurrentRow())
3645 // don't use m_linesPerPage directly as it might not be computed yet
3646 const int pageSize
= GetCountPerPage();
3647 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3649 switch ( event
.GetKeyCode() )
3653 if (m_currentRow
> 0)
3655 wxWindow
*parent
= GetParent();
3656 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3657 le
.SetItem( GetItemByRow(m_currentRow
) );
3658 le
.SetEventObject(parent
);
3659 le
.SetModel(GetOwner()->GetModel());
3661 parent
->GetEventHandler()->ProcessEvent(le
);
3666 if ( m_currentRow
> 0 )
3667 OnArrowChar( m_currentRow
- 1, event
);
3671 if ( m_currentRow
< GetRowCount() - 1 )
3672 OnArrowChar( m_currentRow
+ 1, event
);
3674 //Add the process for tree expanding/collapsing
3676 OnCollapsing(m_currentRow
);
3679 OnExpanding( m_currentRow
);
3683 OnArrowChar( GetRowCount() - 1, event
);
3688 OnArrowChar( 0, event
);
3693 int steps
= pageSize
- 1;
3694 int index
= m_currentRow
- steps
;
3698 OnArrowChar( index
, event
);
3704 int steps
= pageSize
- 1;
3705 unsigned int index
= m_currentRow
+ steps
;
3706 unsigned int count
= GetRowCount();
3707 if ( index
>= count
)
3710 OnArrowChar( index
, event
);
3719 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3721 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3723 // let the base handle mouse wheel events.
3728 int x
= event
.GetX();
3729 int y
= event
.GetY();
3730 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3731 wxDataViewColumn
*col
= NULL
;
3734 unsigned int cols
= GetOwner()->GetColumnCount();
3736 for (i
= 0; i
< cols
; i
++)
3738 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
3740 continue; // skip it!
3742 if (x
< xpos
+ c
->GetWidth())
3747 xpos
+= c
->GetWidth();
3752 wxDataViewRenderer
*cell
= col
->GetRenderer();
3753 unsigned int current
= GetLineAt( y
);
3754 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
3756 // Unselect all if below the last row ?
3760 //Test whether the mouse is hovered on the tree item button
3762 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3764 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3765 if( node
!=NULL
&& node
->HasChildren() )
3767 int indent
= node
->GetIndentLevel();
3768 indent
= GetOwner()->GetIndent()*indent
;
3769 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3770 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3771 m_lineHeight
-2*EXPANDER_MARGIN
,
3772 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3773 if( rect
.Contains( x
, y
) )
3775 //So the mouse is over the expander
3777 if (m_underMouse
&& m_underMouse
!= node
)
3779 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3780 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3782 if (m_underMouse
!= node
)
3784 //wxLogMessage("Do the row: %d", current);
3785 RefreshRow(current
);
3787 m_underMouse
= node
;
3790 if (node
!=NULL
&& !node
->HasChildren())
3795 if (m_underMouse
!= NULL
)
3797 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3798 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3799 m_underMouse
= NULL
;
3803 wxDataViewModel
*model
= GetOwner()->GetModel();
3805 if (event
.Dragging())
3807 if (m_dragCount
== 0)
3809 // we have to report the raw, physical coords as we want to be
3810 // able to call HitTest(event.m_pointDrag) from the user code to
3811 // get the item being dragged
3812 m_dragStart
= event
.GetPosition();
3817 if (m_dragCount
!= 3)
3820 if (event
.LeftIsDown())
3822 // Notify cell about drag
3831 bool forceClick
= false;
3833 if (event
.ButtonDClick())
3835 m_renameTimer
->Stop();
3836 m_lastOnSame
= false;
3839 wxDataViewItem item
= GetItemByRow(current
);
3840 bool ignore_other_columns
=
3841 ((GetOwner()->GetExpanderColumn() != col
) &&
3842 (model
->IsContainer(item
)) &&
3843 (!model
->HasContainerColumns(item
)));
3845 if (event
.LeftDClick())
3847 if ( current
== m_lineLastClicked
)
3849 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3852 model
->GetValue( value
, item
, col
->GetModelColumn() );
3853 cell
->SetValue( value
);
3854 wxRect
cell_rect( xpos
, GetLineStart( current
),
3855 col
->GetWidth(), GetLineHeight( current
) );
3856 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3861 wxWindow
*parent
= GetParent();
3862 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3864 le
.SetEventObject(parent
);
3865 le
.SetModel(GetOwner()->GetModel());
3867 parent
->GetEventHandler()->ProcessEvent(le
);
3873 // The first click was on another item, so don't interpret this as
3874 // a double click, but as a simple click instead
3881 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3883 // select single line
3884 SelectAllRows( false );
3885 SelectRow( m_lineSelectSingleOnUp
, true );
3888 //Process the event of user clicking the expander
3889 bool expander
= false;
3890 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3892 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3893 if( node
!=NULL
&& node
->HasChildren() )
3895 int indent
= node
->GetIndentLevel();
3896 indent
= GetOwner()->GetIndent()*indent
;
3897 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3898 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3899 m_lineHeight
-2*EXPANDER_MARGIN
,
3900 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3902 if( rect
.Contains( x
, y
) )
3905 if( node
->IsOpen() )
3906 OnCollapsing(current
);
3908 OnExpanding( current
);
3911 if (node
&& !node
->HasChildren())
3914 //If the user click the expander, we do not do editing even if the column with expander are editable
3915 if (m_lastOnSame
&& !expander
&& !ignore_other_columns
)
3917 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3918 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3920 m_renameTimer
->Start( 100, true );
3924 m_lastOnSame
= false;
3925 m_lineSelectSingleOnUp
= (unsigned int)-1;
3929 // This is necessary, because after a DnD operation in
3930 // from and to ourself, the up event is swallowed by the
3931 // DnD code. So on next non-up event (which means here and
3932 // now) m_lineSelectSingleOnUp should be reset.
3933 m_lineSelectSingleOnUp
= (unsigned int)-1;
3936 if (event
.RightDown())
3938 m_lineBeforeLastClicked
= m_lineLastClicked
;
3939 m_lineLastClicked
= current
;
3941 // If the item is already selected, do not update the selection.
3942 // Multi-selections should not be cleared if a selected item is clicked.
3943 if (!IsRowSelected(current
))
3945 SelectAllRows(false);
3946 ChangeCurrentRow(current
);
3947 SelectRow(m_currentRow
,true);
3948 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3952 model
->GetValue( value
, item
, col
->GetModelColumn() );
3953 wxWindow
*parent
= GetParent();
3954 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3956 le
.SetEventObject(parent
);
3957 le
.SetModel(GetOwner()->GetModel());
3959 parent
->GetEventHandler()->ProcessEvent(le
);
3961 else if (event
.MiddleDown())
3964 if (event
.LeftDown() || forceClick
)
3968 m_lineBeforeLastClicked
= m_lineLastClicked
;
3969 m_lineLastClicked
= current
;
3971 unsigned int oldCurrentRow
= m_currentRow
;
3972 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3974 bool cmdModifierDown
= event
.CmdDown();
3975 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3977 if ( IsSingleSel() || !IsRowSelected(current
) )
3979 SelectAllRows( false );
3980 ChangeCurrentRow(current
);
3981 SelectRow(m_currentRow
,true);
3982 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3984 else // multi sel & current is highlighted & no mod keys
3986 m_lineSelectSingleOnUp
= current
;
3987 ChangeCurrentRow(current
); // change focus
3990 else // multi sel & either ctrl or shift is down
3992 if (cmdModifierDown
)
3994 ChangeCurrentRow(current
);
3995 ReverseRowSelection(m_currentRow
);
3996 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3998 else if (event
.ShiftDown())
4000 ChangeCurrentRow(current
);
4002 unsigned int lineFrom
= oldCurrentRow
,
4005 if ( lineTo
< lineFrom
)
4008 lineFrom
= m_currentRow
;
4011 SelectRows(lineFrom
, lineTo
, true);
4012 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
4014 else // !ctrl, !shift
4016 // test in the enclosing if should make it impossible
4017 wxFAIL_MSG( _T("how did we get here?") );
4021 if (m_currentRow
!= oldCurrentRow
)
4022 RefreshRow( oldCurrentRow
);
4024 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
4026 // Update selection here...
4029 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
4030 (current
== oldCurrentRow
)) && oldWasSelected
;
4032 // Call LeftClick after everything else as under GTK+
4033 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
4035 // notify cell about right click
4037 model
->GetValue( value
, item
, col
->GetModelColumn() );
4038 cell
->SetValue( value
);
4039 wxRect
cell_rect( xpos
, GetLineStart( current
),
4040 col
->GetWidth(), GetLineHeight( current
) );
4041 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
, model
, item
, col
->GetModelColumn());
4046 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
4050 if (HasCurrentRow())
4056 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
4060 if (HasCurrentRow())
4066 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
4068 if( m_selection
.GetCount() != 1 )
4069 return wxDataViewItem();
4071 return GetItemByRow( m_selection
.Item(0));
4074 //-----------------------------------------------------------------------------
4076 //-----------------------------------------------------------------------------
4077 WX_DEFINE_LIST(wxDataViewColumnList
)
4079 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4081 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
4082 EVT_SIZE(wxDataViewCtrl::OnSize
)
4085 wxDataViewCtrl::~wxDataViewCtrl()
4088 GetModel()->RemoveNotifier( m_notifier
);
4093 void wxDataViewCtrl::Init()
4095 m_cols
.DeleteContents(true);
4098 // No sorting column at start
4099 m_sortingColumn
= NULL
;
4100 m_headerArea
= NULL
;
4103 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4104 const wxPoint
& pos
, const wxSize
& size
,
4105 long style
, const wxValidator
& validator
)
4107 if ( (style
& wxBORDER_MASK
) == 0)
4108 style
|= wxBORDER_SUNKEN
;
4112 if (!wxControl::Create( parent
, id
, pos
, size
,
4113 style
| wxScrolledWindowStyle
, validator
))
4116 SetInitialSize(size
);
4119 MacSetClipChildren( true );
4122 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
4124 if (HasFlag(wxDV_NO_HEADER
))
4125 m_headerArea
= NULL
;
4127 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
4129 SetTargetWindow( m_clientArea
);
4131 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4133 sizer
->Add( m_headerArea
, 0, wxGROW
);
4134 sizer
->Add( m_clientArea
, 1, wxGROW
);
4141 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
4145 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4148 // we need to process arrows ourselves for scrolling
4149 if ( nMsg
== WM_GETDLGCODE
)
4151 rc
|= DLGC_WANTARROWS
;
4159 wxSize
wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize
& size
)
4161 wxSize newsize
= size
;
4162 if (!HasFlag(wxDV_NO_HEADER
) && (m_headerArea
))
4163 newsize
.y
-= m_headerArea
->GetSize().y
;
4168 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4170 // We need to override OnSize so that our scrolled
4171 // window a) does call Layout() to use sizers for
4172 // positioning the controls but b) does not query
4173 // the sizer for their size and use that for setting
4174 // the scrollable area as set that ourselves by
4175 // calling SetScrollbar() further down.
4182 void wxDataViewCtrl::SetFocus()
4185 m_clientArea
->SetFocus();
4188 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4190 if (!wxDataViewCtrlBase::AssociateModel( model
))
4193 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4195 model
->AddNotifier( m_notifier
);
4197 m_clientArea
->DestroyTree();
4199 m_clientArea
->BuildTree(model
);
4201 m_clientArea
->UpdateDisplay();
4206 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4208 if (!wxDataViewCtrlBase::AppendColumn(col
))
4211 m_cols
.Append( col
);
4216 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4218 if (!wxDataViewCtrlBase::PrependColumn(col
))
4221 m_cols
.Insert( col
);
4226 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4228 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4231 m_cols
.Insert( pos
, col
);
4236 void wxDataViewCtrl::OnColumnChange()
4239 m_headerArea
->UpdateDisplay();
4241 m_clientArea
->UpdateDisplay();
4244 void wxDataViewCtrl::DoSetExpanderColumn()
4246 m_clientArea
->UpdateDisplay();
4249 void wxDataViewCtrl::DoSetIndent()
4251 m_clientArea
->UpdateDisplay();
4254 unsigned int wxDataViewCtrl::GetColumnCount() const
4256 return m_cols
.GetCount();
4259 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4261 wxDataViewColumnList::const_iterator iter
;
4263 for (iter
= m_cols
.begin(); iter
!=m_cols
.end(); iter
++)
4268 if ((*iter
)->IsHidden())
4275 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
)
4277 if (new_pos
> m_cols
.GetCount()) return;
4279 // Exchange position
4280 m_cols
.DeleteContents(false);
4281 m_cols
.DeleteObject( col
);
4282 m_cols
.Insert( new_pos
, col
);
4283 m_cols
.DeleteContents(true);
4285 m_clientArea
->UpdateDisplay();
4288 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4290 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4300 bool wxDataViewCtrl::ClearColumns()
4307 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4309 int ret
= 0, dead
= 0;
4310 int len
= GetColumnCount();
4311 for (int i
=0; i
<len
; i
++)
4313 wxDataViewColumn
* col
= GetColumn(i
);
4314 if (col
->IsHidden())
4316 ret
+= col
->GetWidth();
4319 CalcScrolledPosition( ret
, dead
, &ret
, &dead
);
4326 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4331 //Selection code with wxDataViewItem as parameters
4332 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4334 return m_clientArea
->GetSelection();
4337 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4340 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4341 int len
= selection
.GetCount();
4342 for( int i
= 0; i
< len
; i
++)
4344 unsigned int row
= selection
[i
];
4345 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4350 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4352 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4353 int len
= sel
.GetCount();
4354 for( int i
= 0; i
< len
; i
++ )
4356 int row
= m_clientArea
->GetRowByItem( sel
[i
] );
4358 selection
.Add( static_cast<unsigned int>(row
) );
4360 m_clientArea
->SetSelections( selection
);
4363 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4365 int row
= m_clientArea
->GetRowByItem( item
);
4368 //Unselect all rows before select another in the single select mode
4369 if (m_clientArea
->IsSingleSel())
4370 m_clientArea
->SelectAllRows(false);
4371 m_clientArea
->SelectRow(row
, true);
4375 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4377 int row
= m_clientArea
->GetRowByItem( item
);
4379 m_clientArea
->SelectRow(row
, false);
4382 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4384 int row
= m_clientArea
->GetRowByItem( item
);
4387 return m_clientArea
->IsRowSelected(row
);
4392 //Selection code with row number as parameter
4393 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4396 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4397 int len
= selection
.GetCount();
4398 for( int i
= 0; i
< len
; i
++)
4400 unsigned int row
= selection
[i
];
4406 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4408 wxDataViewSelection
selection(wxDataViewSelectionCmp
);
4409 int len
= sel
.GetCount();
4410 for( int i
= 0; i
< len
; i
++ )
4414 selection
.Add( static_cast<unsigned int>(row
) );
4416 m_clientArea
->SetSelections( selection
);
4419 void wxDataViewCtrl::Select( int row
)
4423 if (m_clientArea
->IsSingleSel())
4424 m_clientArea
->SelectAllRows(false);
4425 m_clientArea
->SelectRow( row
, true );
4429 void wxDataViewCtrl::Unselect( int row
)
4432 m_clientArea
->SelectRow(row
, false);
4435 bool wxDataViewCtrl::IsSelected( int row
) const
4438 return m_clientArea
->IsRowSelected(row
);
4442 void wxDataViewCtrl::SelectRange( int from
, int to
)
4445 for( int i
= from
; i
< to
; i
++ )
4447 m_clientArea
->Select(sel
);
4450 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4452 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4453 for( int i
= from
; i
< to
; i
++ )
4454 if( sel
.Index( i
) != wxNOT_FOUND
)
4456 m_clientArea
->SetSelections(sel
);
4459 void wxDataViewCtrl::SelectAll()
4461 m_clientArea
->SelectAllRows(true);
4464 void wxDataViewCtrl::UnselectAll()
4466 m_clientArea
->SelectAllRows(false);
4469 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4473 if( row
> (int) m_clientArea
->GetRowCount() )
4474 row
= m_clientArea
->GetRowCount();
4476 int first
= m_clientArea
->GetFirstVisibleRow();
4477 int last
= m_clientArea
->GetLastVisibleRow();
4479 m_clientArea
->ScrollTo( row
, column
);
4480 else if( row
> last
)
4481 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4483 m_clientArea
->ScrollTo( first
, column
);
4486 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4488 int row
= m_clientArea
->GetRowByItem(item
);
4491 if( column
== NULL
)
4492 EnsureVisible(row
, -1);
4496 int len
= GetColumnCount();
4497 for( int i
= 0; i
< len
; i
++ )
4498 if( GetColumn(i
) == column
)
4503 EnsureVisible( row
, col
);
4509 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const
4511 m_clientArea
->HitTest(point
, item
, column
);
4514 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
) const
4516 return m_clientArea
->GetItemRect(item
, column
);
4519 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4521 return m_clientArea
->GetItemByRow( row
);
4524 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4526 return m_clientArea
->GetRowByItem( item
);
4529 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4531 int row
= m_clientArea
->GetRowByItem( item
);
4533 m_clientArea
->Expand(row
);
4536 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4538 int row
= m_clientArea
->GetRowByItem( item
);
4540 m_clientArea
->Collapse(row
);
4544 // !wxUSE_GENERICDATAVIEWCTRL
4547 // wxUSE_DATAVIEWCTRL