1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/dcclient.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
39 #include "wx/stockitem.h"
40 #include "wx/calctrl.h"
41 #include "wx/popupwin.h"
42 #include "wx/renderer.h"
43 #include "wx/dcbuffer.h"
46 #include "wx/listimpl.cpp"
47 #include "wx/imaglist.h"
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
55 static const int SCROLL_UNIT_X
= 15;
57 // the cell padding on the left/right
58 static const int PADDING_RIGHTLEFT
= 3;
60 // the expander space margin
61 static const int EXPANDER_MARGIN
= 4;
64 static const int EXPANDER_OFFSET
= 4;
66 static const int EXPANDER_OFFSET
= 1;
69 //-----------------------------------------------------------------------------
70 // wxDataViewHeaderWindow
71 //-----------------------------------------------------------------------------
73 // on wxMSW the header window (only that part however) can be made native!
74 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
75 #define USE_NATIVE_HEADER_WINDOW
78 //Below is the compare stuff
79 //For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed
80 static wxDataViewModel
* g_model
;
81 static int g_column
= -2;
82 static bool g_asending
= true;
84 // NB: for some reason, this class must be dllexport'ed or we get warnings from
86 class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase
: public wxControl
89 wxDataViewHeaderWindowBase()
92 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
93 const wxPoint
&pos
, const wxSize
&size
,
96 return wxWindow::Create(parent
, id
, pos
, size
, wxNO_BORDER
, name
);
99 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
100 wxDataViewCtrl
*GetOwner() { return m_owner
; }
102 // called on column addition/removal
103 virtual void UpdateDisplay() { /* by default, do nothing */ }
105 // returns the n-th column
106 virtual wxDataViewColumn
*GetColumn(unsigned int n
)
109 wxDataViewColumn
*ret
= m_owner
->GetColumn(n
);
116 wxDataViewCtrl
*m_owner
;
118 // sends an event generated from the n-th wxDataViewColumn
119 void SendEvent(wxEventType type
, unsigned int n
);
122 #ifdef USE_NATIVE_HEADER_WINDOW
124 #define COLUMN_WIDTH_OFFSET 2
125 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow
127 class wxDataViewHeaderWindowMSW
: public wxDataViewHeaderWindowBase
131 wxDataViewHeaderWindowMSW( wxDataViewCtrl
*parent
,
133 const wxPoint
&pos
= wxDefaultPosition
,
134 const wxSize
&size
= wxDefaultSize
,
135 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
137 Create(parent
, id
, pos
, size
, name
);
140 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
141 const wxPoint
&pos
, const wxSize
&size
,
142 const wxString
&name
);
144 ~wxDataViewHeaderWindowMSW();
146 // called when any column setting is changed and/or changed
148 virtual void UpdateDisplay();
150 virtual void OnInternalIdle();
152 // called Refresh afterwards
153 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
155 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
158 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
160 virtual void DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
);
162 wxSize
DoGetBestSize() const;
164 unsigned int GetColumnIdxFromHeader(NMHEADER
*nmHDR
);
166 wxDataViewColumn
*GetColumnFromHeader(NMHEADER
*nmHDR
)
167 { return GetColumn(GetColumnIdxFromHeader(nmHDR
)); }
171 bool m_delayedUpdate
;
172 wxImageList
*m_imageList
;
175 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW
)
178 #else // !defined(__WXMSW__)
180 #define HEADER_WINDOW_HEIGHT 25
181 #define HEADER_HORIZ_BORDER 5
182 #define HEADER_VERT_BORDER 3
183 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
185 class wxGenericDataViewHeaderWindow
: public wxDataViewHeaderWindowBase
188 wxGenericDataViewHeaderWindow( wxDataViewCtrl
*parent
,
190 const wxPoint
&pos
= wxDefaultPosition
,
191 const wxSize
&size
= wxDefaultSize
,
192 const wxString
&name
= wxT("wxdataviewctrlheaderwindow") )
195 Create(parent
, id
, pos
, size
, name
);
198 bool Create(wxDataViewCtrl
*parent
, wxWindowID id
,
199 const wxPoint
&pos
, const wxSize
&size
,
200 const wxString
&name
);
202 ~wxGenericDataViewHeaderWindow()
204 delete m_resizeCursor
;
207 virtual void UpdateDisplay() { Refresh(); }
211 void OnPaint( wxPaintEvent
&event
);
212 void OnMouse( wxMouseEvent
&event
);
213 void OnSetFocus( wxFocusEvent
&event
);
218 // vars used for column resizing:
220 wxCursor
*m_resizeCursor
;
221 const wxCursor
*m_currentCursor
;
224 bool m_dirty
; // needs refresh?
225 int m_hover
; // index of the column under the mouse
226 int m_column
; // index of the column being resized
227 int m_currentX
; // divider line position in logical (unscrolled) coords
228 int m_minX
; // minimal position beyond which the divider line
229 // can't be dragged in logical coords
231 // the pen used to draw the current column width drag line
232 // when resizing the columsn
236 // internal utilities:
240 m_currentCursor
= (wxCursor
*) NULL
;
241 m_resizeCursor
= new wxCursor( wxCURSOR_SIZEWE
);
243 m_isDragging
= false;
246 m_hover
= wxNOT_FOUND
;
247 m_column
= wxNOT_FOUND
;
251 wxColour col
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
252 m_penCurrent
= wxPen(col
, 1, wxSOLID
);
255 void AdjustDC(wxDC
& dc
);
258 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow
)
259 DECLARE_EVENT_TABLE()
262 #endif // defined(__WXMSW__)
264 //-----------------------------------------------------------------------------
265 // wxDataViewRenameTimer
266 //-----------------------------------------------------------------------------
268 class wxDataViewRenameTimer
: public wxTimer
271 wxDataViewMainWindow
*m_owner
;
274 wxDataViewRenameTimer( wxDataViewMainWindow
*owner
);
278 //-----------------------------------------------------------------------------
279 // wxDataViewTreeNode
280 //-----------------------------------------------------------------------------
281 class wxDataViewTreeNode
;
282 WX_DEFINE_ARRAY( wxDataViewTreeNode
*, wxDataViewTreeNodes
);
283 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves
);
285 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
);
286 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
);
288 class wxDataViewTreeNode
291 wxDataViewTreeNode( wxDataViewTreeNode
* parent
= NULL
)
298 m_hasChildren
= false;
302 ~wxDataViewTreeNode()
306 wxDataViewTreeNode
* GetParent() const { return m_parent
; }
307 void SetParent( wxDataViewTreeNode
* parent
) { m_parent
= parent
; }
308 wxDataViewTreeNodes
& GetNodes() { return m_nodes
; }
309 wxDataViewTreeLeaves
& GetChildren() { return m_leaves
; }
311 void AddNode( wxDataViewTreeNode
* node
)
313 m_leaves
.Add( node
->GetItem().GetID() );
315 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
318 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
320 void AddLeaf( void * leaf
)
322 m_leaves
.Add( leaf
);
324 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
327 wxDataViewItem
& GetItem() { return m_item
; }
328 const wxDataViewItem
& GetItem() const { return m_item
; }
329 void SetItem( const wxDataViewItem
& item
) { m_item
= item
; }
331 unsigned int GetChildrenNumber() const { return m_leaves
.GetCount(); }
332 unsigned int GetNodeNumber() const { return m_nodes
.GetCount(); }
333 int GetIndentLevel() const
336 const wxDataViewTreeNode
* node
= this;
337 while( node
->GetParent()->GetParent() != NULL
)
339 node
= node
->GetParent();
352 int len
= m_nodes
.GetCount();
354 for ( int i
= 0 ;i
< len
; i
++)
355 sum
+= m_nodes
[i
]->GetSubTreeCount();
357 sum
+= m_leaves
.GetCount();
360 ChangeSubTreeCount(-sum
);
366 ChangeSubTreeCount(sum
);
369 bool HasChildren() const { return m_hasChildren
; }
370 void SetHasChildren( bool has
){ m_hasChildren
= has
; }
372 void SetSubTreeCount( int num
) { m_subTreeCount
= num
; }
373 int GetSubTreeCount() const { return m_subTreeCount
; }
374 void ChangeSubTreeCount( int num
)
378 m_subTreeCount
+= num
;
380 m_parent
->ChangeSubTreeCount(num
);
387 m_nodes
.Sort( &wxGenericTreeModelNodeCmp
);
388 int len
= m_nodes
.GetCount();
389 for (int i
= 0; i
< len
; i
++)
390 m_nodes
[i
]->Resort();
391 m_leaves
.Sort( &wxGenericTreeModelItemCmp
);
396 wxDataViewTreeNode
*m_parent
;
397 wxDataViewTreeNodes m_nodes
;
398 wxDataViewTreeLeaves m_leaves
;
399 wxDataViewItem m_item
;
405 int LINKAGEMODE
wxGenericTreeModelNodeCmp( wxDataViewTreeNode
** node1
, wxDataViewTreeNode
** node2
)
407 return g_model
->Compare( (*node1
)->GetItem(), (*node2
)->GetItem(), g_column
, g_asending
);
410 int LINKAGEMODE
wxGenericTreeModelItemCmp( void ** id1
, void ** id2
)
412 return g_model
->Compare( *id1
, *id2
, g_column
, g_asending
);
417 //-----------------------------------------------------------------------------
418 // wxDataViewMainWindow
419 //-----------------------------------------------------------------------------
421 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection
,
423 WX_DECLARE_LIST(wxDataViewItem
, ItemList
);
424 WX_DEFINE_LIST(ItemList
)
426 class wxDataViewMainWindow
: public wxWindow
429 wxDataViewMainWindow( wxDataViewCtrl
*parent
,
431 const wxPoint
&pos
= wxDefaultPosition
,
432 const wxSize
&size
= wxDefaultSize
,
433 const wxString
&name
= wxT("wxdataviewctrlmainwindow") );
434 virtual ~wxDataViewMainWindow();
436 bool IsVirtualList() const { return m_root
== NULL
; }
438 // notifications from wxDataViewModel
439 bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
440 bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
441 bool ItemChanged( const wxDataViewItem
&item
);
442 bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
446 if (!IsVirtualList())
456 g_model
= GetOwner()->GetModel();
457 wxDataViewColumn
* col
= GetOwner()->GetSortingColumn();
460 if (g_model
->HasDefaultCompare())
468 g_column
= col
->GetModelColumn();
469 g_asending
= col
->IsSortOrderAscending();
472 void SetOwner( wxDataViewCtrl
* owner
) { m_owner
= owner
; }
473 wxDataViewCtrl
*GetOwner() { return m_owner
; }
474 const wxDataViewCtrl
*GetOwner() const { return m_owner
; }
476 void OnPaint( wxPaintEvent
&event
);
477 void OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
);
478 void OnChar( wxKeyEvent
&event
);
479 void OnMouse( wxMouseEvent
&event
);
480 void OnSetFocus( wxFocusEvent
&event
);
481 void OnKillFocus( wxFocusEvent
&event
);
483 void UpdateDisplay();
484 void RecalculateDisplay();
485 void OnInternalIdle();
487 void OnRenameTimer();
489 void ScrollWindow( int dx
, int dy
, const wxRect
*rect
= NULL
);
490 void ScrollTo( int rows
, int column
);
492 bool HasCurrentRow() { return m_currentRow
!= (unsigned int)-1; }
493 void ChangeCurrentRow( unsigned int row
);
495 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE
); }
496 bool IsEmpty() { return GetRowCount() == 0; }
498 int GetCountPerPage() const;
499 int GetEndOfLastCol() const;
500 unsigned int GetFirstVisibleRow() const;
501 //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
502 unsigned int GetLastVisibleRow();
503 unsigned int GetRowCount() ;
505 wxDataViewItem
GetSelection() const;
506 wxDataViewSelection
GetSelections(){ return m_selection
; }
507 void SetSelections( const wxDataViewSelection
& sel
) { m_selection
= sel
; UpdateDisplay(); }
508 void Select( const wxArrayInt
& aSelections
);
509 void SelectAllRows( bool on
);
510 void SelectRow( unsigned int row
, bool on
);
511 void SelectRows( unsigned int from
, unsigned int to
, bool on
);
512 void ReverseRowSelection( unsigned int row
);
513 bool IsRowSelected( unsigned int row
);
514 void SendSelectionChangedEvent( const wxDataViewItem
& item
);
516 void RefreshRow( unsigned int row
);
517 void RefreshRows( unsigned int from
, unsigned int to
);
518 void RefreshRowsAfter( unsigned int firstRow
);
520 // returns the colour to be used for drawing the rules
521 wxColour
GetRuleColour() const
523 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
);
526 wxRect
GetLineRect( unsigned int row
) const;
528 int GetLineStart( unsigned int row
) const; // row * m_lineHeight in fixed mode
529 int GetLineHeight( unsigned int row
) const; // m_lineHeight in fixed mode
530 int GetLineAt( unsigned int y
) const; // y / m_lineHeight in fixed mode
532 //Some useful functions for row and item mapping
533 wxDataViewItem
GetItemByRow( unsigned int row
) const;
534 int GetRowByItem( const wxDataViewItem
& item
) const;
536 //Methods for building the mapping tree
537 void BuildTree( wxDataViewModel
* model
);
539 void HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
);
540 wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
);
542 void Expand( unsigned int row
) { OnExpanding( row
); }
543 void Collapse( unsigned int row
) { OnCollapsing( row
); }
545 wxDataViewTreeNode
* GetTreeNodeByRow( unsigned int row
) const;
546 //We did not need this temporarily
547 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
549 int RecalculateCount() ;
551 wxDataViewEvent
SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
);
552 void OnExpanding( unsigned int row
);
553 void OnCollapsing( unsigned int row
);
555 wxDataViewTreeNode
* FindNode( const wxDataViewItem
& item
);
558 wxDataViewCtrl
*m_owner
;
562 wxDataViewColumn
*m_currentCol
;
563 unsigned int m_currentRow
;
564 wxDataViewSelection m_selection
;
566 wxDataViewRenameTimer
*m_renameTimer
;
574 // for double click logic
575 unsigned int m_lineLastClicked
,
576 m_lineBeforeLastClicked
,
577 m_lineSelectSingleOnUp
;
579 // the pen used to draw horiz/vertical rules
582 // the pen used to draw the expander and the lines
585 //This is the tree structure of the model
586 wxDataViewTreeNode
* m_root
;
588 //This is the tree node under the cursor
589 wxDataViewTreeNode
* m_underMouse
;
591 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow
)
592 DECLARE_EVENT_TABLE()
595 // ---------------------------------------------------------
596 // wxGenericDataViewModelNotifier
597 // ---------------------------------------------------------
599 class wxGenericDataViewModelNotifier
: public wxDataViewModelNotifier
602 wxGenericDataViewModelNotifier( wxDataViewMainWindow
*mainWindow
)
603 { m_mainWindow
= mainWindow
; }
605 virtual bool ItemAdded( const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
606 { return m_mainWindow
->ItemAdded( parent
, item
); }
607 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
608 { return m_mainWindow
->ItemDeleted( parent
, item
); }
609 virtual bool ItemChanged( const wxDataViewItem
& item
)
610 { return m_mainWindow
->ItemChanged(item
); }
611 virtual bool ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
612 { return m_mainWindow
->ValueChanged( item
, col
); }
613 virtual bool Cleared()
614 { return m_mainWindow
->Cleared(); }
615 virtual void Resort()
616 { m_mainWindow
->Resort(); }
618 wxDataViewMainWindow
*m_mainWindow
;
621 // ---------------------------------------------------------
622 // wxDataViewRenderer
623 // ---------------------------------------------------------
625 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
, wxDataViewRendererBase
)
627 wxDataViewRenderer::wxDataViewRenderer( const wxString
&varianttype
,
628 wxDataViewCellMode mode
,
630 wxDataViewRendererBase( varianttype
, mode
, align
)
639 wxDataViewRenderer::~wxDataViewRenderer()
645 wxDC
*wxDataViewRenderer::GetDC()
649 if (GetOwner() == NULL
)
651 if (GetOwner()->GetOwner() == NULL
)
653 m_dc
= new wxClientDC( GetOwner()->GetOwner() );
659 void wxDataViewRenderer::SetAlignment( int align
)
664 int wxDataViewRenderer::GetAlignment() const
669 int wxDataViewRenderer::CalculateAlignment() const
671 if (m_align
== wxDVR_DEFAULT_ALIGNMENT
)
673 if (GetOwner() == NULL
)
674 return wxALIGN_LEFT
| wxALIGN_CENTRE_VERTICAL
;
676 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
682 // ---------------------------------------------------------
683 // wxDataViewCustomRenderer
684 // ---------------------------------------------------------
686 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
688 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString
&varianttype
,
689 wxDataViewCellMode mode
, int align
) :
690 wxDataViewRenderer( varianttype
, mode
, align
)
694 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
696 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
697 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
698 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
699 view
->GetForegroundColour();
700 dc
->SetTextForeground(col
);
701 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
704 // ---------------------------------------------------------
705 // wxDataViewTextRenderer
706 // ---------------------------------------------------------
708 IMPLEMENT_CLASS(wxDataViewTextRenderer
, wxDataViewCustomRenderer
)
710 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString
&varianttype
,
711 wxDataViewCellMode mode
, int align
) :
712 wxDataViewCustomRenderer( varianttype
, mode
, align
)
716 bool wxDataViewTextRenderer::SetValue( const wxVariant
&value
)
718 m_text
= value
.GetString();
723 bool wxDataViewTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
728 bool wxDataViewTextRenderer::HasEditorCtrl()
733 wxControl
* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow
*parent
,
734 wxRect labelRect
, const wxVariant
&value
)
736 return new wxTextCtrl( parent
, wxID_ANY
, value
,
737 wxPoint(labelRect
.x
,labelRect
.y
),
738 wxSize(labelRect
.width
,labelRect
.height
) );
741 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl
*editor
, wxVariant
&value
)
743 wxTextCtrl
*text
= (wxTextCtrl
*) editor
;
744 value
= text
->GetValue();
748 bool wxDataViewTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
750 RenderText( m_text
, 0, cell
, dc
, state
);
754 wxSize
wxDataViewTextRenderer::GetSize() const
756 const wxDataViewCtrl
*view
= GetView();
760 view
->GetTextExtent( m_text
, &x
, &y
);
761 return wxSize( x
, y
);
763 return wxSize(80,20);
766 // ---------------------------------------------------------
767 // wxDataViewTextRendererAttr
768 // ---------------------------------------------------------
770 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
, wxDataViewTextRenderer
)
772 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString
&varianttype
,
773 wxDataViewCellMode mode
, int align
) :
774 wxDataViewTextRenderer( varianttype
, mode
, align
)
779 bool wxDataViewTextRendererAttr::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
786 if (m_attr
.HasColour())
788 colour
= dc
->GetTextForeground();
789 dc
->SetTextForeground( m_attr
.GetColour() );
792 if (m_attr
.GetBold() || m_attr
.GetItalic())
794 font
= dc
->GetFont();
795 wxFont myfont
= font
;
796 if (m_attr
.GetBold())
797 myfont
.SetWeight( wxFONTWEIGHT_BOLD
);
798 if (m_attr
.GetItalic())
799 myfont
.SetStyle( wxFONTSTYLE_ITALIC
);
800 dc
->SetFont( myfont
);
804 dc
->DrawText( m_text
, cell
.x
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
809 if (m_attr
.HasColour())
810 dc
->SetTextForeground( colour
);
812 if (m_attr
.GetBold() || m_attr
.GetItalic())
820 // ---------------------------------------------------------
821 // wxDataViewBitmapRenderer
822 // ---------------------------------------------------------
824 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
, wxDataViewCustomRenderer
)
826 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString
&varianttype
,
827 wxDataViewCellMode mode
, int align
) :
828 wxDataViewCustomRenderer( varianttype
, mode
, align
)
832 bool wxDataViewBitmapRenderer::SetValue( const wxVariant
&value
)
834 if (value
.GetType() == wxT("wxBitmap"))
836 if (value
.GetType() == wxT("wxIcon"))
842 bool wxDataViewBitmapRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
847 bool wxDataViewBitmapRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
850 dc
->DrawBitmap( m_bitmap
, cell
.x
, cell
.y
);
851 else if (m_icon
.Ok())
852 dc
->DrawIcon( m_icon
, cell
.x
, cell
.y
);
857 wxSize
wxDataViewBitmapRenderer::GetSize() const
860 return wxSize( m_bitmap
.GetWidth(), m_bitmap
.GetHeight() );
861 else if (m_icon
.Ok())
862 return wxSize( m_icon
.GetWidth(), m_icon
.GetHeight() );
864 return wxSize(16,16);
867 // ---------------------------------------------------------
868 // wxDataViewToggleRenderer
869 // ---------------------------------------------------------
871 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
, wxDataViewCustomRenderer
)
873 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString
&varianttype
,
874 wxDataViewCellMode mode
, int align
) :
875 wxDataViewCustomRenderer( varianttype
, mode
, align
)
880 bool wxDataViewToggleRenderer::SetValue( const wxVariant
&value
)
882 m_toggle
= value
.GetBool();
887 bool wxDataViewToggleRenderer::GetValue( wxVariant
&WXUNUSED(value
) ) const
892 bool wxDataViewToggleRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
894 // User wxRenderer here
897 rect
.x
= cell
.x
+ cell
.width
/2 - 10;
899 rect
.y
= cell
.y
+ cell
.height
/2 - 10;
904 flags
|= wxCONTROL_CHECKED
;
905 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE
)
906 flags
|= wxCONTROL_DISABLED
;
908 wxRendererNative::Get().DrawCheckBox(
909 GetOwner()->GetOwner(),
917 bool wxDataViewToggleRenderer::Activate( wxRect
WXUNUSED(cell
),
918 wxDataViewModel
*model
,
919 const wxDataViewItem
& item
, unsigned int col
)
921 bool value
= !m_toggle
;
922 wxVariant variant
= value
;
923 model
->SetValue( variant
, item
, col
);
924 model
->ValueChanged( item
, col
);
928 wxSize
wxDataViewToggleRenderer::GetSize() const
930 return wxSize(20,20);
933 // ---------------------------------------------------------
934 // wxDataViewProgressRenderer
935 // ---------------------------------------------------------
937 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
, wxDataViewCustomRenderer
)
939 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString
&label
,
940 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
941 wxDataViewCustomRenderer( varianttype
, mode
, align
)
947 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
951 bool wxDataViewProgressRenderer::SetValue( const wxVariant
&value
)
953 m_value
= (long) value
;
955 if (m_value
< 0) m_value
= 0;
956 if (m_value
> 100) m_value
= 100;
961 bool wxDataViewProgressRenderer::GetValue( wxVariant
&value
) const
963 value
= (long) m_value
;
967 bool wxDataViewProgressRenderer::Render( wxRect cell
, wxDC
*dc
, int WXUNUSED(state
) )
969 double pct
= (double)m_value
/ 100.0;
971 bar
.width
= (int)(cell
.width
* pct
);
972 dc
->SetPen( *wxTRANSPARENT_PEN
);
973 dc
->SetBrush( *wxBLUE_BRUSH
);
974 dc
->DrawRectangle( bar
);
976 dc
->SetBrush( *wxTRANSPARENT_BRUSH
);
977 dc
->SetPen( *wxBLACK_PEN
);
978 dc
->DrawRectangle( cell
);
983 wxSize
wxDataViewProgressRenderer::GetSize() const
985 return wxSize(40,12);
988 // ---------------------------------------------------------
989 // wxDataViewDateRenderer
990 // ---------------------------------------------------------
992 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
994 #if wxUSE_DATE_RENDERER_POPUP
996 class wxDataViewDateRendererPopupTransient
: public wxPopupTransientWindow
999 wxDataViewDateRendererPopupTransient( wxWindow
* parent
, wxDateTime
*value
,
1000 wxDataViewModel
*model
, const wxDataViewItem
& item
, unsigned int col
) :
1001 wxPopupTransientWindow( parent
, wxBORDER_SIMPLE
),
1006 m_cal
= new wxCalendarCtrl( this, wxID_ANY
, *value
);
1007 wxBoxSizer
*sizer
= new wxBoxSizer( wxHORIZONTAL
);
1008 sizer
->Add( m_cal
, 1, wxGROW
);
1013 void OnCalendar( wxCalendarEvent
&event
);
1015 wxCalendarCtrl
*m_cal
;
1016 wxDataViewModel
*m_model
;
1018 const wxDataViewItem
& m_item
;
1021 virtual void OnDismiss()
1026 DECLARE_EVENT_TABLE()
1029 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient
,wxPopupTransientWindow
)
1030 EVT_CALENDAR( wxID_ANY
, wxDataViewDateRendererPopupTransient::OnCalendar
)
1033 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent
&event
)
1035 wxDateTime date
= event
.GetDate();
1036 wxVariant value
= date
;
1037 m_model
->SetValue( value
, m_item
, m_col
);
1038 m_model
->ValueChanged( m_item
, m_col
);
1042 #endif // wxUSE_DATE_RENDERER_POPUP
1044 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
, wxDataViewCustomRenderer
)
1046 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString
&varianttype
,
1047 wxDataViewCellMode mode
, int align
) :
1048 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1052 bool wxDataViewDateRenderer::SetValue( const wxVariant
&value
)
1054 m_date
= value
.GetDateTime();
1059 bool wxDataViewDateRenderer::GetValue( wxVariant
&value
) const
1065 bool wxDataViewDateRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1067 wxString tmp
= m_date
.FormatDate();
1068 RenderText( tmp
, 0, cell
, dc
, state
);
1072 wxSize
wxDataViewDateRenderer::GetSize() const
1074 const wxDataViewCtrl
* view
= GetView();
1075 wxString tmp
= m_date
.FormatDate();
1077 view
->GetTextExtent( tmp
, &x
, &y
, &d
);
1078 return wxSize(x
,y
+d
);
1081 bool wxDataViewDateRenderer::Activate( wxRect
WXUNUSED(cell
), wxDataViewModel
*model
,
1082 const wxDataViewItem
& item
, unsigned int col
)
1085 model
->GetValue( variant
, item
, col
);
1086 wxDateTime value
= variant
.GetDateTime();
1088 #if wxUSE_DATE_RENDERER_POPUP
1089 wxDataViewDateRendererPopupTransient
*popup
= new wxDataViewDateRendererPopupTransient(
1090 GetOwner()->GetOwner()->GetParent(), &value
, model
, item
, col
);
1091 wxPoint pos
= wxGetMousePosition();
1094 popup
->Popup( popup
->m_cal
);
1095 #else // !wxUSE_DATE_RENDERER_POPUP
1096 wxMessageBox(value
.Format());
1097 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1101 // ---------------------------------------------------------
1102 // wxDataViewIconTextRenderer
1103 // ---------------------------------------------------------
1105 IMPLEMENT_CLASS(wxDataViewIconTextRenderer
, wxDataViewCustomRenderer
)
1107 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1108 const wxString
&varianttype
, wxDataViewCellMode mode
, int align
) :
1109 wxDataViewCustomRenderer( varianttype
, mode
, align
)
1112 SetAlignment(align
);
1115 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1119 bool wxDataViewIconTextRenderer::SetValue( const wxVariant
&value
)
1125 bool wxDataViewIconTextRenderer::GetValue( wxVariant
& WXUNUSED(value
) ) const
1130 bool wxDataViewIconTextRenderer::Render( wxRect cell
, wxDC
*dc
, int state
)
1133 const wxIcon
&icon
= m_value
.GetIcon();
1136 dc
->DrawIcon( icon
, cell
.x
, cell
.y
+ ((cell
.height
- icon
.GetHeight()) / 2));
1137 xoffset
= icon
.GetWidth()+4;
1140 RenderText( m_value
.GetText(), xoffset
, cell
, dc
, state
);
1145 wxSize
wxDataViewIconTextRenderer::GetSize() const
1147 const wxDataViewCtrl
*view
= GetView();
1148 if (!m_value
.GetText().empty())
1151 view
->GetTextExtent( m_value
.GetText(), &x
, &y
);
1153 if (m_value
.GetIcon().IsOk())
1154 x
+= m_value
.GetIcon().GetWidth() + 4;
1155 return wxSize( x
, y
);
1157 return wxSize(80,20);
1161 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
1162 wxRect
WXUNUSED(labelRect
),
1163 const wxVariant
& WXUNUSED(value
))
1169 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
1170 wxVariant
& WXUNUSED(value
))
1175 // ---------------------------------------------------------
1177 // ---------------------------------------------------------
1179 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
, wxDataViewColumnBase
)
1181 wxDataViewColumn::wxDataViewColumn( const wxString
&title
, wxDataViewRenderer
*cell
,
1182 unsigned int model_column
,
1183 int width
, wxAlignment align
, int flags
) :
1184 wxDataViewColumnBase( title
, cell
, model_column
, width
, align
, flags
)
1186 SetAlignment(align
);
1190 m_autosize
= width
< 0; // TODO
1192 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1195 wxDataViewColumn::wxDataViewColumn( const wxBitmap
&bitmap
, wxDataViewRenderer
*cell
,
1196 unsigned int model_column
,
1197 int width
, wxAlignment align
, int flags
) :
1198 wxDataViewColumnBase( bitmap
, cell
, model_column
, width
, align
, flags
)
1200 SetAlignment(align
);
1203 Init(width
< 0 ? wxDVC_DEFAULT_WIDTH
: width
);
1206 wxDataViewColumn::~wxDataViewColumn()
1210 void wxDataViewColumn::Init( int width
)
1213 m_minWidth
= wxDVC_DEFAULT_MINWIDTH
;
1217 void wxDataViewColumn::SetResizeable( bool resizeable
)
1220 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
1222 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
1225 void wxDataViewColumn::SetHidden( bool hidden
)
1228 m_flags
|= wxDATAVIEW_COL_HIDDEN
;
1230 m_flags
&= ~wxDATAVIEW_COL_HIDDEN
;
1232 // tell our owner to e.g. update its scrollbars:
1234 GetOwner()->OnColumnChange();
1237 void wxDataViewColumn::SetSortable( bool sortable
)
1240 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
1242 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
1244 // Update header button
1246 GetOwner()->OnColumnChange();
1249 void wxDataViewColumn::SetReorderable( bool reorderable
)
1252 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
1254 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
1257 void wxDataViewColumn::SetSortOrder( bool ascending
)
1259 m_ascending
= ascending
;
1261 // Update header button
1263 GetOwner()->OnColumnChange();
1266 bool wxDataViewColumn::IsSortOrderAscending() const
1271 void wxDataViewColumn::SetInternalWidth( int width
)
1275 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
1276 if (m_owner
&& m_owner
->m_clientArea
)
1277 m_owner
->m_clientArea
->RecalculateDisplay();
1280 void wxDataViewColumn::SetWidth( int width
)
1282 if (m_owner
->m_headerArea
) m_owner
->m_headerArea
->UpdateDisplay();
1284 SetInternalWidth(width
);
1288 //-----------------------------------------------------------------------------
1289 // wxDataViewHeaderWindowBase
1290 //-----------------------------------------------------------------------------
1292 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type
, unsigned int n
)
1294 wxWindow
*parent
= GetParent();
1295 wxDataViewEvent
le(type
, parent
->GetId());
1297 le
.SetEventObject(parent
);
1299 le
.SetDataViewColumn(GetColumn(n
));
1300 le
.SetModel(GetOwner()->GetModel());
1302 // for events created by wxDataViewHeaderWindow the
1303 // row / value fields are not valid
1305 parent
->GetEventHandler()->ProcessEvent(le
);
1308 #ifdef USE_NATIVE_HEADER_WINDOW
1310 #ifndef HDS_DRAGDROP
1311 #define HDS_DRAGDROP 0x0040
1313 #ifndef HDS_FULLDRAG
1314 #define HDS_FULLDRAG 0x0080
1317 // implemented in msw/listctrl.cpp:
1318 int WXDLLIMPEXP_CORE
wxMSWGetColumnClicked(NMHDR
*nmhdr
, POINT
*ptClick
);
1320 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW
, wxWindow
)
1322 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl
*parent
, wxWindowID id
,
1323 const wxPoint
&pos
, const wxSize
&size
,
1324 const wxString
&name
)
1328 m_scrollOffsetX
= 0;
1329 m_delayedUpdate
= false;
1330 m_buttonHeight
= wxRendererNative::Get().GetHeaderButtonHeight( this );
1332 int x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
,
1333 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
,
1334 w
= size
.x
== wxDefaultCoord
? 1 : size
.x
,
1337 wxSize
new_size(w
,h
);
1339 if ( !CreateControl(parent
, id
, pos
, new_size
, 0, wxDefaultValidator
, name
) )
1342 // create the native WC_HEADER window:
1343 WXHWND hwndParent
= (HWND
)parent
->GetHandle();
1344 WXDWORD msStyle
= WS_CHILD
| HDS_DRAGDROP
| HDS_BUTTONS
| HDS_HORZ
| HDS_HOTTRACK
| HDS_FULLDRAG
;
1347 msStyle
|= WS_VISIBLE
;
1349 m_hWnd
= CreateWindowEx(0,
1360 wxLogLastError(_T("CreateWindowEx"));
1364 m_imageList
= new wxImageList( 16, 16 );
1365 Header_SetImageList( (HWND
) m_hWnd
, m_imageList
->GetHIMAGELIST() );
1367 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
1368 // to call wxDataViewHeaderWindow::MSWOnNotify
1369 SubclassWin(m_hWnd
);
1371 // the following is required to get the default win's font for
1372 // header windows and must be done befor sending the HDM_LAYOUT msg
1378 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
1384 wxSize
wxDataViewHeaderWindowMSW::DoGetBestSize() const
1386 return wxSize( 80, m_buttonHeight
+2 );
1389 void wxDataViewHeaderWindowMSW::OnInternalIdle()
1391 if (m_delayedUpdate
)
1393 m_delayedUpdate
= false;
1398 void wxDataViewHeaderWindowMSW::UpdateDisplay()
1400 // remove old columns
1401 for (int j
=0, max
=Header_GetItemCount((HWND
)m_hWnd
); j
< max
; j
++)
1402 Header_DeleteItem((HWND
)m_hWnd
, 0);
1404 m_imageList
->RemoveAll();
1406 // add the updated array of columns to the header control
1407 unsigned int cols
= GetOwner()->GetColumnCount();
1408 unsigned int added
= 0;
1409 for (unsigned int i
= 0; i
< cols
; i
++)
1411 wxDataViewColumn
*col
= GetColumn( i
);
1412 if (col
->IsHidden())
1413 continue; // don't add it!
1415 wxString
title( col
->GetTitle() );
1417 hdi
.mask
= HDI_TEXT
| HDI_FORMAT
| HDI_WIDTH
;
1418 if (col
->GetBitmap().IsOk())
1420 m_imageList
->Add( col
->GetBitmap() );
1421 hdi
.mask
|= HDI_IMAGE
;
1422 hdi
.iImage
= m_imageList
->GetImageCount()-1;
1424 hdi
.pszText
= (wxChar
*) title
.wx_str();
1425 hdi
.cxy
= col
->GetWidth();
1426 hdi
.cchTextMax
= sizeof(hdi
.pszText
)/sizeof(hdi
.pszText
[0]);
1427 hdi
.fmt
= HDF_LEFT
| HDF_STRING
;
1428 if (col
->GetBitmap().IsOk())
1429 hdi
.fmt
|= HDF_IMAGE
;
1431 //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
1433 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1435 //The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default
1436 //see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail
1437 // VZ: works with 5.81
1438 hdi
.fmt
|= col
->IsSortOrderAscending() ? HDF_SORTUP
: HDF_SORTDOWN
;
1441 // lParam is reserved for application's use:
1442 // we store there the column index to use it later in MSWOnNotify
1443 // (since columns may have been hidden)
1444 hdi
.lParam
= (LPARAM
)i
;
1446 // the native wxMSW implementation of the header window
1447 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1448 // on the right: to correct this effect we make the column
1449 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1451 hdi
.cxy
+= COLUMN_WIDTH_OFFSET
;
1453 switch (col
->GetAlignment())
1456 hdi
.fmt
|= HDF_LEFT
;
1458 case wxALIGN_CENTER
:
1459 case wxALIGN_CENTER_HORIZONTAL
:
1460 hdi
.fmt
|= HDF_CENTER
;
1463 hdi
.fmt
|= HDF_RIGHT
;
1467 // such alignment is not allowed for the column header!
1471 SendMessage((HWND
)m_hWnd
, HDM_INSERTITEM
,
1472 (WPARAM
)added
, (LPARAM
)&hdi
);
1477 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER
*nmHDR
)
1481 // NOTE: we don't just return nmHDR->iItem because when there are
1482 // hidden columns, nmHDR->iItem may be different from
1483 // nmHDR->pitem->lParam
1485 if (nmHDR
->pitem
&& nmHDR
->pitem
->mask
& HDI_LPARAM
)
1487 idx
= (unsigned int)nmHDR
->pitem
->lParam
;
1492 item
.mask
= HDI_LPARAM
;
1493 Header_GetItem((HWND
)m_hWnd
, nmHDR
->iItem
, &item
);
1495 return (unsigned int)item
.lParam
;
1498 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1500 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1502 // is it a message from the header?
1503 if ( nmhdr
->hwndFrom
!= (HWND
)m_hWnd
)
1504 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1506 NMHEADER
*nmHDR
= (NMHEADER
*)nmhdr
;
1507 switch ( nmhdr
->code
)
1509 case HDN_BEGINTRACK
:
1510 // user has started to resize a column:
1511 // do we need to veto it?
1512 if (!GetColumn(nmHDR
->iItem
)->IsResizeable())
1520 // user has started to reorder a column
1521 if ((nmHDR
->iItem
!= -1) && (!GetColumn(nmHDR
->iItem
)->IsReorderable()))
1528 case HDN_ENDDRAG
: // user has finished reordering a column
1530 wxDataViewColumn
*col
= GetColumn(nmHDR
->iItem
);
1531 unsigned int new_pos
= nmHDR
->pitem
->iOrder
;
1532 m_owner
->ColumnMoved( col
, new_pos
);
1533 m_delayedUpdate
= true;
1537 case HDN_ITEMCHANGING
:
1538 if (nmHDR
->pitem
!= NULL
&&
1539 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1541 int minWidth
= GetColumnFromHeader(nmHDR
)->GetMinWidth();
1542 if (nmHDR
->pitem
->cxy
< minWidth
)
1544 // do not allow the user to resize this column under
1545 // its minimal width:
1551 case HDN_ITEMCHANGED
: // user is resizing a column
1552 case HDN_ENDTRACK
: // user has finished resizing a column
1554 // update the width of the modified column:
1555 if (nmHDR
->pitem
!= NULL
&&
1556 (nmHDR
->pitem
->mask
& HDI_WIDTH
) != 0)
1558 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1559 unsigned int w
= nmHDR
->pitem
->cxy
;
1560 wxDataViewColumn
*col
= GetColumn(idx
);
1562 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1563 if (idx
== 0 && w
> COLUMN_WIDTH_OFFSET
)
1564 w
-= COLUMN_WIDTH_OFFSET
;
1566 if (w
>= (unsigned)col
->GetMinWidth())
1567 col
->SetInternalWidth(w
);
1573 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1574 wxDataViewModel
* model
= GetOwner()->GetModel();
1576 if(nmHDR
->iButton
== 0)
1578 wxDataViewColumn
*col
= GetColumn(idx
);
1579 if(col
->IsSortable())
1581 if(model
&& m_owner
->GetSortingColumn() == col
)
1583 bool order
= col
->IsSortOrderAscending();
1584 col
->SetSortOrder(!order
);
1588 m_owner
->SetSortingColumn(col
);
1596 wxEventType evt
= nmHDR
->iButton
== 0 ?
1597 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1598 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1599 SendEvent(evt
, idx
);
1605 // NOTE: for some reason (i.e. for a bug in Windows)
1606 // the HDN_ITEMCLICK notification is not sent on
1607 // right clicks, so we need to handle NM_RCLICK
1610 int column
= wxMSWGetColumnClicked(nmhdr
, &ptClick
);
1611 if (column
!= wxNOT_FOUND
)
1614 item
.mask
= HDI_LPARAM
;
1615 Header_GetItem((HWND
)m_hWnd
, column
, &item
);
1617 // 'idx' may be different from 'column' if there are
1618 // hidden columns...
1619 unsigned int idx
= (unsigned int)item
.lParam
;
1620 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
,
1626 case HDN_GETDISPINFOW
:
1627 // see wxListCtrl::MSWOnNotify for more info!
1630 case HDN_ITEMDBLCLICK
:
1632 unsigned int idx
= GetColumnIdxFromHeader(nmHDR
);
1633 int w
= GetOwner()->GetBestColumnWidth(idx
);
1635 // update the native control:
1637 ZeroMemory(&hd
, sizeof(hd
));
1638 hd
.mask
= HDI_WIDTH
;
1640 Header_SetItem(GetHwnd(),
1641 nmHDR
->iItem
, // NOTE: we don't want 'idx' here!
1644 // update the wxDataViewColumn class:
1645 GetColumn(idx
)->SetInternalWidth(w
);
1650 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
1656 void wxDataViewHeaderWindowMSW::ScrollWindow(int dx
, int WXUNUSED(dy
),
1657 const wxRect
* WXUNUSED(rect
))
1659 m_scrollOffsetX
+= dx
;
1661 GetParent()->Layout();
1664 void wxDataViewHeaderWindowMSW::DoSetSize(int x
, int y
,
1668 // TODO: why is there a border + 2px around it?
1669 wxControl::DoSetSize( x
+m_scrollOffsetX
+1, y
+1, w
-m_scrollOffsetX
-2, h
-2, f
);
1672 #else // !defined(__WXMSW__)
1674 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow
, wxWindow
)
1675 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow
, wxWindow
)
1676 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint
)
1677 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse
)
1678 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus
)
1681 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl
*parent
, wxWindowID id
,
1682 const wxPoint
&pos
, const wxSize
&size
,
1683 const wxString
&name
)
1687 if (!wxDataViewHeaderWindowBase::Create(parent
, id
, pos
, size
, name
))
1690 wxVisualAttributes attr
= wxPanel::GetClassDefaultAttributes();
1691 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1692 SetOwnForegroundColour( attr
.colFg
);
1693 SetOwnBackgroundColour( attr
.colBg
);
1695 SetOwnFont( attr
.font
);
1697 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1698 // a wxBoxSizer and in order to avoid super-big header windows,
1699 // we need to set our height as fixed
1700 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1701 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT
));
1706 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
1709 GetClientSize( &w
, &h
);
1711 wxAutoBufferedPaintDC
dc( this );
1713 dc
.SetBackground(GetBackgroundColour());
1717 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1720 m_owner
->GetViewStart( &x
, NULL
);
1722 // account for the horz scrollbar offset
1723 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1725 dc
.SetFont( GetFont() );
1727 unsigned int cols
= GetOwner()->GetColumnCount();
1730 for (i
= 0; i
< cols
; i
++)
1732 wxDataViewColumn
*col
= GetColumn( i
);
1733 if (col
->IsHidden())
1734 continue; // skip it!
1736 int cw
= col
->GetWidth();
1739 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
;
1740 if (col
->IsSortable() && GetOwner()->GetSortingColumn() == col
)
1742 if (col
->IsSortOrderAscending())
1743 sortArrow
= wxHDR_SORT_ICON_UP
;
1745 sortArrow
= wxHDR_SORT_ICON_DOWN
;
1749 if (m_parent
->IsEnabled())
1751 if ((int) i
== m_hover
)
1752 state
= wxCONTROL_CURRENT
;
1756 state
= (int) wxCONTROL_DISABLED
;
1759 wxRendererNative::Get().DrawHeaderButton
1763 wxRect(xpos
, 0, cw
, ch
-1),
1768 // align as required the column title:
1770 wxSize titleSz
= dc
.GetTextExtent(col
->GetTitle());
1771 switch (col
->GetAlignment())
1774 x
+= HEADER_HORIZ_BORDER
;
1777 x
+= cw
- titleSz
.GetWidth() - HEADER_HORIZ_BORDER
;
1780 case wxALIGN_CENTER
:
1781 case wxALIGN_CENTER_HORIZONTAL
:
1782 x
+= (cw
- titleSz
.GetWidth() - 2 * HEADER_HORIZ_BORDER
)/2;
1786 // always center the title vertically:
1787 int y
= wxMax((ch
- titleSz
.GetHeight()) / 2, HEADER_VERT_BORDER
);
1789 dc
.SetClippingRegion( xpos
+HEADER_HORIZ_BORDER
,
1791 wxMax(cw
- 2 * HEADER_HORIZ_BORDER
, 1), // width
1792 wxMax(ch
- 2 * HEADER_VERT_BORDER
, 1)); // height
1793 dc
.DrawText( col
->GetTitle(), x
, y
);
1794 dc
.DestroyClippingRegion();
1800 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent
&event
)
1802 GetParent()->SetFocus();
1806 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent
&event
)
1808 // we want to work with logical coords
1810 m_owner
->CalcUnscrolledPosition(event
.GetX(), 0, &x
, NULL
);
1811 int y
= event
.GetY();
1815 // we don't draw the line beyond our window,
1816 // but we allow dragging it there
1818 GetClientSize( &w
, NULL
);
1819 m_owner
->CalcUnscrolledPosition(w
, 0, &w
, NULL
);
1822 if (event
.ButtonUp())
1824 m_isDragging
= false;
1830 m_currentX
= wxMax(m_minX
+ 7, x
);
1834 GetColumn(m_column
)->SetWidth(m_currentX
- m_minX
);
1836 GetOwner()->Refresh();
1840 else // not dragging
1843 m_column
= wxNOT_FOUND
;
1845 bool hit_border
= false;
1847 // end of the current column
1850 // find the column where this event occured
1851 int countCol
= m_owner
->GetColumnCount();
1852 for (int column
= 0; column
< countCol
; column
++)
1854 wxDataViewColumn
*p
= GetColumn(column
);
1857 continue; // skip if not shown
1859 xpos
+= p
->GetWidth();
1861 if ((abs(x
-xpos
) < 3) && (y
< 22))
1869 // inside the column
1876 int old_hover
= m_hover
;
1878 if (event
.Leaving())
1879 m_hover
= wxNOT_FOUND
;
1880 if (old_hover
!= m_hover
)
1883 if (m_column
== wxNOT_FOUND
)
1886 bool resizeable
= GetColumn(m_column
)->IsResizeable();
1887 if (event
.LeftDClick() && resizeable
)
1889 GetColumn(m_column
)->SetWidth(GetOwner()->GetBestColumnWidth(m_column
));
1892 else if (event
.LeftDown() || event
.RightUp())
1894 if (hit_border
&& event
.LeftDown() && resizeable
)
1896 m_isDragging
= true;
1900 else // click on a column
1902 wxDataViewModel
* model
= GetOwner()->GetModel();
1903 wxEventType evt
= event
.LeftDown() ?
1904 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
:
1905 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
;
1906 SendEvent(evt
, m_column
);
1908 //Left click the header
1909 if(event
.LeftDown())
1911 wxDataViewColumn
*col
= GetColumn(m_column
);
1912 if(col
->IsSortable())
1914 wxDataViewColumn
* sortCol
= m_owner
->GetSortingColumn();
1915 if(model
&& sortCol
== col
)
1917 bool order
= col
->IsSortOrderAscending();
1918 col
->SetSortOrder(!order
);
1922 m_owner
->SetSortingColumn(col
);
1928 //Send the column sorted event
1929 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, m_column
);
1933 else if (event
.Moving())
1935 if (hit_border
&& resizeable
)
1936 m_currentCursor
= m_resizeCursor
;
1938 m_currentCursor
= wxSTANDARD_CURSOR
;
1940 SetCursor(*m_currentCursor
);
1945 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC
& dc
)
1949 m_owner
->GetScrollPixelsPerUnit( &xpix
, NULL
);
1950 m_owner
->GetViewStart( &x
, NULL
);
1952 // shift the DC origin to match the position of the main window horizontal
1953 // scrollbar: this allows us to always use logical coords
1954 dc
.SetDeviceOrigin( -x
* xpix
, 0 );
1957 #endif // defined(__WXMSW__)
1959 //-----------------------------------------------------------------------------
1960 // wxDataViewRenameTimer
1961 //-----------------------------------------------------------------------------
1963 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow
*owner
)
1968 void wxDataViewRenameTimer::Notify()
1970 m_owner
->OnRenameTimer();
1973 //-----------------------------------------------------------------------------
1974 // wxDataViewMainWindow
1975 //-----------------------------------------------------------------------------
1977 //The tree building helper, declared firstly
1978 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
);
1980 int LINKAGEMODE
wxDataViewSelectionCmp( unsigned int row1
, unsigned int row2
)
1982 if (row1
> row2
) return 1;
1983 if (row1
== row2
) return 0;
1988 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow
, wxWindow
)
1990 BEGIN_EVENT_TABLE(wxDataViewMainWindow
,wxWindow
)
1991 EVT_PAINT (wxDataViewMainWindow::OnPaint
)
1992 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse
)
1993 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus
)
1994 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus
)
1995 EVT_CHAR (wxDataViewMainWindow::OnChar
)
1998 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl
*parent
, wxWindowID id
,
1999 const wxPoint
&pos
, const wxSize
&size
, const wxString
&name
) :
2000 wxWindow( parent
, id
, pos
, size
, wxWANTS_CHARS
|wxBORDER_NONE
, name
),
2001 m_selection( wxDataViewSelectionCmp
)
2006 m_lastOnSame
= false;
2007 m_renameTimer
= new wxDataViewRenameTimer( this );
2009 // TODO: user better initial values/nothing selected
2010 m_currentCol
= NULL
;
2013 m_lineHeight
= wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
2016 m_dragStart
= wxPoint(0,0);
2017 m_lineLastClicked
= (unsigned int) -1;
2018 m_lineBeforeLastClicked
= (unsigned int) -1;
2019 m_lineSelectSingleOnUp
= (unsigned int) -1;
2023 SetBackgroundColour( *wxWHITE
);
2025 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
2027 m_penRule
= wxPen(GetRuleColour());
2029 //Here I compose a pen can draw black lines, maybe there are something system colour to use
2030 m_penExpander
= wxPen(wxColour(0,0,0));
2031 //Some new added code to deal with the tree structure
2032 m_root
= new wxDataViewTreeNode( NULL
);
2033 m_root
->SetHasChildren(true);
2035 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
2037 m_underMouse
= NULL
;
2041 wxDataViewMainWindow::~wxDataViewMainWindow()
2044 delete m_renameTimer
;
2047 void wxDataViewMainWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
2049 wxDataViewModel
*model
= GetOwner()->GetModel();
2050 wxAutoBufferedPaintDC
dc( this );
2053 dc
.SetPen( *wxTRANSPARENT_PEN
);
2054 dc
.SetBrush( wxBrush( GetBackgroundColour()) );
2055 dc
.SetBrush( *wxWHITE_BRUSH
);
2056 wxSize
size( GetClientSize() );
2057 dc
.DrawRectangle( 0,0,size
.x
,size
.y
);
2061 GetOwner()->PrepareDC( dc
);
2062 dc
.SetFont( GetFont() );
2064 wxRect update
= GetUpdateRegion().GetBox();
2065 m_owner
->CalcUnscrolledPosition( update
.x
, update
.y
, &update
.x
, &update
.y
);
2067 // compute which items needs to be redrawn
2068 unsigned int item_start
= GetLineAt( wxMax(0,update
.y
) );
2069 unsigned int item_count
=
2070 wxMin( (int)( GetLineAt( wxMax(0,update
.y
+update
.height
) ) - item_start
+ 1),
2071 (int)(GetRowCount( ) - item_start
));
2072 unsigned int item_last
= item_start
+ item_count
;
2074 // compute which columns needs to be redrawn
2075 unsigned int cols
= GetOwner()->GetColumnCount();
2076 unsigned int col_start
= 0;
2077 unsigned int x_start
= 0;
2078 for (x_start
= 0; col_start
< cols
; col_start
++)
2080 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_start
);
2081 if (col
->IsHidden())
2082 continue; // skip it!
2084 unsigned int w
= col
->GetWidth();
2085 if (x_start
+w
>= (unsigned int)update
.x
)
2091 unsigned int col_last
= col_start
;
2092 unsigned int x_last
= x_start
;
2093 for (; col_last
< cols
; col_last
++)
2095 wxDataViewColumn
*col
= GetOwner()->GetColumn(col_last
);
2096 if (col
->IsHidden())
2097 continue; // skip it!
2099 if (x_last
> (unsigned int)update
.GetRight())
2102 x_last
+= col
->GetWidth();
2105 // Draw horizontal rules if required
2106 if ( m_owner
->HasFlag(wxDV_HORIZ_RULES
) )
2108 dc
.SetPen(m_penRule
);
2109 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2111 for (unsigned int i
= item_start
; i
<= item_last
+1; i
++)
2113 int y
= GetLineStart( i
);
2114 dc
.DrawLine(x_start
, y
, x_last
, y
);
2118 // Draw vertical rules if required
2119 if ( m_owner
->HasFlag(wxDV_VERT_RULES
) )
2121 dc
.SetPen(m_penRule
);
2122 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
2125 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2127 wxDataViewColumn
*col
= GetOwner()->GetColumn(i
);
2128 if (col
->IsHidden())
2129 continue; // skip it
2131 dc
.DrawLine(x
, GetLineStart( item_start
),
2132 x
, GetLineStart( item_last
) );
2134 x
+= col
->GetWidth();
2137 // Draw last vertical rule
2138 dc
.DrawLine(x
, GetLineStart( item_start
),
2139 x
, GetLineStart( item_last
) );
2142 // redraw the background for the items which are selected/current
2143 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2145 bool selected
= m_selection
.Index( item
) != wxNOT_FOUND
;
2146 if (selected
|| item
== m_currentRow
)
2148 int flags
= selected
? (int)wxCONTROL_SELECTED
: 0;
2149 if (item
== m_currentRow
)
2150 flags
|= wxCONTROL_CURRENT
;
2152 flags
|= wxCONTROL_FOCUSED
;
2154 wxRect
rect( x_start
, GetLineStart( item
), x_last
, GetLineHeight( item
) );
2155 wxRendererNative::Get().DrawItemSelectionRect
2165 wxDataViewColumn
*expander
= GetOwner()->GetExpanderColumn();
2168 // TODO: last column for RTL support
2169 expander
= GetOwner()->GetColumn( 0 );
2170 GetOwner()->SetExpanderColumn(expander
);
2173 // redraw all cells for all rows which must be repainted and all columns
2175 cell_rect
.x
= x_start
;
2176 for (unsigned int i
= col_start
; i
< col_last
; i
++)
2179 wxDataViewColumn
*col
= GetOwner()->GetColumn( i
);
2180 wxDataViewRenderer
*cell
= col
->GetRenderer();
2181 cell_rect
.width
= col
->GetWidth();
2183 if (col
->IsHidden())
2184 continue; // skip it!
2186 for (unsigned int item
= item_start
; item
< item_last
; item
++)
2188 // get the cell value and set it into the renderer
2190 wxDataViewTreeNode
*node
= NULL
;
2191 wxDataViewItem dataitem
;
2193 if (!IsVirtualList())
2195 node
= GetTreeNodeByRow(item
);
2199 dataitem
= node
->GetItem();
2201 if ((i
> 0) && model
->IsContainer(dataitem
) && !model
->HasContainerColumns(dataitem
))
2206 dataitem
= wxDataViewItem( wxUIntToPtr(item
) );
2209 model
->GetValue( value
, dataitem
, col
->GetModelColumn());
2210 cell
->SetValue( value
);
2212 if (cell
->GetWantsAttr())
2214 wxDataViewItemAttr attr
;
2215 bool ret
= model
->GetAttr( dataitem
, col
->GetModelColumn(), attr
);
2217 cell
->SetAttr( attr
);
2218 cell
->SetHasAttr( ret
);
2222 cell_rect
.y
= GetLineStart( item
);
2223 cell_rect
.height
= GetLineHeight( item
); // -1 is for the horizontal rules (?)
2225 //Draw the expander here.
2227 if ((!IsVirtualList()) && (col
== expander
))
2229 indent
= node
->GetIndentLevel();
2231 //Calculate the indent first
2232 indent
= cell_rect
.x
+ GetOwner()->GetIndent() * indent
;
2234 int expander_width
= m_lineHeight
- 2*EXPANDER_MARGIN
;
2235 // change the cell_rect.x to the appropriate pos
2236 int expander_x
= indent
+ EXPANDER_MARGIN
;
2237 int expander_y
= cell_rect
.y
+ EXPANDER_MARGIN
+ (GetLineHeight(item
) / 2) - (expander_width
/2) - EXPANDER_OFFSET
;
2238 indent
= indent
+ m_lineHeight
; //try to use the m_lineHeight as the expander space
2239 dc
.SetPen( m_penExpander
);
2240 dc
.SetBrush( wxNullBrush
);
2241 if( node
->HasChildren() )
2243 wxRect
rect( expander_x
, expander_y
, expander_width
, expander_width
);
2245 if (m_underMouse
== node
)
2247 flag
|= wxCONTROL_CURRENT
;
2249 if( node
->IsOpen() )
2250 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
|wxCONTROL_EXPANDED
);
2252 wxRendererNative::Get().DrawTreeItemButton( this, dc
, rect
, flag
);
2254 //force the expander column to left-center align
2255 cell
->SetAlignment( wxALIGN_CENTER_VERTICAL
);
2257 if (node
&& !node
->HasChildren())
2259 // Yes, if the node does not have any child, it must be a leaf which
2260 // mean that it is a temporarily created by GetTreeNodeByRow
2264 // cannot be bigger than allocated space
2265 wxSize size
= cell
->GetSize();
2266 // Because of the tree structure indent, here we should minus the width of the cell for drawing
2267 size
.x
= wxMin( size
.x
+ 2*PADDING_RIGHTLEFT
, cell_rect
.width
- indent
);
2268 // size.y = wxMin( size.y, cell_rect.height );
2269 size
.y
= cell_rect
.height
;
2271 wxRect
item_rect(cell_rect
.GetTopLeft(), size
);
2272 int align
= cell
->CalculateAlignment();
2274 // horizontal alignment:
2275 item_rect
.x
= cell_rect
.x
;
2276 if (align
& wxALIGN_CENTER_HORIZONTAL
)
2277 item_rect
.x
= cell_rect
.x
+ (cell_rect
.width
/ 2) - (size
.x
/ 2);
2278 else if (align
& wxALIGN_RIGHT
)
2279 item_rect
.x
= cell_rect
.x
+ cell_rect
.width
- size
.x
;
2280 //else: wxALIGN_LEFT is the default
2282 // vertical alignment:
2283 item_rect
.y
= cell_rect
.y
;
2284 if (align
& wxALIGN_CENTER_VERTICAL
)
2285 item_rect
.y
= cell_rect
.y
+ (cell_rect
.height
/ 2) - (size
.y
/ 2);
2286 else if (align
& wxALIGN_BOTTOM
)
2287 item_rect
.y
= cell_rect
.y
+ cell_rect
.height
- size
.y
;
2288 //else: wxALIGN_TOP is the default
2291 item_rect
.x
+= PADDING_RIGHTLEFT
;
2292 item_rect
.width
= size
.x
- 2 * PADDING_RIGHTLEFT
;
2294 //Here we add the tree indent
2295 item_rect
.x
+= indent
;
2298 if (m_hasFocus
&& (m_selection
.Index(item
) != wxNOT_FOUND
))
2299 state
|= wxDATAVIEW_CELL_SELECTED
;
2301 // TODO: it would be much more efficient to create a clipping
2302 // region for the entire column being rendered (in the OnPaint
2303 // of wxDataViewMainWindow) instead of a single clip region for
2304 // each cell. However it would mean that each renderer should
2305 // respect the given wxRect's top & bottom coords, eventually
2306 // violating only the left & right coords - however the user can
2307 // make its own renderer and thus we cannot be sure of that.
2308 dc
.SetClippingRegion( item_rect
);
2309 cell
->Render( item_rect
, &dc
, state
);
2310 dc
.DestroyClippingRegion();
2313 cell_rect
.x
+= cell_rect
.width
;
2317 void wxDataViewMainWindow::OnRenameTimer()
2319 // We have to call this here because changes may just have
2320 // been made and no screen update taken place.
2325 unsigned int cols
= GetOwner()->GetColumnCount();
2327 for (i
= 0; i
< cols
; i
++)
2329 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
2331 continue; // skip it!
2333 if (c
== m_currentCol
)
2335 xpos
+= c
->GetWidth();
2337 wxRect
labelRect( xpos
,
2338 GetLineStart( m_currentRow
),
2339 m_currentCol
->GetWidth(),
2340 GetLineHeight( m_currentRow
) );
2342 GetOwner()->CalcScrolledPosition( labelRect
.x
, labelRect
.y
,
2343 &labelRect
.x
, &labelRect
.y
);
2345 wxDataViewItem item
= GetItemByRow( m_currentRow
);
2346 m_currentCol
->GetRenderer()->StartEditing( item
, labelRect
);
2350 //------------------------------------------------------------------
2351 // Helper class for do operation on the tree node
2352 //------------------------------------------------------------------
2359 //The return value control how the tree-walker tranverse the tree
2360 // 0: Job done, stop tranverse and return
2361 // 1: Ignore the current node's subtree and continue
2362 // 2: Job not done, continue
2363 enum { OK
= 0 , IGR
= 1, CONT
= 2 };
2364 virtual int operator() ( wxDataViewTreeNode
* node
) = 0 ;
2365 virtual int operator() ( void * n
) = 0;
2368 bool Walker( wxDataViewTreeNode
* node
, DoJob
& func
)
2373 switch( func( node
) )
2384 wxDataViewTreeNodes nodes
= node
->GetNodes();
2385 wxDataViewTreeLeaves leaves
= node
->GetChildren();
2387 int len_nodes
= nodes
.GetCount();
2388 int len
= leaves
.GetCount();
2389 int i
= 0, nodes_i
= 0;
2391 for( ; i
< len
; i
++ )
2393 void * n
= leaves
[i
];
2394 if( nodes_i
< len_nodes
&& n
== nodes
[nodes_i
]->GetItem().GetID() )
2396 wxDataViewTreeNode
* nd
= nodes
[nodes_i
];
2399 if( Walker( nd
, func
) )
2418 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem
& parent
, const wxDataViewItem
& item
)
2429 wxDataViewTreeNode
* node
;
2430 node
= FindNode(parent
);
2435 node
->SetHasChildren( true );
2437 if( g_model
->IsContainer( item
) )
2439 wxDataViewTreeNode
* newnode
= new wxDataViewTreeNode( node
);
2440 newnode
->SetItem(item
);
2441 newnode
->SetHasChildren( true );
2442 node
->AddNode( newnode
);
2445 node
->AddLeaf( item
.GetID() );
2447 node
->ChangeSubTreeCount(1);
2455 static void DestroyTreeHelper( wxDataViewTreeNode
* node
);
2457 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem
& parent
,
2458 const wxDataViewItem
& item
)
2463 if( m_currentRow
> GetRowCount() )
2464 m_currentRow
= m_count
- 1;
2466 m_selection
.Empty();
2473 wxDataViewTreeNode
* node
= FindNode(parent
);
2475 wxCHECK_MSG( node
!= NULL
, false, "item not found" );
2476 wxCHECK_MSG( node
->GetChildren().Index( item
.GetID() ) != wxNOT_FOUND
, false, "item not found" );
2479 node
->GetChildren().Remove( item
.GetID() );
2480 //Manuplate selection
2481 if( m_selection
.GetCount() > 1 )
2483 m_selection
.Empty();
2485 bool isContainer
= false;
2486 wxDataViewTreeNodes nds
= node
->GetNodes();
2487 for (size_t i
= 0; i
< nds
.GetCount(); i
++)
2489 if (nds
[i
]->GetItem() == item
)
2497 wxDataViewTreeNode
* n
= NULL
;
2498 wxDataViewTreeNodes nodes
= node
->GetNodes();
2499 int len
= nodes
.GetCount();
2500 for( int i
= 0 ; i
< len
; i
++)
2502 if( nodes
[i
]->GetItem() == item
)
2509 wxCHECK_MSG( n
!= NULL
, false, "item not found" );
2511 node
->GetNodes().Remove( n
);
2512 sub
-= n
->GetSubTreeCount();
2513 ::DestroyTreeHelper(n
);
2515 //Make the row number invalid and get a new valid one when user call GetRowCount
2517 node
->ChangeSubTreeCount(sub
);
2519 //Change the current row to the last row if the current exceed the max row number
2520 if( m_currentRow
> GetRowCount() )
2521 m_currentRow
= m_count
- 1;
2528 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem
& item
)
2534 wxWindow
*parent
= GetParent();
2535 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2536 le
.SetEventObject(parent
);
2537 le
.SetModel(GetOwner()->GetModel());
2539 parent
->GetEventHandler()->ProcessEvent(le
);
2544 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem
& item
, unsigned int col
)
2546 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
2547 /*#define MAX_VIRTUAL_WIDTH 100000
2549 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
2550 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2551 Refresh( true, &rect );
2559 wxWindow
*parent
= GetParent();
2560 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, parent
->GetId());
2561 le
.SetEventObject(parent
);
2562 le
.SetModel(GetOwner()->GetModel());
2565 le
.SetDataViewColumn(GetOwner()->GetColumn(col
));
2566 parent
->GetEventHandler()->ProcessEvent(le
);
2571 bool wxDataViewMainWindow::Cleared()
2576 BuildTree( GetOwner()->GetModel() );
2583 void wxDataViewMainWindow::UpdateDisplay()
2588 void wxDataViewMainWindow::OnInternalIdle()
2590 wxWindow::OnInternalIdle();
2594 RecalculateDisplay();
2599 void wxDataViewMainWindow::RecalculateDisplay()
2601 wxDataViewModel
*model
= GetOwner()->GetModel();
2608 int width
= GetEndOfLastCol();
2609 int height
= GetLineStart( GetRowCount() );
2611 SetVirtualSize( width
, height
);
2612 GetOwner()->SetScrollRate( 10, m_lineHeight
);
2617 void wxDataViewMainWindow::ScrollWindow( int dx
, int dy
, const wxRect
*rect
)
2619 wxWindow::ScrollWindow( dx
, dy
, rect
);
2621 if (GetOwner()->m_headerArea
)
2622 GetOwner()->m_headerArea
->ScrollWindow( dx
, 0 );
2625 void wxDataViewMainWindow::ScrollTo( int rows
, int column
)
2628 m_owner
->GetScrollPixelsPerUnit( &x
, &y
);
2629 int sy
= GetLineStart( rows
)/y
;
2633 wxRect rect
= GetClientRect();
2635 int x_start
= 0, x_end
= 0, w
= 0;
2637 m_owner
->CalcUnscrolledPosition( rect
.x
, rect
.y
, &xx
, &yy
);
2638 for (x_start
= 0; colnum
< column
; colnum
++)
2640 wxDataViewColumn
*col
= GetOwner()->GetColumn(colnum
);
2641 if (col
->IsHidden())
2642 continue; // skip it!
2644 w
= col
->GetWidth();
2648 x_end
= x_start
+ w
;
2649 xe
= xx
+ rect
.width
;
2652 sx
= ( xx
+ x_end
- xe
)/x
;
2659 m_owner
->Scroll( sx
, sy
);
2662 int wxDataViewMainWindow::GetCountPerPage() const
2664 wxSize size
= GetClientSize();
2665 return size
.y
/ m_lineHeight
;
2668 int wxDataViewMainWindow::GetEndOfLastCol() const
2672 for (i
= 0; i
< GetOwner()->GetColumnCount(); i
++)
2674 const wxDataViewColumn
*c
=
2675 wx_const_cast(wxDataViewCtrl
*, GetOwner())->GetColumn( i
);
2678 width
+= c
->GetWidth();
2683 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2687 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
2689 return GetLineAt( y
);
2692 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
2694 wxSize client_size
= GetClientSize();
2695 m_owner
->CalcUnscrolledPosition( client_size
.x
, client_size
.y
,
2696 &client_size
.x
, &client_size
.y
);
2698 //we should deal with the pixel here
2699 unsigned int row
= GetLineAt(client_size
.y
) - 1;
2701 return wxMin( GetRowCount()-1, row
);
2704 unsigned int wxDataViewMainWindow::GetRowCount()
2706 if ( m_count
== -1 )
2708 m_count
= RecalculateCount();
2714 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row
)
2721 void wxDataViewMainWindow::SelectAllRows( bool on
)
2728 m_selection
.Clear();
2729 for (unsigned int i
= 0; i
< GetRowCount(); i
++)
2730 m_selection
.Add( i
);
2735 unsigned int first_visible
= GetFirstVisibleRow();
2736 unsigned int last_visible
= GetLastVisibleRow();
2738 for (i
= 0; i
< m_selection
.GetCount(); i
++)
2740 unsigned int row
= m_selection
[i
];
2741 if ((row
>= first_visible
) && (row
<= last_visible
))
2744 m_selection
.Clear();
2748 void wxDataViewMainWindow::SelectRow( unsigned int row
, bool on
)
2750 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2754 m_selection
.Add( row
);
2762 m_selection
.Remove( row
);
2768 void wxDataViewMainWindow::SelectRows( unsigned int from
, unsigned int to
, bool on
)
2772 unsigned int tmp
= from
;
2778 for (i
= from
; i
<= to
; i
++)
2780 if (m_selection
.Index( i
) == wxNOT_FOUND
)
2783 m_selection
.Add( i
);
2788 m_selection
.Remove( i
);
2791 RefreshRows( from
, to
);
2794 void wxDataViewMainWindow::Select( const wxArrayInt
& aSelections
)
2796 for (size_t i
=0; i
< aSelections
.GetCount(); i
++)
2798 int n
= aSelections
[i
];
2800 m_selection
.Add( n
);
2805 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row
)
2807 if (m_selection
.Index( row
) == wxNOT_FOUND
)
2808 m_selection
.Add( row
);
2810 m_selection
.Remove( row
);
2814 bool wxDataViewMainWindow::IsRowSelected( unsigned int row
)
2816 return (m_selection
.Index( row
) != wxNOT_FOUND
);
2819 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem
& item
)
2821 wxWindow
*parent
= GetParent();
2822 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, parent
->GetId());
2824 le
.SetEventObject(parent
);
2825 le
.SetModel(GetOwner()->GetModel());
2828 parent
->GetEventHandler()->ProcessEvent(le
);
2831 void wxDataViewMainWindow::RefreshRow( unsigned int row
)
2833 wxRect
rect( 0, GetLineStart( row
), GetEndOfLastCol(), GetLineHeight( row
) );
2834 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2836 wxSize client_size
= GetClientSize();
2837 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2838 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2839 if (intersect_rect
.width
> 0)
2840 Refresh( true, &intersect_rect
);
2843 void wxDataViewMainWindow::RefreshRows( unsigned int from
, unsigned int to
)
2847 unsigned int tmp
= to
;
2852 wxRect
rect( 0, GetLineStart( from
), GetEndOfLastCol(), GetLineStart( (to
-from
+1) ) );
2853 m_owner
->CalcScrolledPosition( rect
.x
, rect
.y
, &rect
.x
, &rect
.y
);
2855 wxSize client_size
= GetClientSize();
2856 wxRect
client_rect( 0, 0, client_size
.x
, client_size
.y
);
2857 wxRect intersect_rect
= client_rect
.Intersect( rect
);
2858 if (intersect_rect
.width
> 0)
2859 Refresh( true, &intersect_rect
);
2862 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow
)
2864 wxSize client_size
= GetClientSize();
2865 int start
= GetLineStart( firstRow
);
2866 m_owner
->CalcScrolledPosition( start
, 0, &start
, NULL
);
2867 if (start
> client_size
.y
) return;
2869 wxRect
rect( 0, start
, client_size
.x
, client_size
.y
- start
);
2871 Refresh( true, &rect
);
2874 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent
, const wxKeyEvent
& event
)
2876 wxCHECK_RET( newCurrent
< GetRowCount(),
2877 _T("invalid item index in OnArrowChar()") );
2879 // if there is no selection, we cannot move it anywhere
2880 if (!HasCurrentRow())
2883 unsigned int oldCurrent
= m_currentRow
;
2885 // in single selection we just ignore Shift as we can't select several
2887 if ( event
.ShiftDown() && !IsSingleSel() )
2889 RefreshRow( oldCurrent
);
2891 ChangeCurrentRow( newCurrent
);
2893 // select all the items between the old and the new one
2894 if ( oldCurrent
> newCurrent
)
2896 newCurrent
= oldCurrent
;
2897 oldCurrent
= m_currentRow
;
2900 SelectRows( oldCurrent
, newCurrent
, true );
2901 if (oldCurrent
!=newCurrent
)
2902 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]));
2906 RefreshRow( oldCurrent
);
2908 // all previously selected items are unselected unless ctrl is held
2909 if ( !event
.ControlDown() )
2910 SelectAllRows(false);
2912 ChangeCurrentRow( newCurrent
);
2914 if ( !event
.ControlDown() )
2916 SelectRow( m_currentRow
, true );
2917 SendSelectionChangedEvent(GetItemByRow(m_currentRow
));
2920 RefreshRow( m_currentRow
);
2923 GetOwner()->EnsureVisible( m_currentRow
, -1 );
2926 wxRect
wxDataViewMainWindow::GetLineRect( unsigned int row
) const
2930 rect
.y
= GetLineStart( row
);
2931 rect
.width
= GetEndOfLastCol();
2932 rect
.height
= GetLineHeight( row
);
2937 int wxDataViewMainWindow::GetLineStart( unsigned int row
) const
2939 const wxDataViewModel
*model
= GetOwner()->GetModel();
2941 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
2943 // TODO make more efficient
2948 for (r
= 0; r
< row
; r
++)
2950 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(r
);
2951 if (!node
) return start
;
2953 wxDataViewItem item
= node
->GetItem();
2955 if (node
&& !node
->HasChildren())
2957 // Yes, if the node does not have any child, it must be a leaf which
2958 // mean that it is a temporarily created by GetTreeNodeByRow
2962 unsigned int cols
= GetOwner()->GetColumnCount();
2964 int height
= m_lineHeight
;
2965 for (col
= 0; col
< cols
; col
++)
2967 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
2968 if (column
->IsHidden())
2969 continue; // skip it!
2971 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
2972 continue; // skip it!
2974 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
2976 model
->GetValue( value
, item
, column
->GetModelColumn() );
2977 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
2978 renderer2
->SetValue( value
);
2979 height
= wxMax( height
, renderer
->GetSize().y
);
2990 return row
* m_lineHeight
;
2994 int wxDataViewMainWindow::GetLineAt( unsigned int y
) const
2996 const wxDataViewModel
*model
= GetOwner()->GetModel();
2998 // check for the easy case first
2999 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT
) )
3000 return y
/ m_lineHeight
;
3002 // TODO make more efficient
3003 unsigned int row
= 0;
3004 unsigned int yy
= 0;
3007 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3010 // not really correct...
3011 return row
+ ((y
-yy
) / m_lineHeight
);
3014 wxDataViewItem item
= node
->GetItem();
3016 if (node
&& !node
->HasChildren())
3018 // Yes, if the node does not have any child, it must be a leaf which
3019 // mean that it is a temporarily created by GetTreeNodeByRow
3023 unsigned int cols
= GetOwner()->GetColumnCount();
3025 int height
= m_lineHeight
;
3026 for (col
= 0; col
< cols
; col
++)
3028 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3029 if (column
->IsHidden())
3030 continue; // skip it!
3032 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3033 continue; // skip it!
3035 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3037 model
->GetValue( value
, item
, column
->GetModelColumn() );
3038 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3039 renderer2
->SetValue( value
);
3040 height
= wxMax( height
, renderer
->GetSize().y
);
3051 int wxDataViewMainWindow::GetLineHeight( unsigned int row
) const
3053 const wxDataViewModel
*model
= GetOwner()->GetModel();
3055 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
3057 wxASSERT( !IsVirtualList() );
3059 const wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3060 // wxASSERT( node );
3061 if (!node
) return m_lineHeight
;
3063 wxDataViewItem item
= node
->GetItem();
3065 if (node
&& !node
->HasChildren())
3067 // Yes, if the node does not have any child, it must be a leaf which
3068 // mean that it is a temporarily created by GetTreeNodeByRow
3072 int height
= m_lineHeight
;
3074 unsigned int cols
= GetOwner()->GetColumnCount();
3076 for (col
= 0; col
< cols
; col
++)
3078 const wxDataViewColumn
*column
= GetOwner()->GetColumn(col
);
3079 if (column
->IsHidden())
3080 continue; // skip it!
3082 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
3083 continue; // skip it!
3085 const wxDataViewRenderer
*renderer
= column
->GetRenderer();
3087 model
->GetValue( value
, item
, column
->GetModelColumn() );
3088 wxDataViewRenderer
*renderer2
= const_cast<wxDataViewRenderer
*>(renderer
);
3089 renderer2
->SetValue( value
);
3090 height
= wxMax( height
, renderer
->GetSize().y
);
3097 return m_lineHeight
;
3101 class RowToItemJob
: public DoJob
3104 RowToItemJob( unsigned int row
, int current
) { this->row
= row
; this->current
= current
;}
3105 virtual ~RowToItemJob(){};
3107 virtual int operator() ( wxDataViewTreeNode
* node
)
3110 if( current
== static_cast<int>(row
))
3112 ret
= node
->GetItem() ;
3116 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3118 current
+= node
->GetSubTreeCount();
3123 //If the current has no child node, we can find the desired item of the row number directly.
3124 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3125 if( node
->GetNodes().GetCount() == 0)
3127 int index
= static_cast<int>(row
) - current
- 1;
3128 ret
= node
->GetChildren().Item( index
);
3135 virtual int operator() ( void * n
)
3138 if( current
== static_cast<int>(row
))
3140 ret
= wxDataViewItem( n
) ;
3145 wxDataViewItem
GetResult(){ return ret
; }
3152 wxDataViewItem
wxDataViewMainWindow::GetItemByRow(unsigned int row
) const
3156 return wxDataViewItem( wxUIntToPtr(row
) );
3160 RowToItemJob
job( row
, -2 );
3161 Walker( m_root
, job
);
3162 return job
.GetResult();
3166 class RowToTreeNodeJob
: public DoJob
3169 RowToTreeNodeJob( unsigned int row
, int current
, wxDataViewTreeNode
* node
)
3172 this->current
= current
;
3176 virtual ~RowToTreeNodeJob(){};
3178 virtual int operator() ( wxDataViewTreeNode
* node
)
3181 if( current
== static_cast<int>(row
))
3187 if( node
->GetSubTreeCount() + current
< static_cast<int>(row
) )
3189 current
+= node
->GetSubTreeCount();
3195 //If the current has no child node, we can find the desired item of the row number directly.
3196 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
3197 if( node
->GetNodes().GetCount() == 0)
3199 int index
= static_cast<int>(row
) - current
- 1;
3200 void * n
= node
->GetChildren().Item( index
);
3201 ret
= new wxDataViewTreeNode( parent
) ;
3202 ret
->SetItem( wxDataViewItem( n
));
3203 ret
->SetHasChildren(false);
3212 virtual int operator() ( void * n
)
3215 if( current
== static_cast<int>(row
))
3217 ret
= new wxDataViewTreeNode( parent
) ;
3218 ret
->SetItem( wxDataViewItem( n
));
3219 ret
->SetHasChildren(false);
3225 wxDataViewTreeNode
* GetResult(){ return ret
; }
3229 wxDataViewTreeNode
* ret
;
3230 wxDataViewTreeNode
* parent
;
3234 wxDataViewTreeNode
* wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row
) const
3236 wxASSERT( !IsVirtualList() );
3238 RowToTreeNodeJob
job( row
, -2, m_root
);
3239 Walker( m_root
, job
);
3240 return job
.GetResult();
3243 wxDataViewEvent
wxDataViewMainWindow::SendExpanderEvent( wxEventType type
, const wxDataViewItem
& item
)
3245 wxWindow
*parent
= GetParent();
3246 wxDataViewEvent
le(type
, parent
->GetId());
3248 le
.SetEventObject(parent
);
3249 le
.SetModel(GetOwner()->GetModel());
3252 parent
->GetEventHandler()->ProcessEvent(le
);
3256 void wxDataViewMainWindow::OnExpanding( unsigned int row
)
3258 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3261 if( node
->HasChildren())
3263 if( !node
->IsOpen())
3265 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,node
->GetItem());
3266 //Check if the user prevent expanding
3267 if( e
.GetSkipped() )
3271 //Here I build the children of current node
3272 if( node
->GetChildrenNumber() == 0 )
3275 ::BuildTreeHelper(GetOwner()->GetModel(), node
->GetItem(), node
);
3279 //Send the expanded event
3280 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,node
->GetItem());
3284 SelectRow( row
, false );
3285 SelectRow( row
+ 1, true );
3286 ChangeCurrentRow( row
+ 1 );
3287 SendSelectionChangedEvent( GetItemByRow(row
+1));
3295 void wxDataViewMainWindow::OnCollapsing(unsigned int row
)
3297 wxDataViewTreeNode
* node
= GetTreeNodeByRow(row
);
3300 wxDataViewTreeNode
* nd
= node
;
3302 if( node
->HasChildren() && node
->IsOpen() )
3304 wxDataViewEvent e
= SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,node
->GetItem());
3305 if( e
.GetSkipped() )
3310 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,nd
->GetItem());
3314 node
= node
->GetParent();
3317 int parent
= GetRowByItem( node
->GetItem() ) ;
3320 SelectRow( row
, false);
3321 SelectRow(parent
, true );
3322 ChangeCurrentRow( parent
);
3323 SendSelectionChangedEvent( node
->GetItem() );
3327 if( !nd
->HasChildren())
3332 wxDataViewTreeNode
* wxDataViewMainWindow::FindNode( const wxDataViewItem
& item
)
3334 wxDataViewModel
* model
= GetOwner()->GetModel();
3338 //Compose the a parent-chain of the finding item
3340 list
.DeleteContents( true );
3341 wxDataViewItem
it( item
);
3344 wxDataViewItem
* pItem
= new wxDataViewItem( it
);
3345 list
.Insert( pItem
);
3346 it
= model
->GetParent( it
);
3349 //Find the item along the parent-chain.
3350 //This algorithm is designed to speed up the node-finding method
3351 wxDataViewTreeNode
* node
= m_root
;
3352 for( ItemList::const_iterator iter
= list
.begin(); iter
!=list
.end() ; iter
++ )
3354 if( node
->HasChildren() )
3356 if( node
->GetChildrenNumber() == 0 )
3359 ::BuildTreeHelper(model
, node
->GetItem(), node
);
3362 wxDataViewTreeNodes nodes
= node
->GetNodes();
3366 for (i
= 0; i
< nodes
.GetCount(); i
++)
3368 if (nodes
[i
]->GetItem() == (**iter
))
3370 if (nodes
[i
]->GetItem() == item
)
3387 void wxDataViewMainWindow::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
)
3389 wxDataViewColumn
*col
= NULL
;
3390 unsigned int cols
= GetOwner()->GetColumnCount();
3391 unsigned int colnum
= 0;
3392 unsigned int x_start
= 0;
3394 m_owner
->CalcUnscrolledPosition( point
.x
, point
.y
, &x
, &y
);
3395 for (x_start
= 0; colnum
< cols
; colnum
++)
3397 col
= GetOwner()->GetColumn(colnum
);
3398 if (col
->IsHidden())
3399 continue; // skip it!
3401 unsigned int w
= col
->GetWidth();
3402 if (x_start
+w
>= (unsigned int)x
)
3409 item
= GetItemByRow( GetLineAt( y
) );
3412 wxRect
wxDataViewMainWindow::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
3414 int row
= GetRowByItem(item
);
3415 int y
= GetLineStart( row
);
3416 int h
= GetLineHeight( m_lineHeight
);
3418 wxDataViewColumn
*col
= NULL
;
3419 for( int i
= 0, cols
= GetOwner()->GetColumnCount(); i
< cols
; i
++ )
3421 col
= GetOwner()->GetColumn( i
);
3422 x
+= col
->GetWidth();
3423 if( GetOwner()->GetColumn(i
+1) == column
)
3426 int w
= col
->GetWidth();
3427 m_owner
->CalcScrolledPosition( x
, y
, &x
, &y
);
3428 return wxRect(x
, y
, w
, h
);
3431 int wxDataViewMainWindow::RecalculateCount()
3435 wxDataViewIndexListModel
*list_model
= (wxDataViewIndexListModel
*) GetOwner()->GetModel();
3437 return list_model
->GetLastIndex() + 1;
3439 return list_model
->GetLastIndex() - 1;
3444 return m_root
->GetSubTreeCount();
3448 class ItemToRowJob
: public DoJob
3451 ItemToRowJob(const wxDataViewItem
& item
, ItemList::const_iterator iter
)
3452 { this->item
= item
; ret
= -1 ; m_iter
= iter
; }
3453 virtual ~ItemToRowJob(){};
3455 //Maybe binary search will help to speed up this process
3456 virtual int operator() ( wxDataViewTreeNode
* node
)
3459 if( node
->GetItem() == item
)
3464 if( node
->GetItem() == **m_iter
)
3471 ret
+= node
->GetSubTreeCount();
3477 virtual int operator() ( void * n
)
3480 if( n
== item
.GetID() )
3484 //the row number is begin from zero
3485 int GetResult(){ return ret
-1 ; }
3487 ItemList::const_iterator m_iter
;
3488 wxDataViewItem item
;
3493 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem
& item
) const
3495 const wxDataViewModel
* model
= GetOwner()->GetModel();
3501 return wxPtrToUInt( item
.GetID() );
3508 //Compose the a parent-chain of the finding item
3510 wxDataViewItem
* pItem
= NULL
;
3511 list
.DeleteContents( true );
3512 wxDataViewItem
it( item
);
3515 pItem
= new wxDataViewItem( it
);
3516 list
.Insert( pItem
);
3517 it
= model
->GetParent( it
);
3519 pItem
= new wxDataViewItem( );
3520 list
.Insert( pItem
);
3522 ItemToRowJob
job( item
, list
.begin() );
3523 Walker(m_root
, job
);
3524 return job
.GetResult();
3528 static void BuildTreeHelper( wxDataViewModel
* model
, wxDataViewItem
& item
, wxDataViewTreeNode
* node
)
3530 if( !model
->IsContainer( item
) )
3533 wxDataViewItemArray children
;
3534 unsigned int num
= model
->GetChildren( item
, children
);
3535 unsigned int index
= 0;
3536 while( index
< num
)
3538 if( model
->IsContainer( children
[index
] ) )
3540 wxDataViewTreeNode
* n
= new wxDataViewTreeNode( node
);
3541 n
->SetItem(children
[index
]);
3542 n
->SetHasChildren( true ) ;
3547 node
->AddLeaf( children
[index
].GetID() );
3551 node
->SetSubTreeCount( num
);
3552 wxDataViewTreeNode
* n
= node
->GetParent();
3554 n
->ChangeSubTreeCount(num
);
3558 void wxDataViewMainWindow::BuildTree(wxDataViewModel
* model
)
3562 if (GetOwner()->GetModel()->IsVirtualListModel())
3568 m_root
= new wxDataViewTreeNode( NULL
);
3569 m_root
->SetHasChildren(true);
3571 //First we define a invalid item to fetch the top-level elements
3572 wxDataViewItem item
;
3574 BuildTreeHelper( model
, item
, m_root
);
3578 static void DestroyTreeHelper( wxDataViewTreeNode
* node
)
3580 if( node
->GetNodeNumber() != 0 )
3582 int len
= node
->GetNodeNumber();
3584 wxDataViewTreeNodes
& nodes
= node
->GetNodes();
3585 for( ; i
< len
; i
++ )
3587 DestroyTreeHelper(nodes
[i
]);
3593 void wxDataViewMainWindow::DestroyTree()
3595 if (!IsVirtualList())
3597 ::DestroyTreeHelper(m_root
);
3603 void wxDataViewMainWindow::OnChar( wxKeyEvent
&event
)
3605 if ( HandleAsNavigationKey(event
) )
3608 // no item -> nothing to do
3609 if (!HasCurrentRow())
3615 // don't use m_linesPerPage directly as it might not be computed yet
3616 const int pageSize
= GetCountPerPage();
3617 wxCHECK_RET( pageSize
, _T("should have non zero page size") );
3619 switch ( event
.GetKeyCode() )
3623 if (m_currentRow
> 0)
3625 wxWindow
*parent
= GetParent();
3626 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3627 le
.SetItem( GetItemByRow(m_currentRow
) );
3628 le
.SetEventObject(parent
);
3629 le
.SetModel(GetOwner()->GetModel());
3631 parent
->GetEventHandler()->ProcessEvent(le
);
3636 if ( m_currentRow
> 0 )
3637 OnArrowChar( m_currentRow
- 1, event
);
3641 if ( m_currentRow
< GetRowCount() - 1 )
3642 OnArrowChar( m_currentRow
+ 1, event
);
3644 //Add the process for tree expanding/collapsing
3646 OnCollapsing(m_currentRow
);
3649 OnExpanding( m_currentRow
);
3653 OnArrowChar( GetRowCount() - 1, event
);
3658 OnArrowChar( 0, event
);
3663 int steps
= pageSize
- 1;
3664 int index
= m_currentRow
- steps
;
3668 OnArrowChar( index
, event
);
3674 int steps
= pageSize
- 1;
3675 unsigned int index
= m_currentRow
+ steps
;
3676 unsigned int count
= GetRowCount();
3677 if ( index
>= count
)
3680 OnArrowChar( index
, event
);
3689 void wxDataViewMainWindow::OnMouse( wxMouseEvent
&event
)
3691 if (event
.GetEventType() == wxEVT_MOUSEWHEEL
)
3693 // let the base handle mouse wheel events.
3698 int x
= event
.GetX();
3699 int y
= event
.GetY();
3700 m_owner
->CalcUnscrolledPosition( x
, y
, &x
, &y
);
3701 wxDataViewColumn
*col
= NULL
;
3704 unsigned int cols
= GetOwner()->GetColumnCount();
3706 for (i
= 0; i
< cols
; i
++)
3708 wxDataViewColumn
*c
= GetOwner()->GetColumn( i
);
3710 continue; // skip it!
3712 if (x
< xpos
+ c
->GetWidth())
3717 xpos
+= c
->GetWidth();
3722 wxDataViewRenderer
*cell
= col
->GetRenderer();
3723 unsigned int current
= GetLineAt( y
);
3724 if ((current
> GetRowCount()) || (x
> GetEndOfLastCol()))
3726 // Unselect all if below the last row ?
3730 //Test whether the mouse is hovered on the tree item button
3732 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3734 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3735 if( node
!=NULL
&& node
->HasChildren() )
3737 int indent
= node
->GetIndentLevel();
3738 indent
= GetOwner()->GetIndent()*indent
;
3739 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3740 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3741 m_lineHeight
-2*EXPANDER_MARGIN
,
3742 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3743 if( rect
.Contains( x
, y
) )
3745 //So the mouse is over the expander
3747 if (m_underMouse
&& m_underMouse
!= node
)
3749 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3750 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3752 if (m_underMouse
!= node
)
3754 //wxLogMessage("Do the row: %d", current);
3755 RefreshRow(current
);
3757 m_underMouse
= node
;
3760 if (node
!=NULL
&& !node
->HasChildren())
3765 if (m_underMouse
!= NULL
)
3767 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
3768 RefreshRow(GetRowByItem(m_underMouse
->GetItem()));
3769 m_underMouse
= NULL
;
3773 wxDataViewModel
*model
= GetOwner()->GetModel();
3775 if (event
.Dragging())
3777 if (m_dragCount
== 0)
3779 // we have to report the raw, physical coords as we want to be
3780 // able to call HitTest(event.m_pointDrag) from the user code to
3781 // get the item being dragged
3782 m_dragStart
= event
.GetPosition();
3787 if (m_dragCount
!= 3)
3790 if (event
.LeftIsDown())
3792 // Notify cell about drag
3801 bool forceClick
= false;
3803 if (event
.ButtonDClick())
3805 m_renameTimer
->Stop();
3806 m_lastOnSame
= false;
3809 wxDataViewItem item
= GetItemByRow(current
);
3810 bool ignore_other_columns
=
3811 ((GetOwner()->GetExpanderColumn() != col
) &&
3812 (model
->IsContainer(item
)) &&
3813 (!model
->HasContainerColumns(item
)));
3815 if (event
.LeftDClick())
3817 if ( current
== m_lineLastClicked
)
3819 if ((!ignore_other_columns
) && (cell
->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
3822 model
->GetValue( value
, item
, col
->GetModelColumn() );
3823 cell
->SetValue( value
);
3824 wxRect
cell_rect( xpos
, GetLineStart( current
),
3825 col
->GetWidth(), GetLineHeight( current
) );
3826 cell
->Activate( cell_rect
, model
, item
, col
->GetModelColumn() );
3831 wxWindow
*parent
= GetParent();
3832 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, parent
->GetId());
3834 le
.SetEventObject(parent
);
3835 le
.SetModel(GetOwner()->GetModel());
3837 parent
->GetEventHandler()->ProcessEvent(le
);
3843 // The first click was on another item, so don't interpret this as
3844 // a double click, but as a simple click instead
3851 if (m_lineSelectSingleOnUp
!= (unsigned int)-1)
3853 // select single line
3854 SelectAllRows( false );
3855 SelectRow( m_lineSelectSingleOnUp
, true );
3858 //Process the event of user clicking the expander
3859 bool expander
= false;
3860 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col
))
3862 wxDataViewTreeNode
* node
= GetTreeNodeByRow(current
);
3863 if( node
!=NULL
&& node
->HasChildren() )
3865 int indent
= node
->GetIndentLevel();
3866 indent
= GetOwner()->GetIndent()*indent
;
3867 wxRect
rect( xpos
+ indent
+ EXPANDER_MARGIN
,
3868 GetLineStart( current
) + EXPANDER_MARGIN
+ (GetLineHeight(current
)/2) - (m_lineHeight
/2) - EXPANDER_OFFSET
,
3869 m_lineHeight
-2*EXPANDER_MARGIN
,
3870 m_lineHeight
-2*EXPANDER_MARGIN
+ EXPANDER_OFFSET
);
3872 if( rect
.Contains( x
, y
) )
3875 if( node
->IsOpen() )
3876 OnCollapsing(current
);
3878 OnExpanding( current
);
3881 if (node
&& !node
->HasChildren())
3884 //If the user click the expander, we do not do editing even if the column with expander are editable
3885 if (m_lastOnSame
&& !expander
&& !ignore_other_columns
)
3887 if ((col
== m_currentCol
) && (current
== m_currentRow
) &&
3888 (cell
->GetMode() & wxDATAVIEW_CELL_EDITABLE
) )
3890 m_renameTimer
->Start( 100, true );
3894 m_lastOnSame
= false;
3895 m_lineSelectSingleOnUp
= (unsigned int)-1;
3899 // This is necessary, because after a DnD operation in
3900 // from and to ourself, the up event is swallowed by the
3901 // DnD code. So on next non-up event (which means here and
3902 // now) m_lineSelectSingleOnUp should be reset.
3903 m_lineSelectSingleOnUp
= (unsigned int)-1;
3906 if (event
.RightDown())
3908 m_lineBeforeLastClicked
= m_lineLastClicked
;
3909 m_lineLastClicked
= current
;
3911 // If the item is already selected, do not update the selection.
3912 // Multi-selections should not be cleared if a selected item is clicked.
3913 if (!IsRowSelected(current
))
3915 SelectAllRows(false);
3916 ChangeCurrentRow(current
);
3917 SelectRow(m_currentRow
,true);
3918 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3922 model
->GetValue( value
, item
, col
->GetModelColumn() );
3923 wxWindow
*parent
= GetParent();
3924 wxDataViewEvent
le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, parent
->GetId());
3926 le
.SetEventObject(parent
);
3927 le
.SetModel(GetOwner()->GetModel());
3929 parent
->GetEventHandler()->ProcessEvent(le
);
3931 else if (event
.MiddleDown())
3934 if (event
.LeftDown() || forceClick
)
3938 m_lineBeforeLastClicked
= m_lineLastClicked
;
3939 m_lineLastClicked
= current
;
3941 unsigned int oldCurrentRow
= m_currentRow
;
3942 bool oldWasSelected
= IsRowSelected(m_currentRow
);
3944 bool cmdModifierDown
= event
.CmdDown();
3945 if ( IsSingleSel() || !(cmdModifierDown
|| event
.ShiftDown()) )
3947 if ( IsSingleSel() || !IsRowSelected(current
) )
3949 SelectAllRows( false );
3950 ChangeCurrentRow(current
);
3951 SelectRow(m_currentRow
,true);
3952 SendSelectionChangedEvent(GetItemByRow( m_currentRow
) );
3954 else // multi sel & current is highlighted & no mod keys
3956 m_lineSelectSingleOnUp
= current
;
3957 ChangeCurrentRow(current
); // change focus
3960 else // multi sel & either ctrl or shift is down
3962 if (cmdModifierDown
)
3964 ChangeCurrentRow(current
);
3965 ReverseRowSelection(m_currentRow
);
3966 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3968 else if (event
.ShiftDown())
3970 ChangeCurrentRow(current
);
3972 unsigned int lineFrom
= oldCurrentRow
,
3975 if ( lineTo
< lineFrom
)
3978 lineFrom
= m_currentRow
;
3981 SelectRows(lineFrom
, lineTo
, true);
3982 SendSelectionChangedEvent(GetItemByRow(m_selection
[0]) );
3984 else // !ctrl, !shift
3986 // test in the enclosing if should make it impossible
3987 wxFAIL_MSG( _T("how did we get here?") );
3991 if (m_currentRow
!= oldCurrentRow
)
3992 RefreshRow( oldCurrentRow
);
3994 wxDataViewColumn
*oldCurrentCol
= m_currentCol
;
3996 // Update selection here...
3999 m_lastOnSame
= !forceClick
&& ((col
== oldCurrentCol
) &&
4000 (current
== oldCurrentRow
)) && oldWasSelected
;
4002 // Call LeftClick after everything else as under GTK+
4003 if (cell
->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE
)
4005 // notify cell about right click
4007 model
->GetValue( value
, item
, col
->GetModelColumn() );
4008 cell
->SetValue( value
);
4009 wxRect
cell_rect( xpos
, GetLineStart( current
),
4010 col
->GetWidth(), GetLineHeight( current
) );
4011 /* ignore ret */ cell
->LeftClick( event
.GetPosition(), cell_rect
, model
, item
, col
->GetModelColumn());
4016 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent
&event
)
4020 if (HasCurrentRow())
4026 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent
&event
)
4030 if (HasCurrentRow())
4036 wxDataViewItem
wxDataViewMainWindow::GetSelection() const
4038 if( m_selection
.GetCount() != 1 )
4039 return wxDataViewItem();
4041 return GetItemByRow( m_selection
.Item(0));
4044 //-----------------------------------------------------------------------------
4046 //-----------------------------------------------------------------------------
4047 WX_DEFINE_LIST(wxDataViewColumnList
)
4049 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
, wxDataViewCtrlBase
)
4051 BEGIN_EVENT_TABLE(wxDataViewCtrl
, wxDataViewCtrlBase
)
4052 EVT_SIZE(wxDataViewCtrl::OnSize
)
4055 wxDataViewCtrl::~wxDataViewCtrl()
4058 GetModel()->RemoveNotifier( m_notifier
);
4063 void wxDataViewCtrl::Init()
4065 m_cols
.DeleteContents(true);
4069 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
,
4070 const wxPoint
& pos
, const wxSize
& size
,
4071 long style
, const wxValidator
& validator
)
4073 if ( (style
& wxBORDER_MASK
) == 0)
4074 style
|= wxBORDER_SUNKEN
;
4076 if (!wxControl::Create( parent
, id
, pos
, size
,
4077 style
| wxScrolledWindowStyle
, validator
))
4080 SetInitialSize(size
);
4085 MacSetClipChildren( true ) ;
4088 m_clientArea
= new wxDataViewMainWindow( this, wxID_ANY
);
4090 if (HasFlag(wxDV_NO_HEADER
))
4091 m_headerArea
= NULL
;
4093 m_headerArea
= new wxDataViewHeaderWindow( this, wxID_ANY
);
4095 SetTargetWindow( m_clientArea
);
4097 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
4099 sizer
->Add( m_headerArea
, 0, wxGROW
);
4100 sizer
->Add( m_clientArea
, 1, wxGROW
);
4107 WXLRESULT
wxDataViewCtrl::MSWWindowProc(WXUINT nMsg
,
4111 WXLRESULT rc
= wxDataViewCtrlBase::MSWWindowProc(nMsg
, wParam
, lParam
);
4114 // we need to process arrows ourselves for scrolling
4115 if ( nMsg
== WM_GETDLGCODE
)
4117 rc
|= DLGC_WANTARROWS
;
4125 void wxDataViewCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
4127 // We need to override OnSize so that our scrolled
4128 // window a) does call Layout() to use sizers for
4129 // positioning the controls but b) does not query
4130 // the sizer for their size and use that for setting
4131 // the scrollable area as set that ourselves by
4132 // calling SetScrollbar() further down.
4139 bool wxDataViewCtrl::AssociateModel( wxDataViewModel
*model
)
4141 if (!wxDataViewCtrlBase::AssociateModel( model
))
4144 m_notifier
= new wxGenericDataViewModelNotifier( m_clientArea
);
4146 model
->AddNotifier( m_notifier
);
4148 m_clientArea
->DestroyTree();
4150 m_clientArea
->BuildTree(model
);
4152 m_clientArea
->UpdateDisplay();
4157 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn
*col
)
4159 if (!wxDataViewCtrlBase::AppendColumn(col
))
4162 m_cols
.Append( col
);
4167 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn
*col
)
4169 if (!wxDataViewCtrlBase::PrependColumn(col
))
4172 m_cols
.Insert( col
);
4177 bool wxDataViewCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
4179 if (!wxDataViewCtrlBase::InsertColumn(pos
,col
))
4182 m_cols
.Insert( pos
, col
);
4187 void wxDataViewCtrl::OnColumnChange()
4190 m_headerArea
->UpdateDisplay();
4192 m_clientArea
->UpdateDisplay();
4195 void wxDataViewCtrl::DoSetExpanderColumn()
4197 m_clientArea
->UpdateDisplay();
4200 void wxDataViewCtrl::DoSetIndent()
4202 m_clientArea
->UpdateDisplay();
4205 unsigned int wxDataViewCtrl::GetColumnCount() const
4207 return m_cols
.GetCount();
4210 wxDataViewColumn
* wxDataViewCtrl::GetColumn( unsigned int pos
) const
4212 wxDataViewColumnList::const_iterator iter
;
4214 for (iter
= m_cols
.begin(); iter
!=m_cols
.end(); iter
++)
4219 if ((*iter
)->IsHidden())
4226 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn
* col
, unsigned int new_pos
)
4228 if (new_pos
> m_cols
.GetCount()) return;
4229 m_cols
.DeleteObject( col
);
4230 m_cols
.Insert( new_pos
, col
);
4232 m_clientArea
->UpdateDisplay();
4235 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn
*column
)
4237 wxDataViewColumnList::compatibility_iterator ret
= m_cols
.Find( column
);
4247 bool wxDataViewCtrl::ClearColumns()
4254 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn
*column
) const
4256 int ret
= 0, dead
= 0;
4257 int len
= GetColumnCount();
4258 for (int i
=0; i
<len
; i
++)
4260 wxDataViewColumn
* col
= GetColumn(i
);
4261 if (col
->IsHidden())
4263 ret
+= col
->GetWidth();
4266 CalcScrolledPosition( ret
, dead
, &ret
, &dead
);
4273 wxDataViewColumn
*wxDataViewCtrl::GetSortingColumn() const
4278 //Selection code with wxDataViewItem as parameters
4279 wxDataViewItem
wxDataViewCtrl::GetSelection() const
4281 return m_clientArea
->GetSelection();
4284 int wxDataViewCtrl::GetSelections( wxDataViewItemArray
& sel
) const
4287 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4288 int len
= selection
.GetCount();
4289 for( int i
= 0; i
< len
; i
++)
4291 unsigned int row
= selection
[i
];
4292 sel
.Add( m_clientArea
->GetItemByRow( row
) );
4297 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray
& sel
)
4299 wxDataViewSelection
selection(wxDataViewSelectionCmp
) ;
4300 int len
= sel
.GetCount();
4301 for( int i
= 0; i
< len
; i
++ )
4303 int row
= m_clientArea
->GetRowByItem( sel
[i
] );
4305 selection
.Add( static_cast<unsigned int>(row
) );
4307 m_clientArea
->SetSelections( selection
);
4310 void wxDataViewCtrl::Select( const wxDataViewItem
& item
)
4312 int row
= m_clientArea
->GetRowByItem( item
);
4315 //Unselect all rows before select another in the single select mode
4316 if (m_clientArea
->IsSingleSel())
4317 m_clientArea
->SelectAllRows(false);
4318 m_clientArea
->SelectRow(row
, true);
4322 void wxDataViewCtrl::Unselect( const wxDataViewItem
& item
)
4324 int row
= m_clientArea
->GetRowByItem( item
);
4326 m_clientArea
->SelectRow(row
, false);
4329 bool wxDataViewCtrl::IsSelected( const wxDataViewItem
& item
) const
4331 int row
= m_clientArea
->GetRowByItem( item
);
4334 return m_clientArea
->IsRowSelected(row
);
4339 //Selection code with row number as parameter
4340 int wxDataViewCtrl::GetSelections( wxArrayInt
& sel
) const
4343 wxDataViewSelection selection
= m_clientArea
->GetSelections();
4344 int len
= selection
.GetCount();
4345 for( int i
= 0; i
< len
; i
++)
4347 unsigned int row
= selection
[i
];
4353 void wxDataViewCtrl::SetSelections( const wxArrayInt
& sel
)
4355 wxDataViewSelection
selection(wxDataViewSelectionCmp
) ;
4356 int len
= sel
.GetCount();
4357 for( int i
= 0; i
< len
; i
++ )
4361 selection
.Add( static_cast<unsigned int>(row
) );
4363 m_clientArea
->SetSelections( selection
);
4366 void wxDataViewCtrl::Select( int row
)
4370 if (m_clientArea
->IsSingleSel())
4371 m_clientArea
->SelectAllRows(false);
4372 m_clientArea
->SelectRow( row
, true );
4376 void wxDataViewCtrl::Unselect( int row
)
4379 m_clientArea
->SelectRow(row
, false);
4382 bool wxDataViewCtrl::IsSelected( int row
) const
4385 return m_clientArea
->IsRowSelected(row
);
4389 void wxDataViewCtrl::SelectRange( int from
, int to
)
4392 for( int i
= from
; i
< to
; i
++ )
4394 m_clientArea
->Select(sel
);
4397 void wxDataViewCtrl::UnselectRange( int from
, int to
)
4399 wxDataViewSelection sel
= m_clientArea
->GetSelections();
4400 for( int i
= from
; i
< to
; i
++ )
4401 if( sel
.Index( i
) != wxNOT_FOUND
)
4403 m_clientArea
->SetSelections(sel
);
4406 void wxDataViewCtrl::SelectAll()
4408 m_clientArea
->SelectAllRows(true);
4411 void wxDataViewCtrl::UnselectAll()
4413 m_clientArea
->SelectAllRows(false);
4416 void wxDataViewCtrl::EnsureVisible( int row
, int column
)
4420 if( row
> (int) m_clientArea
->GetRowCount() )
4421 row
= m_clientArea
->GetRowCount();
4423 int first
= m_clientArea
->GetFirstVisibleRow();
4424 int last
= m_clientArea
->GetLastVisibleRow();
4426 m_clientArea
->ScrollTo( row
, column
);
4427 else if( row
> last
)
4428 m_clientArea
->ScrollTo( row
- last
+ first
, column
);
4430 m_clientArea
->ScrollTo( first
, column
);
4433 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem
& item
, const wxDataViewColumn
* column
)
4435 int row
= m_clientArea
->GetRowByItem(item
);
4438 if( column
== NULL
)
4439 EnsureVisible(row
, -1);
4443 int len
= GetColumnCount();
4444 for( int i
= 0; i
< len
; i
++ )
4445 if( GetColumn(i
) == column
)
4450 EnsureVisible( row
, col
);
4456 void wxDataViewCtrl::HitTest( const wxPoint
& point
, wxDataViewItem
& item
, wxDataViewColumn
* &column
) const
4458 m_clientArea
->HitTest(point
, item
, column
);
4461 wxRect
wxDataViewCtrl::GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
* column
) const
4463 return m_clientArea
->GetItemRect(item
, column
);
4466 wxDataViewItem
wxDataViewCtrl::GetItemByRow( unsigned int row
) const
4468 return m_clientArea
->GetItemByRow( row
);
4471 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem
& item
) const
4473 return m_clientArea
->GetRowByItem( item
);
4476 void wxDataViewCtrl::Expand( const wxDataViewItem
& item
)
4478 int row
= m_clientArea
->GetRowByItem( item
);
4480 m_clientArea
->Expand(row
);
4483 void wxDataViewCtrl::Collapse( const wxDataViewItem
& item
)
4485 int row
= m_clientArea
->GetRowByItem( item
);
4487 m_clientArea
->Collapse(row
);
4491 // !wxUSE_GENERICDATAVIEWCTRL
4494 // wxUSE_DATAVIEWCTRL