]> git.saurik.com Git - wxWidgets.git/blob - src/generic/datavgen.cpp
fix another logical/physical coords confusion and update the comment to help with...
[wxWidgets.git] / src / generic / datavgen.cpp
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
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_DATAVIEWCTRL
19
20 #include "wx/dataview.h"
21
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
23
24 #ifndef WX_PRECOMP
25 #ifdef __WXMSW__
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
29 #endif
30 #include "wx/sizer.h"
31 #include "wx/log.h"
32 #include "wx/dcclient.h"
33 #include "wx/timer.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
37 #endif
38
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"
44 #include "wx/icon.h"
45 #include "wx/list.h"
46 #include "wx/listimpl.cpp"
47 #include "wx/imaglist.h"
48 #include "wx/headerctrl.h"
49
50 //-----------------------------------------------------------------------------
51 // classes
52 //-----------------------------------------------------------------------------
53
54 class wxDataViewCtrl;
55
56 static const int SCROLL_UNIT_X = 15;
57
58 // the cell padding on the left/right
59 static const int PADDING_RIGHTLEFT = 3;
60
61 // the expander space margin
62 static const int EXPANDER_MARGIN = 4;
63
64 #ifdef __WXMSW__
65 static const int EXPANDER_OFFSET = 4;
66 #else
67 static const int EXPANDER_OFFSET = 1;
68 #endif
69
70 //Below is the compare stuff
71 //For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed
72 static wxDataViewModel * g_model;
73 static int g_column = -2;
74 static bool g_asending = true;
75
76 //-----------------------------------------------------------------------------
77 // wxDataViewHeaderWindow
78 //-----------------------------------------------------------------------------
79
80 class wxDataViewHeaderWindow : public wxHeaderCtrl
81 {
82 public:
83 wxDataViewHeaderWindow(wxDataViewCtrl *parent)
84 : wxHeaderCtrl(parent)
85 {
86 }
87
88 wxDataViewCtrl *GetOwner() const
89 { return static_cast<wxDataViewCtrl *>(GetParent()); }
90
91 protected:
92 // implement/override wxHeaderCtrl functions by forwarding them to the main
93 // control
94 virtual wxHeaderColumnBase& GetColumn(unsigned int idx)
95 {
96 return *(GetOwner()->GetColumn(idx));
97 }
98
99 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
100 {
101 wxDataViewCtrl * const owner = GetOwner();
102
103 int widthContents = owner->GetBestColumnWidth(idx);
104 owner->GetColumn(idx)->SetWidth(wxMax(widthTitle, widthContents));
105 owner->OnColumnChange(idx);
106
107 return true;
108 }
109
110 private:
111 bool SendEvent(wxEventType type, unsigned int n)
112 {
113 wxDataViewCtrl * const owner = GetOwner();
114 wxDataViewEvent event(type, owner->GetId());
115
116 event.SetEventObject(owner);
117 event.SetColumn(n);
118 event.SetDataViewColumn(owner->GetColumn(n));
119 event.SetModel(owner->GetModel());
120
121 // for events created by wxDataViewHeaderWindow the
122 // row / value fields are not valid
123 return owner->GetEventHandler()->ProcessEvent(event);
124 }
125
126 void OnClick(wxHeaderCtrlEvent& event)
127 {
128 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,
129 event.GetColumn()) )
130 event.Skip();
131 }
132
133 void OnRClick(wxHeaderCtrlEvent& event)
134 {
135 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
136 event.GetColumn()) )
137 event.Skip();
138 }
139
140 void OnBeginDrag(wxHeaderCtrlEvent& event)
141 {
142 if ( !GetColumn(event.GetColumn()).IsResizeable() )
143 event.Veto();
144 }
145
146 void OnDragging(wxHeaderCtrlEvent& event)
147 {
148 const wxHeaderColumnBase& col = GetColumn(event.GetColumn());
149
150 const int minWidth = col.GetMinWidth();
151 if ( event.GetWidth() < minWidth )
152 event.Veto();
153 }
154
155 void OnEndDrag(wxHeaderCtrlEvent& event)
156 {
157 const unsigned col = event.GetColumn();
158 GetColumn(col).SetWidth(event.GetWidth());
159 GetOwner()->OnColumnChange(col);
160 }
161
162 DECLARE_EVENT_TABLE()
163 DECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow)
164 };
165
166 BEGIN_EVENT_TABLE(wxDataViewHeaderWindow, wxHeaderCtrl)
167 EVT_HEADER_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnClick)
168 EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnRClick)
169
170 EVT_HEADER_BEGIN_DRAG(wxID_ANY, wxDataViewHeaderWindow::OnBeginDrag)
171 EVT_HEADER_DRAGGING(wxID_ANY, wxDataViewHeaderWindow::OnDragging)
172 EVT_HEADER_END_DRAG(wxID_ANY, wxDataViewHeaderWindow::OnEndDrag)
173 END_EVENT_TABLE()
174
175 //-----------------------------------------------------------------------------
176 // wxDataViewRenameTimer
177 //-----------------------------------------------------------------------------
178
179 class wxDataViewRenameTimer: public wxTimer
180 {
181 private:
182 wxDataViewMainWindow *m_owner;
183
184 public:
185 wxDataViewRenameTimer( wxDataViewMainWindow *owner );
186 void Notify();
187 };
188
189 //-----------------------------------------------------------------------------
190 // wxDataViewTreeNode
191 //-----------------------------------------------------------------------------
192 class wxDataViewTreeNode;
193 WX_DEFINE_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
194 WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves);
195
196 int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2);
197 int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2);
198
199 class wxDataViewTreeNode
200 {
201 public:
202 wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL )
203 {
204 m_parent = parent;
205 if (!parent)
206 m_open = true;
207 else
208 m_open = false;
209 m_hasChildren = false;
210 m_subTreeCount = 0;
211 }
212
213 ~wxDataViewTreeNode()
214 {
215 }
216
217 wxDataViewTreeNode * GetParent() const { return m_parent; }
218 void SetParent( wxDataViewTreeNode * parent ) { m_parent = parent; }
219 wxDataViewTreeNodes & GetNodes() { return m_nodes; }
220 wxDataViewTreeLeaves & GetChildren() { return m_leaves; }
221
222 void AddNode( wxDataViewTreeNode * node )
223 {
224 m_leaves.Add( node->GetItem().GetID() );
225 if (g_column >= -1)
226 m_leaves.Sort( &wxGenericTreeModelItemCmp );
227 m_nodes.Add( node );
228 if (g_column >= -1)
229 m_nodes.Sort( &wxGenericTreeModelNodeCmp );
230 }
231 void AddLeaf( void * leaf )
232 {
233 m_leaves.Add( leaf );
234 if (g_column >= -1)
235 m_leaves.Sort( &wxGenericTreeModelItemCmp );
236 }
237
238 wxDataViewItem & GetItem() { return m_item; }
239 const wxDataViewItem & GetItem() const { return m_item; }
240 void SetItem( const wxDataViewItem & item ) { m_item = item; }
241
242 unsigned int GetChildrenNumber() const { return m_leaves.GetCount(); }
243 unsigned int GetNodeNumber() const { return m_nodes.GetCount(); }
244 int GetIndentLevel() const
245 {
246 int ret = 0;
247 const wxDataViewTreeNode * node = this;
248 while( node->GetParent()->GetParent() != NULL )
249 {
250 node = node->GetParent();
251 ret ++;
252 }
253 return ret;
254 }
255
256 bool IsOpen() const
257 {
258 return m_open;
259 }
260
261 void ToggleOpen()
262 {
263 int len = m_nodes.GetCount();
264 int sum = 0;
265 for ( int i = 0;i < len; i ++)
266 sum += m_nodes[i]->GetSubTreeCount();
267
268 sum += m_leaves.GetCount();
269 if (m_open)
270 {
271 ChangeSubTreeCount(-sum);
272 m_open = !m_open;
273 }
274 else
275 {
276 m_open = !m_open;
277 ChangeSubTreeCount(sum);
278 }
279 }
280 bool HasChildren() const { return m_hasChildren; }
281 void SetHasChildren( bool has ){ m_hasChildren = has; }
282
283 void SetSubTreeCount( int num ) { m_subTreeCount = num; }
284 int GetSubTreeCount() const { return m_subTreeCount; }
285 void ChangeSubTreeCount( int num )
286 {
287 if( !m_open )
288 return;
289 m_subTreeCount += num;
290 if( m_parent )
291 m_parent->ChangeSubTreeCount(num);
292 }
293
294 void Resort()
295 {
296 if (g_column >= -1)
297 {
298 m_nodes.Sort( &wxGenericTreeModelNodeCmp );
299 int len = m_nodes.GetCount();
300 for (int i = 0; i < len; i ++)
301 m_nodes[i]->Resort();
302 m_leaves.Sort( &wxGenericTreeModelItemCmp );
303 }
304 }
305
306 private:
307 wxDataViewTreeNode *m_parent;
308 wxDataViewTreeNodes m_nodes;
309 wxDataViewTreeLeaves m_leaves;
310 wxDataViewItem m_item;
311 bool m_open;
312 bool m_hasChildren;
313 int m_subTreeCount;
314 };
315
316 int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2)
317 {
318 return g_model->Compare( (*node1)->GetItem(), (*node2)->GetItem(), g_column, g_asending );
319 }
320
321 int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2)
322 {
323 return g_model->Compare( *id1, *id2, g_column, g_asending );
324 }
325
326
327
328 //-----------------------------------------------------------------------------
329 // wxDataViewMainWindow
330 //-----------------------------------------------------------------------------
331
332 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection,
333 WXDLLIMPEXP_ADV);
334 WX_DECLARE_LIST(wxDataViewItem, ItemList);
335 WX_DEFINE_LIST(ItemList)
336
337 class wxDataViewMainWindow: public wxWindow
338 {
339 public:
340 wxDataViewMainWindow( wxDataViewCtrl *parent,
341 wxWindowID id,
342 const wxPoint &pos = wxDefaultPosition,
343 const wxSize &size = wxDefaultSize,
344 const wxString &name = wxT("wxdataviewctrlmainwindow") );
345 virtual ~wxDataViewMainWindow();
346
347 bool IsVirtualList() const { return m_root == NULL; }
348
349 // notifications from wxDataViewModel
350 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
351 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
352 bool ItemChanged( const wxDataViewItem &item );
353 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
354 bool Cleared();
355 void Resort()
356 {
357 if (!IsVirtualList())
358 {
359 SortPrepare();
360 m_root->Resort();
361 }
362 UpdateDisplay();
363 }
364
365 void SortPrepare()
366 {
367 g_model = GetOwner()->GetModel();
368 wxDataViewColumn* col = GetOwner()->GetSortingColumn();
369 if( !col )
370 {
371 if (g_model->HasDefaultCompare())
372 g_column = -1;
373 else
374 g_column = -2;
375
376 g_asending = true;
377 return;
378 }
379 g_column = col->GetModelColumn();
380 g_asending = col->IsSortOrderAscending();
381 }
382
383 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
384 wxDataViewCtrl *GetOwner() { return m_owner; }
385 const wxDataViewCtrl *GetOwner() const { return m_owner; }
386
387 void OnPaint( wxPaintEvent &event );
388 void OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event);
389 void OnChar( wxKeyEvent &event );
390 void OnMouse( wxMouseEvent &event );
391 void OnSetFocus( wxFocusEvent &event );
392 void OnKillFocus( wxFocusEvent &event );
393
394 void UpdateDisplay();
395 void RecalculateDisplay();
396 void OnInternalIdle();
397
398 void OnRenameTimer();
399
400 void ScrollWindow( int dx, int dy, const wxRect *rect = NULL );
401 void ScrollTo( int rows, int column );
402
403 bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; }
404 void ChangeCurrentRow( unsigned int row );
405
406 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); }
407 bool IsEmpty() { return GetRowCount() == 0; }
408
409 int GetCountPerPage() const;
410 int GetEndOfLastCol() const;
411 unsigned int GetFirstVisibleRow() const;
412 //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
413 unsigned int GetLastVisibleRow();
414 unsigned int GetRowCount();
415
416 wxDataViewItem GetSelection() const;
417 wxDataViewSelection GetSelections(){ return m_selection; }
418 void SetSelections( const wxDataViewSelection & sel ) { m_selection = sel; UpdateDisplay(); }
419 void Select( const wxArrayInt& aSelections );
420 void SelectAllRows( bool on );
421 void SelectRow( unsigned int row, bool on );
422 void SelectRows( unsigned int from, unsigned int to, bool on );
423 void ReverseRowSelection( unsigned int row );
424 bool IsRowSelected( unsigned int row );
425 void SendSelectionChangedEvent( const wxDataViewItem& item);
426
427 void RefreshRow( unsigned int row );
428 void RefreshRows( unsigned int from, unsigned int to );
429 void RefreshRowsAfter( unsigned int firstRow );
430
431 // returns the colour to be used for drawing the rules
432 wxColour GetRuleColour() const
433 {
434 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
435 }
436
437 wxRect GetLineRect( unsigned int row ) const;
438
439 int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode
440 int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
441 int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode
442
443 //Some useful functions for row and item mapping
444 wxDataViewItem GetItemByRow( unsigned int row ) const;
445 int GetRowByItem( const wxDataViewItem & item ) const;
446
447 //Methods for building the mapping tree
448 void BuildTree( wxDataViewModel * model );
449 void DestroyTree();
450 void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column );
451 wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column );
452
453 void Expand( unsigned int row ) { OnExpanding( row ); }
454 void Collapse( unsigned int row ) { OnCollapsing( row ); }
455 private:
456 wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row ) const;
457 //We did not need this temporarily
458 //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
459
460 int RecalculateCount();
461
462 wxDataViewEvent SendExpanderEvent( wxEventType type, const wxDataViewItem & item );
463 void OnExpanding( unsigned int row );
464 void OnCollapsing( unsigned int row );
465
466 wxDataViewTreeNode * FindNode( const wxDataViewItem & item );
467
468 private:
469 wxDataViewCtrl *m_owner;
470 int m_lineHeight;
471 bool m_dirty;
472
473 wxDataViewColumn *m_currentCol;
474 unsigned int m_currentRow;
475 wxDataViewSelection m_selection;
476
477 wxDataViewRenameTimer *m_renameTimer;
478 bool m_lastOnSame;
479
480 bool m_hasFocus;
481
482 int m_dragCount;
483 wxPoint m_dragStart;
484
485 // for double click logic
486 unsigned int m_lineLastClicked,
487 m_lineBeforeLastClicked,
488 m_lineSelectSingleOnUp;
489
490 // the pen used to draw horiz/vertical rules
491 wxPen m_penRule;
492
493 // the pen used to draw the expander and the lines
494 wxPen m_penExpander;
495
496 //This is the tree structure of the model
497 wxDataViewTreeNode * m_root;
498 int m_count;
499 //This is the tree node under the cursor
500 wxDataViewTreeNode * m_underMouse;
501 private:
502 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
503 DECLARE_EVENT_TABLE()
504 };
505
506 // ---------------------------------------------------------
507 // wxGenericDataViewModelNotifier
508 // ---------------------------------------------------------
509
510 class wxGenericDataViewModelNotifier: public wxDataViewModelNotifier
511 {
512 public:
513 wxGenericDataViewModelNotifier( wxDataViewMainWindow *mainWindow )
514 { m_mainWindow = mainWindow; }
515
516 virtual bool ItemAdded( const wxDataViewItem & parent, const wxDataViewItem & item )
517 { return m_mainWindow->ItemAdded( parent , item ); }
518 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
519 { return m_mainWindow->ItemDeleted( parent, item ); }
520 virtual bool ItemChanged( const wxDataViewItem & item )
521 { return m_mainWindow->ItemChanged(item); }
522 virtual bool ValueChanged( const wxDataViewItem & item , unsigned int col )
523 { return m_mainWindow->ValueChanged( item, col ); }
524 virtual bool Cleared()
525 { return m_mainWindow->Cleared(); }
526 virtual void Resort()
527 { m_mainWindow->Resort(); }
528
529 wxDataViewMainWindow *m_mainWindow;
530 };
531
532 // ---------------------------------------------------------
533 // wxDataViewRenderer
534 // ---------------------------------------------------------
535
536 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
537
538 wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype,
539 wxDataViewCellMode mode,
540 int align) :
541 wxDataViewRendererBase( varianttype, mode, align )
542 {
543 m_dc = NULL;
544 m_align = align;
545 m_mode = mode;
546 m_wantsAttr = false;
547 m_hasAttr = false;
548 }
549
550 wxDataViewRenderer::~wxDataViewRenderer()
551 {
552 if (m_dc)
553 delete m_dc;
554 }
555
556 wxDC *wxDataViewRenderer::GetDC()
557 {
558 if (m_dc == NULL)
559 {
560 if (GetOwner() == NULL)
561 return NULL;
562 if (GetOwner()->GetOwner() == NULL)
563 return NULL;
564 m_dc = new wxClientDC( GetOwner()->GetOwner() );
565 }
566
567 return m_dc;
568 }
569
570 void wxDataViewRenderer::SetAlignment( int align )
571 {
572 m_align=align;
573 }
574
575 int wxDataViewRenderer::GetAlignment() const
576 {
577 return m_align;
578 }
579
580 int wxDataViewRenderer::CalculateAlignment() const
581 {
582 if (m_align == wxDVR_DEFAULT_ALIGNMENT)
583 {
584 if (GetOwner() == NULL)
585 return wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL;
586
587 return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
588 }
589
590 return m_align;
591 }
592
593 // ---------------------------------------------------------
594 // wxDataViewCustomRenderer
595 // ---------------------------------------------------------
596
597 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
598
599 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
600 wxDataViewCellMode mode, int align ) :
601 wxDataViewRenderer( varianttype, mode, align )
602 {
603 }
604
605 void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
606 {
607 wxDataViewCtrl *view = GetOwner()->GetOwner();
608 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
609 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
610 view->GetForegroundColour();
611 dc->SetTextForeground(col);
612 dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
613 }
614
615 // ---------------------------------------------------------
616 // wxDataViewTextRenderer
617 // ---------------------------------------------------------
618
619 IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer)
620
621 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype,
622 wxDataViewCellMode mode, int align ) :
623 wxDataViewCustomRenderer( varianttype, mode, align )
624 {
625 }
626
627 bool wxDataViewTextRenderer::SetValue( const wxVariant &value )
628 {
629 m_text = value.GetString();
630
631 return true;
632 }
633
634 bool wxDataViewTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
635 {
636 return false;
637 }
638
639 bool wxDataViewTextRenderer::HasEditorCtrl()
640 {
641 return true;
642 }
643
644 wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
645 wxRect labelRect, const wxVariant &value )
646 {
647 return new wxTextCtrl( parent, wxID_ANY, value,
648 wxPoint(labelRect.x,labelRect.y),
649 wxSize(labelRect.width,labelRect.height) );
650 }
651
652 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
653 {
654 wxTextCtrl *text = (wxTextCtrl*) editor;
655 value = text->GetValue();
656 return true;
657 }
658
659 bool wxDataViewTextRenderer::Render( wxRect cell, wxDC *dc, int state )
660 {
661 RenderText( m_text, 0, cell, dc, state );
662 return true;
663 }
664
665 wxSize wxDataViewTextRenderer::GetSize() const
666 {
667 const wxDataViewCtrl *view = GetView();
668 if (!m_text.empty())
669 {
670 int x,y;
671 view->GetTextExtent( m_text, &x, &y );
672 return wxSize( x, y );
673 }
674 return wxSize(80,20);
675 }
676
677 // ---------------------------------------------------------
678 // wxDataViewTextRendererAttr
679 // ---------------------------------------------------------
680
681 IMPLEMENT_CLASS(wxDataViewTextRendererAttr, wxDataViewTextRenderer)
682
683 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr( const wxString &varianttype,
684 wxDataViewCellMode mode, int align ) :
685 wxDataViewTextRenderer( varianttype, mode, align )
686 {
687 m_wantsAttr = true;
688 }
689
690 bool wxDataViewTextRendererAttr::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
691 {
692 wxFont font;
693 wxColour colour;
694
695 if (m_hasAttr)
696 {
697 if (m_attr.HasColour())
698 {
699 colour = dc->GetTextForeground();
700 dc->SetTextForeground( m_attr.GetColour() );
701 }
702
703 if (m_attr.GetBold() || m_attr.GetItalic())
704 {
705 font = dc->GetFont();
706 wxFont myfont = font;
707 if (m_attr.GetBold())
708 myfont.SetWeight( wxFONTWEIGHT_BOLD );
709 if (m_attr.GetItalic())
710 myfont.SetStyle( wxFONTSTYLE_ITALIC );
711 dc->SetFont( myfont );
712 }
713 }
714
715 dc->DrawText( m_text, cell.x, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
716
717 // restore dc
718 if (m_hasAttr)
719 {
720 if (m_attr.HasColour())
721 dc->SetTextForeground( colour );
722
723 if (m_attr.GetBold() || m_attr.GetItalic())
724 dc->SetFont( font );
725 }
726
727 return true;
728 }
729
730
731 // ---------------------------------------------------------
732 // wxDataViewBitmapRenderer
733 // ---------------------------------------------------------
734
735 IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer)
736
737 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
738 wxDataViewCellMode mode, int align ) :
739 wxDataViewCustomRenderer( varianttype, mode, align )
740 {
741 }
742
743 bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
744 {
745 if (value.GetType() == wxT("wxBitmap"))
746 m_bitmap << value;
747 if (value.GetType() == wxT("wxIcon"))
748 m_icon << value;
749
750 return true;
751 }
752
753 bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
754 {
755 return false;
756 }
757
758 bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
759 {
760 if (m_bitmap.Ok())
761 dc->DrawBitmap( m_bitmap, cell.x, cell.y );
762 else if (m_icon.Ok())
763 dc->DrawIcon( m_icon, cell.x, cell.y );
764
765 return true;
766 }
767
768 wxSize wxDataViewBitmapRenderer::GetSize() const
769 {
770 if (m_bitmap.Ok())
771 return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
772 else if (m_icon.Ok())
773 return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
774
775 return wxSize(16,16);
776 }
777
778 // ---------------------------------------------------------
779 // wxDataViewToggleRenderer
780 // ---------------------------------------------------------
781
782 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewCustomRenderer)
783
784 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
785 wxDataViewCellMode mode, int align ) :
786 wxDataViewCustomRenderer( varianttype, mode, align )
787 {
788 m_toggle = false;
789 }
790
791 bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
792 {
793 m_toggle = value.GetBool();
794
795 return true;
796 }
797
798 bool wxDataViewToggleRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
799 {
800 return false;
801 }
802
803 bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
804 {
805 // User wxRenderer here
806
807 wxRect rect;
808 rect.x = cell.x + cell.width/2 - 10;
809 rect.width = 20;
810 rect.y = cell.y + cell.height/2 - 10;
811 rect.height = 20;
812
813 int flags = 0;
814 if (m_toggle)
815 flags |= wxCONTROL_CHECKED;
816 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE)
817 flags |= wxCONTROL_DISABLED;
818
819 wxRendererNative::Get().DrawCheckBox(
820 GetOwner()->GetOwner(),
821 *dc,
822 rect,
823 flags );
824
825 return true;
826 }
827
828 bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell),
829 wxDataViewModel *model,
830 const wxDataViewItem & item, unsigned int col)
831 {
832 bool value = !m_toggle;
833 wxVariant variant = value;
834 model->SetValue( variant, item, col);
835 model->ValueChanged( item, col );
836 return true;
837 }
838
839 wxSize wxDataViewToggleRenderer::GetSize() const
840 {
841 return wxSize(20,20);
842 }
843
844 // ---------------------------------------------------------
845 // wxDataViewProgressRenderer
846 // ---------------------------------------------------------
847
848 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
849
850 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
851 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
852 wxDataViewCustomRenderer( varianttype, mode, align )
853 {
854 m_label = label;
855 m_value = 0;
856 }
857
858 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
859 {
860 }
861
862 bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
863 {
864 m_value = (long) value;
865
866 if (m_value < 0) m_value = 0;
867 if (m_value > 100) m_value = 100;
868
869 return true;
870 }
871
872 bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
873 {
874 value = (long) m_value;
875 return true;
876 }
877
878 bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
879 {
880 double pct = (double)m_value / 100.0;
881 wxRect bar = cell;
882 bar.width = (int)(cell.width * pct);
883 dc->SetPen( *wxTRANSPARENT_PEN );
884 dc->SetBrush( *wxBLUE_BRUSH );
885 dc->DrawRectangle( bar );
886
887 dc->SetBrush( *wxTRANSPARENT_BRUSH );
888 dc->SetPen( *wxBLACK_PEN );
889 dc->DrawRectangle( cell );
890
891 return true;
892 }
893
894 wxSize wxDataViewProgressRenderer::GetSize() const
895 {
896 return wxSize(40,12);
897 }
898
899 // ---------------------------------------------------------
900 // wxDataViewDateRenderer
901 // ---------------------------------------------------------
902
903 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
904
905 #if wxUSE_DATE_RENDERER_POPUP
906
907 class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
908 {
909 public:
910 wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
911 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col) :
912 wxPopupTransientWindow( parent, wxBORDER_SIMPLE ),
913 m_item( item )
914 {
915 m_model = model;
916 m_col = col;
917 m_cal = new wxCalendarCtrl( this, wxID_ANY, *value );
918 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
919 sizer->Add( m_cal, 1, wxGROW );
920 SetSizer( sizer );
921 sizer->Fit( this );
922 }
923
924 void OnCalendar( wxCalendarEvent &event );
925
926 wxCalendarCtrl *m_cal;
927 wxDataViewModel *m_model;
928 unsigned int m_col;
929 const wxDataViewItem & m_item;
930
931 protected:
932 virtual void OnDismiss()
933 {
934 }
935
936 private:
937 DECLARE_EVENT_TABLE()
938 };
939
940 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
941 EVT_CALENDAR( wxID_ANY, wxDataViewDateRendererPopupTransient::OnCalendar )
942 END_EVENT_TABLE()
943
944 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
945 {
946 wxDateTime date = event.GetDate();
947 wxVariant value = date;
948 m_model->SetValue( value, m_item, m_col );
949 m_model->ValueChanged( m_item, m_col );
950 DismissAndNotify();
951 }
952
953 #endif // wxUSE_DATE_RENDERER_POPUP
954
955 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer)
956
957 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
958 wxDataViewCellMode mode, int align ) :
959 wxDataViewCustomRenderer( varianttype, mode, align )
960 {
961 }
962
963 bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
964 {
965 m_date = value.GetDateTime();
966
967 return true;
968 }
969
970 bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
971 {
972 value = m_date;
973 return true;
974 }
975
976 bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
977 {
978 wxString tmp = m_date.FormatDate();
979 RenderText( tmp, 0, cell, dc, state );
980 return true;
981 }
982
983 wxSize wxDataViewDateRenderer::GetSize() const
984 {
985 const wxDataViewCtrl* view = GetView();
986 wxString tmp = m_date.FormatDate();
987 wxCoord x,y,d;
988 view->GetTextExtent( tmp, &x, &y, &d );
989 return wxSize(x,y+d);
990 }
991
992 bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model,
993 const wxDataViewItem & item, unsigned int col )
994 {
995 wxVariant variant;
996 model->GetValue( variant, item, col );
997 wxDateTime value = variant.GetDateTime();
998
999 #if wxUSE_DATE_RENDERER_POPUP
1000 wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
1001 GetOwner()->GetOwner()->GetParent(), &value, model, item, col);
1002 wxPoint pos = wxGetMousePosition();
1003 popup->Move( pos );
1004 popup->Layout();
1005 popup->Popup( popup->m_cal );
1006 #else // !wxUSE_DATE_RENDERER_POPUP
1007 wxMessageBox(value.Format());
1008 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
1009 return true;
1010 }
1011
1012 // ---------------------------------------------------------
1013 // wxDataViewIconTextRenderer
1014 // ---------------------------------------------------------
1015
1016 IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
1017
1018 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
1019 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
1020 wxDataViewCustomRenderer( varianttype, mode, align )
1021 {
1022 SetMode(mode);
1023 SetAlignment(align);
1024 }
1025
1026 wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
1027 {
1028 }
1029
1030 bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
1031 {
1032 m_value << value;
1033 return true;
1034 }
1035
1036 bool wxDataViewIconTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
1037 {
1038 return false;
1039 }
1040
1041 bool wxDataViewIconTextRenderer::Render( wxRect cell, wxDC *dc, int state )
1042 {
1043 int xoffset = 0;
1044 const wxIcon &icon = m_value.GetIcon();
1045 if (icon.IsOk())
1046 {
1047 dc->DrawIcon( icon, cell.x, cell.y + ((cell.height - icon.GetHeight()) / 2));
1048 xoffset = icon.GetWidth()+4;
1049 }
1050
1051 RenderText( m_value.GetText(), xoffset, cell, dc, state );
1052
1053 return true;
1054 }
1055
1056 wxSize wxDataViewIconTextRenderer::GetSize() const
1057 {
1058 const wxDataViewCtrl *view = GetView();
1059 if (!m_value.GetText().empty())
1060 {
1061 int x,y;
1062 view->GetTextExtent( m_value.GetText(), &x, &y );
1063
1064 if (m_value.GetIcon().IsOk())
1065 x += m_value.GetIcon().GetWidth() + 4;
1066 return wxSize( x, y );
1067 }
1068 return wxSize(80,20);
1069 }
1070
1071 wxControl *
1072 wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow * WXUNUSED(parent),
1073 wxRect WXUNUSED(labelRect),
1074 const wxVariant& WXUNUSED(value))
1075 {
1076 return NULL;
1077 }
1078
1079 bool
1080 wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl* WXUNUSED(editor),
1081 wxVariant& WXUNUSED(value))
1082 {
1083 return false;
1084 }
1085
1086 //-----------------------------------------------------------------------------
1087 // wxDataViewRenameTimer
1088 //-----------------------------------------------------------------------------
1089
1090 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow *owner )
1091 {
1092 m_owner = owner;
1093 }
1094
1095 void wxDataViewRenameTimer::Notify()
1096 {
1097 m_owner->OnRenameTimer();
1098 }
1099
1100 //-----------------------------------------------------------------------------
1101 // wxDataViewMainWindow
1102 //-----------------------------------------------------------------------------
1103
1104 //The tree building helper, declared firstly
1105 static void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node);
1106
1107 int LINKAGEMODE wxDataViewSelectionCmp( unsigned int row1, unsigned int row2 )
1108 {
1109 if (row1 > row2) return 1;
1110 if (row1 == row2) return 0;
1111 return -1;
1112 }
1113
1114
1115 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
1116
1117 BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
1118 EVT_PAINT (wxDataViewMainWindow::OnPaint)
1119 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse)
1120 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus)
1121 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus)
1122 EVT_CHAR (wxDataViewMainWindow::OnChar)
1123 END_EVENT_TABLE()
1124
1125 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id,
1126 const wxPoint &pos, const wxSize &size, const wxString &name ) :
1127 wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE, name ),
1128 m_selection( wxDataViewSelectionCmp )
1129
1130 {
1131 SetOwner( parent );
1132
1133 m_lastOnSame = false;
1134 m_renameTimer = new wxDataViewRenameTimer( this );
1135
1136 // TODO: user better initial values/nothing selected
1137 m_currentCol = NULL;
1138 m_currentRow = 0;
1139
1140 m_lineHeight = wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
1141
1142 m_dragCount = 0;
1143 m_dragStart = wxPoint(0,0);
1144 m_lineLastClicked = (unsigned int) -1;
1145 m_lineBeforeLastClicked = (unsigned int) -1;
1146 m_lineSelectSingleOnUp = (unsigned int) -1;
1147
1148 m_hasFocus = false;
1149
1150 SetBackgroundColour( *wxWHITE );
1151
1152 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1153
1154 m_penRule = wxPen(GetRuleColour());
1155
1156 //Here I compose a pen can draw black lines, maybe there are something system colour to use
1157 m_penExpander = wxPen(wxColour(0,0,0));
1158 //Some new added code to deal with the tree structure
1159 m_root = new wxDataViewTreeNode( NULL );
1160 m_root->SetHasChildren(true);
1161
1162 //Make m_count = -1 will cause the class recaculate the real displaying number of rows.
1163 m_count = -1;
1164 m_underMouse = NULL;
1165 UpdateDisplay();
1166 }
1167
1168 wxDataViewMainWindow::~wxDataViewMainWindow()
1169 {
1170 DestroyTree();
1171 delete m_renameTimer;
1172 }
1173
1174 void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1175 {
1176 wxDataViewModel *model = GetOwner()->GetModel();
1177 wxAutoBufferedPaintDC dc( this );
1178
1179 #ifdef __WXMSW__
1180 dc.SetPen( *wxTRANSPARENT_PEN );
1181 dc.SetBrush( wxBrush( GetBackgroundColour()) );
1182 dc.SetBrush( *wxWHITE_BRUSH );
1183 wxSize size( GetClientSize() );
1184 dc.DrawRectangle( 0,0,size.x,size.y );
1185 #endif
1186
1187 // prepare the DC
1188 GetOwner()->PrepareDC( dc );
1189 dc.SetFont( GetFont() );
1190
1191 wxRect update = GetUpdateRegion().GetBox();
1192 m_owner->CalcUnscrolledPosition( update.x, update.y, &update.x, &update.y );
1193
1194 // compute which items needs to be redrawn
1195 unsigned int item_start = GetLineAt( wxMax(0,update.y) );
1196 unsigned int item_count =
1197 wxMin( (int)( GetLineAt( wxMax(0,update.y+update.height) ) - item_start + 1),
1198 (int)(GetRowCount( ) - item_start));
1199 unsigned int item_last = item_start + item_count;
1200
1201 // compute which columns needs to be redrawn
1202 unsigned int cols = GetOwner()->GetColumnCount();
1203 unsigned int col_start = 0;
1204 unsigned int x_start;
1205 for (x_start = 0; col_start < cols; col_start++)
1206 {
1207 wxDataViewColumn *col = GetOwner()->GetColumn(col_start);
1208 if (col->IsHidden())
1209 continue; // skip it!
1210
1211 unsigned int w = col->GetWidth();
1212 if (x_start+w >= (unsigned int)update.x)
1213 break;
1214
1215 x_start += w;
1216 }
1217
1218 unsigned int col_last = col_start;
1219 unsigned int x_last = x_start;
1220 for (; col_last < cols; col_last++)
1221 {
1222 wxDataViewColumn *col = GetOwner()->GetColumn(col_last);
1223 if (col->IsHidden())
1224 continue; // skip it!
1225
1226 if (x_last > (unsigned int)update.GetRight())
1227 break;
1228
1229 x_last += col->GetWidth();
1230 }
1231
1232 // Draw horizontal rules if required
1233 if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
1234 {
1235 dc.SetPen(m_penRule);
1236 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1237
1238 for (unsigned int i = item_start; i <= item_last+1; i++)
1239 {
1240 int y = GetLineStart( i );
1241 dc.DrawLine(x_start, y, x_last, y);
1242 }
1243 }
1244
1245 // Draw vertical rules if required
1246 if ( m_owner->HasFlag(wxDV_VERT_RULES) )
1247 {
1248 dc.SetPen(m_penRule);
1249 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1250
1251 int x = x_start;
1252 for (unsigned int i = col_start; i < col_last; i++)
1253 {
1254 wxDataViewColumn *col = GetOwner()->GetColumn(i);
1255 if (col->IsHidden())
1256 continue; // skip it
1257
1258 dc.DrawLine(x, GetLineStart( item_start ),
1259 x, GetLineStart( item_last ) );
1260
1261 x += col->GetWidth();
1262 }
1263
1264 // Draw last vertical rule
1265 dc.DrawLine(x, GetLineStart( item_start ),
1266 x, GetLineStart( item_last ) );
1267 }
1268
1269 // redraw the background for the items which are selected/current
1270 for (unsigned int item = item_start; item < item_last; item++)
1271 {
1272 bool selected = m_selection.Index( item ) != wxNOT_FOUND;
1273 if (selected || item == m_currentRow)
1274 {
1275 int flags = selected ? (int)wxCONTROL_SELECTED : 0;
1276 if (item == m_currentRow)
1277 flags |= wxCONTROL_CURRENT;
1278 if (m_hasFocus)
1279 flags |= wxCONTROL_FOCUSED;
1280
1281 wxRect rect( x_start, GetLineStart( item ), x_last, GetLineHeight( item ) );
1282 wxRendererNative::Get().DrawItemSelectionRect
1283 (
1284 this,
1285 dc,
1286 rect,
1287 flags
1288 );
1289 }
1290 }
1291
1292 wxDataViewColumn *expander = GetOwner()->GetExpanderColumn();
1293 if (!expander)
1294 {
1295 // TODO: last column for RTL support
1296 expander = GetOwner()->GetColumn( 0 );
1297 GetOwner()->SetExpanderColumn(expander);
1298 }
1299
1300 // redraw all cells for all rows which must be repainted and all columns
1301 wxRect cell_rect;
1302 cell_rect.x = x_start;
1303 for (unsigned int i = col_start; i < col_last; i++)
1304 {
1305
1306 wxDataViewColumn *col = GetOwner()->GetColumn( i );
1307 wxDataViewRenderer *cell = col->GetRenderer();
1308 cell_rect.width = col->GetWidth();
1309
1310 if (col->IsHidden())
1311 continue; // skip it!
1312
1313 for (unsigned int item = item_start; item < item_last; item++)
1314 {
1315 // get the cell value and set it into the renderer
1316 wxVariant value;
1317 wxDataViewTreeNode *node = NULL;
1318 wxDataViewItem dataitem;
1319
1320 if (!IsVirtualList())
1321 {
1322 node = GetTreeNodeByRow(item);
1323 if( node == NULL )
1324 continue;
1325
1326 dataitem = node->GetItem();
1327
1328 if ((i > 0) && model->IsContainer(dataitem) && !model->HasContainerColumns(dataitem))
1329 continue;
1330 }
1331 else
1332 {
1333 dataitem = wxDataViewItem( wxUIntToPtr(item) );
1334 }
1335
1336 model->GetValue( value, dataitem, col->GetModelColumn());
1337 cell->SetValue( value );
1338
1339 if (cell->GetWantsAttr())
1340 {
1341 wxDataViewItemAttr attr;
1342 bool ret = model->GetAttr( dataitem, col->GetModelColumn(), attr );
1343 if (ret)
1344 cell->SetAttr( attr );
1345 cell->SetHasAttr( ret );
1346 }
1347
1348 // update cell_rect
1349 cell_rect.y = GetLineStart( item );
1350 cell_rect.height = GetLineHeight( item ); // -1 is for the horizontal rules (?)
1351
1352 //Draw the expander here.
1353 int indent = 0;
1354 if ((!IsVirtualList()) && (col == expander))
1355 {
1356 indent = node->GetIndentLevel();
1357
1358 //Calculate the indent first
1359 indent = cell_rect.x + GetOwner()->GetIndent() * indent;
1360
1361 int expander_width = m_lineHeight - 2*EXPANDER_MARGIN;
1362 // change the cell_rect.x to the appropriate pos
1363 int expander_x = indent + EXPANDER_MARGIN;
1364 int expander_y = cell_rect.y + EXPANDER_MARGIN + (GetLineHeight(item) / 2) - (expander_width/2) - EXPANDER_OFFSET;
1365 indent = indent + m_lineHeight; //try to use the m_lineHeight as the expander space
1366 dc.SetPen( m_penExpander );
1367 dc.SetBrush( wxNullBrush );
1368 if( node->HasChildren() )
1369 {
1370 wxRect rect( expander_x , expander_y, expander_width, expander_width);
1371 int flag = 0;
1372 if (m_underMouse == node)
1373 {
1374 flag |= wxCONTROL_CURRENT;
1375 }
1376 if( node->IsOpen() )
1377 wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, flag|wxCONTROL_EXPANDED );
1378 else
1379 wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, flag);
1380 }
1381 //force the expander column to left-center align
1382 cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
1383 }
1384 if (node && !node->HasChildren())
1385 {
1386 // Yes, if the node does not have any child, it must be a leaf which
1387 // mean that it is a temporarily created by GetTreeNodeByRow
1388 wxDELETE(node);
1389 }
1390
1391 // cannot be bigger than allocated space
1392 wxSize size = cell->GetSize();
1393 // Because of the tree structure indent, here we should minus the width of the cell for drawing
1394 size.x = wxMin( size.x + 2*PADDING_RIGHTLEFT, cell_rect.width - indent );
1395 // size.y = wxMin( size.y, cell_rect.height );
1396 size.y = cell_rect.height;
1397
1398 wxRect item_rect(cell_rect.GetTopLeft(), size);
1399 int align = cell->CalculateAlignment();
1400
1401 // horizontal alignment:
1402 item_rect.x = cell_rect.x;
1403 if (align & wxALIGN_CENTER_HORIZONTAL)
1404 item_rect.x = cell_rect.x + (cell_rect.width / 2) - (size.x / 2);
1405 else if (align & wxALIGN_RIGHT)
1406 item_rect.x = cell_rect.x + cell_rect.width - size.x;
1407 //else: wxALIGN_LEFT is the default
1408
1409 // vertical alignment:
1410 item_rect.y = cell_rect.y;
1411 if (align & wxALIGN_CENTER_VERTICAL)
1412 item_rect.y = cell_rect.y + (cell_rect.height / 2) - (size.y / 2);
1413 else if (align & wxALIGN_BOTTOM)
1414 item_rect.y = cell_rect.y + cell_rect.height - size.y;
1415 //else: wxALIGN_TOP is the default
1416
1417 // add padding
1418 item_rect.x += PADDING_RIGHTLEFT;
1419 item_rect.width = size.x - 2 * PADDING_RIGHTLEFT;
1420
1421 //Here we add the tree indent
1422 item_rect.x += indent;
1423
1424 int state = 0;
1425 if (m_hasFocus && (m_selection.Index(item) != wxNOT_FOUND))
1426 state |= wxDATAVIEW_CELL_SELECTED;
1427
1428 // TODO: it would be much more efficient to create a clipping
1429 // region for the entire column being rendered (in the OnPaint
1430 // of wxDataViewMainWindow) instead of a single clip region for
1431 // each cell. However it would mean that each renderer should
1432 // respect the given wxRect's top & bottom coords, eventually
1433 // violating only the left & right coords - however the user can
1434 // make its own renderer and thus we cannot be sure of that.
1435 dc.SetClippingRegion( item_rect );
1436 cell->Render( item_rect, &dc, state );
1437 dc.DestroyClippingRegion();
1438 }
1439
1440 cell_rect.x += cell_rect.width;
1441 }
1442 }
1443
1444 void wxDataViewMainWindow::OnRenameTimer()
1445 {
1446 // We have to call this here because changes may just have
1447 // been made and no screen update taken place.
1448 if ( m_dirty )
1449 wxSafeYield();
1450
1451 int xpos = 0;
1452 unsigned int cols = GetOwner()->GetColumnCount();
1453 unsigned int i;
1454 for (i = 0; i < cols; i++)
1455 {
1456 wxDataViewColumn *c = GetOwner()->GetColumn( i );
1457 if (c->IsHidden())
1458 continue; // skip it!
1459
1460 if (c == m_currentCol)
1461 break;
1462 xpos += c->GetWidth();
1463 }
1464 wxRect labelRect( xpos,
1465 GetLineStart( m_currentRow ),
1466 m_currentCol->GetWidth(),
1467 GetLineHeight( m_currentRow ) );
1468
1469 GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y,
1470 &labelRect.x, &labelRect.y);
1471
1472 wxDataViewItem item = GetItemByRow( m_currentRow );
1473 m_currentCol->GetRenderer()->StartEditing( item, labelRect );
1474
1475 }
1476
1477 //------------------------------------------------------------------
1478 // Helper class for do operation on the tree node
1479 //------------------------------------------------------------------
1480 class DoJob
1481 {
1482 public:
1483 DoJob() { }
1484 virtual ~DoJob() { }
1485
1486 //The return value control how the tree-walker tranverse the tree
1487 // 0: Job done, stop tranverse and return
1488 // 1: Ignore the current node's subtree and continue
1489 // 2: Job not done, continue
1490 enum { OK = 0 , IGR = 1, CONT = 2 };
1491 virtual int operator() ( wxDataViewTreeNode * node ) = 0;
1492 virtual int operator() ( void * n ) = 0;
1493 };
1494
1495 bool Walker( wxDataViewTreeNode * node, DoJob & func )
1496 {
1497 if( node==NULL )
1498 return false;
1499
1500 switch( func( node ) )
1501 {
1502 case DoJob::OK :
1503 return true;
1504 case DoJob::IGR:
1505 return false;
1506 case DoJob::CONT:
1507 default:
1508 ;
1509 }
1510
1511 wxDataViewTreeNodes nodes = node->GetNodes();
1512 wxDataViewTreeLeaves leaves = node->GetChildren();
1513
1514 int len_nodes = nodes.GetCount();
1515 int len = leaves.GetCount();
1516 int i = 0, nodes_i = 0;
1517
1518 for(; i < len; i ++ )
1519 {
1520 void * n = leaves[i];
1521 if( nodes_i < len_nodes && n == nodes[nodes_i]->GetItem().GetID() )
1522 {
1523 wxDataViewTreeNode * nd = nodes[nodes_i];
1524 nodes_i++;
1525
1526 if( Walker( nd , func ) )
1527 return true;
1528
1529 }
1530 else
1531 switch( func( n ) )
1532 {
1533 case DoJob::OK :
1534 return true;
1535 case DoJob::IGR:
1536 continue;
1537 case DoJob::CONT:
1538 default:
1539 ;
1540 }
1541 }
1542 return false;
1543 }
1544
1545 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
1546 {
1547 if (!m_root)
1548 {
1549 m_count++;
1550 UpdateDisplay();
1551 return true;
1552 }
1553
1554 SortPrepare();
1555
1556 wxDataViewTreeNode * node;
1557 node = FindNode(parent);
1558
1559 if( node == NULL )
1560 return false;
1561
1562 node->SetHasChildren( true );
1563
1564 if( g_model->IsContainer( item ) )
1565 {
1566 wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
1567 newnode->SetItem(item);
1568 newnode->SetHasChildren( true );
1569 node->AddNode( newnode);
1570 }
1571 else
1572 node->AddLeaf( item.GetID() );
1573
1574 node->ChangeSubTreeCount(1);
1575
1576 m_count = -1;
1577 UpdateDisplay();
1578
1579 return true;
1580 }
1581
1582 static void DestroyTreeHelper( wxDataViewTreeNode * node);
1583
1584 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
1585 const wxDataViewItem& item)
1586 {
1587 if (!m_root)
1588 {
1589 m_count--;
1590 if( m_currentRow > GetRowCount() )
1591 m_currentRow = m_count - 1;
1592
1593 m_selection.Empty();
1594
1595 UpdateDisplay();
1596
1597 return true;
1598 }
1599
1600 wxDataViewTreeNode * node = FindNode(parent);
1601
1602 wxCHECK_MSG( node != NULL, false, "item not found" );
1603 wxCHECK_MSG( node->GetChildren().Index( item.GetID() ) != wxNOT_FOUND, false, "item not found" );
1604
1605 int sub = -1;
1606 node->GetChildren().Remove( item.GetID() );
1607 //Manuplate selection
1608 if( m_selection.GetCount() > 1 )
1609 {
1610 m_selection.Empty();
1611 }
1612 bool isContainer = false;
1613 wxDataViewTreeNodes nds = node->GetNodes();
1614 for (size_t i = 0; i < nds.GetCount(); i ++)
1615 {
1616 if (nds[i]->GetItem() == item)
1617 {
1618 isContainer = true;
1619 break;
1620 }
1621 }
1622 if( isContainer )
1623 {
1624 wxDataViewTreeNode * n = NULL;
1625 wxDataViewTreeNodes nodes = node->GetNodes();
1626 int len = nodes.GetCount();
1627 for( int i = 0; i < len; i ++)
1628 {
1629 if( nodes[i]->GetItem() == item )
1630 {
1631 n = nodes[i];
1632 break;
1633 }
1634 }
1635
1636 wxCHECK_MSG( n != NULL, false, "item not found" );
1637
1638 node->GetNodes().Remove( n );
1639 sub -= n->GetSubTreeCount();
1640 ::DestroyTreeHelper(n);
1641 }
1642 //Make the row number invalid and get a new valid one when user call GetRowCount
1643 m_count = -1;
1644 node->ChangeSubTreeCount(sub);
1645
1646 //Change the current row to the last row if the current exceed the max row number
1647 if( m_currentRow > GetRowCount() )
1648 m_currentRow = m_count - 1;
1649
1650 UpdateDisplay();
1651
1652 return true;
1653 }
1654
1655 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
1656 {
1657 SortPrepare();
1658 g_model->Resort();
1659
1660 //Send event
1661 wxWindow *parent = GetParent();
1662 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
1663 le.SetEventObject(parent);
1664 le.SetModel(GetOwner()->GetModel());
1665 le.SetItem(item);
1666 parent->GetEventHandler()->ProcessEvent(le);
1667
1668 return true;
1669 }
1670
1671 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int col )
1672 {
1673 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1674 /*#define MAX_VIRTUAL_WIDTH 100000
1675
1676 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
1677 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1678 Refresh( true, &rect );
1679
1680 return true;
1681 */
1682 SortPrepare();
1683 g_model->Resort();
1684
1685 //Send event
1686 wxWindow *parent = GetParent();
1687 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
1688 le.SetEventObject(parent);
1689 le.SetModel(GetOwner()->GetModel());
1690 le.SetItem(item);
1691 le.SetColumn(col);
1692 le.SetDataViewColumn(GetOwner()->GetColumn(col));
1693 parent->GetEventHandler()->ProcessEvent(le);
1694
1695 return true;
1696 }
1697
1698 bool wxDataViewMainWindow::Cleared()
1699 {
1700 DestroyTree();
1701
1702 SortPrepare();
1703 BuildTree( GetOwner()->GetModel() );
1704
1705 UpdateDisplay();
1706
1707 return true;
1708 }
1709
1710 void wxDataViewMainWindow::UpdateDisplay()
1711 {
1712 m_dirty = true;
1713 }
1714
1715 void wxDataViewMainWindow::OnInternalIdle()
1716 {
1717 wxWindow::OnInternalIdle();
1718
1719 if (m_dirty)
1720 {
1721 RecalculateDisplay();
1722 m_dirty = false;
1723 }
1724 }
1725
1726 void wxDataViewMainWindow::RecalculateDisplay()
1727 {
1728 wxDataViewModel *model = GetOwner()->GetModel();
1729 if (!model)
1730 {
1731 Refresh();
1732 return;
1733 }
1734
1735 int width = GetEndOfLastCol();
1736 int height = GetLineStart( GetRowCount() );
1737
1738 SetVirtualSize( width, height );
1739 GetOwner()->SetScrollRate( 10, m_lineHeight );
1740
1741 Refresh();
1742 }
1743
1744 void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
1745 {
1746 wxWindow::ScrollWindow( dx, dy, rect );
1747
1748 if (GetOwner()->m_headerArea)
1749 GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
1750 }
1751
1752 void wxDataViewMainWindow::ScrollTo( int rows, int column )
1753 {
1754 int x, y;
1755 m_owner->GetScrollPixelsPerUnit( &x, &y );
1756 int sy = GetLineStart( rows )/y;
1757 int sx = 0;
1758 if( column != -1 )
1759 {
1760 wxRect rect = GetClientRect();
1761 int colnum = 0;
1762 int x_start, w = 0;
1763 int xx, yy, xe;
1764 m_owner->CalcUnscrolledPosition( rect.x, rect.y, &xx, &yy );
1765 for (x_start = 0; colnum < column; colnum++)
1766 {
1767 wxDataViewColumn *col = GetOwner()->GetColumn(colnum);
1768 if (col->IsHidden())
1769 continue; // skip it!
1770
1771 w = col->GetWidth();
1772 x_start += w;
1773 }
1774
1775 int x_end = x_start + w;
1776 xe = xx + rect.width;
1777 if( x_end > xe )
1778 {
1779 sx = ( xx + x_end - xe )/x;
1780 }
1781 if( x_start < xx )
1782 {
1783 sx = x_start/x;
1784 }
1785 }
1786 m_owner->Scroll( sx, sy );
1787 }
1788
1789 int wxDataViewMainWindow::GetCountPerPage() const
1790 {
1791 wxSize size = GetClientSize();
1792 return size.y / m_lineHeight;
1793 }
1794
1795 int wxDataViewMainWindow::GetEndOfLastCol() const
1796 {
1797 int width = 0;
1798 unsigned int i;
1799 for (i = 0; i < GetOwner()->GetColumnCount(); i++)
1800 {
1801 const wxDataViewColumn *c =
1802 const_cast<wxDataViewCtrl*>(GetOwner())->GetColumn( i );
1803
1804 if (!c->IsHidden())
1805 width += c->GetWidth();
1806 }
1807 return width;
1808 }
1809
1810 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
1811 {
1812 int x = 0;
1813 int y = 0;
1814 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
1815
1816 return GetLineAt( y );
1817 }
1818
1819 unsigned int wxDataViewMainWindow::GetLastVisibleRow()
1820 {
1821 wxSize client_size = GetClientSize();
1822 m_owner->CalcUnscrolledPosition( client_size.x, client_size.y,
1823 &client_size.x, &client_size.y );
1824
1825 //we should deal with the pixel here
1826 unsigned int row = GetLineAt(client_size.y) - 1;
1827
1828 return wxMin( GetRowCount()-1, row );
1829 }
1830
1831 unsigned int wxDataViewMainWindow::GetRowCount()
1832 {
1833 if ( m_count == -1 )
1834 {
1835 m_count = RecalculateCount();
1836 UpdateDisplay();
1837 }
1838 return m_count;
1839 }
1840
1841 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row )
1842 {
1843 m_currentRow = row;
1844
1845 // send event
1846 }
1847
1848 void wxDataViewMainWindow::SelectAllRows( bool on )
1849 {
1850 if (IsEmpty())
1851 return;
1852
1853 if (on)
1854 {
1855 m_selection.Clear();
1856 for (unsigned int i = 0; i < GetRowCount(); i++)
1857 m_selection.Add( i );
1858 Refresh();
1859 }
1860 else
1861 {
1862 unsigned int first_visible = GetFirstVisibleRow();
1863 unsigned int last_visible = GetLastVisibleRow();
1864 unsigned int i;
1865 for (i = 0; i < m_selection.GetCount(); i++)
1866 {
1867 unsigned int row = m_selection[i];
1868 if ((row >= first_visible) && (row <= last_visible))
1869 RefreshRow( row );
1870 }
1871 m_selection.Clear();
1872 }
1873 }
1874
1875 void wxDataViewMainWindow::SelectRow( unsigned int row, bool on )
1876 {
1877 if (m_selection.Index( row ) == wxNOT_FOUND)
1878 {
1879 if (on)
1880 {
1881 m_selection.Add( row );
1882 RefreshRow( row );
1883 }
1884 }
1885 else
1886 {
1887 if (!on)
1888 {
1889 m_selection.Remove( row );
1890 RefreshRow( row );
1891 }
1892 }
1893 }
1894
1895 void wxDataViewMainWindow::SelectRows( unsigned int from, unsigned int to, bool on )
1896 {
1897 if (from > to)
1898 {
1899 unsigned int tmp = from;
1900 from = to;
1901 to = tmp;
1902 }
1903
1904 unsigned int i;
1905 for (i = from; i <= to; i++)
1906 {
1907 if (m_selection.Index( i ) == wxNOT_FOUND)
1908 {
1909 if (on)
1910 m_selection.Add( i );
1911 }
1912 else
1913 {
1914 if (!on)
1915 m_selection.Remove( i );
1916 }
1917 }
1918 RefreshRows( from, to );
1919 }
1920
1921 void wxDataViewMainWindow::Select( const wxArrayInt& aSelections )
1922 {
1923 for (size_t i=0; i < aSelections.GetCount(); i++)
1924 {
1925 int n = aSelections[i];
1926
1927 m_selection.Add( n );
1928 RefreshRow( n );
1929 }
1930 }
1931
1932 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row )
1933 {
1934 if (m_selection.Index( row ) == wxNOT_FOUND)
1935 m_selection.Add( row );
1936 else
1937 m_selection.Remove( row );
1938 RefreshRow( row );
1939 }
1940
1941 bool wxDataViewMainWindow::IsRowSelected( unsigned int row )
1942 {
1943 return (m_selection.Index( row ) != wxNOT_FOUND);
1944 }
1945
1946 void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem& item)
1947 {
1948 wxWindow *parent = GetParent();
1949 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, parent->GetId());
1950
1951 le.SetEventObject(parent);
1952 le.SetModel(GetOwner()->GetModel());
1953 le.SetItem( item );
1954
1955 parent->GetEventHandler()->ProcessEvent(le);
1956 }
1957
1958 void wxDataViewMainWindow::RefreshRow( unsigned int row )
1959 {
1960 wxRect rect( 0, GetLineStart( row ), GetEndOfLastCol(), GetLineHeight( row ) );
1961 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1962
1963 wxSize client_size = GetClientSize();
1964 wxRect client_rect( 0, 0, client_size.x, client_size.y );
1965 wxRect intersect_rect = client_rect.Intersect( rect );
1966 if (intersect_rect.width > 0)
1967 Refresh( true, &intersect_rect );
1968 }
1969
1970 void wxDataViewMainWindow::RefreshRows( unsigned int from, unsigned int to )
1971 {
1972 if (from > to)
1973 {
1974 unsigned int tmp = to;
1975 to = from;
1976 from = tmp;
1977 }
1978
1979 wxRect rect( 0, GetLineStart( from ), GetEndOfLastCol(), GetLineStart( (to-from+1) ) );
1980 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1981
1982 wxSize client_size = GetClientSize();
1983 wxRect client_rect( 0, 0, client_size.x, client_size.y );
1984 wxRect intersect_rect = client_rect.Intersect( rect );
1985 if (intersect_rect.width > 0)
1986 Refresh( true, &intersect_rect );
1987 }
1988
1989 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow )
1990 {
1991 wxSize client_size = GetClientSize();
1992 int start = GetLineStart( firstRow );
1993 m_owner->CalcScrolledPosition( start, 0, &start, NULL );
1994 if (start > client_size.y) return;
1995
1996 wxRect rect( 0, start, client_size.x, client_size.y - start );
1997
1998 Refresh( true, &rect );
1999 }
2000
2001 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event)
2002 {
2003 wxCHECK_RET( newCurrent < GetRowCount(),
2004 _T("invalid item index in OnArrowChar()") );
2005
2006 // if there is no selection, we cannot move it anywhere
2007 if (!HasCurrentRow())
2008 return;
2009
2010 unsigned int oldCurrent = m_currentRow;
2011
2012 // in single selection we just ignore Shift as we can't select several
2013 // items anyhow
2014 if ( event.ShiftDown() && !IsSingleSel() )
2015 {
2016 RefreshRow( oldCurrent );
2017
2018 ChangeCurrentRow( newCurrent );
2019
2020 // select all the items between the old and the new one
2021 if ( oldCurrent > newCurrent )
2022 {
2023 newCurrent = oldCurrent;
2024 oldCurrent = m_currentRow;
2025 }
2026
2027 SelectRows( oldCurrent, newCurrent, true );
2028 if (oldCurrent!=newCurrent)
2029 SendSelectionChangedEvent(GetItemByRow(m_selection[0]));
2030 }
2031 else // !shift
2032 {
2033 RefreshRow( oldCurrent );
2034
2035 // all previously selected items are unselected unless ctrl is held
2036 if ( !event.ControlDown() )
2037 SelectAllRows(false);
2038
2039 ChangeCurrentRow( newCurrent );
2040
2041 if ( !event.ControlDown() )
2042 {
2043 SelectRow( m_currentRow, true );
2044 SendSelectionChangedEvent(GetItemByRow(m_currentRow));
2045 }
2046 else
2047 RefreshRow( m_currentRow );
2048 }
2049
2050 GetOwner()->EnsureVisible( m_currentRow, -1 );
2051 }
2052
2053 wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const
2054 {
2055 wxRect rect;
2056 rect.x = 0;
2057 rect.y = GetLineStart( row );
2058 rect.width = GetEndOfLastCol();
2059 rect.height = GetLineHeight( row );
2060
2061 return rect;
2062 }
2063
2064 int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
2065 {
2066 const wxDataViewModel *model = GetOwner()->GetModel();
2067
2068 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
2069 {
2070 // TODO make more efficient
2071
2072 int start = 0;
2073
2074 unsigned int r;
2075 for (r = 0; r < row; r++)
2076 {
2077 const wxDataViewTreeNode* node = GetTreeNodeByRow(r);
2078 if (!node) return start;
2079
2080 wxDataViewItem item = node->GetItem();
2081
2082 if (node && !node->HasChildren())
2083 {
2084 // Yes, if the node does not have any child, it must be a leaf which
2085 // mean that it is a temporarily created by GetTreeNodeByRow
2086 wxDELETE(node);
2087 }
2088
2089 unsigned int cols = GetOwner()->GetColumnCount();
2090 unsigned int col;
2091 int height = m_lineHeight;
2092 for (col = 0; col < cols; col++)
2093 {
2094 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2095 if (column->IsHidden())
2096 continue; // skip it!
2097
2098 if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item))
2099 continue; // skip it!
2100
2101 const wxDataViewRenderer *renderer = column->GetRenderer();
2102 wxVariant value;
2103 model->GetValue( value, item, column->GetModelColumn() );
2104 wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
2105 renderer2->SetValue( value );
2106 height = wxMax( height, renderer->GetSize().y );
2107 }
2108
2109
2110 start += height;
2111 }
2112
2113 return start;
2114 }
2115 else
2116 {
2117 return row * m_lineHeight;
2118 }
2119 }
2120
2121 int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
2122 {
2123 const wxDataViewModel *model = GetOwner()->GetModel();
2124
2125 // check for the easy case first
2126 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) )
2127 return y / m_lineHeight;
2128
2129 // TODO make more efficient
2130 unsigned int row = 0;
2131 unsigned int yy = 0;
2132 for (;;)
2133 {
2134 const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
2135 if (!node)
2136 {
2137 // not really correct...
2138 return row + ((y-yy) / m_lineHeight);
2139 }
2140
2141 wxDataViewItem item = node->GetItem();
2142
2143 if (node && !node->HasChildren())
2144 {
2145 // Yes, if the node does not have any child, it must be a leaf which
2146 // mean that it is a temporarily created by GetTreeNodeByRow
2147 wxDELETE(node);
2148 }
2149
2150 unsigned int cols = GetOwner()->GetColumnCount();
2151 unsigned int col;
2152 int height = m_lineHeight;
2153 for (col = 0; col < cols; col++)
2154 {
2155 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2156 if (column->IsHidden())
2157 continue; // skip it!
2158
2159 if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item))
2160 continue; // skip it!
2161
2162 const wxDataViewRenderer *renderer = column->GetRenderer();
2163 wxVariant value;
2164 model->GetValue( value, item, column->GetModelColumn() );
2165 wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
2166 renderer2->SetValue( value );
2167 height = wxMax( height, renderer->GetSize().y );
2168 }
2169
2170 yy += height;
2171 if (y < yy)
2172 return row;
2173
2174 row++;
2175 }
2176 }
2177
2178 int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
2179 {
2180 const wxDataViewModel *model = GetOwner()->GetModel();
2181
2182 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
2183 {
2184 wxASSERT( !IsVirtualList() );
2185
2186 const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
2187 // wxASSERT( node );
2188 if (!node) return m_lineHeight;
2189
2190 wxDataViewItem item = node->GetItem();
2191
2192 if (node && !node->HasChildren())
2193 {
2194 // Yes, if the node does not have any child, it must be a leaf which
2195 // mean that it is a temporarily created by GetTreeNodeByRow
2196 wxDELETE(node);
2197 }
2198
2199 int height = m_lineHeight;
2200
2201 unsigned int cols = GetOwner()->GetColumnCount();
2202 unsigned int col;
2203 for (col = 0; col < cols; col++)
2204 {
2205 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2206 if (column->IsHidden())
2207 continue; // skip it!
2208
2209 if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item))
2210 continue; // skip it!
2211
2212 const wxDataViewRenderer *renderer = column->GetRenderer();
2213 wxVariant value;
2214 model->GetValue( value, item, column->GetModelColumn() );
2215 wxDataViewRenderer *renderer2 = const_cast<wxDataViewRenderer*>(renderer);
2216 renderer2->SetValue( value );
2217 height = wxMax( height, renderer->GetSize().y );
2218 }
2219
2220 return height;
2221 }
2222 else
2223 {
2224 return m_lineHeight;
2225 }
2226 }
2227
2228 class RowToItemJob: public DoJob
2229 {
2230 public:
2231 RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current;}
2232 virtual ~RowToItemJob() { }
2233
2234 virtual int operator() ( wxDataViewTreeNode * node )
2235 {
2236 current ++;
2237 if( current == static_cast<int>(row))
2238 {
2239 ret = node->GetItem();
2240 return DoJob::OK;
2241 }
2242
2243 if( node->GetSubTreeCount() + current < static_cast<int>(row) )
2244 {
2245 current += node->GetSubTreeCount();
2246 return DoJob::IGR;
2247 }
2248 else
2249 {
2250 //If the current has no child node, we can find the desired item of the row number directly.
2251 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2252 if( node->GetNodes().GetCount() == 0)
2253 {
2254 int index = static_cast<int>(row) - current - 1;
2255 ret = node->GetChildren().Item( index );
2256 return DoJob::OK;
2257 }
2258 return DoJob::CONT;
2259 }
2260 }
2261
2262 virtual int operator() ( void * n )
2263 {
2264 current ++;
2265 if( current == static_cast<int>(row))
2266 {
2267 ret = wxDataViewItem( n );
2268 return DoJob::OK;
2269 }
2270 return DoJob::CONT;
2271 }
2272 wxDataViewItem GetResult(){ return ret; }
2273 private:
2274 unsigned int row;
2275 int current;
2276 wxDataViewItem ret;
2277 };
2278
2279 wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
2280 {
2281 if (!m_root)
2282 {
2283 return wxDataViewItem( wxUIntToPtr(row) );
2284 }
2285 else
2286 {
2287 RowToItemJob job( row, -2 );
2288 Walker( m_root , job );
2289 return job.GetResult();
2290 }
2291 }
2292
2293 class RowToTreeNodeJob: public DoJob
2294 {
2295 public:
2296 RowToTreeNodeJob( unsigned int row , int current, wxDataViewTreeNode * node )
2297 {
2298 this->row = row;
2299 this->current = current;
2300 ret = NULL;
2301 parent = node;
2302 }
2303 virtual ~RowToTreeNodeJob(){ }
2304
2305 virtual int operator() ( wxDataViewTreeNode * node )
2306 {
2307 current ++;
2308 if( current == static_cast<int>(row))
2309 {
2310 ret = node;
2311 return DoJob::OK;
2312 }
2313
2314 if( node->GetSubTreeCount() + current < static_cast<int>(row) )
2315 {
2316 current += node->GetSubTreeCount();
2317 return DoJob::IGR;
2318 }
2319 else
2320 {
2321 parent = node;
2322 //If the current has no child node, we can find the desired item of the row number directly.
2323 //This if can speed up finding in some case, and will has a very good effect when it comes to list view
2324 if( node->GetNodes().GetCount() == 0)
2325 {
2326 int index = static_cast<int>(row) - current - 1;
2327 void * n = node->GetChildren().Item( index );
2328 ret = new wxDataViewTreeNode( parent );
2329 ret->SetItem( wxDataViewItem( n ));
2330 ret->SetHasChildren(false);
2331 return DoJob::OK;
2332 }
2333 return DoJob::CONT;
2334 }
2335
2336
2337 }
2338
2339 virtual int operator() ( void * n )
2340 {
2341 current ++;
2342 if( current == static_cast<int>(row))
2343 {
2344 ret = new wxDataViewTreeNode( parent );
2345 ret->SetItem( wxDataViewItem( n ));
2346 ret->SetHasChildren(false);
2347 return DoJob::OK;
2348 }
2349
2350 return DoJob::CONT;
2351 }
2352 wxDataViewTreeNode * GetResult(){ return ret; }
2353 private:
2354 unsigned int row;
2355 int current;
2356 wxDataViewTreeNode * ret;
2357 wxDataViewTreeNode * parent;
2358 };
2359
2360
2361 wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) const
2362 {
2363 wxASSERT( !IsVirtualList() );
2364
2365 RowToTreeNodeJob job( row , -2, m_root );
2366 Walker( m_root , job );
2367 return job.GetResult();
2368 }
2369
2370 wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
2371 {
2372 wxWindow *parent = GetParent();
2373 wxDataViewEvent le(type, parent->GetId());
2374
2375 le.SetEventObject(parent);
2376 le.SetModel(GetOwner()->GetModel());
2377 le.SetItem( item );
2378
2379 parent->GetEventHandler()->ProcessEvent(le);
2380 return le;
2381 }
2382
2383 void wxDataViewMainWindow::OnExpanding( unsigned int row )
2384 {
2385 if (IsVirtualList())
2386 return;
2387
2388 wxDataViewTreeNode * node = GetTreeNodeByRow(row);
2389 if( node != NULL )
2390 {
2391 if( node->HasChildren())
2392 {
2393 if( !node->IsOpen())
2394 {
2395 wxDataViewEvent e = SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,node->GetItem());
2396 //Check if the user prevent expanding
2397 if( e.GetSkipped() )
2398 return;
2399
2400 node->ToggleOpen();
2401 //Here I build the children of current node
2402 if( node->GetChildrenNumber() == 0 )
2403 {
2404 SortPrepare();
2405 ::BuildTreeHelper(GetOwner()->GetModel(), node->GetItem(), node);
2406 }
2407 m_count = -1;
2408 UpdateDisplay();
2409 //Send the expanded event
2410 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,node->GetItem());
2411 }
2412 else
2413 {
2414 SelectRow( row, false );
2415 SelectRow( row + 1, true );
2416 ChangeCurrentRow( row + 1 );
2417 SendSelectionChangedEvent( GetItemByRow(row+1));
2418 }
2419 }
2420 else
2421 delete node;
2422 }
2423 }
2424
2425 void wxDataViewMainWindow::OnCollapsing(unsigned int row)
2426 {
2427 if (IsVirtualList())
2428 return;
2429
2430 wxDataViewTreeNode * node = GetTreeNodeByRow(row);
2431 if( node != NULL )
2432 {
2433 wxDataViewTreeNode * nd = node;
2434
2435 if( node->HasChildren() && node->IsOpen() )
2436 {
2437 wxDataViewEvent e = SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem());
2438 if( e.GetSkipped() )
2439 return;
2440 node->ToggleOpen();
2441 m_count = -1;
2442 UpdateDisplay();
2443 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,nd->GetItem());
2444 }
2445 else
2446 {
2447 node = node->GetParent();
2448 if( node != NULL )
2449 {
2450 int parent = GetRowByItem( node->GetItem() );
2451 if( parent >= 0 )
2452 {
2453 SelectRow( row, false);
2454 SelectRow(parent , true );
2455 ChangeCurrentRow( parent );
2456 SendSelectionChangedEvent( node->GetItem() );
2457 }
2458 }
2459 }
2460 if( !nd->HasChildren())
2461 delete nd;
2462 }
2463 }
2464
2465 wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item )
2466 {
2467 wxDataViewModel * model = GetOwner()->GetModel();
2468 if( model == NULL )
2469 return NULL;
2470
2471 //Compose the a parent-chain of the finding item
2472 ItemList list;
2473 list.DeleteContents( true );
2474 wxDataViewItem it( item );
2475 while( it.IsOk() )
2476 {
2477 wxDataViewItem * pItem = new wxDataViewItem( it );
2478 list.Insert( pItem );
2479 it = model->GetParent( it );
2480 }
2481
2482 //Find the item along the parent-chain.
2483 //This algorithm is designed to speed up the node-finding method
2484 wxDataViewTreeNode * node = m_root;
2485 for( ItemList::const_iterator iter = list.begin(); iter !=list.end(); iter++ )
2486 {
2487 if( node->HasChildren() )
2488 {
2489 if( node->GetChildrenNumber() == 0 )
2490 {
2491 SortPrepare();
2492 ::BuildTreeHelper(model, node->GetItem(), node);
2493 }
2494
2495 wxDataViewTreeNodes nodes = node->GetNodes();
2496 unsigned int i;
2497 bool found = false;
2498
2499 for (i = 0; i < nodes.GetCount(); i ++)
2500 {
2501 if (nodes[i]->GetItem() == (**iter))
2502 {
2503 if (nodes[i]->GetItem() == item)
2504 return nodes[i];
2505
2506 node = nodes[i];
2507 found = true;
2508 break;
2509 }
2510 }
2511 if (!found)
2512 return NULL;
2513 }
2514 else
2515 return NULL;
2516 }
2517 return NULL;
2518 }
2519
2520 void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column )
2521 {
2522 wxDataViewColumn *col = NULL;
2523 unsigned int cols = GetOwner()->GetColumnCount();
2524 unsigned int colnum = 0;
2525 int x, y;
2526 m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y );
2527 for (unsigned x_start = 0; colnum < cols; colnum++)
2528 {
2529 col = GetOwner()->GetColumn(colnum);
2530 if (col->IsHidden())
2531 continue; // skip it!
2532
2533 unsigned int w = col->GetWidth();
2534 if (x_start+w >= (unsigned int)x)
2535 break;
2536
2537 x_start += w;
2538 }
2539
2540 column = col;
2541 item = GetItemByRow( GetLineAt( y ) );
2542 }
2543
2544 wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column )
2545 {
2546 int row = GetRowByItem(item);
2547 int y = GetLineStart( row );
2548 int h = GetLineHeight( m_lineHeight );
2549 int x = 0;
2550 wxDataViewColumn *col = NULL;
2551 for( int i = 0, cols = GetOwner()->GetColumnCount(); i < cols; i ++ )
2552 {
2553 col = GetOwner()->GetColumn( i );
2554 x += col->GetWidth();
2555 if( GetOwner()->GetColumn(i+1) == column )
2556 break;
2557 }
2558 int w = col->GetWidth();
2559 m_owner->CalcScrolledPosition( x, y, &x, &y );
2560 return wxRect(x, y, w, h);
2561 }
2562
2563 int wxDataViewMainWindow::RecalculateCount()
2564 {
2565 if (!m_root)
2566 {
2567 wxDataViewIndexListModel *list_model = (wxDataViewIndexListModel*) GetOwner()->GetModel();
2568 #ifndef __WXMAC__
2569 return list_model->GetLastIndex() + 1;
2570 #else
2571 return list_model->GetLastIndex() - 1;
2572 #endif
2573 }
2574 else
2575 {
2576 return m_root->GetSubTreeCount();
2577 }
2578 }
2579
2580 class ItemToRowJob : public DoJob
2581 {
2582 public:
2583 ItemToRowJob(const wxDataViewItem& item_, ItemList::const_iterator iter)
2584 : m_iter(iter),
2585 item(item_)
2586 {
2587 ret = -1;
2588 }
2589
2590 //Maybe binary search will help to speed up this process
2591 virtual int operator() ( wxDataViewTreeNode * node)
2592 {
2593 ret ++;
2594 if( node->GetItem() == item )
2595 {
2596 return DoJob::OK;
2597 }
2598
2599 if( node->GetItem() == **m_iter )
2600 {
2601 m_iter++;
2602 return DoJob::CONT;
2603 }
2604 else
2605 {
2606 ret += node->GetSubTreeCount();
2607 return DoJob::IGR;
2608 }
2609
2610 }
2611
2612 virtual int operator() ( void * n )
2613 {
2614 ret ++;
2615 if( n == item.GetID() )
2616 return DoJob::OK;
2617 return DoJob::CONT;
2618 }
2619 //the row number is begin from zero
2620 int GetResult() { return ret -1; }
2621
2622 private:
2623 ItemList::const_iterator m_iter;
2624 wxDataViewItem item;
2625 int ret;
2626
2627 };
2628
2629 int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const
2630 {
2631 const wxDataViewModel * model = GetOwner()->GetModel();
2632 if( model == NULL )
2633 return -1;
2634
2635 if (!m_root)
2636 {
2637 return wxPtrToUInt( item.GetID() );
2638 }
2639 else
2640 {
2641 if( !item.IsOk() )
2642 return -1;
2643
2644 //Compose the a parent-chain of the finding item
2645 ItemList list;
2646 wxDataViewItem * pItem;
2647 list.DeleteContents( true );
2648 wxDataViewItem it( item );
2649 while( it.IsOk() )
2650 {
2651 pItem = new wxDataViewItem( it );
2652 list.Insert( pItem );
2653 it = model->GetParent( it );
2654 }
2655 pItem = new wxDataViewItem( );
2656 list.Insert( pItem );
2657
2658 ItemToRowJob job( item, list.begin() );
2659 Walker(m_root , job );
2660 return job.GetResult();
2661 }
2662 }
2663
2664 static void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
2665 {
2666 if( !model->IsContainer( item ) )
2667 return;
2668
2669 wxDataViewItemArray children;
2670 unsigned int num = model->GetChildren( item, children);
2671 unsigned int index = 0;
2672 while( index < num )
2673 {
2674 if( model->IsContainer( children[index] ) )
2675 {
2676 wxDataViewTreeNode * n = new wxDataViewTreeNode( node );
2677 n->SetItem(children[index]);
2678 n->SetHasChildren( true );
2679 node->AddNode( n );
2680 }
2681 else
2682 {
2683 node->AddLeaf( children[index].GetID() );
2684 }
2685 index ++;
2686 }
2687 node->SetSubTreeCount( num );
2688 wxDataViewTreeNode * n = node->GetParent();
2689 if( n != NULL)
2690 n->ChangeSubTreeCount(num);
2691
2692 }
2693
2694 void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
2695 {
2696 DestroyTree();
2697
2698 if (GetOwner()->GetModel()->IsVirtualListModel())
2699 {
2700 m_count = -1;
2701 return;
2702 }
2703
2704 m_root = new wxDataViewTreeNode( NULL );
2705 m_root->SetHasChildren(true);
2706
2707 //First we define a invalid item to fetch the top-level elements
2708 wxDataViewItem item;
2709 SortPrepare();
2710 BuildTreeHelper( model, item, m_root);
2711 m_count = -1;
2712 }
2713
2714 static void DestroyTreeHelper( wxDataViewTreeNode * node )
2715 {
2716 if( node->GetNodeNumber() != 0 )
2717 {
2718 int len = node->GetNodeNumber();
2719 int i = 0;
2720 wxDataViewTreeNodes& nodes = node->GetNodes();
2721 for(; i < len; i ++ )
2722 {
2723 DestroyTreeHelper(nodes[i]);
2724 }
2725 }
2726 delete node;
2727 }
2728
2729 void wxDataViewMainWindow::DestroyTree()
2730 {
2731 if (!IsVirtualList())
2732 {
2733 ::DestroyTreeHelper(m_root);
2734 m_count = 0;
2735 m_root = NULL;
2736 }
2737 }
2738
2739 void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
2740 {
2741 if ( GetParent()->HandleAsNavigationKey(event) )
2742 return;
2743
2744 // no item -> nothing to do
2745 if (!HasCurrentRow())
2746 {
2747 event.Skip();
2748 return;
2749 }
2750
2751 // don't use m_linesPerPage directly as it might not be computed yet
2752 const int pageSize = GetCountPerPage();
2753 wxCHECK_RET( pageSize, _T("should have non zero page size") );
2754
2755 switch ( event.GetKeyCode() )
2756 {
2757 case WXK_RETURN:
2758 {
2759 if (m_currentRow > 0)
2760 {
2761 wxWindow *parent = GetParent();
2762 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
2763 le.SetItem( GetItemByRow(m_currentRow) );
2764 le.SetEventObject(parent);
2765 le.SetModel(GetOwner()->GetModel());
2766
2767 parent->GetEventHandler()->ProcessEvent(le);
2768 }
2769 break;
2770 }
2771 case WXK_UP:
2772 if ( m_currentRow > 0 )
2773 OnArrowChar( m_currentRow - 1, event );
2774 break;
2775
2776 case WXK_DOWN:
2777 if ( m_currentRow < GetRowCount() - 1 )
2778 OnArrowChar( m_currentRow + 1, event );
2779 break;
2780 //Add the process for tree expanding/collapsing
2781 case WXK_LEFT:
2782 OnCollapsing(m_currentRow);
2783 break;
2784 case WXK_RIGHT:
2785 OnExpanding( m_currentRow);
2786 break;
2787 case WXK_END:
2788 if (!IsEmpty())
2789 OnArrowChar( GetRowCount() - 1, event );
2790 break;
2791
2792 case WXK_HOME:
2793 if (!IsEmpty())
2794 OnArrowChar( 0, event );
2795 break;
2796
2797 case WXK_PAGEUP:
2798 {
2799 int steps = pageSize - 1;
2800 int index = m_currentRow - steps;
2801 if (index < 0)
2802 index = 0;
2803
2804 OnArrowChar( index, event );
2805 }
2806 break;
2807
2808 case WXK_PAGEDOWN:
2809 {
2810 int steps = pageSize - 1;
2811 unsigned int index = m_currentRow + steps;
2812 unsigned int count = GetRowCount();
2813 if ( index >= count )
2814 index = count - 1;
2815
2816 OnArrowChar( index, event );
2817 }
2818 break;
2819
2820 default:
2821 event.Skip();
2822 }
2823 }
2824
2825 void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
2826 {
2827 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
2828 {
2829 // let the base handle mouse wheel events.
2830 event.Skip();
2831 return;
2832 }
2833
2834 int x = event.GetX();
2835 int y = event.GetY();
2836 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
2837 wxDataViewColumn *col = NULL;
2838
2839 int xpos = 0;
2840 unsigned int cols = GetOwner()->GetColumnCount();
2841 unsigned int i;
2842 for (i = 0; i < cols; i++)
2843 {
2844 wxDataViewColumn *c = GetOwner()->GetColumn( i );
2845 if (c->IsHidden())
2846 continue; // skip it!
2847
2848 if (x < xpos + c->GetWidth())
2849 {
2850 col = c;
2851 break;
2852 }
2853 xpos += c->GetWidth();
2854 }
2855 if (!col)
2856 return;
2857
2858 wxDataViewRenderer *cell = col->GetRenderer();
2859 unsigned int current = GetLineAt( y );
2860 if ((current > GetRowCount()) || (x > GetEndOfLastCol()))
2861 {
2862 // Unselect all if below the last row ?
2863 return;
2864 }
2865
2866 //Test whether the mouse is hovered on the tree item button
2867 bool hover = false;
2868 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col))
2869 {
2870 wxDataViewTreeNode * node = GetTreeNodeByRow(current);
2871 if( node!=NULL && node->HasChildren() )
2872 {
2873 int indent = node->GetIndentLevel();
2874 indent = GetOwner()->GetIndent()*indent;
2875 wxRect rect( xpos + indent + EXPANDER_MARGIN,
2876 GetLineStart( current ) + EXPANDER_MARGIN + (GetLineHeight(current)/2) - (m_lineHeight/2) - EXPANDER_OFFSET,
2877 m_lineHeight-2*EXPANDER_MARGIN,
2878 m_lineHeight-2*EXPANDER_MARGIN + EXPANDER_OFFSET);
2879 if( rect.Contains( x, y) )
2880 {
2881 //So the mouse is over the expander
2882 hover = true;
2883 if (m_underMouse && m_underMouse != node)
2884 {
2885 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2886 RefreshRow(GetRowByItem(m_underMouse->GetItem()));
2887 }
2888 if (m_underMouse != node)
2889 {
2890 //wxLogMessage("Do the row: %d", current);
2891 RefreshRow(current);
2892 }
2893 m_underMouse = node;
2894 }
2895 }
2896 if (node!=NULL && !node->HasChildren())
2897 delete node;
2898 }
2899 if (!hover)
2900 {
2901 if (m_underMouse != NULL)
2902 {
2903 //wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
2904 RefreshRow(GetRowByItem(m_underMouse->GetItem()));
2905 m_underMouse = NULL;
2906 }
2907 }
2908
2909 wxDataViewModel *model = GetOwner()->GetModel();
2910
2911 if (event.Dragging())
2912 {
2913 if (m_dragCount == 0)
2914 {
2915 // we have to report the raw, physical coords as we want to be
2916 // able to call HitTest(event.m_pointDrag) from the user code to
2917 // get the item being dragged
2918 m_dragStart = event.GetPosition();
2919 }
2920
2921 m_dragCount++;
2922
2923 if (m_dragCount != 3)
2924 return;
2925
2926 if (event.LeftIsDown())
2927 {
2928 // Notify cell about drag
2929 }
2930 return;
2931 }
2932 else
2933 {
2934 m_dragCount = 0;
2935 }
2936
2937 bool forceClick = false;
2938
2939 if (event.ButtonDClick())
2940 {
2941 m_renameTimer->Stop();
2942 m_lastOnSame = false;
2943 }
2944
2945 wxDataViewItem item = GetItemByRow(current);
2946 bool ignore_other_columns =
2947 ((GetOwner()->GetExpanderColumn() != col) &&
2948 (model->IsContainer(item)) &&
2949 (!model->HasContainerColumns(item)));
2950
2951 if (event.LeftDClick())
2952 {
2953 if ( current == m_lineLastClicked )
2954 {
2955 if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
2956 {
2957 wxVariant value;
2958 model->GetValue( value, item, col->GetModelColumn() );
2959 cell->SetValue( value );
2960 wxRect cell_rect( xpos, GetLineStart( current ),
2961 col->GetWidth(), GetLineHeight( current ) );
2962 cell->Activate( cell_rect, model, item, col->GetModelColumn() );
2963
2964 }
2965 else
2966 {
2967 wxWindow *parent = GetParent();
2968 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
2969 le.SetItem( item );
2970 le.SetEventObject(parent);
2971 le.SetModel(GetOwner()->GetModel());
2972
2973 parent->GetEventHandler()->ProcessEvent(le);
2974 }
2975 return;
2976 }
2977 else
2978 {
2979 // The first click was on another item, so don't interpret this as
2980 // a double click, but as a simple click instead
2981 forceClick = true;
2982 }
2983 }
2984
2985 if (event.LeftUp())
2986 {
2987 if (m_lineSelectSingleOnUp != (unsigned int)-1)
2988 {
2989 // select single line
2990 SelectAllRows( false );
2991 SelectRow( m_lineSelectSingleOnUp, true );
2992 }
2993
2994 //Process the event of user clicking the expander
2995 bool expander = false;
2996 if ((!IsVirtualList()) && (GetOwner()->GetExpanderColumn() == col))
2997 {
2998 wxDataViewTreeNode * node = GetTreeNodeByRow(current);
2999 if( node!=NULL && node->HasChildren() )
3000 {
3001 int indent = node->GetIndentLevel();
3002 indent = GetOwner()->GetIndent()*indent;
3003 wxRect rect( xpos + indent + EXPANDER_MARGIN,
3004 GetLineStart( current ) + EXPANDER_MARGIN + (GetLineHeight(current)/2) - (m_lineHeight/2) - EXPANDER_OFFSET,
3005 m_lineHeight-2*EXPANDER_MARGIN,
3006 m_lineHeight-2*EXPANDER_MARGIN + EXPANDER_OFFSET);
3007
3008 if( rect.Contains( x, y) )
3009 {
3010 expander = true;
3011 if( node->IsOpen() )
3012 OnCollapsing(current);
3013 else
3014 OnExpanding( current );
3015 }
3016 }
3017 if (node && !node->HasChildren())
3018 delete node;
3019 }
3020 //If the user click the expander, we do not do editing even if the column with expander are editable
3021 if (m_lastOnSame && !expander && !ignore_other_columns)
3022 {
3023 if ((col == m_currentCol) && (current == m_currentRow) &&
3024 (cell->GetMode() & wxDATAVIEW_CELL_EDITABLE) )
3025 {
3026 m_renameTimer->Start( 100, true );
3027 }
3028 }
3029
3030 m_lastOnSame = false;
3031 m_lineSelectSingleOnUp = (unsigned int)-1;
3032 }
3033 else
3034 {
3035 // This is necessary, because after a DnD operation in
3036 // from and to ourself, the up event is swallowed by the
3037 // DnD code. So on next non-up event (which means here and
3038 // now) m_lineSelectSingleOnUp should be reset.
3039 m_lineSelectSingleOnUp = (unsigned int)-1;
3040 }
3041
3042 if (event.RightDown())
3043 {
3044 m_lineBeforeLastClicked = m_lineLastClicked;
3045 m_lineLastClicked = current;
3046
3047 // If the item is already selected, do not update the selection.
3048 // Multi-selections should not be cleared if a selected item is clicked.
3049 if (!IsRowSelected(current))
3050 {
3051 SelectAllRows(false);
3052 ChangeCurrentRow(current);
3053 SelectRow(m_currentRow,true);
3054 SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
3055 }
3056
3057 wxVariant value;
3058 model->GetValue( value, item, col->GetModelColumn() );
3059 wxWindow *parent = GetParent();
3060 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
3061 le.SetItem( item );
3062 le.SetEventObject(parent);
3063 le.SetModel(GetOwner()->GetModel());
3064 le.SetValue(value);
3065 parent->GetEventHandler()->ProcessEvent(le);
3066 }
3067 else if (event.MiddleDown())
3068 {
3069 }
3070 if (event.LeftDown() || forceClick)
3071 {
3072 SetFocus();
3073
3074 m_lineBeforeLastClicked = m_lineLastClicked;
3075 m_lineLastClicked = current;
3076
3077 unsigned int oldCurrentRow = m_currentRow;
3078 bool oldWasSelected = IsRowSelected(m_currentRow);
3079
3080 bool cmdModifierDown = event.CmdDown();
3081 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
3082 {
3083 if ( IsSingleSel() || !IsRowSelected(current) )
3084 {
3085 SelectAllRows( false );
3086 ChangeCurrentRow(current);
3087 SelectRow(m_currentRow,true);
3088 SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
3089 }
3090 else // multi sel & current is highlighted & no mod keys
3091 {
3092 m_lineSelectSingleOnUp = current;
3093 ChangeCurrentRow(current); // change focus
3094 }
3095 }
3096 else // multi sel & either ctrl or shift is down
3097 {
3098 if (cmdModifierDown)
3099 {
3100 ChangeCurrentRow(current);
3101 ReverseRowSelection(m_currentRow);
3102 SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
3103 }
3104 else if (event.ShiftDown())
3105 {
3106 ChangeCurrentRow(current);
3107
3108 unsigned int lineFrom = oldCurrentRow,
3109 lineTo = current;
3110
3111 if ( lineTo < lineFrom )
3112 {
3113 lineTo = lineFrom;
3114 lineFrom = m_currentRow;
3115 }
3116
3117 SelectRows(lineFrom, lineTo, true);
3118 SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
3119 }
3120 else // !ctrl, !shift
3121 {
3122 // test in the enclosing if should make it impossible
3123 wxFAIL_MSG( _T("how did we get here?") );
3124 }
3125 }
3126
3127 if (m_currentRow != oldCurrentRow)
3128 RefreshRow( oldCurrentRow );
3129
3130 wxDataViewColumn *oldCurrentCol = m_currentCol;
3131
3132 // Update selection here...
3133 m_currentCol = col;
3134
3135 m_lastOnSame = !forceClick && ((col == oldCurrentCol) &&
3136 (current == oldCurrentRow)) && oldWasSelected;
3137
3138 // Call LeftClick after everything else as under GTK+
3139 if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
3140 {
3141 // notify cell about right click
3142 wxVariant value;
3143 model->GetValue( value, item, col->GetModelColumn() );
3144 cell->SetValue( value );
3145 wxRect cell_rect( xpos, GetLineStart( current ),
3146 col->GetWidth(), GetLineHeight( current ) );
3147 /* ignore ret */ cell->LeftClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn());
3148 }
3149 }
3150 }
3151
3152 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
3153 {
3154 m_hasFocus = true;
3155
3156 if (HasCurrentRow())
3157 Refresh();
3158
3159 event.Skip();
3160 }
3161
3162 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event )
3163 {
3164 m_hasFocus = false;
3165
3166 if (HasCurrentRow())
3167 Refresh();
3168
3169 event.Skip();
3170 }
3171
3172 wxDataViewItem wxDataViewMainWindow::GetSelection() const
3173 {
3174 if( m_selection.GetCount() != 1 )
3175 return wxDataViewItem();
3176
3177 return GetItemByRow( m_selection.Item(0));
3178 }
3179
3180 //-----------------------------------------------------------------------------
3181 // wxDataViewCtrl
3182 //-----------------------------------------------------------------------------
3183 WX_DEFINE_LIST(wxDataViewColumnList)
3184
3185 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
3186
3187 BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
3188 EVT_SIZE(wxDataViewCtrl::OnSize)
3189 END_EVENT_TABLE()
3190
3191 wxDataViewCtrl::~wxDataViewCtrl()
3192 {
3193 if (m_notifier)
3194 GetModel()->RemoveNotifier( m_notifier );
3195
3196 m_cols.Clear();
3197 }
3198
3199 void wxDataViewCtrl::Init()
3200 {
3201 m_cols.DeleteContents(true);
3202 m_notifier = NULL;
3203
3204 // No sorting column at start
3205 m_sortingColumn = NULL;
3206 m_headerArea = NULL;
3207 }
3208
3209 bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
3210 const wxPoint& pos, const wxSize& size,
3211 long style, const wxValidator& validator )
3212 {
3213 if ( (style & wxBORDER_MASK) == 0)
3214 style |= wxBORDER_SUNKEN;
3215
3216 Init();
3217
3218 if (!wxControl::Create( parent, id, pos, size,
3219 style | wxScrolledWindowStyle, validator))
3220 return false;
3221
3222 SetInitialSize(size);
3223
3224 #ifdef __WXMAC__
3225 MacSetClipChildren( true );
3226 #endif
3227
3228 m_clientArea = new wxDataViewMainWindow( this, wxID_ANY );
3229
3230 if (HasFlag(wxDV_NO_HEADER))
3231 m_headerArea = NULL;
3232 else
3233 m_headerArea = new wxDataViewHeaderWindow(this);
3234
3235 SetTargetWindow( m_clientArea );
3236
3237 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
3238 if (m_headerArea)
3239 sizer->Add( m_headerArea, 0, wxGROW );
3240 sizer->Add( m_clientArea, 1, wxGROW );
3241 SetSizer( sizer );
3242
3243 return true;
3244 }
3245
3246 #ifdef __WXMSW__
3247 WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
3248 WXWPARAM wParam,
3249 WXLPARAM lParam)
3250 {
3251 WXLRESULT rc = wxDataViewCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
3252
3253 #ifndef __WXWINCE__
3254 // we need to process arrows ourselves for scrolling
3255 if ( nMsg == WM_GETDLGCODE )
3256 {
3257 rc |= DLGC_WANTARROWS;
3258 }
3259 #endif
3260
3261 return rc;
3262 }
3263 #endif
3264
3265 wxSize wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize& size)
3266 {
3267 wxSize newsize = size;
3268 if (!HasFlag(wxDV_NO_HEADER) && (m_headerArea))
3269 newsize.y -= m_headerArea->GetSize().y;
3270
3271 return newsize;
3272 }
3273
3274 void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
3275 {
3276 // We need to override OnSize so that our scrolled
3277 // window a) does call Layout() to use sizers for
3278 // positioning the controls but b) does not query
3279 // the sizer for their size and use that for setting
3280 // the scrollable area as set that ourselves by
3281 // calling SetScrollbar() further down.
3282
3283 Layout();
3284
3285 AdjustScrollbars();
3286 }
3287
3288 void wxDataViewCtrl::SetFocus()
3289 {
3290 if (m_clientArea)
3291 m_clientArea->SetFocus();
3292 }
3293
3294 bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
3295 {
3296 if (!wxDataViewCtrlBase::AssociateModel( model ))
3297 return false;
3298
3299 m_notifier = new wxGenericDataViewModelNotifier( m_clientArea );
3300
3301 model->AddNotifier( m_notifier );
3302
3303 m_clientArea->DestroyTree();
3304
3305 m_clientArea->BuildTree(model);
3306
3307 m_clientArea->UpdateDisplay();
3308
3309 return true;
3310 }
3311
3312 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
3313 {
3314 if (!wxDataViewCtrlBase::AppendColumn(col))
3315 return false;
3316
3317 m_cols.Append( col );
3318 OnColumnsCountChanged();
3319 return true;
3320 }
3321
3322 bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
3323 {
3324 if (!wxDataViewCtrlBase::PrependColumn(col))
3325 return false;
3326
3327 m_cols.Insert( col );
3328 OnColumnsCountChanged();
3329 return true;
3330 }
3331
3332 bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
3333 {
3334 if (!wxDataViewCtrlBase::InsertColumn(pos,col))
3335 return false;
3336
3337 m_cols.Insert( pos, col );
3338 OnColumnsCountChanged();
3339 return true;
3340 }
3341
3342 void wxDataViewCtrl::OnColumnChange(unsigned int idx)
3343 {
3344 if ( m_headerArea )
3345 m_headerArea->UpdateColumn(idx);
3346
3347 m_clientArea->UpdateDisplay();
3348 }
3349
3350 void wxDataViewCtrl::OnColumnsCountChanged()
3351 {
3352 if (m_headerArea)
3353 m_headerArea->SetColumnCount(GetColumnCount());
3354
3355 m_clientArea->UpdateDisplay();
3356 }
3357
3358 void wxDataViewCtrl::DoSetExpanderColumn()
3359 {
3360 m_clientArea->UpdateDisplay();
3361 }
3362
3363 void wxDataViewCtrl::DoSetIndent()
3364 {
3365 m_clientArea->UpdateDisplay();
3366 }
3367
3368 unsigned int wxDataViewCtrl::GetColumnCount() const
3369 {
3370 return m_cols.GetCount();
3371 }
3372
3373 wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int idx ) const
3374 {
3375 return m_cols[idx];
3376 }
3377
3378 void wxDataViewCtrl::ColumnMoved( wxDataViewColumn* col, unsigned int new_pos )
3379 {
3380 if (new_pos > m_cols.GetCount()) return;
3381
3382 // Exchange position
3383 m_cols.DeleteContents(false);
3384 m_cols.DeleteObject( col );
3385 m_cols.Insert( new_pos, col );
3386 m_cols.DeleteContents(true);
3387
3388 m_clientArea->UpdateDisplay();
3389 }
3390
3391 bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
3392 {
3393 wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column );
3394 if (!ret)
3395 return false;
3396
3397 m_cols.Erase(ret);
3398 OnColumnsCountChanged();
3399
3400 return true;
3401 }
3402
3403 bool wxDataViewCtrl::ClearColumns()
3404 {
3405 m_cols.Clear();
3406 OnColumnsCountChanged();
3407 return true;
3408 }
3409
3410 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
3411 {
3412 int ret = 0, dead = 0;
3413 int len = GetColumnCount();
3414 for (int i=0; i<len; i++)
3415 {
3416 wxDataViewColumn * col = GetColumn(i);
3417 if (col->IsHidden())
3418 continue;
3419 ret += col->GetWidth();
3420 if (column==col)
3421 {
3422 CalcScrolledPosition( ret, dead, &ret, &dead );
3423 break;
3424 }
3425 }
3426 return ret;
3427 }
3428
3429 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
3430 {
3431 return NULL;
3432 }
3433
3434 //Selection code with wxDataViewItem as parameters
3435 wxDataViewItem wxDataViewCtrl::GetSelection() const
3436 {
3437 return m_clientArea->GetSelection();
3438 }
3439
3440 int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
3441 {
3442 sel.Empty();
3443 wxDataViewSelection selection = m_clientArea->GetSelections();
3444 int len = selection.GetCount();
3445 for( int i = 0; i < len; i ++)
3446 {
3447 unsigned int row = selection[i];
3448 sel.Add( m_clientArea->GetItemByRow( row ) );
3449 }
3450 return len;
3451 }
3452
3453 void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
3454 {
3455 wxDataViewSelection selection(wxDataViewSelectionCmp);
3456 int len = sel.GetCount();
3457 for( int i = 0; i < len; i ++ )
3458 {
3459 int row = m_clientArea->GetRowByItem( sel[i] );
3460 if( row >= 0 )
3461 selection.Add( static_cast<unsigned int>(row) );
3462 }
3463 m_clientArea->SetSelections( selection );
3464 }
3465
3466 void wxDataViewCtrl::Select( const wxDataViewItem & item )
3467 {
3468 int row = m_clientArea->GetRowByItem( item );
3469 if( row >= 0 )
3470 {
3471 //Unselect all rows before select another in the single select mode
3472 if (m_clientArea->IsSingleSel())
3473 m_clientArea->SelectAllRows(false);
3474 m_clientArea->SelectRow(row, true);
3475 }
3476 }
3477
3478 void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
3479 {
3480 int row = m_clientArea->GetRowByItem( item );
3481 if( row >= 0 )
3482 m_clientArea->SelectRow(row, false);
3483 }
3484
3485 bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
3486 {
3487 int row = m_clientArea->GetRowByItem( item );
3488 if( row >= 0 )
3489 {
3490 return m_clientArea->IsRowSelected(row);
3491 }
3492 return false;
3493 }
3494
3495 //Selection code with row number as parameter
3496 int wxDataViewCtrl::GetSelections( wxArrayInt & sel ) const
3497 {
3498 sel.Empty();
3499 wxDataViewSelection selection = m_clientArea->GetSelections();
3500 int len = selection.GetCount();
3501 for( int i = 0; i < len; i ++)
3502 {
3503 unsigned int row = selection[i];
3504 sel.Add( row );
3505 }
3506 return len;
3507 }
3508
3509 void wxDataViewCtrl::SetSelections( const wxArrayInt & sel )
3510 {
3511 wxDataViewSelection selection(wxDataViewSelectionCmp);
3512 int len = sel.GetCount();
3513 for( int i = 0; i < len; i ++ )
3514 {
3515 int row = sel[i];
3516 if( row >= 0 )
3517 selection.Add( static_cast<unsigned int>(row) );
3518 }
3519 m_clientArea->SetSelections( selection );
3520 }
3521
3522 void wxDataViewCtrl::Select( int row )
3523 {
3524 if( row >= 0 )
3525 {
3526 if (m_clientArea->IsSingleSel())
3527 m_clientArea->SelectAllRows(false);
3528 m_clientArea->SelectRow( row, true );
3529 }
3530 }
3531
3532 void wxDataViewCtrl::Unselect( int row )
3533 {
3534 if( row >= 0 )
3535 m_clientArea->SelectRow(row, false);
3536 }
3537
3538 bool wxDataViewCtrl::IsSelected( int row ) const
3539 {
3540 if( row >= 0 )
3541 return m_clientArea->IsRowSelected(row);
3542 return false;
3543 }
3544
3545 void wxDataViewCtrl::SelectRange( int from, int to )
3546 {
3547 wxArrayInt sel;
3548 for( int i = from; i < to; i ++ )
3549 sel.Add( i );
3550 m_clientArea->Select(sel);
3551 }
3552
3553 void wxDataViewCtrl::UnselectRange( int from, int to )
3554 {
3555 wxDataViewSelection sel = m_clientArea->GetSelections();
3556 for( int i = from; i < to; i ++ )
3557 if( sel.Index( i ) != wxNOT_FOUND )
3558 sel.Remove( i );
3559 m_clientArea->SetSelections(sel);
3560 }
3561
3562 void wxDataViewCtrl::SelectAll()
3563 {
3564 m_clientArea->SelectAllRows(true);
3565 }
3566
3567 void wxDataViewCtrl::UnselectAll()
3568 {
3569 m_clientArea->SelectAllRows(false);
3570 }
3571
3572 void wxDataViewCtrl::EnsureVisible( int row, int column )
3573 {
3574 if( row < 0 )
3575 row = 0;
3576 if( row > (int) m_clientArea->GetRowCount() )
3577 row = m_clientArea->GetRowCount();
3578
3579 int first = m_clientArea->GetFirstVisibleRow();
3580 int last = m_clientArea->GetLastVisibleRow();
3581 if( row < first )
3582 m_clientArea->ScrollTo( row, column );
3583 else if( row > last )
3584 m_clientArea->ScrollTo( row - last + first, column );
3585 else
3586 m_clientArea->ScrollTo( first, column );
3587 }
3588
3589 void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn * column )
3590 {
3591 int row = m_clientArea->GetRowByItem(item);
3592 if( row >= 0 )
3593 {
3594 if( column == NULL )
3595 EnsureVisible(row, -1);
3596 else
3597 {
3598 int col = 0;
3599 int len = GetColumnCount();
3600 for( int i = 0; i < len; i ++ )
3601 if( GetColumn(i) == column )
3602 {
3603 col = i;
3604 break;
3605 }
3606 EnsureVisible( row, col );
3607 }
3608 }
3609
3610 }
3611
3612 void wxDataViewCtrl::HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const
3613 {
3614 m_clientArea->HitTest(point, item, column);
3615 }
3616
3617 wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column ) const
3618 {
3619 return m_clientArea->GetItemRect(item, column);
3620 }
3621
3622 wxDataViewItem wxDataViewCtrl::GetItemByRow( unsigned int row ) const
3623 {
3624 return m_clientArea->GetItemByRow( row );
3625 }
3626
3627 int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
3628 {
3629 return m_clientArea->GetRowByItem( item );
3630 }
3631
3632 void wxDataViewCtrl::Expand( const wxDataViewItem & item )
3633 {
3634 int row = m_clientArea->GetRowByItem( item );
3635 if (row != -1)
3636 m_clientArea->Expand(row);
3637 }
3638
3639 void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
3640 {
3641 int row = m_clientArea->GetRowByItem( item );
3642 if (row != -1)
3643 m_clientArea->Collapse(row);
3644 }
3645
3646 #endif
3647 // !wxUSE_GENERICDATAVIEWCTRL
3648
3649 #endif
3650 // wxUSE_DATAVIEWCTRL