]> git.saurik.com Git - wxWidgets.git/blame - src/generic/datavgen.cpp
No changes, just extract wxCreateHiddenWindow() declaration in a header.
[wxWidgets.git] / src / generic / datavgen.cpp
CommitLineData
4ed7af08 1/////////////////////////////////////////////////////////////////////////////
f554a14b 2// Name: src/generic/datavgen.cpp
4ed7af08
RR
3// Purpose: wxDataViewCtrl generic implementation
4// Author: Robert Roebling
7274390f 5// Modified by: Francesco Montorsi, Guru Kathiresan, Bo Yang
4ed7af08
RR
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
ed4b0fdc
WS
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
4ed7af08
RR
18#if wxUSE_DATAVIEWCTRL
19
20#include "wx/dataview.h"
21
22#ifdef wxUSE_GENERICDATAVIEWCTRL
23
f554a14b 24#ifndef WX_PRECOMP
57bd4c60 25 #ifdef __WXMSW__
87f0efe2 26 #include "wx/msw/private.h"
57bd4c60 27 #include "wx/msw/wrapwin.h"
87f0efe2 28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
57bd4c60 29 #endif
f554a14b
WS
30 #include "wx/sizer.h"
31 #include "wx/log.h"
ed4b0fdc 32 #include "wx/dcclient.h"
c0badb70 33 #include "wx/timer.h"
9eddec69 34 #include "wx/settings.h"
8d0ca292 35 #include "wx/msgdlg.h"
99d471a5 36 #include "wx/dcscreen.h"
818d91a9 37 #include "wx/frame.h"
f554a14b
WS
38#endif
39
4ed7af08 40#include "wx/stockitem.h"
4ed7af08
RR
41#include "wx/calctrl.h"
42#include "wx/popupwin.h"
4ed7af08 43#include "wx/renderer.h"
2e992e06 44#include "wx/dcbuffer.h"
2586d4a1 45#include "wx/icon.h"
351461fc
RR
46#include "wx/list.h"
47#include "wx/listimpl.cpp"
0c8ed3eb 48#include "wx/imaglist.h"
e2bfe673 49#include "wx/headerctrl.h"
592883ed 50#include "wx/dnd.h"
0645bd38 51#include "wx/stopwatch.h"
4ed7af08 52
4ed7af08
RR
53//-----------------------------------------------------------------------------
54// classes
55//-----------------------------------------------------------------------------
56
5d9e1605
RR
57class wxDataViewColumn;
58class wxDataViewHeaderWindow;
4ed7af08
RR
59class wxDataViewCtrl;
60
5d9e1605
RR
61//-----------------------------------------------------------------------------
62// classes
63//-----------------------------------------------------------------------------
64
9861f022
RR
65static const int SCROLL_UNIT_X = 15;
66
67// the cell padding on the left/right
68static const int PADDING_RIGHTLEFT = 3;
69
3b6280be
RR
70// the expander space margin
71static const int EXPANDER_MARGIN = 4;
9861f022 72
344ed1f3
RR
73#ifdef __WXMSW__
74static const int EXPANDER_OFFSET = 4;
75#else
76static const int EXPANDER_OFFSET = 1;
77#endif
78
bc4f1ff2 79// Below is the compare stuff.
4cef3873 80// For the generic implementation, both the leaf nodes and the nodes are sorted for
bc4f1ff2
FM
81// fast search when needed
82static wxDataViewModel* g_model;
24c4a50f
RR
83static int g_column = -2;
84static bool g_asending = true;
57f2a652 85
1841f079
VZ
86// ----------------------------------------------------------------------------
87// helper functions
88// ----------------------------------------------------------------------------
89
90namespace
91{
92
93// Return the expander column or, if it is not set, the first column and also
94// set it as the expander one for the future.
95wxDataViewColumn* GetExpanderColumnOrFirstOne(wxDataViewCtrl* dataview)
96{
97 wxDataViewColumn* expander = dataview->GetExpanderColumn();
98 if (!expander)
99 {
100 // TODO-RTL: last column for RTL support
101 expander = dataview->GetColumnAt( 0 );
102 dataview->SetExpanderColumn(expander);
103 }
104
105 return expander;
106}
107
108} // anonymous namespace
109
5d9e1605
RR
110//-----------------------------------------------------------------------------
111// wxDataViewColumn
112//-----------------------------------------------------------------------------
113
114void wxDataViewColumn::Init(int width, wxAlignment align, int flags)
115{
d0154e3a 116 m_width = width;
5d9e1605
RR
117 m_minWidth = 0;
118 m_align = align;
119 m_flags = flags;
120 m_sort = false;
121 m_sortAscending = true;
122}
ce00f59b 123
d0154e3a
VS
124int wxDataViewColumn::GetWidth() const
125{
126 switch ( m_width )
127 {
128 case wxCOL_WIDTH_DEFAULT:
129 return wxDVC_DEFAULT_WIDTH;
130
131 case wxCOL_WIDTH_AUTOSIZE:
132 wxCHECK_MSG( m_owner, wxDVC_DEFAULT_WIDTH, "no owner control" );
133 return m_owner->GetBestColumnWidth(m_owner->GetColumnIndex(this));
134
135 default:
136 return m_width;
137 }
138}
139
5d9e1605
RR
140void wxDataViewColumn::UpdateDisplay()
141{
142 if (m_owner)
143 {
144 int idx = m_owner->GetColumnIndex( this );
145 m_owner->OnColumnChange( idx );
146 }
147}
148
fa3d4aaf
VZ
149//-----------------------------------------------------------------------------
150// wxDataViewHeaderWindow
151//-----------------------------------------------------------------------------
152
e2bfe673 153class wxDataViewHeaderWindow : public wxHeaderCtrl
87f0efe2
RR
154{
155public:
e2bfe673
VZ
156 wxDataViewHeaderWindow(wxDataViewCtrl *parent)
157 : wxHeaderCtrl(parent)
87f0efe2 158 {
87f0efe2
RR
159 }
160
e2bfe673
VZ
161 wxDataViewCtrl *GetOwner() const
162 { return static_cast<wxDataViewCtrl *>(GetParent()); }
87f0efe2 163
3bfaa5a7
VZ
164protected:
165 // implement/override wxHeaderCtrl functions by forwarding them to the main
166 // control
482d06f8 167 virtual const wxHeaderColumn& GetColumn(unsigned int idx) const
87f0efe2 168 {
e2bfe673 169 return *(GetOwner()->GetColumn(idx));
87f0efe2
RR
170 }
171
3bfaa5a7
VZ
172 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
173 {
174 wxDataViewCtrl * const owner = GetOwner();
175
176 int widthContents = owner->GetBestColumnWidth(idx);
177 owner->GetColumn(idx)->SetWidth(wxMax(widthTitle, widthContents));
aef252d9 178 owner->OnColumnChange(idx);
3bfaa5a7
VZ
179
180 return true;
181 }
182
183private:
fa3d4aaf
VZ
184 bool SendEvent(wxEventType type, unsigned int n)
185 {
186 wxDataViewCtrl * const owner = GetOwner();
187 wxDataViewEvent event(type, owner->GetId());
188
189 event.SetEventObject(owner);
190 event.SetColumn(n);
191 event.SetDataViewColumn(owner->GetColumn(n));
192 event.SetModel(owner->GetModel());
193
194 // for events created by wxDataViewHeaderWindow the
195 // row / value fields are not valid
857f05e1 196 return owner->ProcessWindowEvent(event);
fa3d4aaf
VZ
197 }
198
199 void OnClick(wxHeaderCtrlEvent& event)
200 {
46234a03
VZ
201 const unsigned idx = event.GetColumn();
202
203 if ( SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, idx) )
204 return;
205
206 // default handling for the column click is to sort by this column or
207 // toggle its sort order
208 wxDataViewCtrl * const owner = GetOwner();
209 wxDataViewColumn * const col = owner->GetColumn(idx);
210 if ( !col->IsSortable() )
211 {
212 // no default handling for non-sortable columns
fa3d4aaf 213 event.Skip();
46234a03
VZ
214 return;
215 }
216
217 if ( col->IsSortKey() )
218 {
219 // already using this column for sorting, just change the order
220 col->ToggleSortOrder();
221 }
222 else // not using this column for sorting yet
223 {
224 // first unset the old sort column if any
225 int oldSortKey = owner->GetSortingColumnIndex();
226 if ( oldSortKey != wxNOT_FOUND )
227 {
228 owner->GetColumn(oldSortKey)->UnsetAsSortKey();
229 owner->OnColumnChange(oldSortKey);
230 }
231
232 owner->SetSortingColumnIndex(idx);
233 col->SetAsSortKey();
234 }
235
236 wxDataViewModel * const model = owner->GetModel();
237 if ( model )
238 model->Resort();
239
240 owner->OnColumnChange(idx);
ff7bc95e
VZ
241
242 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, idx);
fa3d4aaf
VZ
243 }
244
245 void OnRClick(wxHeaderCtrlEvent& event)
246 {
247 if ( !SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
248 event.GetColumn()) )
249 event.Skip();
250 }
251
bc4f1ff2 252 void OnResize(wxHeaderCtrlEvent& event)
aef252d9 253 {
dcb6cbec
VZ
254 wxDataViewCtrl * const owner = GetOwner();
255
565804f2 256 const unsigned col = event.GetColumn();
dcb6cbec 257 owner->GetColumn(col)->SetWidth(event.GetWidth());
565804f2 258 GetOwner()->OnColumnChange(col);
aef252d9
VZ
259 }
260
702f5349
VZ
261 void OnEndReorder(wxHeaderCtrlEvent& event)
262 {
263 wxDataViewCtrl * const owner = GetOwner();
264 owner->ColumnMoved(owner->GetColumn(event.GetColumn()),
977a41ec 265 event.GetNewOrder());
702f5349
VZ
266 }
267
fa3d4aaf 268 DECLARE_EVENT_TABLE()
c0c133e1 269 wxDECLARE_NO_COPY_CLASS(wxDataViewHeaderWindow);
a0f3af5f 270};
4ed7af08 271
fa3d4aaf
VZ
272BEGIN_EVENT_TABLE(wxDataViewHeaderWindow, wxHeaderCtrl)
273 EVT_HEADER_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnClick)
274 EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnRClick)
aef252d9 275
bc4f1ff2
FM
276 EVT_HEADER_RESIZING(wxID_ANY, wxDataViewHeaderWindow::OnResize)
277 EVT_HEADER_END_RESIZE(wxID_ANY, wxDataViewHeaderWindow::OnResize)
702f5349
VZ
278
279 EVT_HEADER_END_REORDER(wxID_ANY, wxDataViewHeaderWindow::OnEndReorder)
fa3d4aaf
VZ
280END_EVENT_TABLE()
281
0fcce6b9
RR
282//-----------------------------------------------------------------------------
283// wxDataViewRenameTimer
284//-----------------------------------------------------------------------------
285
286class wxDataViewRenameTimer: public wxTimer
287{
288private:
289 wxDataViewMainWindow *m_owner;
290
291public:
292 wxDataViewRenameTimer( wxDataViewMainWindow *owner );
293 void Notify();
294};
295
aba9bfd0
RR
296//-----------------------------------------------------------------------------
297// wxDataViewTreeNode
298//-----------------------------------------------------------------------------
bc4f1ff2 299
442c56e6 300class wxDataViewTreeNode;
57f2a652 301WX_DEFINE_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes );
d47db7e0 302
4cef3873 303int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1,
bc4f1ff2 304 wxDataViewTreeNode ** node2);
aba9bfd0
RR
305
306class wxDataViewTreeNode
307{
308public:
422aa8ec
VS
309 wxDataViewTreeNode(wxDataViewTreeNode *parent, const wxDataViewItem& item)
310 : m_item(item),
311 m_parent(parent),
d0cfefc4 312 m_branchData(NULL)
b5ec7dd6 313 {
438fb233 314 }
b5ec7dd6 315
d0cfefc4
VS
316 ~wxDataViewTreeNode()
317 {
a2d3c415
VS
318 if ( m_branchData )
319 {
320 wxDataViewTreeNodes& nodes = m_branchData->children;
321 for ( wxDataViewTreeNodes::iterator i = nodes.begin();
322 i != nodes.end();
323 ++i )
324 {
325 delete *i;
326 }
327
328 delete m_branchData;
329 }
d0cfefc4
VS
330 }
331
422aa8ec 332 static wxDataViewTreeNode* CreateRootNode()
d47db7e0 333 {
422aa8ec 334 wxDataViewTreeNode *n = new wxDataViewTreeNode(NULL, wxDataViewItem());
d0cfefc4
VS
335 n->SetHasChildren(true);
336 n->m_branchData->open = true;
422aa8ec 337 return n;
d47db7e0 338 }
aba9bfd0 339
344ed1f3 340 wxDataViewTreeNode * GetParent() const { return m_parent; }
422aa8ec 341
a2d3c415 342 const wxDataViewTreeNodes& GetChildNodes() const
d0cfefc4
VS
343 {
344 wxASSERT( m_branchData != NULL );
ff3c5ad3 345 return m_branchData->children;
d0cfefc4 346 }
442c56e6 347
35219832 348 void InsertChild(wxDataViewTreeNode *node, unsigned index)
d47db7e0 349 {
d0cfefc4
VS
350 if ( !m_branchData )
351 m_branchData = new BranchNodeData;
352
35219832
VS
353 m_branchData->children.Insert(node, index);
354
422aa8ec 355 // TODO: insert into sorted array directly in O(log n) instead of resorting in O(n log n)
24c4a50f 356 if (g_column >= -1)
ff3c5ad3 357 m_branchData->children.Sort( &wxGenericTreeModelNodeCmp );
57f2a652 358 }
aba9bfd0 359
a2d3c415
VS
360 void RemoveChild(wxDataViewTreeNode *node)
361 {
362 wxCHECK_RET( m_branchData != NULL, "leaf node doesn't have children" );
363 m_branchData->children.Remove(node);
364 }
365
344ed1f3 366 const wxDataViewItem & GetItem() const { return m_item; }
438fb233 367 void SetItem( const wxDataViewItem & item ) { m_item = item; }
aba9bfd0 368
344ed1f3 369 int GetIndentLevel() const
3b6280be 370 {
59e60167 371 int ret = 0;
344ed1f3 372 const wxDataViewTreeNode * node = this;
438fb233
RR
373 while( node->GetParent()->GetParent() != NULL )
374 {
375 node = node->GetParent();
376 ret ++;
377 }
378 return ret;
3b6280be 379 }
aba9bfd0 380
344ed1f3 381 bool IsOpen() const
442c56e6 382 {
d0cfefc4 383 return m_branchData && m_branchData->open;
442c56e6 384 }
d47db7e0
RR
385
386 void ToggleOpen()
442c56e6 387 {
d0cfefc4
VS
388 wxCHECK_RET( m_branchData != NULL, "can't open leaf node" );
389
d47db7e0 390 int sum = 0;
422aa8ec 391
ff3c5ad3 392 const wxDataViewTreeNodes& nodes = m_branchData->children;
d0cfefc4 393 const int len = nodes.GetCount();
59e60167 394 for ( int i = 0;i < len; i ++)
d0cfefc4 395 sum += 1 + nodes[i]->GetSubTreeCount();
d47db7e0 396
d0cfefc4 397 if (m_branchData->open)
d47db7e0
RR
398 {
399 ChangeSubTreeCount(-sum);
d0cfefc4 400 m_branchData->open = !m_branchData->open;
d47db7e0
RR
401 }
402 else
403 {
d0cfefc4 404 m_branchData->open = !m_branchData->open;
422aa8ec 405 ChangeSubTreeCount(+sum);
d47db7e0
RR
406 }
407 }
422aa8ec
VS
408
409 // "HasChildren" property corresponds to model's IsContainer(). Note that it may be true
ff3c5ad3 410 // even if GetChildNodes() is empty; see below.
d0cfefc4
VS
411 bool HasChildren() const
412 {
413 return m_branchData != NULL;
414 }
415
416 void SetHasChildren(bool has)
417 {
418 if ( !has )
419 {
420 wxDELETE(m_branchData);
421 }
422 else if ( m_branchData == NULL )
423 {
424 m_branchData = new BranchNodeData;
425 }
426 }
427
428 int GetSubTreeCount() const
429 {
430 return m_branchData ? m_branchData->subTreeCount : 0;
431 }
d47db7e0 432
442c56e6 433 void ChangeSubTreeCount( int num )
d47db7e0 434 {
d0cfefc4
VS
435 wxASSERT( m_branchData != NULL );
436
437 if( !m_branchData->open )
59e60167 438 return;
422aa8ec 439
d0cfefc4
VS
440 m_branchData->subTreeCount += num;
441 wxASSERT( m_branchData->subTreeCount >= 0 );
422aa8ec 442
438fb233
RR
443 if( m_parent )
444 m_parent->ChangeSubTreeCount(num);
d47db7e0
RR
445 }
446
d3f00f59
VZ
447 void Resort()
448 {
d0cfefc4
VS
449 if ( !m_branchData )
450 return;
451
24c4a50f 452 if (g_column >= -1)
d3f00f59 453 {
ff3c5ad3 454 wxDataViewTreeNodes& nodes = m_branchData->children;
d0cfefc4
VS
455
456 nodes.Sort( &wxGenericTreeModelNodeCmp );
457 int len = nodes.GetCount();
57f2a652 458 for (int i = 0; i < len; i ++)
422aa8ec 459 {
d0cfefc4
VS
460 if ( nodes[i]->HasChildren() )
461 nodes[i]->Resort();
422aa8ec 462 }
57ab4546 463 }
57ab4546
VS
464 }
465
466
aba9bfd0 467private:
d0cfefc4
VS
468 wxDataViewTreeNode *m_parent;
469
422aa8ec
VS
470 // Corresponding model item.
471 wxDataViewItem m_item;
472
d0cfefc4
VS
473 // Data specific to non-leaf (branch, inner) nodes. They are kept in a
474 // separate struct in order to conserve memory.
475 struct BranchNodeData
476 {
477 BranchNodeData()
478 : open(false),
479 subTreeCount(0)
480 {
481 }
422aa8ec 482
d0cfefc4
VS
483 // Child nodes. Note that this may be empty even if m_hasChildren in
484 // case this branch of the tree wasn't expanded and realized yet.
ff3c5ad3 485 wxDataViewTreeNodes children;
422aa8ec 486
d0cfefc4
VS
487 // Is the branch node currently open (expanded)?
488 bool open;
422aa8ec 489
d0cfefc4
VS
490 // Total count of expanded (i.e. visible with the help of some
491 // scrolling) items in the subtree, but excluding this node. I.e. it is
492 // 0 for leaves and is the number of rows the subtree occupies for
493 // branch nodes.
494 int subTreeCount;
495 };
422aa8ec 496
d0cfefc4 497 BranchNodeData *m_branchData;
aba9bfd0
RR
498};
499
422aa8ec 500
4cef3873 501int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1,
bc4f1ff2 502 wxDataViewTreeNode ** node2)
d47db7e0 503{
57f2a652 504 return g_model->Compare( (*node1)->GetItem(), (*node2)->GetItem(), g_column, g_asending );
d47db7e0
RR
505}
506
d47db7e0 507
a0f3af5f
RR
508//-----------------------------------------------------------------------------
509// wxDataViewMainWindow
510//-----------------------------------------------------------------------------
4ed7af08 511
c3b0247d 512WX_DEFINE_SORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection);
cab07038 513
a0f3af5f 514class wxDataViewMainWindow: public wxWindow
4ed7af08 515{
a0f3af5f
RR
516public:
517 wxDataViewMainWindow( wxDataViewCtrl *parent,
518 wxWindowID id,
519 const wxPoint &pos = wxDefaultPosition,
520 const wxSize &size = wxDefaultSize,
521 const wxString &name = wxT("wxdataviewctrlmainwindow") );
d3c7fc99 522 virtual ~wxDataViewMainWindow();
777f9cef 523
c2c89730 524 bool IsList() const { return GetModel()->IsListModel(); }
344ed1f3 525 bool IsVirtualList() const { return m_root == NULL; }
4ed7af08 526
aba9bfd0
RR
527 // notifications from wxDataViewModel
528 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
32143117 529 bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
aba9bfd0 530 bool ItemChanged( const wxDataViewItem &item );
d93cc830 531 bool ValueChanged( const wxDataViewItem &item, unsigned int model_column );
a0f3af5f 532 bool Cleared();
d3f00f59 533 void Resort()
b7fe2261 534 {
344ed1f3 535 if (!IsVirtualList())
a3cc79d9
RR
536 {
537 SortPrepare();
538 m_root->Resort();
539 }
b7fe2261 540 UpdateDisplay();
66e09788 541 }
4ed7af08 542
66e09788
RR
543 void SortPrepare()
544 {
c2c89730 545 g_model = GetModel();
57f2a652 546 wxDataViewColumn* col = GetOwner()->GetSortingColumn();
66e09788
RR
547 if( !col )
548 {
24c4a50f
RR
549 if (g_model->HasDefaultCompare())
550 g_column = -1;
551 else
552 g_column = -2;
553
66e09788
RR
554 g_asending = true;
555 return;
556 }
57f2a652 557 g_column = col->GetModelColumn();
b7fe2261 558 g_asending = col->IsSortOrderAscending();
66e09788 559 }
b7fe2261 560
a0f3af5f
RR
561 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
562 wxDataViewCtrl *GetOwner() { return m_owner; }
9861f022 563 const wxDataViewCtrl *GetOwner() const { return m_owner; }
4ed7af08 564
c2c89730
VS
565 wxDataViewModel* GetModel() { return GetOwner()->GetModel(); }
566 const wxDataViewModel* GetModel() const { return GetOwner()->GetModel(); }
567
9adeb77a 568#if wxUSE_DRAG_AND_DROP
818d91a9 569 wxBitmap CreateItemBitmap( unsigned int row, int &indent );
9adeb77a 570#endif // wxUSE_DRAG_AND_DROP
a0f3af5f 571 void OnPaint( wxPaintEvent &event );
cab07038 572 void OnChar( wxKeyEvent &event );
1dc779fc 573 void OnVerticalNavigation(unsigned int newCurrent, const wxKeyEvent& event);
cfc21881
VS
574 void OnLeftKey();
575 void OnRightKey();
a0f3af5f
RR
576 void OnMouse( wxMouseEvent &event );
577 void OnSetFocus( wxFocusEvent &event );
cab07038 578 void OnKillFocus( wxFocusEvent &event );
f554a14b 579
a0f3af5f
RR
580 void UpdateDisplay();
581 void RecalculateDisplay();
582 void OnInternalIdle();
f554a14b 583
0fcce6b9 584 void OnRenameTimer();
0fcce6b9 585
9861f022 586 void ScrollWindow( int dx, int dy, const wxRect *rect = NULL );
fbda518c 587 void ScrollTo( int rows, int column );
120b9b05 588
80ce465c 589 unsigned GetCurrentRow() const { return m_currentRow; }
0a71f9e9
RR
590 bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; }
591 void ChangeCurrentRow( unsigned int row );
120b9b05 592
47b378bd 593 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); }
cab07038 594 bool IsEmpty() { return GetRowCount() == 0; }
120b9b05 595
9861f022
RR
596 int GetCountPerPage() const;
597 int GetEndOfLastCol() const;
598 unsigned int GetFirstVisibleRow() const;
bc4f1ff2 599
4cef3873
VZ
600 // I change this method to un const because in the tree view,
601 // the displaying number of the tree are changing along with the
bc4f1ff2 602 // expanding/collapsing of the tree nodes
3b6280be 603 unsigned int GetLastVisibleRow();
59e60167 604 unsigned int GetRowCount();
120b9b05 605
f23b8c0d 606 const wxDataViewSelection& GetSelections() const { return m_selection; }
4cef3873 607 void SetSelections( const wxDataViewSelection & sel )
bc4f1ff2 608 { m_selection = sel; UpdateDisplay(); }
87f0efe2 609 void Select( const wxArrayInt& aSelections );
cab07038 610 void SelectAllRows( bool on );
0a71f9e9
RR
611 void SelectRow( unsigned int row, bool on );
612 void SelectRows( unsigned int from, unsigned int to, bool on );
613 void ReverseRowSelection( unsigned int row );
614 bool IsRowSelected( unsigned int row );
526e19e2 615 void SendSelectionChangedEvent( const wxDataViewItem& item);
120b9b05 616
0a71f9e9
RR
617 void RefreshRow( unsigned int row );
618 void RefreshRows( unsigned int from, unsigned int to );
619 void RefreshRowsAfter( unsigned int firstRow );
120b9b05 620
9861f022
RR
621 // returns the colour to be used for drawing the rules
622 wxColour GetRuleColour() const
623 {
624 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
625 }
626
9861f022 627 wxRect GetLineRect( unsigned int row ) const;
777f9cef 628
344ed1f3
RR
629 int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode
630 int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
631 int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode
9861f022 632
bbfd4548
VZ
633 void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; }
634
bc4f1ff2 635 // Some useful functions for row and item mapping
fbda518c 636 wxDataViewItem GetItemByRow( unsigned int row ) const;
344ed1f3 637 int GetRowByItem( const wxDataViewItem & item ) const;
777f9cef 638
bc4f1ff2 639 // Methods for building the mapping tree
aba9bfd0
RR
640 void BuildTree( wxDataViewModel * model );
641 void DestroyTree();
a87b466d 642 void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column );
fbda518c 643 wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column );
afebb87b 644
235d5f88
RR
645 void Expand( unsigned int row );
646 void Collapse( unsigned int row );
739a8399 647 bool IsExpanded( unsigned int row ) const;
235d5f88 648 bool HasChildren( unsigned int row ) const;
821baf7d 649
9adeb77a 650#if wxUSE_DRAG_AND_DROP
a653c966
RR
651 bool EnableDragSource( const wxDataFormat &format );
652 bool EnableDropTarget( const wxDataFormat &format );
653
9deec111 654 void RemoveDropHint();
a653c966
RR
655 wxDragResult OnDragOver( wxDataFormat format, wxCoord x, wxCoord y, wxDragResult def );
656 bool OnDrop( wxDataFormat format, wxCoord x, wxCoord y );
657 wxDragResult OnData( wxDataFormat format, wxCoord x, wxCoord y, wxDragResult def );
658 void OnLeave();
9adeb77a 659#endif // wxUSE_DRAG_AND_DROP
821baf7d 660
3b6280be 661private:
344ed1f3 662 wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row ) const;
bc4f1ff2
FM
663 // We did not need this temporarily
664 // wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item );
3b6280be 665
59e60167 666 int RecalculateCount();
3b6280be 667
fd48fe89
VZ
668 // Return false only if the event was vetoed by its handler.
669 bool SendExpanderEvent(wxEventType type, const wxDataViewItem& item);
aba9bfd0 670
442c56e6 671 wxDataViewTreeNode * FindNode( const wxDataViewItem & item );
351461fc 672
a0f3af5f 673private:
0fcce6b9
RR
674 wxDataViewCtrl *m_owner;
675 int m_lineHeight;
676 bool m_dirty;
120b9b05 677
0fcce6b9 678 wxDataViewColumn *m_currentCol;
99d471a5 679 unsigned int m_currentRow;
cab07038 680 wxDataViewSelection m_selection;
120b9b05 681
0fcce6b9 682 wxDataViewRenameTimer *m_renameTimer;
0fcce6b9 683 bool m_lastOnSame;
f554a14b 684
cab07038
RR
685 bool m_hasFocus;
686
9adeb77a 687#if wxUSE_DRAG_AND_DROP
e21f75bd
RR
688 int m_dragCount;
689 wxPoint m_dragStart;
9adeb77a 690
821baf7d
RR
691 bool m_dragEnabled;
692 wxDataFormat m_dragFormat;
9adeb77a 693
821baf7d
RR
694 bool m_dropEnabled;
695 wxDataFormat m_dropFormat;
9deec111
RR
696 bool m_dropHint;
697 unsigned int m_dropHintLine;
9adeb77a 698#endif // wxUSE_DRAG_AND_DROP
e21f75bd
RR
699
700 // for double click logic
0a71f9e9 701 unsigned int m_lineLastClicked,
977a41ec
FM
702 m_lineBeforeLastClicked,
703 m_lineSelectSingleOnUp;
cab07038 704
9861f022
RR
705 // the pen used to draw horiz/vertical rules
706 wxPen m_penRule;
707
3b6280be
RR
708 // the pen used to draw the expander and the lines
709 wxPen m_penExpander;
710
bc4f1ff2 711 // This is the tree structure of the model
442c56e6 712 wxDataViewTreeNode * m_root;
3b6280be 713 int m_count;
bc4f1ff2
FM
714
715 // This is the tree node under the cursor
24c4a50f 716 wxDataViewTreeNode * m_underMouse;
bc4f1ff2 717
a0f3af5f
RR
718private:
719 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
720 DECLARE_EVENT_TABLE()
721};
4ed7af08 722
f554a14b 723// ---------------------------------------------------------
aba9bfd0 724// wxGenericDataViewModelNotifier
f554a14b 725// ---------------------------------------------------------
a0f3af5f 726
aba9bfd0 727class wxGenericDataViewModelNotifier: public wxDataViewModelNotifier
4ed7af08 728{
a0f3af5f 729public:
aba9bfd0 730 wxGenericDataViewModelNotifier( wxDataViewMainWindow *mainWindow )
a0f3af5f 731 { m_mainWindow = mainWindow; }
f554a14b 732
aba9bfd0
RR
733 virtual bool ItemAdded( const wxDataViewItem & parent, const wxDataViewItem & item )
734 { return m_mainWindow->ItemAdded( parent , item ); }
442c56e6 735 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
071691a0 736 { return m_mainWindow->ItemDeleted( parent, item ); }
aba9bfd0
RR
737 virtual bool ItemChanged( const wxDataViewItem & item )
738 { return m_mainWindow->ItemChanged(item); }
739 virtual bool ValueChanged( const wxDataViewItem & item , unsigned int col )
740 { return m_mainWindow->ValueChanged( item, col ); }
a0f3af5f
RR
741 virtual bool Cleared()
742 { return m_mainWindow->Cleared(); }
d3f00f59 743 virtual void Resort()
977a41ec 744 { m_mainWindow->Resort(); }
f554a14b 745
a0f3af5f
RR
746 wxDataViewMainWindow *m_mainWindow;
747};
4ed7af08 748
f554a14b 749// ---------------------------------------------------------
baa9ebc4 750// wxDataViewRenderer
f554a14b 751// ---------------------------------------------------------
4ed7af08 752
baa9ebc4 753IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
4ed7af08 754
c741d33f 755wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype,
9861f022
RR
756 wxDataViewCellMode mode,
757 int align) :
6eec70b9 758 wxDataViewCustomRendererBase( varianttype, mode, align )
4ed7af08 759{
9861f022
RR
760 m_align = align;
761 m_mode = mode;
c937bcac 762 m_ellipsizeMode = wxELLIPSIZE_MIDDLE;
6eec70b9 763 m_dc = NULL;
4ed7af08
RR
764}
765
baa9ebc4 766wxDataViewRenderer::~wxDataViewRenderer()
3d9d7cc4 767{
6eec70b9
VZ
768 delete m_dc;
769}
770
771wxDC *wxDataViewRenderer::GetDC()
772{
773 if (m_dc == NULL)
774 {
775 if (GetOwner() == NULL)
776 return NULL;
777 if (GetOwner()->GetOwner() == NULL)
778 return NULL;
779 m_dc = new wxClientDC( GetOwner()->GetOwner() );
780 }
781
782 return m_dc;
783}
784
785void wxDataViewRenderer::SetAlignment( int align )
786{
787 m_align=align;
788}
789
790int wxDataViewRenderer::GetAlignment() const
791{
792 return m_align;
793}
794
6eec70b9
VZ
795// ---------------------------------------------------------
796// wxDataViewCustomRenderer
797// ---------------------------------------------------------
798
799IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
800
801wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
802 wxDataViewCellMode mode, int align ) :
803 wxDataViewRenderer( varianttype, mode, align )
804{
805}
806
f554a14b 807// ---------------------------------------------------------
baa9ebc4 808// wxDataViewTextRenderer
f554a14b 809// ---------------------------------------------------------
4ed7af08 810
6eec70b9 811IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer)
4ed7af08 812
c741d33f 813wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype,
9861f022 814 wxDataViewCellMode mode, int align ) :
6eec70b9 815 wxDataViewRenderer( varianttype, mode, align )
4ed7af08
RR
816{
817}
818
baa9ebc4 819bool wxDataViewTextRenderer::SetValue( const wxVariant &value )
4ed7af08 820{
90675b95 821 m_text = value.GetString();
f554a14b 822
90675b95 823 return true;
4ed7af08
RR
824}
825
9861f022 826bool wxDataViewTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
4ed7af08
RR
827{
828 return false;
829}
830
bc4f1ff2 831bool wxDataViewTextRenderer::HasEditorCtrl() const
442c56e6 832{
99d471a5
RR
833 return true;
834}
835
64c70359 836wxWindow* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
99d471a5
RR
837 wxRect labelRect, const wxVariant &value )
838{
0a807957
RR
839 wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value,
840 wxPoint(labelRect.x,labelRect.y),
dd90475f
VS
841 wxSize(labelRect.width,labelRect.height),
842 wxTE_PROCESS_ENTER );
0a807957
RR
843
844 // select the text in the control an place the cursor at the end
845 ctrl->SetInsertionPointEnd();
846 ctrl->SelectAll();
847
848 return ctrl;
99d471a5
RR
849}
850
64c70359 851bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant &value )
99d471a5
RR
852{
853 wxTextCtrl *text = (wxTextCtrl*) editor;
854 value = text->GetValue();
855 return true;
856}
857
62265c2c 858bool wxDataViewTextRenderer::Render(wxRect rect, wxDC *dc, int state)
3d9d7cc4 859{
62265c2c 860 RenderText(m_text, 0, rect, dc, state);
90675b95 861 return true;
3d9d7cc4
RR
862}
863
9861f022 864wxSize wxDataViewTextRenderer::GetSize() const
3d9d7cc4 865{
87f0efe2 866 if (!m_text.empty())
86755098
VS
867 return GetTextExtent(m_text);
868 else
869 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
3d9d7cc4
RR
870}
871
2586d4a1 872// ---------------------------------------------------------
baa9ebc4 873// wxDataViewBitmapRenderer
2586d4a1
RR
874// ---------------------------------------------------------
875
6eec70b9 876IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
2586d4a1 877
c741d33f 878wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
9861f022 879 wxDataViewCellMode mode, int align ) :
6eec70b9 880 wxDataViewRenderer( varianttype, mode, align )
2586d4a1
RR
881{
882}
883
baa9ebc4 884bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
2586d4a1
RR
885{
886 if (value.GetType() == wxT("wxBitmap"))
887 m_bitmap << value;
888 if (value.GetType() == wxT("wxIcon"))
889 m_icon << value;
890
891 return true;
892}
893
9861f022 894bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
2586d4a1
RR
895{
896 return false;
897}
898
baa9ebc4 899bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
2586d4a1 900{
a1b806b9 901 if (m_bitmap.IsOk())
2586d4a1 902 dc->DrawBitmap( m_bitmap, cell.x, cell.y );
a1b806b9 903 else if (m_icon.IsOk())
2586d4a1
RR
904 dc->DrawIcon( m_icon, cell.x, cell.y );
905
906 return true;
907}
908
9861f022 909wxSize wxDataViewBitmapRenderer::GetSize() const
2586d4a1 910{
a1b806b9 911 if (m_bitmap.IsOk())
2586d4a1 912 return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
a1b806b9 913 else if (m_icon.IsOk())
2586d4a1
RR
914 return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
915
ce468dc2 916 return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
2586d4a1
RR
917}
918
f554a14b 919// ---------------------------------------------------------
baa9ebc4 920// wxDataViewToggleRenderer
f554a14b 921// ---------------------------------------------------------
4ed7af08 922
6eec70b9 923IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
4ed7af08 924
baa9ebc4 925wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
9861f022 926 wxDataViewCellMode mode, int align ) :
6eec70b9 927 wxDataViewRenderer( varianttype, mode, align )
4ed7af08 928{
90675b95 929 m_toggle = false;
4ed7af08
RR
930}
931
baa9ebc4 932bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
4ed7af08 933{
90675b95 934 m_toggle = value.GetBool();
f554a14b 935
a8461d31 936 return true;
4ed7af08
RR
937}
938
9861f022 939bool wxDataViewToggleRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
4ed7af08
RR
940{
941 return false;
942}
f554a14b 943
baa9ebc4 944bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
4ed7af08 945{
862d8041 946 int flags = 0;
90675b95 947 if (m_toggle)
862d8041 948 flags |= wxCONTROL_CHECKED;
98f8e666
VZ
949 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE ||
950 GetEnabled() == false)
862d8041
RR
951 flags |= wxCONTROL_DISABLED;
952
68d7680d
VZ
953 // check boxes we draw must always have the same, standard size (if it's
954 // bigger than the cell size the checkbox will be truncated because the
955 // caller had set the clipping rectangle to prevent us from drawing outside
956 // the cell)
957 cell.SetSize(GetSize());
958
90b903c2 959 wxRendererNative::Get().DrawCheckBox(
862d8041
RR
960 GetOwner()->GetOwner(),
961 *dc,
de4bf0b3 962 cell,
862d8041 963 flags );
f554a14b 964
90675b95 965 return true;
4ed7af08
RR
966}
967
fce2dc61 968bool wxDataViewToggleRenderer::WXOnLeftClick(const wxPoint& cursor,
297e2532 969 const wxRect& cell,
d2425a43
VS
970 wxDataViewModel *model,
971 const wxDataViewItem& item,
972 unsigned int col)
0fdc2321 973{
fce2dc61
VS
974 // only react to clicks directly on the checkbox, not elsewhere in the same cell:
975 if (!wxRect(GetSize()).Contains(cursor))
976 return false;
977
297e2532
VS
978 return WXOnActivate(cell, model, item, col);
979}
980
981bool wxDataViewToggleRenderer::WXOnActivate(const wxRect& WXUNUSED(cell),
982 wxDataViewModel *model,
983 const wxDataViewItem& item,
984 unsigned int col)
985{
98f8e666
VZ
986 if (model->IsEnabled(item, col))
987 {
dbc3aec1
VS
988 model->ChangeValue(!m_toggle, item, col);
989 return true;
98f8e666 990 }
dbc3aec1
VS
991
992 return false;
0fdc2321
RR
993}
994
9861f022 995wxSize wxDataViewToggleRenderer::GetSize() const
4ed7af08 996{
de4bf0b3
FM
997 // the window parameter is not used by GetCheckBoxSize() so it's
998 // safe to pass NULL
999 return wxRendererNative::Get().GetCheckBoxSize(NULL);
4ed7af08
RR
1000}
1001
f554a14b 1002// ---------------------------------------------------------
baa9ebc4 1003// wxDataViewProgressRenderer
f554a14b 1004// ---------------------------------------------------------
4ed7af08 1005
6eec70b9 1006IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewRenderer)
4ed7af08 1007
baa9ebc4 1008wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
9861f022 1009 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
6eec70b9 1010 wxDataViewRenderer( varianttype, mode, align )
4ed7af08
RR
1011{
1012 m_label = label;
1013 m_value = 0;
1014}
1015
baa9ebc4 1016bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
4ed7af08
RR
1017{
1018 m_value = (long) value;
f554a14b 1019
4ed7af08
RR
1020 if (m_value < 0) m_value = 0;
1021 if (m_value > 100) m_value = 100;
f554a14b 1022
4ed7af08
RR
1023 return true;
1024}
f554a14b 1025
9861f022
RR
1026bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
1027{
1028 value = (long) m_value;
1029 return true;
1030}
1031
62265c2c
VZ
1032bool
1033wxDataViewProgressRenderer::Render(wxRect rect, wxDC *dc, int WXUNUSED(state))
4ed7af08 1034{
62265c2c 1035 // deflate the rect to leave a small border between bars in adjacent rows
3e60a3c1
VZ
1036 wxRect bar = rect.Deflate(0, 1);
1037
62265c2c
VZ
1038 dc->SetBrush( *wxTRANSPARENT_BRUSH );
1039 dc->SetPen( *wxBLACK_PEN );
1040 dc->DrawRectangle( bar );
4ed7af08 1041
3e60a3c1 1042 bar.width = (int)(bar.width * m_value / 100.);
62265c2c
VZ
1043 dc->SetPen( *wxTRANSPARENT_PEN );
1044
1045 const wxDataViewItemAttr& attr = GetAttr();
1046 dc->SetBrush( attr.HasColour() ? wxBrush(attr.GetColour())
1047 : *wxBLUE_BRUSH );
1048 dc->DrawRectangle( bar );
f554a14b 1049
4ed7af08
RR
1050 return true;
1051}
1052
9861f022 1053wxSize wxDataViewProgressRenderer::GetSize() const
4ed7af08
RR
1054{
1055 return wxSize(40,12);
1056}
f554a14b
WS
1057
1058// ---------------------------------------------------------
baa9ebc4 1059// wxDataViewDateRenderer
f554a14b 1060// ---------------------------------------------------------
4ed7af08 1061
21ead767
VZ
1062#define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
1063
1064#if wxUSE_DATE_RENDERER_POPUP
8d0ca292 1065
baa9ebc4 1066class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
4ed7af08 1067{
f554a14b 1068public:
baa9ebc4 1069 wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
aba9bfd0
RR
1070 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col) :
1071 wxPopupTransientWindow( parent, wxBORDER_SIMPLE ),
1072 m_item( item )
4ed7af08
RR
1073 {
1074 m_model = model;
1075 m_col = col;
f554a14b 1076 m_cal = new wxCalendarCtrl( this, wxID_ANY, *value );
4ed7af08
RR
1077 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
1078 sizer->Add( m_cal, 1, wxGROW );
1079 SetSizer( sizer );
1080 sizer->Fit( this );
1081 }
f554a14b 1082
4ed7af08 1083 void OnCalendar( wxCalendarEvent &event );
f554a14b 1084
4ed7af08 1085 wxCalendarCtrl *m_cal;
aba9bfd0 1086 wxDataViewModel *m_model;
0a71f9e9 1087 unsigned int m_col;
aba9bfd0 1088 const wxDataViewItem & m_item;
f554a14b 1089
a8461d31
PC
1090protected:
1091 virtual void OnDismiss()
1092 {
1093 }
1094
4ed7af08
RR
1095private:
1096 DECLARE_EVENT_TABLE()
1097};
1098
baa9ebc4
RR
1099BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
1100 EVT_CALENDAR( wxID_ANY, wxDataViewDateRendererPopupTransient::OnCalendar )
4ed7af08
RR
1101END_EVENT_TABLE()
1102
baa9ebc4 1103void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
4ed7af08 1104{
795dac4c 1105 m_model->ChangeValue( event.GetDate(), m_item, m_col );
4ed7af08
RR
1106 DismissAndNotify();
1107}
1108
21ead767 1109#endif // wxUSE_DATE_RENDERER_POPUP
8d0ca292 1110
6eec70b9 1111IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewRenderer)
4ed7af08 1112
baa9ebc4 1113wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
9861f022 1114 wxDataViewCellMode mode, int align ) :
6eec70b9 1115 wxDataViewRenderer( varianttype, mode, align )
4ed7af08
RR
1116{
1117}
f554a14b 1118
baa9ebc4 1119bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
4ed7af08
RR
1120{
1121 m_date = value.GetDateTime();
f554a14b 1122
4ed7af08
RR
1123 return true;
1124}
1125
9861f022
RR
1126bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
1127{
1128 value = m_date;
1129 return true;
1130}
1131
52e750fc 1132bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int state )
4ed7af08 1133{
4ed7af08 1134 wxString tmp = m_date.FormatDate();
52e750fc 1135 RenderText( tmp, 0, cell, dc, state );
4ed7af08
RR
1136 return true;
1137}
1138
9861f022 1139wxSize wxDataViewDateRenderer::GetSize() const
4ed7af08 1140{
86755098 1141 return GetTextExtent(m_date.FormatDate());
4ed7af08
RR
1142}
1143
548fa9c1 1144bool wxDataViewDateRenderer::WXOnActivate(const wxRect& WXUNUSED(cell),
dbc3aec1
VS
1145 wxDataViewModel *model,
1146 const wxDataViewItem& item,
1147 unsigned int col)
4ed7af08 1148{
dbc3aec1 1149 wxDateTime dtOld = m_date;
4ed7af08 1150
21ead767 1151#if wxUSE_DATE_RENDERER_POPUP
baa9ebc4 1152 wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
62186006 1153 GetOwner()->GetOwner()->GetParent(), &dtOld, model, item, col);
4ed7af08
RR
1154 wxPoint pos = wxGetMousePosition();
1155 popup->Move( pos );
1156 popup->Layout();
1157 popup->Popup( popup->m_cal );
21ead767 1158#else // !wxUSE_DATE_RENDERER_POPUP
62186006 1159 wxMessageBox(dtOld.Format());
21ead767 1160#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
dbc3aec1
VS
1161
1162 return true;
4ed7af08
RR
1163}
1164
b7fe2261 1165// ---------------------------------------------------------
24c4a50f 1166// wxDataViewIconTextRenderer
b7fe2261 1167// ---------------------------------------------------------
24c4a50f 1168
6eec70b9 1169IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewRenderer)
24c4a50f 1170
b7fe2261 1171wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
977a41ec 1172const wxString &varianttype, wxDataViewCellMode mode, int align ) :
6eec70b9 1173 wxDataViewRenderer( varianttype, mode, align )
24c4a50f
RR
1174{
1175 SetMode(mode);
1176 SetAlignment(align);
1177}
1178
24c4a50f
RR
1179bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
1180{
1181 m_value << value;
1182 return true;
1183}
1184
b5ec7dd6 1185bool wxDataViewIconTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
24c4a50f
RR
1186{
1187 return false;
1188}
b7fe2261 1189
62265c2c 1190bool wxDataViewIconTextRenderer::Render(wxRect rect, wxDC *dc, int state)
24c4a50f 1191{
52e750fc 1192 int xoffset = 0;
38c34918
VZ
1193
1194 const wxIcon& icon = m_value.GetIcon();
1195 if ( icon.IsOk() )
24c4a50f 1196 {
62265c2c 1197 dc->DrawIcon(icon, rect.x, rect.y + (rect.height - icon.GetHeight())/2);
38c34918 1198 xoffset = icon.GetWidth()+4;
24c4a50f 1199 }
b5ec7dd6 1200
62265c2c 1201 RenderText(m_value.GetText(), xoffset, rect, dc, state);
24c4a50f
RR
1202
1203 return true;
1204}
1205
1206wxSize wxDataViewIconTextRenderer::GetSize() const
1207{
e44ac7bc
RR
1208 if (!m_value.GetText().empty())
1209 {
86755098 1210 wxSize size = GetTextExtent(m_value.GetText());
b5ec7dd6 1211
e44ac7bc 1212 if (m_value.GetIcon().IsOk())
86755098
VS
1213 size.x += m_value.GetIcon().GetWidth() + 4;
1214 return size;
e44ac7bc
RR
1215 }
1216 return wxSize(80,20);
24c4a50f
RR
1217}
1218
64c70359 1219wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
24c4a50f 1220{
c937344c
RR
1221 wxDataViewIconText iconText;
1222 iconText << value;
1223
1224 wxString text = iconText.GetText();
1225
1226 // adjust the label rect to take the width of the icon into account
1227 if (iconText.GetIcon().IsOk())
1228 {
1229 int w = iconText.GetIcon().GetWidth() + 4;
1230 labelRect.x += w;
1231 labelRect.width -= w;
1232 }
1233
0a807957
RR
1234 wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, text,
1235 wxPoint(labelRect.x,labelRect.y),
dd90475f
VS
1236 wxSize(labelRect.width,labelRect.height),
1237 wxTE_PROCESS_ENTER );
0a807957
RR
1238
1239 // select the text in the control an place the cursor at the end
1240 ctrl->SetInsertionPointEnd();
1241 ctrl->SelectAll();
1242
1243 return ctrl;
24c4a50f
RR
1244}
1245
64c70359 1246bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant& value )
24c4a50f 1247{
c937344c
RR
1248 wxTextCtrl *text = (wxTextCtrl*) editor;
1249
1250 wxDataViewIconText iconText(text->GetValue(), m_value.GetIcon());
1251 value << iconText;
1252 return true;
24c4a50f
RR
1253}
1254
a653c966
RR
1255//-----------------------------------------------------------------------------
1256// wxDataViewDropTarget
1257//-----------------------------------------------------------------------------
1258
9adeb77a
VZ
1259#if wxUSE_DRAG_AND_DROP
1260
818d91a9
RR
1261class wxBitmapCanvas: public wxWindow
1262{
1263public:
1264 wxBitmapCanvas( wxWindow *parent, const wxBitmap &bitmap, const wxSize &size ) :
977a41ec 1265 wxWindow( parent, wxID_ANY, wxPoint(0,0), size )
818d91a9
RR
1266 {
1267 m_bitmap = bitmap;
1268 Connect( wxEVT_PAINT, wxPaintEventHandler(wxBitmapCanvas::OnPaint) );
1269 }
9adeb77a 1270
818d91a9
RR
1271 void OnPaint( wxPaintEvent &WXUNUSED(event) )
1272 {
1273 wxPaintDC dc(this);
1274 dc.DrawBitmap( m_bitmap, 0, 0);
1275 }
9adeb77a 1276
818d91a9
RR
1277 wxBitmap m_bitmap;
1278};
1279
1280class wxDataViewDropSource: public wxDropSource
1281{
1282public:
1283 wxDataViewDropSource( wxDataViewMainWindow *win, unsigned int row ) :
977a41ec 1284 wxDropSource( win )
818d91a9
RR
1285 {
1286 m_win = win;
1287 m_row = row;
1288 m_hint = NULL;
1289 }
9adeb77a 1290
818d91a9
RR
1291 ~wxDataViewDropSource()
1292 {
1293 delete m_hint;
1294 }
9adeb77a 1295
818d91a9
RR
1296 virtual bool GiveFeedback( wxDragResult WXUNUSED(effect) )
1297 {
1298 wxPoint pos = wxGetMousePosition();
9adeb77a 1299
818d91a9
RR
1300 if (!m_hint)
1301 {
1302 int liney = m_win->GetLineStart( m_row );
1303 int linex = 0;
1304 m_win->GetOwner()->CalcUnscrolledPosition( 0, liney, NULL, &liney );
1305 m_win->ClientToScreen( &linex, &liney );
1306 m_dist_x = pos.x - linex;
1307 m_dist_y = pos.y - liney;
9adeb77a 1308
818d91a9
RR
1309 int indent = 0;
1310 wxBitmap ib = m_win->CreateItemBitmap( m_row, indent );
1311 m_dist_x -= indent;
9adeb77a 1312 m_hint = new wxFrame( m_win->GetParent(), wxID_ANY, wxEmptyString,
977a41ec
FM
1313 wxPoint(pos.x - m_dist_x, pos.y + 5 ),
1314 ib.GetSize(),
1315 wxFRAME_TOOL_WINDOW |
1316 wxFRAME_FLOAT_ON_PARENT |
1317 wxFRAME_NO_TASKBAR |
1318 wxNO_BORDER );
818d91a9
RR
1319 new wxBitmapCanvas( m_hint, ib, ib.GetSize() );
1320 m_hint->Show();
1321 }
1322 else
1323 {
1324 m_hint->Move( pos.x - m_dist_x, pos.y + 5 );
1325 m_hint->SetTransparent( 128 );
1326 }
9adeb77a 1327
818d91a9
RR
1328 return false;
1329 }
9adeb77a 1330
818d91a9
RR
1331 wxDataViewMainWindow *m_win;
1332 unsigned int m_row;
1333 wxFrame *m_hint;
1334 int m_dist_x,m_dist_y;
1335};
1336
1337
a653c966
RR
1338class wxDataViewDropTarget: public wxDropTarget
1339{
1340public:
1341 wxDataViewDropTarget( wxDataObject *obj, wxDataViewMainWindow *win ) :
1342 wxDropTarget( obj )
1343 {
1344 m_win = win;
1345 }
1346
1347 virtual wxDragResult OnDragOver( wxCoord x, wxCoord y, wxDragResult def )
ce468dc2 1348 {
977a41ec
FM
1349 wxDataFormat format = GetMatchingPair();
1350 if (format == wxDF_INVALID)
1351 return wxDragNone;
1352 return m_win->OnDragOver( format, x, y, def);
ce468dc2 1353 }
9adeb77a 1354
a653c966 1355 virtual bool OnDrop( wxCoord x, wxCoord y )
ce468dc2 1356 {
977a41ec
FM
1357 wxDataFormat format = GetMatchingPair();
1358 if (format == wxDF_INVALID)
1359 return false;
1360 return m_win->OnDrop( format, x, y );
ce468dc2 1361 }
9adeb77a 1362
a653c966 1363 virtual wxDragResult OnData( wxCoord x, wxCoord y, wxDragResult def )
ce468dc2 1364 {
977a41ec
FM
1365 wxDataFormat format = GetMatchingPair();
1366 if (format == wxDF_INVALID)
1367 return wxDragNone;
1368 if (!GetData())
1369 return wxDragNone;
1370 return m_win->OnData( format, x, y, def );
ce468dc2 1371 }
9adeb77a 1372
a653c966
RR
1373 virtual void OnLeave()
1374 { m_win->OnLeave(); }
1375
1376 wxDataViewMainWindow *m_win;
1377};
1378
9adeb77a
VZ
1379#endif // wxUSE_DRAG_AND_DROP
1380
0fcce6b9
RR
1381//-----------------------------------------------------------------------------
1382// wxDataViewRenameTimer
1383//-----------------------------------------------------------------------------
1384
1385wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow *owner )
1386{
1387 m_owner = owner;
1388}
1389
1390void wxDataViewRenameTimer::Notify()
1391{
1392 m_owner->OnRenameTimer();
1393}
1394
4ed7af08
RR
1395//-----------------------------------------------------------------------------
1396// wxDataViewMainWindow
1397//-----------------------------------------------------------------------------
1398
bc4f1ff2 1399// The tree building helper, declared firstly
10875c13 1400static void BuildTreeHelper( const wxDataViewModel * model, const wxDataViewItem & item,
bc4f1ff2 1401 wxDataViewTreeNode * node);
704c3490 1402
0a71f9e9 1403int LINKAGEMODE wxDataViewSelectionCmp( unsigned int row1, unsigned int row2 )
cab07038
RR
1404{
1405 if (row1 > row2) return 1;
1406 if (row1 == row2) return 0;
1407 return -1;
1408}
1409
45778c96 1410IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
4ed7af08
RR
1411
1412BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
1413 EVT_PAINT (wxDataViewMainWindow::OnPaint)
1414 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse)
1415 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus)
cab07038
RR
1416 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus)
1417 EVT_CHAR (wxDataViewMainWindow::OnChar)
4ed7af08
RR
1418END_EVENT_TABLE()
1419
1420wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id,
1421 const wxPoint &pos, const wxSize &size, const wxString &name ) :
d81ad1f0 1422 wxWindow( parent, id, pos, size, wxWANTS_CHARS|wxBORDER_NONE, name ),
cab07038 1423 m_selection( wxDataViewSelectionCmp )
120b9b05 1424
4ed7af08
RR
1425{
1426 SetOwner( parent );
f554a14b 1427
0fcce6b9
RR
1428 m_lastOnSame = false;
1429 m_renameTimer = new wxDataViewRenameTimer( this );
120b9b05 1430
0fcce6b9
RR
1431 // TODO: user better initial values/nothing selected
1432 m_currentCol = NULL;
1433 m_currentRow = 0;
1434
e44ac7bc 1435 m_lineHeight = wxMax( 17, GetCharHeight() + 2 ); // 17 = mini icon height + 1
e21f75bd 1436
9adeb77a 1437#if wxUSE_DRAG_AND_DROP
e21f75bd
RR
1438 m_dragCount = 0;
1439 m_dragStart = wxPoint(0,0);
120b9b05 1440
821baf7d
RR
1441 m_dragEnabled = false;
1442 m_dropEnabled = false;
9deec111
RR
1443 m_dropHint = false;
1444 m_dropHintLine = (unsigned int) -1;
9adeb77a
VZ
1445#endif // wxUSE_DRAG_AND_DROP
1446
1447 m_lineLastClicked = (unsigned int) -1;
1448 m_lineBeforeLastClicked = (unsigned int) -1;
1449 m_lineSelectSingleOnUp = (unsigned int) -1;
821baf7d 1450
cab07038 1451 m_hasFocus = false;
f554a14b 1452
72664514
RR
1453 SetBackgroundColour( *wxWHITE );
1454
cfa42cb8
JS
1455 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
1456
069b2e59 1457 m_penRule = wxPen(GetRuleColour());
9861f022 1458
bc4f1ff2
FM
1459 // compose a pen whichcan draw black lines
1460 // TODO: maybe there is something system colour to use
069b2e59 1461 m_penExpander = wxPen(wxColour(0,0,0));
bc4f1ff2 1462
422aa8ec 1463 m_root = wxDataViewTreeNode::CreateRootNode();
704c3490 1464
bc4f1ff2 1465 // Make m_count = -1 will cause the class recaculate the real displaying number of rows.
59e60167 1466 m_count = -1;
24c4a50f 1467 m_underMouse = NULL;
4b3feaa7 1468 UpdateDisplay();
4ed7af08
RR
1469}
1470
1471wxDataViewMainWindow::~wxDataViewMainWindow()
1472{
aba9bfd0 1473 DestroyTree();
0fcce6b9
RR
1474 delete m_renameTimer;
1475}
1476
9adeb77a
VZ
1477
1478#if wxUSE_DRAG_AND_DROP
a653c966
RR
1479bool wxDataViewMainWindow::EnableDragSource( const wxDataFormat &format )
1480{
1481 m_dragFormat = format;
1482 m_dragEnabled = format != wxDF_INVALID;
9adeb77a 1483
a653c966
RR
1484 return true;
1485}
9adeb77a 1486
a653c966
RR
1487bool wxDataViewMainWindow::EnableDropTarget( const wxDataFormat &format )
1488{
1489 m_dropFormat = format;
1490 m_dropEnabled = format != wxDF_INVALID;
9adeb77a 1491
a653c966
RR
1492 if (m_dropEnabled)
1493 SetDropTarget( new wxDataViewDropTarget( new wxCustomDataObject( format ), this ) );
9adeb77a 1494
a653c966
RR
1495 return true;
1496}
1497
9deec111
RR
1498void wxDataViewMainWindow::RemoveDropHint()
1499{
1500 if (m_dropHint)
1501 {
1502 m_dropHint = false;
1503 RefreshRow( m_dropHintLine );
1504 m_dropHintLine = (unsigned int) -1;
1505 }
1506}
1507
4cef3873 1508wxDragResult wxDataViewMainWindow::OnDragOver( wxDataFormat format, wxCoord x,
bc4f1ff2 1509 wxCoord y, wxDragResult def )
a653c966
RR
1510{
1511 int xx = x;
1512 int yy = y;
1513 m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
1514 unsigned int row = GetLineAt( yy );
1515
aecf930c 1516 if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
9adeb77a 1517 {
9deec111 1518 RemoveDropHint();
a653c966 1519 return wxDragNone;
9deec111 1520 }
a653c966
RR
1521
1522 wxDataViewItem item = GetItemByRow( row );
9adeb77a 1523
c2c89730 1524 wxDataViewModel *model = GetModel();
9adeb77a 1525
a653c966
RR
1526 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
1527 event.SetEventObject( m_owner );
1528 event.SetItem( item );
1529 event.SetModel( model );
1530 event.SetDataFormat( format );
1531 if (!m_owner->HandleWindowEvent( event ))
9deec111
RR
1532 {
1533 RemoveDropHint();
a653c966 1534 return wxDragNone;
9deec111 1535 }
a653c966
RR
1536
1537 if (!event.IsAllowed())
9deec111
RR
1538 {
1539 RemoveDropHint();
a653c966 1540 return wxDragNone;
9deec111
RR
1541 }
1542
9adeb77a 1543
9deec111
RR
1544 if (m_dropHint && (row != m_dropHintLine))
1545 RefreshRow( m_dropHintLine );
1546 m_dropHint = true;
1547 m_dropHintLine = row;
1548 RefreshRow( row );
9adeb77a 1549
a653c966
RR
1550 return def;
1551}
1552
1553bool wxDataViewMainWindow::OnDrop( wxDataFormat format, wxCoord x, wxCoord y )
1554{
9deec111
RR
1555 RemoveDropHint();
1556
a653c966
RR
1557 int xx = x;
1558 int yy = y;
1559 m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
1560 unsigned int row = GetLineAt( yy );
1561
aecf930c 1562 if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
a653c966
RR
1563 return false;
1564
1565 wxDataViewItem item = GetItemByRow( row );
9adeb77a 1566
c2c89730 1567 wxDataViewModel *model = GetModel();
9adeb77a 1568
a653c966
RR
1569 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
1570 event.SetEventObject( m_owner );
1571 event.SetItem( item );
1572 event.SetModel( model );
1573 event.SetDataFormat( format );
1574 if (!m_owner->HandleWindowEvent( event ))
1575 return false;
1576
1577 if (!event.IsAllowed())
1578 return false;
9deec111 1579
a653c966
RR
1580 return true;
1581}
1582
4cef3873 1583wxDragResult wxDataViewMainWindow::OnData( wxDataFormat format, wxCoord x, wxCoord y,
bc4f1ff2 1584 wxDragResult def )
a653c966
RR
1585{
1586 int xx = x;
1587 int yy = y;
1588 m_owner->CalcUnscrolledPosition( xx, yy, &xx, &yy );
1589 unsigned int row = GetLineAt( yy );
1590
aecf930c 1591 if ((row >= GetRowCount()) || (xx > GetEndOfLastCol()))
a653c966
RR
1592 return wxDragNone;
1593
1594 wxDataViewItem item = GetItemByRow( row );
9adeb77a 1595
c2c89730 1596 wxDataViewModel *model = GetModel();
9adeb77a 1597
a653c966
RR
1598 wxCustomDataObject *obj = (wxCustomDataObject *) GetDropTarget()->GetDataObject();
1599
1600 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, m_owner->GetId() );
1601 event.SetEventObject( m_owner );
1602 event.SetItem( item );
1603 event.SetModel( model );
1604 event.SetDataFormat( format );
1605 event.SetDataSize( obj->GetSize() );
1606 event.SetDataBuffer( obj->GetData() );
1607 if (!m_owner->HandleWindowEvent( event ))
1608 return wxDragNone;
1609
1610 if (!event.IsAllowed())
1611 return wxDragNone;
1612
1613 return def;
1614}
1615
1616void wxDataViewMainWindow::OnLeave()
1617{
9deec111 1618 RemoveDropHint();
a653c966
RR
1619}
1620
818d91a9
RR
1621wxBitmap wxDataViewMainWindow::CreateItemBitmap( unsigned int row, int &indent )
1622{
1623 int height = GetLineHeight( row );
1624 int width = 0;
1625 unsigned int cols = GetOwner()->GetColumnCount();
1626 unsigned int col;
1627 for (col = 0; col < cols; col++)
1628 {
1629 wxDataViewColumn *column = GetOwner()->GetColumnAt(col);
1630 if (column->IsHidden())
1631 continue; // skip it!
1632 width += column->GetWidth();
1633 }
1634
1635 indent = 0;
ce5abbf9 1636 if (!IsList())
818d91a9
RR
1637 {
1638 wxDataViewTreeNode *node = GetTreeNodeByRow(row);
1639 indent = GetOwner()->GetIndent() * node->GetIndentLevel();
4cef3873 1640 indent = indent + m_lineHeight;
bc4f1ff2 1641 // try to use the m_lineHeight as the expander space
818d91a9
RR
1642 }
1643 width -= indent;
1644
1645 wxBitmap bitmap( width, height );
1646 wxMemoryDC dc( bitmap );
1647 dc.SetFont( GetFont() );
1648 dc.SetPen( *wxBLACK_PEN );
1649 dc.SetBrush( *wxWHITE_BRUSH );
1650 dc.DrawRectangle( 0,0,width,height );
9adeb77a 1651
818d91a9 1652 wxDataViewModel *model = m_owner->GetModel();
9adeb77a 1653
1841f079
VZ
1654 wxDataViewColumn * const
1655 expander = GetExpanderColumnOrFirstOne(GetOwner());
9adeb77a 1656
818d91a9
RR
1657 int x = 0;
1658 for (col = 0; col < cols; col++)
1659 {
1660 wxDataViewColumn *column = GetOwner()->GetColumnAt( col );
1661 wxDataViewRenderer *cell = column->GetRenderer();
1662
1663 if (column->IsHidden())
1664 continue; // skip it!
1665
1666 width = column->GetWidth();
9adeb77a 1667
818d91a9
RR
1668 if (column == expander)
1669 width -= indent;
9adeb77a 1670
818d91a9 1671 wxDataViewItem item = GetItemByRow( row );
f0ccd2cb 1672 cell->PrepareForItem(model, item, column->GetModelColumn());
62265c2c 1673
a6f1201f
VZ
1674 wxRect item_rect(x, 0, width, height);
1675 item_rect.Deflate(PADDING_RIGHTLEFT, 0);
818d91a9 1676
bc4f1ff2 1677 // dc.SetClippingRegion( item_rect );
62265c2c 1678 cell->WXCallRender(item_rect, &dc, 0);
bc4f1ff2 1679 // dc.DestroyClippingRegion();
9adeb77a 1680
818d91a9
RR
1681 x += width;
1682 }
9adeb77a 1683
818d91a9
RR
1684 return bitmap;
1685}
1686
9adeb77a
VZ
1687#endif // wxUSE_DRAG_AND_DROP
1688
1689
1117d56f 1690void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
0fcce6b9 1691{
c2c89730 1692 wxDataViewModel *model = GetModel();
1117d56f 1693 wxAutoBufferedPaintDC dc( this );
0fcce6b9 1694
1117d56f 1695#ifdef __WXMSW__
bb58fa37 1696 dc.SetBrush(GetOwner()->GetBackgroundColour());
1117d56f 1697 dc.SetPen( *wxTRANSPARENT_PEN );
bb58fa37 1698 dc.DrawRectangle(GetClientSize());
1117d56f
RR
1699#endif
1700
da87ce5a
VZ
1701 if ( IsEmpty() )
1702 {
1703 // No items to draw.
1704 return;
1705 }
1706
1117d56f
RR
1707 // prepare the DC
1708 GetOwner()->PrepareDC( dc );
1709 dc.SetFont( GetFont() );
1710
1711 wxRect update = GetUpdateRegion().GetBox();
1712 m_owner->CalcUnscrolledPosition( update.x, update.y, &update.x, &update.y );
1713
1714 // compute which items needs to be redrawn
344ed1f3 1715 unsigned int item_start = GetLineAt( wxMax(0,update.y) );
1117d56f 1716 unsigned int item_count =
344ed1f3 1717 wxMin( (int)( GetLineAt( wxMax(0,update.y+update.height) ) - item_start + 1),
977a41ec 1718 (int)(GetRowCount( ) - item_start));
1117d56f 1719 unsigned int item_last = item_start + item_count;
99f44d97
VZ
1720
1721 // Send the event to wxDataViewCtrl itself.
1722 wxWindow * const parent = GetParent();
47a8b1e1 1723 wxDataViewEvent cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT, parent->GetId());
99f44d97 1724 cache_event.SetEventObject(parent);
47a8b1e1
VZ
1725 cache_event.SetCache(item_start, item_last - 1);
1726 parent->ProcessWindowEvent(cache_event);
1117d56f
RR
1727
1728 // compute which columns needs to be redrawn
9861f022 1729 unsigned int cols = GetOwner()->GetColumnCount();
f03c22f9
VZ
1730 if ( !cols )
1731 {
1732 // we assume that we have at least one column below and painting an
1733 // empty control is unnecessary anyhow
1734 return;
1735 }
1736
1117d56f 1737 unsigned int col_start = 0;
e822d1bd 1738 unsigned int x_start;
1117d56f 1739 for (x_start = 0; col_start < cols; col_start++)
0fcce6b9 1740 {
702f5349 1741 wxDataViewColumn *col = GetOwner()->GetColumnAt(col_start);
1117d56f 1742 if (col->IsHidden())
9861f022
RR
1743 continue; // skip it!
1744
1117d56f
RR
1745 unsigned int w = col->GetWidth();
1746 if (x_start+w >= (unsigned int)update.x)
0fcce6b9 1747 break;
0fcce6b9 1748
1117d56f
RR
1749 x_start += w;
1750 }
1e510b1e 1751
1117d56f
RR
1752 unsigned int col_last = col_start;
1753 unsigned int x_last = x_start;
1754 for (; col_last < cols; col_last++)
1755 {
702f5349 1756 wxDataViewColumn *col = GetOwner()->GetColumnAt(col_last);
1117d56f
RR
1757 if (col->IsHidden())
1758 continue; // skip it!
afebb87b 1759
1117d56f
RR
1760 if (x_last > (unsigned int)update.GetRight())
1761 break;
4ed7af08 1762
1117d56f
RR
1763 x_last += col->GetWidth();
1764 }
d5025dc0 1765
1117d56f
RR
1766 // Draw horizontal rules if required
1767 if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
1768 {
1769 dc.SetPen(m_penRule);
1770 dc.SetBrush(*wxTRANSPARENT_BRUSH);
aba9bfd0 1771
de4bf0b3 1772 for (unsigned int i = item_start; i <= item_last; i++)
1117d56f 1773 {
344ed1f3 1774 int y = GetLineStart( i );
1117d56f
RR
1775 dc.DrawLine(x_start, y, x_last, y);
1776 }
1777 }
aba9bfd0 1778
1117d56f
RR
1779 // Draw vertical rules if required
1780 if ( m_owner->HasFlag(wxDV_VERT_RULES) )
b7e9f8b1 1781 {
1117d56f
RR
1782 dc.SetPen(m_penRule);
1783 dc.SetBrush(*wxTRANSPARENT_BRUSH);
b7e9f8b1 1784
3999336c
VS
1785 // NB: Vertical rules are drawn in the last pixel of a column so that
1786 // they align perfectly with native MSW wxHeaderCtrl as well as for
1787 // consistency with MSW native list control. There's no vertical
1788 // rule at the most-left side of the control.
1789
1790 int x = x_start - 1;
1117d56f
RR
1791 for (unsigned int i = col_start; i < col_last; i++)
1792 {
702f5349 1793 wxDataViewColumn *col = GetOwner()->GetColumnAt(i);
1117d56f
RR
1794 if (col->IsHidden())
1795 continue; // skip it
d47db7e0 1796
3999336c
VS
1797 x += col->GetWidth();
1798
344ed1f3
RR
1799 dc.DrawLine(x, GetLineStart( item_start ),
1800 x, GetLineStart( item_last ) );
1117d56f 1801 }
1117d56f
RR
1802 }
1803
1804 // redraw the background for the items which are selected/current
1805 for (unsigned int item = item_start; item < item_last; item++)
aba9bfd0 1806 {
1117d56f
RR
1807 bool selected = m_selection.Index( item ) != wxNOT_FOUND;
1808 if (selected || item == m_currentRow)
d5025dc0 1809 {
1117d56f
RR
1810 int flags = selected ? (int)wxCONTROL_SELECTED : 0;
1811 if (item == m_currentRow)
1812 flags |= wxCONTROL_CURRENT;
1813 if (m_hasFocus)
1814 flags |= wxCONTROL_FOCUSED;
d47db7e0 1815
e3dbeaaf
VZ
1816 wxRect rect( x_start, GetLineStart( item ),
1817 x_last - x_start, GetLineHeight( item ) );
1117d56f
RR
1818 wxRendererNative::Get().DrawItemSelectionRect
1819 (
1820 this,
1821 dc,
1822 rect,
1823 flags
1824 );
d47db7e0 1825 }
aba9bfd0 1826 }
9adeb77a
VZ
1827
1828#if wxUSE_DRAG_AND_DROP
9deec111 1829 if (m_dropHint)
9adeb77a
VZ
1830 {
1831 wxRect rect( x_start, GetLineStart( m_dropHintLine ),
e3dbeaaf 1832 x_last - x_start, GetLineHeight( m_dropHintLine ) );
9deec111
RR
1833 dc.SetPen( *wxBLACK_PEN );
1834 dc.SetBrush( *wxTRANSPARENT_BRUSH );
1835 dc.DrawRectangle( rect );
1836 }
9adeb77a 1837#endif // wxUSE_DRAG_AND_DROP
a0f3af5f 1838
1841f079
VZ
1839 wxDataViewColumn * const
1840 expander = GetExpanderColumnOrFirstOne(GetOwner());
d47db7e0 1841
344ed1f3 1842 // redraw all cells for all rows which must be repainted and all columns
1117d56f
RR
1843 wxRect cell_rect;
1844 cell_rect.x = x_start;
1117d56f 1845 for (unsigned int i = col_start; i < col_last; i++)
d47db7e0 1846 {
702f5349 1847 wxDataViewColumn *col = GetOwner()->GetColumnAt( i );
1117d56f
RR
1848 wxDataViewRenderer *cell = col->GetRenderer();
1849 cell_rect.width = col->GetWidth();
d47db7e0 1850
b10c4089 1851 if ( col->IsHidden() || cell_rect.width <= 0 )
344ed1f3 1852 continue; // skip it!
fbda518c 1853
1117d56f
RR
1854 for (unsigned int item = item_start; item < item_last; item++)
1855 {
1856 // get the cell value and set it into the renderer
1117d56f
RR
1857 wxDataViewTreeNode *node = NULL;
1858 wxDataViewItem dataitem;
cfa42cb8 1859
344ed1f3 1860 if (!IsVirtualList())
1117d56f
RR
1861 {
1862 node = GetTreeNodeByRow(item);
1863 if( node == NULL )
1864 continue;
a0f3af5f 1865
1117d56f 1866 dataitem = node->GetItem();
704c3490 1867
311c4a7a
VZ
1868 // Skip all columns of "container" rows except the expander
1869 // column itself unless HasContainerColumns() overrides this.
1841f079 1870 if ( col != expander &&
311c4a7a
VZ
1871 model->IsContainer(dataitem) &&
1872 !model->HasContainerColumns(dataitem) )
1117d56f
RR
1873 continue;
1874 }
1875 else
1876 {
86ba79ed 1877 dataitem = wxDataViewItem( wxUIntToPtr(item+1) );
1117d56f 1878 }
8b6cf9bf 1879
f0ccd2cb 1880 cell->PrepareForItem(model, dataitem, col->GetModelColumn());
62265c2c 1881
c9287446 1882 // update cell_rect
344ed1f3 1883 cell_rect.y = GetLineStart( item );
bc4f1ff2 1884 cell_rect.height = GetLineHeight( item );
8b6cf9bf 1885
b10c4089 1886 // deal with the expander
1117d56f 1887 int indent = 0;
ce5abbf9 1888 if ((!IsList()) && (col == expander))
1117d56f 1889 {
bc4f1ff2 1890 // Calculate the indent first
b10c4089 1891 indent = GetOwner()->GetIndent() * node->GetIndentLevel();
bc4f1ff2 1892
b10c4089
VZ
1893 // we reserve m_lineHeight of horizontal space for the expander
1894 // but leave EXPANDER_MARGIN around the expander itself
1895 int exp_x = cell_rect.x + indent + EXPANDER_MARGIN;
bc4f1ff2 1896
b10c4089 1897 indent += m_lineHeight;
bc4f1ff2 1898
b10c4089
VZ
1899 // draw expander if needed and visible
1900 if ( node->HasChildren() && exp_x < cell_rect.GetRight() )
1117d56f 1901 {
b10c4089
VZ
1902 dc.SetPen( m_penExpander );
1903 dc.SetBrush( wxNullBrush );
1904
1905 int exp_size = m_lineHeight - 2*EXPANDER_MARGIN;
1906 int exp_y = cell_rect.y + (cell_rect.height - exp_size)/2
1907 + EXPANDER_MARGIN - EXPANDER_OFFSET;
1908
1909 const wxRect rect(exp_x, exp_y, exp_size, exp_size);
1910
1117d56f 1911 int flag = 0;
b10c4089 1912 if ( m_underMouse == node )
1117d56f 1913 flag |= wxCONTROL_CURRENT;
b10c4089
VZ
1914 if ( node->IsOpen() )
1915 flag |= wxCONTROL_EXPANDED;
1916
1917 // ensure that we don't overflow the cell (which might
1918 // happen if the column is very narrow)
1919 wxDCClipper clip(dc, cell_rect);
1920
1921 wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, flag);
1117d56f 1922 }
bc4f1ff2
FM
1923
1924 // force the expander column to left-center align
977a41ec 1925 cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
1117d56f 1926 }
1117d56f 1927
a6f1201f
VZ
1928 wxRect item_rect = cell_rect;
1929 item_rect.Deflate(PADDING_RIGHTLEFT, 0);
1930
1931 // account for the tree indent (harmless if we're not indented)
1117d56f 1932 item_rect.x += indent;
a6f1201f 1933 item_rect.width -= indent;
1117d56f 1934
b10c4089
VZ
1935 if ( item_rect.width <= 0 )
1936 continue;
1937
1117d56f
RR
1938 int state = 0;
1939 if (m_hasFocus && (m_selection.Index(item) != wxNOT_FOUND))
1940 state |= wxDATAVIEW_CELL_SELECTED;
1941
1942 // TODO: it would be much more efficient to create a clipping
1943 // region for the entire column being rendered (in the OnPaint
1944 // of wxDataViewMainWindow) instead of a single clip region for
1945 // each cell. However it would mean that each renderer should
1946 // respect the given wxRect's top & bottom coords, eventually
1947 // violating only the left & right coords - however the user can
1948 // make its own renderer and thus we cannot be sure of that.
a6f1201f 1949 wxDCClipper clip(dc, item_rect);
2d0d7813 1950
62265c2c 1951 cell->WXCallRender(item_rect, &dc, state);
1117d56f
RR
1952 }
1953
1954 cell_rect.x += cell_rect.width;
1955 }
1956}
1957
1958void wxDataViewMainWindow::OnRenameTimer()
1959{
1960 // We have to call this here because changes may just have
1961 // been made and no screen update taken place.
1962 if ( m_dirty )
977a41ec
FM
1963 {
1964 // TODO: use wxTheApp->SafeYieldFor(NULL, wxEVT_CATEGORY_UI) instead
1965 // (needs to be tested!)
1117d56f 1966 wxSafeYield();
977a41ec 1967 }
1117d56f 1968
0a807957 1969 wxDataViewItem item = GetItemByRow( m_currentRow );
1117d56f 1970
0a807957 1971 wxRect labelRect = GetItemRect(item, m_currentCol);
1117d56f 1972
1117d56f 1973 m_currentCol->GetRenderer()->StartEditing( item, labelRect );
1117d56f
RR
1974}
1975
bc4f1ff2 1976//-----------------------------------------------------------------------------
1117d56f 1977// Helper class for do operation on the tree node
bc4f1ff2 1978//-----------------------------------------------------------------------------
1117d56f
RR
1979class DoJob
1980{
1981public:
59e60167
VZ
1982 DoJob() { }
1983 virtual ~DoJob() { }
1117d56f 1984
bc4f1ff2 1985 // The return value control how the tree-walker tranverse the tree
d54f0605
VS
1986 enum
1987 {
1988 DONE, // Job done, stop traversing and return
1989 SKIP_SUBTREE, // Ignore the current node's subtree and continue
1990 CONTINUE // Job not done, continue
1991 };
1992
59e60167 1993 virtual int operator() ( wxDataViewTreeNode * node ) = 0;
1117d56f
RR
1994};
1995
1996bool Walker( wxDataViewTreeNode * node, DoJob & func )
1997{
422aa8ec 1998 wxCHECK_MSG( node, false, "can't walk NULL node" );
1117d56f
RR
1999
2000 switch( func( node ) )
2001 {
d54f0605 2002 case DoJob::DONE:
59e60167 2003 return true;
d54f0605 2004 case DoJob::SKIP_SUBTREE:
1117d56f 2005 return false;
d54f0605 2006 case DoJob::CONTINUE:
422aa8ec 2007 break;
1117d56f
RR
2008 }
2009
d0cfefc4 2010 if ( node->HasChildren() )
1117d56f 2011 {
ff3c5ad3 2012 const wxDataViewTreeNodes& nodes = node->GetChildNodes();
d0cfefc4
VS
2013
2014 for ( wxDataViewTreeNodes::const_iterator i = nodes.begin();
2015 i != nodes.end();
2016 ++i )
2017 {
2018 if ( Walker(*i, func) )
2019 return true;
2020 }
1117d56f 2021 }
422aa8ec 2022
1117d56f
RR
2023 return false;
2024}
2025
2026bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
2027{
86ba79ed 2028 if (IsVirtualList())
1117d56f 2029 {
49d2b75d 2030 wxDataViewVirtualListModel *list_model =
c2c89730 2031 (wxDataViewVirtualListModel*) GetModel();
49d2b75d 2032 m_count = list_model->GetCount();
1117d56f 2033 }
0b93babd
VS
2034 else
2035 {
2036 SortPrepare();
cfa42cb8 2037
422aa8ec 2038 wxDataViewTreeNode *parentNode = FindNode(parent);
1117d56f 2039
422aa8ec 2040 if ( !parentNode )
0b93babd 2041 return false;
1117d56f 2042
35219832
VS
2043 wxDataViewItemArray siblings;
2044 GetModel()->GetChildren(parent, siblings);
2045 int itemPos = siblings.Index(item, /*fromEnd=*/true);
2046 wxCHECK_MSG( itemPos != wxNOT_FOUND, false, "adding non-existent item?" );
2047
422aa8ec 2048 wxDataViewTreeNode *itemNode = new wxDataViewTreeNode(parentNode, item);
c2c89730 2049 itemNode->SetHasChildren(GetModel()->IsContainer(item));
1117d56f 2050
422aa8ec 2051 parentNode->SetHasChildren(true);
35219832 2052 parentNode->InsertChild(itemNode, itemPos);
422aa8ec 2053 parentNode->ChangeSubTreeCount(+1);
1117d56f 2054
0b93babd 2055 m_count = -1;
1117d56f 2056 }
1117d56f 2057
bed74e48 2058 GetOwner()->InvalidateColBestWidths();
1117d56f
RR
2059 UpdateDisplay();
2060
2061 return true;
2062}
2063
1117d56f 2064bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
86ba79ed 2065 const wxDataViewItem& item)
1117d56f 2066{
86ba79ed 2067 if (IsVirtualList())
1117d56f 2068 {
49d2b75d 2069 wxDataViewVirtualListModel *list_model =
c2c89730 2070 (wxDataViewVirtualListModel*) GetModel();
49d2b75d 2071 m_count = list_model->GetCount();
03647350 2072
57ab4546
VS
2073 if ( !m_selection.empty() )
2074 {
2075 const int row = GetRowByItem(item);
2076
f6410588
VS
2077 int rowIndexInSelection = wxNOT_FOUND;
2078
57ab4546
VS
2079 const size_t selCount = m_selection.size();
2080 for ( size_t i = 0; i < selCount; i++ )
2081 {
f6410588
VS
2082 if ( m_selection[i] == (unsigned)row )
2083 rowIndexInSelection = i;
2084 else if ( m_selection[i] > (unsigned)row )
57ab4546
VS
2085 m_selection[i]--;
2086 }
2087
f6410588
VS
2088 if ( rowIndexInSelection != wxNOT_FOUND )
2089 m_selection.RemoveAt(rowIndexInSelection);
57ab4546
VS
2090 }
2091
1117d56f 2092 }
b6252949
VS
2093 else // general case
2094 {
422aa8ec 2095 wxDataViewTreeNode *parentNode = FindNode(parent);
1117d56f 2096
b6252949
VS
2097 // Notice that it is possible that the item being deleted is not in the
2098 // tree at all, for example we could be deleting a never shown (because
2099 // collapsed) item in a tree model. So it's not an error if we don't know
2100 // about this item, just return without doing anything then.
b632efe0 2101 if ( !parentNode )
b23de238
VS
2102 return false;
2103
d0cfefc4 2104 wxCHECK_MSG( parentNode->HasChildren(), false, "parent node doesn't have children?" );
ff3c5ad3 2105 const wxDataViewTreeNodes& parentsChildren = parentNode->GetChildNodes();
351461fc 2106
422aa8ec
VS
2107 // We can't use FindNode() to find 'item', because it was already
2108 // removed from the model by the time ItemDeleted() is called, so we
2109 // have to do it manually. We keep track of its position as well for
2110 // later use.
2111 int itemPosInNode = 0;
57ab4546 2112 wxDataViewTreeNode *itemNode = NULL;
422aa8ec
VS
2113 for ( wxDataViewTreeNodes::const_iterator i = parentsChildren.begin();
2114 i != parentsChildren.end();
2115 ++i, ++itemPosInNode )
d47db7e0 2116 {
422aa8ec 2117 if( (*i)->GetItem() == item )
d47db7e0 2118 {
422aa8ec 2119 itemNode = *i;
d47db7e0
RR
2120 break;
2121 }
2122 }
57ab4546 2123
422aa8ec
VS
2124 // If the parent wasn't expanded, it's possible that we didn't have a
2125 // node corresponding to 'item' and so there's nothing left to do.
2126 if ( !itemNode )
b6252949 2127 {
422aa8ec
VS
2128 // If this was the last child to be removed, it's possible the parent
2129 // node became a leaf. Let's ask the model about it.
ff3c5ad3 2130 if ( parentNode->GetChildNodes().empty() )
c2c89730 2131 parentNode->SetHasChildren(GetModel()->IsContainer(parent));
a8505db0 2132
422aa8ec 2133 return false;
b6252949 2134 }
57ab4546 2135
422aa8ec
VS
2136 // Delete the item from wxDataViewTreeNode representation:
2137 const int itemsDeleted = 1 + itemNode->GetSubTreeCount();
2138
a2d3c415
VS
2139 parentNode->RemoveChild(itemNode);
2140 delete itemNode;
422aa8ec
VS
2141 parentNode->ChangeSubTreeCount(-itemsDeleted);
2142
b6252949
VS
2143 // Make the row number invalid and get a new valid one when user call GetRowCount
2144 m_count = -1;
422aa8ec
VS
2145
2146 // If this was the last child to be removed, it's possible the parent
2147 // node became a leaf. Let's ask the model about it.
ff3c5ad3 2148 if ( parentNode->GetChildNodes().empty() )
c2c89730 2149 parentNode->SetHasChildren(GetModel()->IsContainer(parent));
57ab4546
VS
2150
2151 // Update selection by removing 'item' and its entire children tree from the selection.
2152 if ( !m_selection.empty() )
2153 {
2154 // we can't call GetRowByItem() on 'item', as it's already deleted, so compute it from
b632efe0 2155 // the parent ('parentNode') and position in its list of children
57ab4546
VS
2156 int itemRow;
2157 if ( itemPosInNode == 0 )
2158 {
b632efe0
VS
2159 // 1st child, row number is that of the parent parentNode + 1
2160 itemRow = GetRowByItem(parentNode->GetItem()) + 1;
57ab4546
VS
2161 }
2162 else
2163 {
2164 // row number is that of the sibling above 'item' + its subtree if any + 1
ff3c5ad3 2165 const wxDataViewTreeNode *siblingNode = parentNode->GetChildNodes()[itemPosInNode - 1];
57ab4546 2166
422aa8ec
VS
2167 itemRow = GetRowByItem(siblingNode->GetItem()) +
2168 siblingNode->GetSubTreeCount() +
2169 1;
57ab4546
VS
2170 }
2171
2172 wxDataViewSelection newsel(wxDataViewSelectionCmp);
2173
3823a15e
VZ
2174 const size_t numSelections = m_selection.size();
2175 for ( size_t i = 0; i < numSelections; ++i )
57ab4546 2176 {
3823a15e 2177 const int s = m_selection[i];
57ab4546
VS
2178 if ( s < itemRow )
2179 newsel.push_back(s);
2180 else if ( s >= itemRow + itemsDeleted )
2181 newsel.push_back(s - itemsDeleted);
2182 // else: deleted item, remove from selection
2183 }
2184
2185 m_selection = newsel;
2186 }
d47db7e0 2187 }
24c4a50f 2188
bc4f1ff2 2189 // Change the current row to the last row if the current exceed the max row number
d47db7e0 2190 if( m_currentRow > GetRowCount() )
8c7b8711 2191 ChangeCurrentRow(m_count - 1);
351461fc 2192
bed74e48 2193 GetOwner()->InvalidateColBestWidths();
99d471a5 2194 UpdateDisplay();
b7fe2261 2195
99d471a5 2196 return true;
a0f3af5f
RR
2197}
2198
aba9bfd0 2199bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
a0f3af5f 2200{
66e09788 2201 SortPrepare();
b7e9f8b1
RR
2202 g_model->Resort();
2203
bed74e48 2204 GetOwner()->InvalidateColBestWidths();
ac098108 2205
bc4f1ff2 2206 // Send event
6608fdab
RR
2207 wxWindow *parent = GetParent();
2208 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
2209 le.SetEventObject(parent);
c2c89730 2210 le.SetModel(GetModel());
6608fdab 2211 le.SetItem(item);
857f05e1 2212 parent->ProcessWindowEvent(le);
b5ec7dd6 2213
99d471a5 2214 return true;
a0f3af5f
RR
2215}
2216
d93cc830 2217bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int model_column )
a0f3af5f 2218{
d93cc830
RR
2219 int view_column = -1;
2220 unsigned int n_col = m_owner->GetColumnCount();
2221 for (unsigned i = 0; i < n_col; i++)
2222 {
2223 wxDataViewColumn *column = m_owner->GetColumn( i );
2224 if (column->GetModelColumn() == model_column)
2225 {
2226 view_column = (int) i;
2227 break;
2228 }
2229 }
2230 if (view_column == -1)
2231 return false;
2232
9861f022 2233 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
aba9bfd0 2234/*#define MAX_VIRTUAL_WIDTH 100000
9861f022
RR
2235
2236 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
0fdc2321
RR
2237 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2238 Refresh( true, &rect );
2239
2240 return true;
aba9bfd0 2241*/
66e09788 2242 SortPrepare();
b7e9f8b1
RR
2243 g_model->Resort();
2244
bed74e48 2245 GetOwner()->InvalidateColBestWidth(view_column);
ac098108 2246
bc4f1ff2 2247 // Send event
b7e9f8b1 2248 wxWindow *parent = GetParent();
6608fdab 2249 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
b7e9f8b1 2250 le.SetEventObject(parent);
c2c89730 2251 le.SetModel(GetModel());
b7e9f8b1 2252 le.SetItem(item);
d93cc830
RR
2253 le.SetColumn(view_column);
2254 le.SetDataViewColumn(GetOwner()->GetColumn(view_column));
857f05e1 2255 parent->ProcessWindowEvent(le);
d47db7e0 2256
0fcce6b9 2257 return true;
a0f3af5f
RR
2258}
2259
2260bool wxDataViewMainWindow::Cleared()
2261{
704c3490 2262 DestroyTree();
97e5b064 2263 m_selection.Clear();
cfa42cb8 2264
33ba5a05 2265 SortPrepare();
c2c89730 2266 BuildTree( GetModel() );
cfa42cb8 2267
bed74e48 2268 GetOwner()->InvalidateColBestWidths();
99d471a5 2269 UpdateDisplay();
b7e9f8b1 2270
99d471a5 2271 return true;
a0f3af5f
RR
2272}
2273
4b3feaa7
RR
2274void wxDataViewMainWindow::UpdateDisplay()
2275{
2276 m_dirty = true;
7d5d2f23 2277 m_underMouse = NULL;
4b3feaa7
RR
2278}
2279
2280void wxDataViewMainWindow::OnInternalIdle()
2281{
2282 wxWindow::OnInternalIdle();
f554a14b 2283
4b3feaa7
RR
2284 if (m_dirty)
2285 {
2286 RecalculateDisplay();
2287 m_dirty = false;
2288 }
2289}
2290
2291void wxDataViewMainWindow::RecalculateDisplay()
2292{
c2c89730 2293 wxDataViewModel *model = GetModel();
4b3feaa7
RR
2294 if (!model)
2295 {
2296 Refresh();
2297 return;
2298 }
f554a14b 2299
9861f022 2300 int width = GetEndOfLastCol();
344ed1f3 2301 int height = GetLineStart( GetRowCount() );
4b3feaa7
RR
2302
2303 SetVirtualSize( width, height );
2304 GetOwner()->SetScrollRate( 10, m_lineHeight );
f554a14b 2305
4b3feaa7
RR
2306 Refresh();
2307}
2308
2309void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
2310{
d93cc830
RR
2311 m_underMouse = NULL;
2312
4b3feaa7 2313 wxWindow::ScrollWindow( dx, dy, rect );
9861f022
RR
2314
2315 if (GetOwner()->m_headerArea)
2316 GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
4b3feaa7
RR
2317}
2318
fbda518c 2319void wxDataViewMainWindow::ScrollTo( int rows, int column )
b7e9f8b1 2320{
d93cc830
RR
2321 m_underMouse = NULL;
2322
b7e9f8b1
RR
2323 int x, y;
2324 m_owner->GetScrollPixelsPerUnit( &x, &y );
344ed1f3 2325 int sy = GetLineStart( rows )/y;
fbda518c
RR
2326 int sx = 0;
2327 if( column != -1 )
2328 {
2329 wxRect rect = GetClientRect();
67be459b 2330 int colnum = 0;
dd639a4f 2331 int x_start, w = 0;
fbda518c
RR
2332 int xx, yy, xe;
2333 m_owner->CalcUnscrolledPosition( rect.x, rect.y, &xx, &yy );
2334 for (x_start = 0; colnum < column; colnum++)
2335 {
702f5349 2336 wxDataViewColumn *col = GetOwner()->GetColumnAt(colnum);
fbda518c
RR
2337 if (col->IsHidden())
2338 continue; // skip it!
2339
2340 w = col->GetWidth();
2341 x_start += w;
2342 }
2343
e822d1bd 2344 int x_end = x_start + w;
fbda518c
RR
2345 xe = xx + rect.width;
2346 if( x_end > xe )
2347 {
2348 sx = ( xx + x_end - xe )/x;
2349 }
2350 if( x_start < xx )
2351 {
b7fe2261 2352 sx = x_start/x;
fbda518c
RR
2353 }
2354 }
2355 m_owner->Scroll( sx, sy );
b7e9f8b1
RR
2356}
2357
9861f022 2358int wxDataViewMainWindow::GetCountPerPage() const
cab07038
RR
2359{
2360 wxSize size = GetClientSize();
2361 return size.y / m_lineHeight;
2362}
2363
9861f022 2364int wxDataViewMainWindow::GetEndOfLastCol() const
e21f75bd
RR
2365{
2366 int width = 0;
0a71f9e9 2367 unsigned int i;
9861f022 2368 for (i = 0; i < GetOwner()->GetColumnCount(); i++)
e21f75bd 2369 {
c741d33f 2370 const wxDataViewColumn *c =
702f5349 2371 const_cast<wxDataViewCtrl*>(GetOwner())->GetColumnAt( i );
9861f022
RR
2372
2373 if (!c->IsHidden())
2374 width += c->GetWidth();
e21f75bd
RR
2375 }
2376 return width;
2377}
2378
9861f022 2379unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
72664514
RR
2380{
2381 int x = 0;
2382 int y = 0;
2383 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
120b9b05 2384
344ed1f3 2385 return GetLineAt( y );
72664514
RR
2386}
2387
442c56e6 2388unsigned int wxDataViewMainWindow::GetLastVisibleRow()
72664514
RR
2389{
2390 wxSize client_size = GetClientSize();
c741d33f 2391 m_owner->CalcUnscrolledPosition( client_size.x, client_size.y,
977a41ec 2392 &client_size.x, &client_size.y );
72664514 2393
bc4f1ff2 2394 // we should deal with the pixel here
344ed1f3 2395 unsigned int row = GetLineAt(client_size.y) - 1;
b7fe2261 2396
fbda518c 2397 return wxMin( GetRowCount()-1, row );
72664514
RR
2398}
2399
442c56e6 2400unsigned int wxDataViewMainWindow::GetRowCount()
cab07038 2401{
3b6280be
RR
2402 if ( m_count == -1 )
2403 {
2404 m_count = RecalculateCount();
344ed1f3 2405 UpdateDisplay();
3b6280be 2406 }
aba9bfd0 2407 return m_count;
cab07038
RR
2408}
2409
0a71f9e9 2410void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row )
e21f75bd
RR
2411{
2412 m_currentRow = row;
120b9b05 2413
e21f75bd
RR
2414 // send event
2415}
2416
cab07038
RR
2417void wxDataViewMainWindow::SelectAllRows( bool on )
2418{
4a851b11
VZ
2419 if (IsEmpty())
2420 return;
120b9b05 2421
cab07038
RR
2422 if (on)
2423 {
72664514 2424 m_selection.Clear();
0a71f9e9 2425 for (unsigned int i = 0; i < GetRowCount(); i++)
cab07038 2426 m_selection.Add( i );
72664514
RR
2427 Refresh();
2428 }
2429 else
2430 {
0a71f9e9
RR
2431 unsigned int first_visible = GetFirstVisibleRow();
2432 unsigned int last_visible = GetLastVisibleRow();
2433 unsigned int i;
72664514 2434 for (i = 0; i < m_selection.GetCount(); i++)
120b9b05 2435 {
0a71f9e9 2436 unsigned int row = m_selection[i];
72664514
RR
2437 if ((row >= first_visible) && (row <= last_visible))
2438 RefreshRow( row );
2439 }
2440 m_selection.Clear();
cab07038 2441 }
cab07038
RR
2442}
2443
0a71f9e9 2444void wxDataViewMainWindow::SelectRow( unsigned int row, bool on )
cab07038
RR
2445{
2446 if (m_selection.Index( row ) == wxNOT_FOUND)
2447 {
2448 if (on)
2449 {
2450 m_selection.Add( row );
2451 RefreshRow( row );
2452 }
2453 }
2454 else
2455 {
2456 if (!on)
2457 {
2458 m_selection.Remove( row );
2459 RefreshRow( row );
2460 }
2461 }
2462}
2463
0a71f9e9 2464void wxDataViewMainWindow::SelectRows( unsigned int from, unsigned int to, bool on )
cab07038
RR
2465{
2466 if (from > to)
2467 {
0a71f9e9 2468 unsigned int tmp = from;
cab07038
RR
2469 from = to;
2470 to = tmp;
2471 }
2472
0a71f9e9 2473 unsigned int i;
cab07038
RR
2474 for (i = from; i <= to; i++)
2475 {
2476 if (m_selection.Index( i ) == wxNOT_FOUND)
2477 {
2478 if (on)
2479 m_selection.Add( i );
2480 }
2481 else
2482 {
2483 if (!on)
2484 m_selection.Remove( i );
2485 }
2486 }
2487 RefreshRows( from, to );
2488}
2489
87f0efe2
RR
2490void wxDataViewMainWindow::Select( const wxArrayInt& aSelections )
2491{
2492 for (size_t i=0; i < aSelections.GetCount(); i++)
2493 {
2494 int n = aSelections[i];
2495
2496 m_selection.Add( n );
2497 RefreshRow( n );
2498 }
2499}
2500
0a71f9e9 2501void wxDataViewMainWindow::ReverseRowSelection( unsigned int row )
cab07038
RR
2502{
2503 if (m_selection.Index( row ) == wxNOT_FOUND)
2504 m_selection.Add( row );
2505 else
2506 m_selection.Remove( row );
120b9b05 2507 RefreshRow( row );
cab07038
RR
2508}
2509
0a71f9e9 2510bool wxDataViewMainWindow::IsRowSelected( unsigned int row )
cab07038
RR
2511{
2512 return (m_selection.Index( row ) != wxNOT_FOUND);
2513}
2514
526e19e2
RR
2515void wxDataViewMainWindow::SendSelectionChangedEvent( const wxDataViewItem& item)
2516{
2517 wxWindow *parent = GetParent();
2518 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, parent->GetId());
2519
2520 le.SetEventObject(parent);
c2c89730 2521 le.SetModel(GetModel());
526e19e2
RR
2522 le.SetItem( item );
2523
857f05e1 2524 parent->ProcessWindowEvent(le);
526e19e2
RR
2525}
2526
0a71f9e9 2527void wxDataViewMainWindow::RefreshRow( unsigned int row )
cab07038 2528{
344ed1f3 2529 wxRect rect( 0, GetLineStart( row ), GetEndOfLastCol(), GetLineHeight( row ) );
cab07038 2530 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
120b9b05 2531
cab07038
RR
2532 wxSize client_size = GetClientSize();
2533 wxRect client_rect( 0, 0, client_size.x, client_size.y );
2534 wxRect intersect_rect = client_rect.Intersect( rect );
2535 if (intersect_rect.width > 0)
2536 Refresh( true, &intersect_rect );
2537}
2538
0a71f9e9 2539void wxDataViewMainWindow::RefreshRows( unsigned int from, unsigned int to )
cab07038
RR
2540{
2541 if (from > to)
2542 {
0a71f9e9 2543 unsigned int tmp = to;
cab07038
RR
2544 to = from;
2545 from = tmp;
2546 }
2547
344ed1f3 2548 wxRect rect( 0, GetLineStart( from ), GetEndOfLastCol(), GetLineStart( (to-from+1) ) );
cab07038 2549 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
120b9b05 2550
cab07038
RR
2551 wxSize client_size = GetClientSize();
2552 wxRect client_rect( 0, 0, client_size.x, client_size.y );
2553 wxRect intersect_rect = client_rect.Intersect( rect );
2554 if (intersect_rect.width > 0)
2555 Refresh( true, &intersect_rect );
2556}
2557
0a71f9e9 2558void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow )
cab07038 2559{
cab07038 2560 wxSize client_size = GetClientSize();
344ed1f3
RR
2561 int start = GetLineStart( firstRow );
2562 m_owner->CalcScrolledPosition( start, 0, &start, NULL );
2563 if (start > client_size.y) return;
2564
2565 wxRect rect( 0, start, client_size.x, client_size.y - start );
777f9cef 2566
344ed1f3 2567 Refresh( true, &rect );
cab07038
RR
2568}
2569
9861f022
RR
2570wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const
2571{
2572 wxRect rect;
2573 rect.x = 0;
344ed1f3 2574 rect.y = GetLineStart( row );
9861f022 2575 rect.width = GetEndOfLastCol();
344ed1f3 2576 rect.height = GetLineHeight( row );
9861f022
RR
2577
2578 return rect;
cab07038
RR
2579}
2580
344ed1f3
RR
2581int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
2582{
c2c89730 2583 const wxDataViewModel *model = GetModel();
777f9cef 2584
344ed1f3
RR
2585 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
2586 {
2587 // TODO make more efficient
777f9cef 2588
344ed1f3 2589 int start = 0;
777f9cef 2590
344ed1f3
RR
2591 unsigned int r;
2592 for (r = 0; r < row; r++)
2593 {
e170469f
RR
2594 const wxDataViewTreeNode* node = GetTreeNodeByRow(r);
2595 if (!node) return start;
777f9cef 2596
e170469f 2597 wxDataViewItem item = node->GetItem();
777f9cef 2598
e170469f
RR
2599 unsigned int cols = GetOwner()->GetColumnCount();
2600 unsigned int col;
2601 int height = m_lineHeight;
2602 for (col = 0; col < cols; col++)
2603 {
344ed1f3
RR
2604 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2605 if (column->IsHidden())
2606 continue; // skip it!
777f9cef 2607
4cef3873
VZ
2608 if ((col != 0) &&
2609 model->IsContainer(item) &&
ce468dc2 2610 !model->HasContainerColumns(item))
ba5f54e6 2611 continue; // skip it!
777f9cef 2612
4cef3873 2613 wxDataViewRenderer *renderer =
ce468dc2 2614 const_cast<wxDataViewRenderer*>(column->GetRenderer());
f0ccd2cb 2615 renderer->PrepareForItem(model, item, column->GetModelColumn());
86755098 2616
344ed1f3 2617 height = wxMax( height, renderer->GetSize().y );
e170469f 2618 }
777f9cef 2619
e170469f 2620 start += height;
344ed1f3 2621 }
777f9cef 2622
344ed1f3
RR
2623 return start;
2624 }
2625 else
2626 {
2627 return row * m_lineHeight;
2628 }
2629}
2630
2631int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
2632{
c2c89730 2633 const wxDataViewModel *model = GetModel();
ba5f54e6 2634
777f9cef
VZ
2635 // check for the easy case first
2636 if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) )
2637 return y / m_lineHeight;
2638
2639 // TODO make more efficient
2640 unsigned int row = 0;
2641 unsigned int yy = 0;
2642 for (;;)
344ed1f3 2643 {
ce468dc2
FM
2644 const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
2645 if (!node)
2646 {
2647 // not really correct...
2648 return row + ((y-yy) / m_lineHeight);
2649 }
777f9cef 2650
ce468dc2 2651 wxDataViewItem item = node->GetItem();
777f9cef 2652
ce468dc2
FM
2653 unsigned int cols = GetOwner()->GetColumnCount();
2654 unsigned int col;
2655 int height = m_lineHeight;
2656 for (col = 0; col < cols; col++)
2657 {
777f9cef
VZ
2658 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2659 if (column->IsHidden())
2660 continue; // skip it!
2661
4cef3873
VZ
2662 if ((col != 0) &&
2663 model->IsContainer(item) &&
ce468dc2 2664 !model->HasContainerColumns(item))
777f9cef
VZ
2665 continue; // skip it!
2666
4cef3873 2667 wxDataViewRenderer *renderer =
ce468dc2 2668 const_cast<wxDataViewRenderer*>(column->GetRenderer());
f0ccd2cb 2669 renderer->PrepareForItem(model, item, column->GetModelColumn());
86755098 2670
777f9cef 2671 height = wxMax( height, renderer->GetSize().y );
ce468dc2 2672 }
777f9cef 2673
ce468dc2
FM
2674 yy += height;
2675 if (y < yy)
2676 return row;
777f9cef 2677
ce468dc2 2678 row++;
344ed1f3
RR
2679 }
2680}
2681
2682int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
2683{
c2c89730 2684 const wxDataViewModel *model = GetModel();
777f9cef 2685
344ed1f3
RR
2686 if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
2687 {
2688 wxASSERT( !IsVirtualList() );
777f9cef 2689
344ed1f3
RR
2690 const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
2691 // wxASSERT( node );
2692 if (!node) return m_lineHeight;
2693
ba5f54e6 2694 wxDataViewItem item = node->GetItem();
777f9cef 2695
981cd83e 2696 int height = m_lineHeight;
777f9cef 2697
344ed1f3
RR
2698 unsigned int cols = GetOwner()->GetColumnCount();
2699 unsigned int col;
2700 for (col = 0; col < cols; col++)
2701 {
2702 const wxDataViewColumn *column = GetOwner()->GetColumn(col);
2703 if (column->IsHidden())
2704 continue; // skip it!
ba5f54e6 2705
4cef3873
VZ
2706 if ((col != 0) &&
2707 model->IsContainer(item) &&
ce468dc2 2708 !model->HasContainerColumns(item))
ba5f54e6 2709 continue; // skip it!
777f9cef 2710
4cef3873 2711 wxDataViewRenderer *renderer =
ce468dc2 2712 const_cast<wxDataViewRenderer*>(column->GetRenderer());
f0ccd2cb 2713 renderer->PrepareForItem(model, item, column->GetModelColumn());
86755098 2714
344ed1f3
RR
2715 height = wxMax( height, renderer->GetSize().y );
2716 }
2717
2718 return height;
2719 }
2720 else
2721 {
2722 return m_lineHeight;
2723 }
2724}
2725
aba9bfd0 2726
3b6280be
RR
2727class RowToTreeNodeJob: public DoJob
2728{
2729public:
442c56e6
VZ
2730 RowToTreeNodeJob( unsigned int row , int current, wxDataViewTreeNode * node )
2731 {
2732 this->row = row;
59e60167
VZ
2733 this->current = current;
2734 ret = NULL;
d47db7e0
RR
2735 parent = node;
2736 }
3b6280be
RR
2737
2738 virtual int operator() ( wxDataViewTreeNode * node )
d5025dc0 2739 {
d47db7e0 2740 current ++;
704c3490 2741 if( current == static_cast<int>(row))
977a41ec 2742 {
59e60167 2743 ret = node;
d54f0605 2744 return DoJob::DONE;
3b6280be 2745 }
d47db7e0
RR
2746
2747 if( node->GetSubTreeCount() + current < static_cast<int>(row) )
2748 {
2749 current += node->GetSubTreeCount();
d54f0605 2750 return DoJob::SKIP_SUBTREE;
d47db7e0 2751 }
d5025dc0 2752 else
d47db7e0
RR
2753 {
2754 parent = node;
bc4f1ff2 2755
422aa8ec
VS
2756 // If the current node has only leaf children, we can find the
2757 // desired node directly. This can speed up finding the node
2758 // in some cases, and will have a very good effect for list views.
d0cfefc4 2759 if ( node->HasChildren() &&
ff3c5ad3 2760 (int)node->GetChildNodes().size() == node->GetSubTreeCount() )
b7e9f8b1 2761 {
422aa8ec 2762 const int index = static_cast<int>(row) - current - 1;
ff3c5ad3 2763 ret = node->GetChildNodes()[index];
d54f0605 2764 return DoJob::DONE;
b7e9f8b1 2765 }
d0cfefc4 2766
d54f0605 2767 return DoJob::CONTINUE;
d47db7e0 2768 }
d5025dc0 2769 }
3b6280be 2770
bc4f1ff2
FM
2771 wxDataViewTreeNode * GetResult() const
2772 { return ret; }
2773
3b6280be
RR
2774private:
2775 unsigned int row;
59e60167 2776 int current;
3b6280be 2777 wxDataViewTreeNode * ret;
59e60167 2778 wxDataViewTreeNode * parent;
3b6280be
RR
2779};
2780
344ed1f3 2781wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) const
3b6280be 2782{
344ed1f3 2783 wxASSERT( !IsVirtualList() );
777f9cef 2784
344ed1f3
RR
2785 RowToTreeNodeJob job( row , -2, m_root );
2786 Walker( m_root , job );
2787 return job.GetResult();
3b6280be
RR
2788}
2789
422aa8ec
VS
2790wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
2791{
2792 if (IsVirtualList())
2793 {
2794 return wxDataViewItem( wxUIntToPtr(row+1) );
2795 }
2796 else
2797 {
2798 wxDataViewTreeNode *node = GetTreeNodeByRow(row);
2799 return node ? node->GetItem() : wxDataViewItem();
2800 }
2801}
2802
fd48fe89
VZ
2803bool
2804wxDataViewMainWindow::SendExpanderEvent(wxEventType type,
2805 const wxDataViewItem& item)
66e09788
RR
2806{
2807 wxWindow *parent = GetParent();
2808 wxDataViewEvent le(type, parent->GetId());
2809
2810 le.SetEventObject(parent);
c2c89730 2811 le.SetModel(GetModel());
66e09788
RR
2812 le.SetItem( item );
2813
fd48fe89 2814 return !parent->ProcessWindowEvent(le) || le.IsAllowed();
66e09788
RR
2815}
2816
739a8399
RR
2817bool wxDataViewMainWindow::IsExpanded( unsigned int row ) const
2818{
ce5abbf9 2819 if (IsList())
bc4f1ff2 2820 return false;
9adeb77a 2821
739a8399
RR
2822 wxDataViewTreeNode * node = GetTreeNodeByRow(row);
2823 if (!node)
bc4f1ff2 2824 return false;
9adeb77a 2825
739a8399 2826 if (!node->HasChildren())
bc4f1ff2 2827 return false;
9adeb77a 2828
739a8399
RR
2829 return node->IsOpen();
2830}
2831
235d5f88
RR
2832bool wxDataViewMainWindow::HasChildren( unsigned int row ) const
2833{
ce5abbf9 2834 if (IsList())
235d5f88
RR
2835 return false;
2836
2837 wxDataViewTreeNode * node = GetTreeNodeByRow(row);
2838 if (!node)
2839 return false;
739a8399 2840
235d5f88 2841 if (!node->HasChildren())
235d5f88 2842 return false;
235d5f88
RR
2843
2844 return true;
2845}
2846
2847void wxDataViewMainWindow::Expand( unsigned int row )
3b6280be 2848{
ce5abbf9 2849 if (IsList())
bc4f1ff2 2850 return;
9657c197 2851
3b6280be 2852 wxDataViewTreeNode * node = GetTreeNodeByRow(row);
235d5f88
RR
2853 if (!node)
2854 return;
4cef3873 2855
235d5f88 2856 if (!node->HasChildren())
235d5f88 2857 return;
4cef3873 2858
235d5f88 2859 if (!node->IsOpen())
3b6280be 2860 {
fd48fe89
VZ
2861 if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, node->GetItem()) )
2862 {
2863 // Vetoed by the event handler.
66e09788 2864 return;
fd48fe89 2865 }
b7fe2261 2866
bc4f1ff2 2867 node->ToggleOpen();
977a41ec 2868
bc4f1ff2 2869 // build the children of current node
ff3c5ad3 2870 if( node->GetChildNodes().empty() )
bc4f1ff2
FM
2871 {
2872 SortPrepare();
c2c89730 2873 ::BuildTreeHelper(GetModel(), node->GetItem(), node);
bc4f1ff2 2874 }
977a41ec 2875
bc4f1ff2
FM
2876 // By expanding the node all row indices that are currently in the selection list
2877 // and are greater than our node have become invalid. So we have to correct that now.
2878 const unsigned rowAdjustment = node->GetSubTreeCount();
2879 for(unsigned i=0; i<m_selection.size(); ++i)
2880 {
2881 const unsigned testRow = m_selection[i];
2882 // all rows above us are not affected, so skip them
2883 if(testRow <= row)
2884 continue;
2885
2886 m_selection[i] += rowAdjustment;
2887 }
977a41ec 2888
bc4f1ff2
FM
2889 if(m_currentRow > row)
2890 ChangeCurrentRow(m_currentRow + rowAdjustment);
977a41ec 2891
bc4f1ff2
FM
2892 m_count = -1;
2893 UpdateDisplay();
2894 // Send the expanded event
2895 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,node->GetItem());
351461fc 2896 }
3b6280be
RR
2897}
2898
235d5f88 2899void wxDataViewMainWindow::Collapse(unsigned int row)
3b6280be 2900{
ce5abbf9 2901 if (IsList())
bc4f1ff2 2902 return;
e822d1bd 2903
7d835958
RR
2904 wxDataViewTreeNode *node = GetTreeNodeByRow(row);
2905 if (!node)
2906 return;
4cef3873 2907
235d5f88 2908 if (!node->HasChildren())
7d835958 2909 return;
d47db7e0 2910
235d5f88 2911 if (node->IsOpen())
3b6280be 2912 {
fd48fe89
VZ
2913 if ( !SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,node->GetItem()) )
2914 {
2915 // Vetoed by the event handler.
66e09788 2916 return;
fd48fe89 2917 }
abdb8c18 2918
977a41ec
FM
2919 // Find out if there are selected items below the current node.
2920 bool selectCollapsingRow = false;
2921 const unsigned rowAdjustment = node->GetSubTreeCount();
2922 unsigned maxRowToBeTested = row + rowAdjustment;
2923 for(unsigned i=0; i<m_selection.size(); ++i)
2924 {
2925 const unsigned testRow = m_selection[i];
2926 if(testRow > row && testRow <= maxRowToBeTested)
2927 {
2928 selectCollapsingRow = true;
2929 // get out as soon as we have found a node that is selected
2930 break;
2931 }
2932 }
2933
2934 node->ToggleOpen();
2935
2936 // If the node to be closed has selected items the user won't see those any longer.
2937 // We select the collapsing node in this case.
2938 if(selectCollapsingRow)
2939 {
2940 SelectAllRows(false);
2941 ChangeCurrentRow(row);
2942 SelectRow(row, true);
2943 SendSelectionChangedEvent(GetItemByRow(row));
2944 }
2945 else
2946 {
2947 // if there were no selected items below our node we still need to "fix" the
2948 // selection list to adjust for the changing of the row indices.
235d5f88 2949 // We actually do the opposite of what we are doing in Expand().
977a41ec
FM
2950 for(unsigned i=0; i<m_selection.size(); ++i)
2951 {
2952 const unsigned testRow = m_selection[i];
2953 // all rows above us are not affected, so skip them
2954 if(testRow <= row)
2955 continue;
2956
2957 m_selection[i] -= rowAdjustment;
2958 }
2959
2960 // if the "current row" is being collapsed away we change it to the current row ;-)
2961 if(m_currentRow > row && m_currentRow <= maxRowToBeTested)
2962 ChangeCurrentRow(row);
2963 else if(m_currentRow > row)
2964 ChangeCurrentRow(m_currentRow - rowAdjustment);
2965 }
abdb8c18 2966
3b6280be 2967 m_count = -1;
351461fc 2968 UpdateDisplay();
7d835958 2969 SendExpanderEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,node->GetItem());
66e09788 2970 }
3b6280be
RR
2971}
2972
351461fc
RR
2973wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item )
2974{
c2c89730 2975 const wxDataViewModel * model = GetModel();
351461fc
RR
2976 if( model == NULL )
2977 return NULL;
9adeb77a 2978
ce2fe798
RR
2979 if (!item.IsOk())
2980 return m_root;
351461fc 2981
10875c13
VZ
2982 // Compose the parent-chain for the item we are looking for
2983 wxVector<wxDataViewItem> parentChain;
351461fc
RR
2984 wxDataViewItem it( item );
2985 while( it.IsOk() )
2986 {
10875c13
VZ
2987 parentChain.push_back(it);
2988 it = model->GetParent(it);
351461fc
RR
2989 }
2990
bc4f1ff2
FM
2991 // Find the item along the parent-chain.
2992 // This algorithm is designed to speed up the node-finding method
10875c13 2993 wxDataViewTreeNode* node = m_root;
99ef4372 2994 for( unsigned iter = parentChain.size()-1; ; --iter )
351461fc
RR
2995 {
2996 if( node->HasChildren() )
2997 {
ff3c5ad3 2998 if( node->GetChildNodes().empty() )
24c4a50f 2999 {
422aa8ec
VS
3000 // Even though the item is a container, it doesn't have any
3001 // child nodes in the control's representation yet. We have
3002 // to realize its subtree now.
24c4a50f 3003 SortPrepare();
74123073 3004 ::BuildTreeHelper(model, node->GetItem(), node);
24c4a50f 3005 }
351461fc 3006
ff3c5ad3 3007 const wxDataViewTreeNodes& nodes = node->GetChildNodes();
d2c1ee8a 3008 bool found = false;
777f9cef 3009
10875c13 3010 for (unsigned i = 0; i < nodes.GetCount(); ++i)
d92cb015 3011 {
10875c13
VZ
3012 wxDataViewTreeNode* currentNode = nodes[i];
3013 if (currentNode->GetItem() == parentChain[iter])
b7fe2261 3014 {
10875c13
VZ
3015 if (currentNode->GetItem() == item)
3016 return currentNode;
777f9cef 3017
10875c13 3018 node = currentNode;
d2c1ee8a 3019 found = true;
d92cb015
RR
3020 break;
3021 }
3022 }
d2c1ee8a 3023 if (!found)
351461fc 3024 return NULL;
351461fc
RR
3025 }
3026 else
3027 return NULL;
99ef4372
VZ
3028
3029 if ( !iter )
3030 break;
351461fc 3031 }
d2c1ee8a 3032 return NULL;
351461fc
RR
3033}
3034
4cef3873 3035void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item,
bc4f1ff2 3036 wxDataViewColumn* &column )
66e09788 3037{
fbda518c 3038 wxDataViewColumn *col = NULL;
66e09788
RR
3039 unsigned int cols = GetOwner()->GetColumnCount();
3040 unsigned int colnum = 0;
66e09788
RR
3041 int x, y;
3042 m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y );
e822d1bd 3043 for (unsigned x_start = 0; colnum < cols; colnum++)
66e09788 3044 {
702f5349 3045 col = GetOwner()->GetColumnAt(colnum);
66e09788
RR
3046 if (col->IsHidden())
3047 continue; // skip it!
3048
3049 unsigned int w = col->GetWidth();
3050 if (x_start+w >= (unsigned int)x)
3051 break;
3052
3053 x_start += w;
3054 }
3055
fbda518c 3056 column = col;
344ed1f3 3057 item = GetItemByRow( GetLineAt( y ) );
66e09788
RR
3058}
3059
4cef3873 3060wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
bc4f1ff2 3061 const wxDataViewColumn* column )
66e09788 3062{
c937344c
RR
3063 int xpos = 0;
3064 int width = 0;
4cef3873 3065
c937344c
RR
3066 unsigned int cols = GetOwner()->GetColumnCount();
3067 // If column is null the loop will compute the combined width of all columns.
3068 // Otherwise, it will compute the x position of the column we are looking for.
3069 for (unsigned int i = 0; i < cols; i++)
3070 {
3071 wxDataViewColumn* col = GetOwner()->GetColumnAt( i );
3072
3073 if (col == column)
3074 break;
3075
3076 if (col->IsHidden())
3077 continue; // skip it!
3078
3079 xpos += col->GetWidth();
3080 width += col->GetWidth();
3081 }
3082
3083 if(column != 0)
3084 {
3085 // If we have a column, we need can get its width directly.
3086 if(column->IsHidden())
3087 width = 0;
3088 else
3089 width = column->GetWidth();
3090
3091 }
3092 else
3093 {
3094 // If we have no column, we reset the x position back to zero.
3095 xpos = 0;
3096 }
3097
3098 // we have to take an expander column into account and compute its indentation
3099 // to get the correct x position where the actual text is
3100 int indent = 0;
66e09788 3101 int row = GetRowByItem(item);
1841f079
VZ
3102 if (!IsList() &&
3103 (column == 0 || GetExpanderColumnOrFirstOne(GetOwner()) == column) )
66e09788 3104 {
c937344c
RR
3105 wxDataViewTreeNode* node = GetTreeNodeByRow(row);
3106 indent = GetOwner()->GetIndent() * node->GetIndentLevel();
03647350 3107 indent = indent + m_lineHeight; // use m_lineHeight as the width of the expander
66e09788 3108 }
c937344c
RR
3109
3110 wxRect itemRect( xpos + indent,
3111 GetLineStart( row ),
3112 width - indent,
3113 GetLineHeight( row ) );
3114
3115 GetOwner()->CalcScrolledPosition( itemRect.x, itemRect.y,
3116 &itemRect.x, &itemRect.y );
3117
3118 return itemRect;
66e09788
RR
3119}
3120
442c56e6 3121int wxDataViewMainWindow::RecalculateCount()
3b6280be 3122{
86ba79ed 3123 if (IsVirtualList())
a3cc79d9 3124 {
9330d5af 3125 wxDataViewVirtualListModel *list_model =
c2c89730 3126 (wxDataViewVirtualListModel*) GetModel();
03647350 3127
9330d5af 3128 return list_model->GetCount();
a3cc79d9
RR
3129 }
3130 else
3131 {
3132 return m_root->GetSubTreeCount();
3133 }
3b6280be
RR
3134}
3135
aba9bfd0
RR
3136class ItemToRowJob : public DoJob
3137{
3138public:
10875c13 3139 ItemToRowJob(const wxDataViewItem& item_, wxVector<wxDataViewItem>::reverse_iterator iter)
59e60167 3140 : m_iter(iter),
977a41ec 3141 item(item_)
59e60167
VZ
3142 {
3143 ret = -1;
3144 }
aba9bfd0 3145
bc4f1ff2 3146 // Maybe binary search will help to speed up this process
d5025dc0
RR
3147 virtual int operator() ( wxDataViewTreeNode * node)
3148 {
977a41ec
FM
3149 ret ++;
3150 if( node->GetItem() == item )
3151 {
d54f0605 3152 return DoJob::DONE;
977a41ec 3153 }
d5025dc0 3154
10875c13 3155 if( node->GetItem() == *m_iter )
977a41ec
FM
3156 {
3157 m_iter++;
d54f0605 3158 return DoJob::CONTINUE;
977a41ec
FM
3159 }
3160 else
3161 {
3162 ret += node->GetSubTreeCount();
d54f0605 3163 return DoJob::SKIP_SUBTREE;
977a41ec 3164 }
442c56e6 3165
d5025dc0 3166 }
aba9bfd0 3167
bc4f1ff2
FM
3168 // the row number is begin from zero
3169 int GetResult() const
3170 { return ret -1; }
59e60167 3171
aba9bfd0 3172private:
10875c13 3173 wxVector<wxDataViewItem>::reverse_iterator m_iter;
aba9bfd0
RR
3174 wxDataViewItem item;
3175 int ret;
442c56e6 3176
aba9bfd0
RR
3177};
3178
344ed1f3 3179int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const
aba9bfd0 3180{
c2c89730 3181 const wxDataViewModel * model = GetModel();
d47db7e0 3182 if( model == NULL )
fbda518c 3183 return -1;
d47db7e0 3184
86ba79ed 3185 if (IsVirtualList())
d47db7e0 3186 {
86ba79ed 3187 return wxPtrToUInt( item.GetID() ) -1;
d47db7e0 3188 }
a3cc79d9
RR
3189 else
3190 {
3191 if( !item.IsOk() )
3192 return -1;
3193
10875c13
VZ
3194 // Compose the parent-chain of the item we are looking for
3195 wxVector<wxDataViewItem> parentChain;
a3cc79d9
RR
3196 wxDataViewItem it( item );
3197 while( it.IsOk() )
3198 {
10875c13
VZ
3199 parentChain.push_back(it);
3200 it = model->GetParent(it);
a3cc79d9 3201 }
d47db7e0 3202
10875c13
VZ
3203 // add an 'invalid' item to represent our 'invisible' root node
3204 parentChain.push_back(wxDataViewItem());
3205
3206 // the parent chain was created by adding the deepest parent first.
3207 // so if we want to start at the root node, we have to iterate backwards through the vector
3208 ItemToRowJob job( item, parentChain.rbegin() );
3209 Walker( m_root, job );
a3cc79d9
RR
3210 return job.GetResult();
3211 }
aba9bfd0
RR
3212}
3213
10875c13 3214static void BuildTreeHelper( const wxDataViewModel * model, const wxDataViewItem & item,
bc4f1ff2 3215 wxDataViewTreeNode * node)
aba9bfd0 3216{
351461fc 3217 if( !model->IsContainer( item ) )
59e60167 3218 return;
442c56e6 3219
c899416d
RR
3220 wxDataViewItemArray children;
3221 unsigned int num = model->GetChildren( item, children);
9adeb77a 3222
422aa8ec 3223 for ( unsigned int index = 0; index < num; index++ )
aba9bfd0 3224 {
422aa8ec
VS
3225 wxDataViewTreeNode *n = new wxDataViewTreeNode(node, children[index]);
3226
3227 if( model->IsContainer(children[index]) )
59e60167 3228 n->SetHasChildren( true );
422aa8ec 3229
35219832 3230 node->InsertChild(n, index);
aba9bfd0 3231 }
d47db7e0 3232
422aa8ec
VS
3233 wxASSERT( node->IsOpen() );
3234 node->ChangeSubTreeCount(+num);
aba9bfd0
RR
3235}
3236
3237void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
3238{
51bdecff
RR
3239 DestroyTree();
3240
c2c89730 3241 if (GetModel()->IsVirtualListModel())
a3cc79d9 3242 {
59e60167 3243 m_count = -1;
a3cc79d9
RR
3244 return;
3245 }
3246
422aa8ec 3247 m_root = wxDataViewTreeNode::CreateRootNode();
51bdecff 3248
bc4f1ff2 3249 // First we define a invalid item to fetch the top-level elements
aba9bfd0 3250 wxDataViewItem item;
66e09788 3251 SortPrepare();
3b6280be 3252 BuildTreeHelper( model, item, m_root);
59e60167 3253 m_count = -1;
aba9bfd0
RR
3254}
3255
aba9bfd0
RR
3256void wxDataViewMainWindow::DestroyTree()
3257{
344ed1f3 3258 if (!IsVirtualList())
51bdecff 3259 {
a2d3c415
VS
3260 wxDELETE(m_root);
3261 m_count = 0;
51bdecff 3262 }
aba9bfd0
RR
3263}
3264
cab07038
RR
3265void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
3266{
63ced01b
VZ
3267 wxWindow * const parent = GetParent();
3268
3269 // propagate the char event upwards
3270 wxKeyEvent eventForParent(event);
3271 eventForParent.SetEventObject(parent);
3272 if ( parent->ProcessWindowEvent(eventForParent) )
3273 return;
3274
3275 if ( parent->HandleAsNavigationKey(event) )
f029f1d1 3276 return;
cab07038
RR
3277
3278 // no item -> nothing to do
3279 if (!HasCurrentRow())
3280 {
3281 event.Skip();
3282 return;
3283 }
120b9b05 3284
cab07038
RR
3285 // don't use m_linesPerPage directly as it might not be computed yet
3286 const int pageSize = GetCountPerPage();
9a83f860 3287 wxCHECK_RET( pageSize, wxT("should have non zero page size") );
cab07038
RR
3288
3289 switch ( event.GetKeyCode() )
3290 {
d37b709c 3291 case WXK_RETURN:
d37b709c 3292 {
c2efa4b4
VS
3293 // Enter activates the item, i.e. sends wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED to
3294 // it. Only if that event is not handled do we activate column renderer (which
3295 // is normally done by Space).
3296
276227fc 3297 const wxDataViewItem item = GetItemByRow(m_currentRow);
d37b709c 3298
c2efa4b4
VS
3299 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
3300 parent->GetId());
3301 le.SetItem(item);
3302 le.SetEventObject(parent);
3303 le.SetModel(GetModel());
3304
857f05e1 3305 if ( parent->ProcessWindowEvent(le) )
c2efa4b4
VS
3306 break;
3307 // else: fall through to WXK_SPACE handling
3308 }
3309
3310 case WXK_SPACE:
3311 {
276227fc
VS
3312 // Activate the first activatable column if there is any:
3313 wxDataViewColumn *activatableCol = NULL;
3314
3315 const unsigned cols = GetOwner()->GetColumnCount();
3316 for ( unsigned i = 0; i < cols; i++ )
3317 {
3318 wxDataViewColumn *c = GetOwner()->GetColumnAt(i);
3319 if ( c->IsHidden() )
3320 continue;
3321 if ( c->GetRenderer()->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE )
3322 {
3323 activatableCol = c;
3324 break;
3325 }
3326 }
3327
3328 if ( activatableCol )
3329 {
c2efa4b4
VS
3330 const wxDataViewItem item = GetItemByRow(m_currentRow);
3331
276227fc
VS
3332 const unsigned colIdx = activatableCol->GetModelColumn();
3333 const wxRect cell_rect = GetOwner()->GetItemRect(item, activatableCol);
3334
3335 wxDataViewRenderer *cell = activatableCol->GetRenderer();
3336 cell->PrepareForItem(GetModel(), item, colIdx);
c2efa4b4 3337 cell->WXOnActivate(cell_rect, GetModel(), item, colIdx);
276227fc 3338 }
d37b709c
RR
3339 }
3340 break;
48ae48a9 3341
cab07038
RR
3342 case WXK_UP:
3343 if ( m_currentRow > 0 )
1dc779fc 3344 OnVerticalNavigation( m_currentRow - 1, event );
cab07038
RR
3345 break;
3346
3347 case WXK_DOWN:
4385e702 3348 if ( m_currentRow + 1 < GetRowCount() )
1dc779fc 3349 OnVerticalNavigation( m_currentRow + 1, event );
cab07038 3350 break;
bc4f1ff2 3351 // Add the process for tree expanding/collapsing
3b6280be 3352 case WXK_LEFT:
cfc21881 3353 OnLeftKey();
235d5f88 3354 break;
cfc21881 3355
235d5f88 3356 case WXK_RIGHT:
cfc21881 3357 OnRightKey();
235d5f88 3358 break;
cfc21881 3359
cab07038 3360 case WXK_END:
235d5f88 3361 {
cab07038 3362 if (!IsEmpty())
1dc779fc 3363 OnVerticalNavigation( GetRowCount() - 1, event );
cab07038 3364 break;
235d5f88 3365 }
cab07038
RR
3366 case WXK_HOME:
3367 if (!IsEmpty())
1dc779fc 3368 OnVerticalNavigation( 0, event );
cab07038
RR
3369 break;
3370
3371 case WXK_PAGEUP:
3372 {
3373 int steps = pageSize - 1;
3374 int index = m_currentRow - steps;
3375 if (index < 0)
3376 index = 0;
3377
1dc779fc 3378 OnVerticalNavigation( index, event );
cab07038
RR
3379 }
3380 break;
3381
3382 case WXK_PAGEDOWN:
3383 {
3384 int steps = pageSize - 1;
0a71f9e9
RR
3385 unsigned int index = m_currentRow + steps;
3386 unsigned int count = GetRowCount();
cab07038
RR
3387 if ( index >= count )
3388 index = count - 1;
3389
1dc779fc 3390 OnVerticalNavigation( index, event );
cab07038
RR
3391 }
3392 break;
3393
0a807957
RR
3394 case WXK_F2:
3395 {
a027a36f 3396 if( !m_selection.empty() )
0a807957
RR
3397 {
3398 // TODO: we need to revise that when we have a concept for a 'current column'
3399 GetOwner()->StartEditor(GetItemByRow(m_selection[0]), 0);
3400 }
3401 }
3402 break;
3403
cab07038
RR
3404 default:
3405 event.Skip();
3406 }
3407}
3408
1dc779fc
VS
3409void wxDataViewMainWindow::OnVerticalNavigation(unsigned int newCurrent, const wxKeyEvent& event)
3410{
3411 wxCHECK_RET( newCurrent < GetRowCount(),
3412 wxT("invalid item index in OnVerticalNavigation()") );
3413
3414 // if there is no selection, we cannot move it anywhere
3415 if (!HasCurrentRow())
3416 return;
3417
3418 unsigned int oldCurrent = m_currentRow;
3419
3420 // in single selection we just ignore Shift as we can't select several
3421 // items anyhow
3422 if ( event.ShiftDown() && !IsSingleSel() )
3423 {
3424 RefreshRow( oldCurrent );
3425
3426 ChangeCurrentRow( newCurrent );
3427
3428 // select all the items between the old and the new one
3429 if ( oldCurrent > newCurrent )
3430 {
3431 newCurrent = oldCurrent;
3432 oldCurrent = m_currentRow;
3433 }
3434
3435 SelectRows( oldCurrent, newCurrent, true );
3436 if (oldCurrent!=newCurrent)
3437 SendSelectionChangedEvent(GetItemByRow(m_selection[0]));
3438 }
3439 else // !shift
3440 {
3441 RefreshRow( oldCurrent );
3442
3443 // all previously selected items are unselected unless ctrl is held
3444 if ( !event.ControlDown() )
3445 SelectAllRows(false);
3446
3447 ChangeCurrentRow( newCurrent );
3448
3449 if ( !event.ControlDown() )
3450 {
3451 SelectRow( m_currentRow, true );
3452 SendSelectionChangedEvent(GetItemByRow(m_currentRow));
3453 }
3454 else
3455 RefreshRow( m_currentRow );
3456 }
3457
3458 GetOwner()->EnsureVisible( m_currentRow, -1 );
3459}
3460
cfc21881
VS
3461void wxDataViewMainWindow::OnLeftKey()
3462{
3463 if (IsList())
3464 return;
3465
3466 wxDataViewTreeNode* node = GetTreeNodeByRow(m_currentRow);
3467 if (!node)
3468 return;
3469
3470 if (node->HasChildren() && node->IsOpen())
3471 {
3472 Collapse(m_currentRow);
3473 }
3474 else // if the node is already closed we move the selection to its parent
3475 {
3476 wxDataViewTreeNode *parent_node = node->GetParent();
3477
3478 if (parent_node)
3479 {
3480 int parent = GetRowByItem( parent_node->GetItem() );
3481 if ( parent >= 0 )
3482 {
3483 unsigned int row = m_currentRow;
3484 SelectRow( row, false);
3485 SelectRow( parent, true );
3486 ChangeCurrentRow( parent );
3487 GetOwner()->EnsureVisible( parent, -1 );
3488 SendSelectionChangedEvent( parent_node->GetItem() );
3489 }
3490 }
3491 }
3492}
3493
3494void wxDataViewMainWindow::OnRightKey()
3495{
3496 if (!IsExpanded( m_currentRow ))
3497 Expand( m_currentRow );
3498 else
3499 {
3500 unsigned int row = m_currentRow;
3501 SelectRow( row, false );
3502 SelectRow( row + 1, true );
3503 ChangeCurrentRow( row + 1 );
3504 GetOwner()->EnsureVisible( row + 1, -1 );
3505 SendSelectionChangedEvent( GetItemByRow(row+1) );
3506 }
3507}
3508
4ed7af08
RR
3509void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
3510{
e21f75bd
RR
3511 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
3512 {
3513 // let the base handle mouse wheel events.
3514 event.Skip();
3515 return;
3516 }
3517
3d9bff2f
RR
3518 // set the focus to ourself if any of the mouse buttons are pressed
3519 if(event.ButtonDown() && !HasFocus())
3520 SetFocus();
3521
0fdc2321
RR
3522 int x = event.GetX();
3523 int y = event.GetY();
3524 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
0fdc2321 3525 wxDataViewColumn *col = NULL;
b7fe2261 3526
0fdc2321 3527 int xpos = 0;
9861f022 3528 unsigned int cols = GetOwner()->GetColumnCount();
0a71f9e9 3529 unsigned int i;
0fdc2321
RR
3530 for (i = 0; i < cols; i++)
3531 {
702f5349 3532 wxDataViewColumn *c = GetOwner()->GetColumnAt( i );
9861f022
RR
3533 if (c->IsHidden())
3534 continue; // skip it!
3535
0fdc2321
RR
3536 if (x < xpos + c->GetWidth())
3537 {
3538 col = c;
3539 break;
3540 }
3541 xpos += c->GetWidth();
3542 }
f554a14b 3543 if (!col)
737883f2
VZ
3544 {
3545 event.Skip();
0fdc2321 3546 return;
737883f2 3547 }
f554a14b 3548
24c4a50f 3549 wxDataViewRenderer *cell = col->GetRenderer();
344ed1f3 3550 unsigned int current = GetLineAt( y );
5179bc0b 3551 if ((current >= GetRowCount()) || (x > GetEndOfLastCol()))
e21f75bd
RR
3552 {
3553 // Unselect all if below the last row ?
737883f2 3554 event.Skip();
e21f75bd
RR
3555 return;
3556 }
f554a14b 3557
1841f079
VZ
3558 wxDataViewColumn* const
3559 expander = GetExpanderColumnOrFirstOne(GetOwner());
3560
902334c8
VZ
3561 // Test whether the mouse is hovering over the expander (a.k.a tree "+"
3562 // button) and also determine the offset of the real cell start, skipping
3563 // the indentation and the expander itself.
abdb8c18 3564 bool hoverOverExpander = false;
c46ecbe3 3565 int itemOffset = 0;
1841f079 3566 if ((!IsList()) && (expander == col))
24c4a50f
RR
3567 {
3568 wxDataViewTreeNode * node = GetTreeNodeByRow(current);
abdb8c18 3569
c46ecbe3
VZ
3570 int indent = node->GetIndentLevel();
3571 itemOffset = GetOwner()->GetIndent()*indent;
3572
3573 if ( node->HasChildren() )
3574 {
977a41ec
FM
3575 // we make the rectangle we are looking in a bit bigger than the actual
3576 // visual expander so the user can hit that little thing reliably
c46ecbe3 3577 wxRect rect(itemOffset,
977a41ec
FM
3578 GetLineStart( current ) + (GetLineHeight(current) - m_lineHeight)/2,
3579 m_lineHeight, m_lineHeight);
902334c8 3580
abdb8c18 3581 if( rect.Contains(x, y) )
24c4a50f 3582 {
bc4f1ff2 3583 // So the mouse is over the expander
abdb8c18 3584 hoverOverExpander = true;
24c4a50f
RR
3585 if (m_underMouse && m_underMouse != node)
3586 {
bc4f1ff2 3587 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
df2c23e7 3588 RefreshRow(GetRowByItem(m_underMouse->GetItem()));
24c4a50f
RR
3589 }
3590 if (m_underMouse != node)
3591 {
bc4f1ff2 3592 // wxLogMessage("Do the row: %d", current);
df2c23e7 3593 RefreshRow(current);
24c4a50f
RR
3594 }
3595 m_underMouse = node;
3596 }
3597 }
c46ecbe3
VZ
3598
3599 // Account for the expander as well, even if this item doesn't have it,
3600 // its parent does so it still counts for the offset.
3601 itemOffset += m_lineHeight;
24c4a50f 3602 }
abdb8c18 3603 if (!hoverOverExpander)
24c4a50f
RR
3604 {
3605 if (m_underMouse != NULL)
3606 {
bc4f1ff2 3607 // wxLogMessage("Undo the row: %d", GetRowByItem(m_underMouse->GetItem()));
df2c23e7 3608 RefreshRow(GetRowByItem(m_underMouse->GetItem()));
24c4a50f
RR
3609 m_underMouse = NULL;
3610 }
3611 }
3612
c2c89730 3613 wxDataViewModel *model = GetModel();
0fdc2321 3614
9adeb77a 3615#if wxUSE_DRAG_AND_DROP
e21f75bd
RR
3616 if (event.Dragging())
3617 {
3618 if (m_dragCount == 0)
3619 {
3620 // we have to report the raw, physical coords as we want to be
3621 // able to call HitTest(event.m_pointDrag) from the user code to
3622 // get the item being dragged
3623 m_dragStart = event.GetPosition();
3624 }
3625
3626 m_dragCount++;
3627
3628 if (m_dragCount != 3)
3629 return;
3630
3631 if (event.LeftIsDown())
3632 {
4cef3873 3633 m_owner->CalcUnscrolledPosition( m_dragStart.x, m_dragStart.y,
bc4f1ff2 3634 &m_dragStart.x, &m_dragStart.y );
821baf7d
RR
3635 unsigned int drag_item_row = GetLineAt( m_dragStart.y );
3636 wxDataViewItem item = GetItemByRow( drag_item_row );
3637
e21f75bd 3638 // Notify cell about drag
821baf7d
RR
3639 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
3640 event.SetEventObject( m_owner );
3641 event.SetItem( item );
3642 event.SetModel( model );
3643 if (!m_owner->HandleWindowEvent( event ))
3644 return;
9adeb77a 3645
821baf7d
RR
3646 if (!event.IsAllowed())
3647 return;
9adeb77a 3648
821baf7d
RR
3649 wxDataObject *obj = event.GetDataObject();
3650 if (!obj)
3651 return;
9adeb77a 3652
818d91a9 3653 wxDataViewDropSource drag( this, drag_item_row );
592883ed 3654 drag.SetData( *obj );
818d91a9 3655 /* wxDragResult res = */ drag.DoDragDrop();
592883ed 3656 delete obj;
e21f75bd
RR
3657 }
3658 return;
3659 }
3660 else
3661 {
3662 m_dragCount = 0;
3663 }
9adeb77a 3664#endif // wxUSE_DRAG_AND_DROP
e21f75bd 3665
abdb8c18 3666 bool simulateClick = false;
e21f75bd 3667
0fcce6b9
RR
3668 if (event.ButtonDClick())
3669 {
3670 m_renameTimer->Stop();
3671 m_lastOnSame = false;
3672 }
3673
438fb233
RR
3674 wxDataViewItem item = GetItemByRow(current);
3675 bool ignore_other_columns =
1841f079 3676 ((expander != col) &&
977a41ec
FM
3677 (model->IsContainer(item)) &&
3678 (!model->HasContainerColumns(item)));
b5ec7dd6 3679
0fdc2321
RR
3680 if (event.LeftDClick())
3681 {
977a41ec
FM
3682 if(hoverOverExpander)
3683 {
3684 // a double click on the expander will be converted into a "simulated" normal click
3685 simulateClick = true;
3686 }
3687 else if ( current == m_lineLastClicked )
0fdc2321 3688 {
77b555c2
VS
3689 bool activated = false;
3690
438fb233 3691 if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
e21f75bd 3692 {
62186006
VZ
3693 const unsigned colIdx = col->GetModelColumn();
3694
dbc3aec1 3695 cell->PrepareForItem(model, item, colIdx);
62186006 3696
dbc3aec1
VS
3697 wxRect cell_rect( xpos, GetLineStart( current ),
3698 col->GetWidth(), GetLineHeight( current ) );
77b555c2 3699 activated = cell->WXOnActivate( cell_rect, model, item, colIdx );
2c3f6edd 3700 }
77b555c2
VS
3701
3702 if ( !activated )
2c3f6edd 3703 {
b7e9f8b1
RR
3704 wxWindow *parent = GetParent();
3705 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, parent->GetId());
45c156e0 3706 le.SetItem( item );
ca81b52e
VZ
3707 le.SetColumn( col->GetModelColumn() );
3708 le.SetDataViewColumn( col );
b7e9f8b1 3709 le.SetEventObject(parent);
c2c89730 3710 le.SetModel(GetModel());
b7e9f8b1 3711
857f05e1 3712 parent->ProcessWindowEvent(le);
e21f75bd
RR
3713 }
3714 return;
3715 }
3716 else
3717 {
3718 // The first click was on another item, so don't interpret this as
3719 // a double click, but as a simple click instead
abdb8c18 3720 simulateClick = true;
0fdc2321 3721 }
120b9b05 3722 }
f554a14b 3723
abdb8c18 3724 if (event.LeftUp() && !hoverOverExpander)
0fcce6b9 3725 {
0a71f9e9 3726 if (m_lineSelectSingleOnUp != (unsigned int)-1)
e21f75bd
RR
3727 {
3728 // select single line
3729 SelectAllRows( false );
3730 SelectRow( m_lineSelectSingleOnUp, true );
4a745e76 3731 SendSelectionChangedEvent( GetItemByRow(m_lineSelectSingleOnUp) );
e21f75bd 3732 }
120b9b05 3733
4cef3873 3734 // If the user click the expander, we do not do editing even if the column
bc4f1ff2 3735 // with expander are editable
abdb8c18 3736 if (m_lastOnSame && !ignore_other_columns)
0fcce6b9 3737 {
a8461d31 3738 if ((col == m_currentCol) && (current == m_currentRow) &&
0bdfa388 3739 (cell->GetMode() & wxDATAVIEW_CELL_EDITABLE) )
0fcce6b9
RR
3740 {
3741 m_renameTimer->Start( 100, true );
3742 }
3743 }
3744
3745 m_lastOnSame = false;
0a71f9e9 3746 m_lineSelectSingleOnUp = (unsigned int)-1;
120b9b05 3747 }
abdb8c18 3748 else if(!event.LeftUp())
e21f75bd
RR
3749 {
3750 // This is necessary, because after a DnD operation in
3751 // from and to ourself, the up event is swallowed by the
3752 // DnD code. So on next non-up event (which means here and
3753 // now) m_lineSelectSingleOnUp should be reset.
0a71f9e9 3754 m_lineSelectSingleOnUp = (unsigned int)-1;
e21f75bd
RR
3755 }
3756
3757 if (event.RightDown())
3758 {
3759 m_lineBeforeLastClicked = m_lineLastClicked;
3760 m_lineLastClicked = current;
3761
3762 // If the item is already selected, do not update the selection.
3763 // Multi-selections should not be cleared if a selected item is clicked.
3764 if (!IsRowSelected(current))
3765 {
3766 SelectAllRows(false);
a09da78b 3767 const unsigned oldCurrent = m_currentRow;
e21f75bd
RR
3768 ChangeCurrentRow(current);
3769 SelectRow(m_currentRow,true);
a09da78b 3770 RefreshRow(oldCurrent);
526e19e2 3771 SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
e21f75bd 3772 }
0a807957
RR
3773 }
3774 else if (event.RightUp())
3775 {
f210b1b5
RR
3776 wxVariant value;
3777 model->GetValue( value, item, col->GetModelColumn() );
0bdfa388
RR
3778 wxWindow *parent = GetParent();
3779 wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
3780 le.SetItem( item );
ca81b52e
VZ
3781 le.SetColumn( col->GetModelColumn() );
3782 le.SetDataViewColumn( col );
0bdfa388 3783 le.SetEventObject(parent);
c2c89730 3784 le.SetModel(GetModel());
0bdfa388 3785 le.SetValue(value);
857f05e1 3786 parent->ProcessWindowEvent(le);
e21f75bd
RR
3787 }
3788 else if (event.MiddleDown())
3789 {
e21f75bd 3790 }
abdb8c18 3791
977a41ec
FM
3792 if((event.LeftDown() || simulateClick) && hoverOverExpander)
3793 {
3794 wxDataViewTreeNode* node = GetTreeNodeByRow(current);
bc4f1ff2 3795
4cef3873 3796 // hoverOverExpander being true tells us that our node must be
bc4f1ff2 3797 // valid and have children.
977a41ec
FM
3798 // So we don't need any extra checks.
3799 if( node->IsOpen() )
235d5f88 3800 Collapse(current);
977a41ec 3801 else
235d5f88 3802 Expand(current);
977a41ec
FM
3803 }
3804 else if ((event.LeftDown() || simulateClick) && !hoverOverExpander)
0fcce6b9 3805 {
e21f75bd
RR
3806 m_lineBeforeLastClicked = m_lineLastClicked;
3807 m_lineLastClicked = current;
3808
0a71f9e9 3809 unsigned int oldCurrentRow = m_currentRow;
e21f75bd
RR
3810 bool oldWasSelected = IsRowSelected(m_currentRow);
3811
3812 bool cmdModifierDown = event.CmdDown();
3813 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
3814 {
3815 if ( IsSingleSel() || !IsRowSelected(current) )
3816 {
3817 SelectAllRows( false );
e21f75bd 3818 ChangeCurrentRow(current);
e21f75bd 3819 SelectRow(m_currentRow,true);
526e19e2 3820 SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
e21f75bd
RR
3821 }
3822 else // multi sel & current is highlighted & no mod keys
3823 {
3824 m_lineSelectSingleOnUp = current;
3825 ChangeCurrentRow(current); // change focus
3826 }
3827 }
3828 else // multi sel & either ctrl or shift is down
3829 {
3830 if (cmdModifierDown)
3831 {
3832 ChangeCurrentRow(current);
e21f75bd 3833 ReverseRowSelection(m_currentRow);
9439bc69 3834 SendSelectionChangedEvent(GetItemByRow(m_currentRow));
e21f75bd
RR
3835 }
3836 else if (event.ShiftDown())
3837 {
3838 ChangeCurrentRow(current);
3839
0a71f9e9 3840 unsigned int lineFrom = oldCurrentRow,
977a41ec 3841 lineTo = current;
e21f75bd
RR
3842
3843 if ( lineTo < lineFrom )
3844 {
3845 lineTo = lineFrom;
3846 lineFrom = m_currentRow;
3847 }
3848
3849 SelectRows(lineFrom, lineTo, true);
526e19e2 3850 SendSelectionChangedEvent(GetItemByRow(m_selection[0]) );
e21f75bd
RR
3851 }
3852 else // !ctrl, !shift
3853 {
3854 // test in the enclosing if should make it impossible
9a83f860 3855 wxFAIL_MSG( wxT("how did we get here?") );
e21f75bd
RR
3856 }
3857 }
777f9cef 3858
72664514
RR
3859 if (m_currentRow != oldCurrentRow)
3860 RefreshRow( oldCurrentRow );
e21f75bd 3861
0fcce6b9 3862 wxDataViewColumn *oldCurrentCol = m_currentCol;
120b9b05 3863
0fcce6b9
RR
3864 // Update selection here...
3865 m_currentCol = col;
120b9b05 3866
abdb8c18 3867 m_lastOnSame = !simulateClick && ((col == oldCurrentCol) &&
87f0efe2 3868 (current == oldCurrentRow)) && oldWasSelected;
0bdfa388
RR
3869
3870 // Call LeftClick after everything else as under GTK+
3871 if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
3872 {
dbc3aec1
VS
3873 // notify cell about click
3874 cell->PrepareForItem(model, item, col->GetModelColumn());
86755098 3875
c46ecbe3 3876 wxRect cell_rect( xpos + itemOffset,
902334c8 3877 GetLineStart( current ),
c46ecbe3 3878 col->GetWidth() - itemOffset,
902334c8 3879 GetLineHeight( current ) );
a3a8d81d 3880
dbc3aec1
VS
3881 // Report position relative to the cell's custom area, i.e.
3882 // no the entire space as given by the control but the one
3883 // used by the renderer after calculation of alignment etc.
a3a8d81d 3884
dbc3aec1
VS
3885 // adjust the rectangle ourselves to account for the alignment
3886 wxRect rectItem = cell_rect;
3887 const int align = cell->GetAlignment();
3888 if ( align != wxDVR_DEFAULT_ALIGNMENT )
3889 {
3890 const wxSize size = cell->GetSize();
a3a8d81d 3891
dbc3aec1
VS
3892 if ( size.x >= 0 && size.x < cell_rect.width )
3893 {
3894 if ( align & wxALIGN_CENTER_HORIZONTAL )
3895 rectItem.x += (cell_rect.width - size.x)/2;
3896 else if ( align & wxALIGN_RIGHT )
3897 rectItem.x += cell_rect.width - size.x;
3898 // else: wxALIGN_LEFT is the default
3899 }
a3a8d81d 3900
dbc3aec1
VS
3901 if ( size.y >= 0 && size.y < cell_rect.height )
3902 {
3903 if ( align & wxALIGN_CENTER_VERTICAL )
3904 rectItem.y += (cell_rect.height - size.y)/2;
3905 else if ( align & wxALIGN_BOTTOM )
3906 rectItem.y += cell_rect.height - size.y;
3907 // else: wxALIGN_TOP is the default
a3a8d81d 3908 }
dbc3aec1 3909 }
a3a8d81d 3910
dbc3aec1
VS
3911 wxPoint pos( event.GetPosition() );
3912 pos.x -= rectItem.x;
3913 pos.y -= rectItem.y;
a3a8d81d 3914
dbc3aec1 3915 m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
a3a8d81d 3916
dbc3aec1
VS
3917 /* ignore ret */ cell->WXOnLeftClick( pos, cell_rect,
3918 model, item, col->GetModelColumn());
0bdfa388 3919 }
0fdc2321 3920 }
4ed7af08
RR
3921}
3922
3923void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
3924{
cab07038 3925 m_hasFocus = true;
120b9b05 3926
cab07038
RR
3927 if (HasCurrentRow())
3928 Refresh();
120b9b05 3929
cab07038
RR
3930 event.Skip();
3931}
3932
3933void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event )
3934{
3935 m_hasFocus = false;
120b9b05 3936
cab07038
RR
3937 if (HasCurrentRow())
3938 Refresh();
120b9b05 3939
4ed7af08
RR
3940 event.Skip();
3941}
3942
3943//-----------------------------------------------------------------------------
3944// wxDataViewCtrl
3945//-----------------------------------------------------------------------------
bc4f1ff2 3946
a76c2f37 3947WX_DEFINE_LIST(wxDataViewColumnList)
4ed7af08
RR
3948
3949IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
4b3feaa7
RR
3950BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
3951 EVT_SIZE(wxDataViewCtrl::OnSize)
3952END_EVENT_TABLE()
3953
4ed7af08
RR
3954wxDataViewCtrl::~wxDataViewCtrl()
3955{
3956 if (m_notifier)
3957 GetModel()->RemoveNotifier( m_notifier );
74123073 3958
b3a3c9d8 3959 m_cols.Clear();
d0154e3a 3960 m_colsBestWidths.clear();
4ed7af08
RR
3961}
3962
3963void wxDataViewCtrl::Init()
3964{
b3a3c9d8 3965 m_cols.DeleteContents(true);
4ed7af08 3966 m_notifier = NULL;
e822d1bd 3967
236a34ef 3968 // No sorting column at start
46234a03
VZ
3969 m_sortingColumnIdx = wxNOT_FOUND;
3970
236a34ef 3971 m_headerArea = NULL;
bed74e48
VS
3972
3973 m_colsDirty = false;
4ed7af08
RR
3974}
3975
62e9285a
VZ
3976bool wxDataViewCtrl::Create(wxWindow *parent,
3977 wxWindowID id,
3978 const wxPoint& pos,
3979 const wxSize& size,
3980 long style,
3981 const wxValidator& validator,
3982 const wxString& name)
4ed7af08 3983{
3fdf86f9
RR
3984// if ( (style & wxBORDER_MASK) == 0)
3985// style |= wxBORDER_SUNKEN;
777f9cef 3986
236a34ef
RR
3987 Init();
3988
c741d33f 3989 if (!wxControl::Create( parent, id, pos, size,
62e9285a 3990 style | wxScrolledWindowStyle, validator, name))
4b3feaa7
RR
3991 return false;
3992
b89cac3f 3993 SetInitialSize(size);
b5ec7dd6 3994
4ed7af08 3995#ifdef __WXMAC__
59e60167 3996 MacSetClipChildren( true );
4ed7af08
RR
3997#endif
3998
f554a14b 3999 m_clientArea = new wxDataViewMainWindow( this, wxID_ANY );
9861f022 4000
63ced01b
VZ
4001 // We use the cursor keys for moving the selection, not scrolling, so call
4002 // this method to ensure wxScrollHelperEvtHandler doesn't catch all
4003 // keyboard events forwarded to us from wxListMainWindow.
4004 DisableKeyboardScrolling();
4005
9861f022
RR
4006 if (HasFlag(wxDV_NO_HEADER))
4007 m_headerArea = NULL;
4008 else
56873923 4009 m_headerArea = new wxDataViewHeaderWindow(this);
f554a14b 4010
4ed7af08 4011 SetTargetWindow( m_clientArea );
f554a14b 4012
4ed7af08 4013 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
9861f022
RR
4014 if (m_headerArea)
4015 sizer->Add( m_headerArea, 0, wxGROW );
4ed7af08
RR
4016 sizer->Add( m_clientArea, 1, wxGROW );
4017 SetSizer( sizer );
b5ec7dd6 4018
4ed7af08
RR
4019 return true;
4020}
4021
3fdf86f9
RR
4022wxBorder wxDataViewCtrl::GetDefaultBorder() const
4023{
4024 return wxBORDER_THEME;
4025}
4026
4ed7af08
RR
4027#ifdef __WXMSW__
4028WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
bc4f1ff2
FM
4029 WXWPARAM wParam,
4030 WXLPARAM lParam)
4ed7af08 4031{
b910a8ad 4032 WXLRESULT rc = wxDataViewCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
4ed7af08
RR
4033
4034#ifndef __WXWINCE__
4035 // we need to process arrows ourselves for scrolling
4036 if ( nMsg == WM_GETDLGCODE )
4037 {
4038 rc |= DLGC_WANTARROWS;
4039 }
4040#endif
4041
4042 return rc;
4043}
4044#endif
4045
2571a33f
RR
4046wxSize wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize& size)
4047{
4048 wxSize newsize = size;
d7cda9b2 4049 if (!HasFlag(wxDV_NO_HEADER) && (m_headerArea))
977a41ec 4050 newsize.y -= m_headerArea->GetSize().y;
e822d1bd 4051
2571a33f
RR
4052 return newsize;
4053}
4054
f554a14b 4055void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
4ed7af08 4056{
4b3feaa7
RR
4057 // We need to override OnSize so that our scrolled
4058 // window a) does call Layout() to use sizers for
4059 // positioning the controls but b) does not query
4060 // the sizer for their size and use that for setting
4061 // the scrollable area as set that ourselves by
4062 // calling SetScrollbar() further down.
4063
4064 Layout();
4065
4066 AdjustScrollbars();
cd9b34ef
VZ
4067
4068 // We must redraw the headers if their height changed. Normally this
4069 // shouldn't happen as the control shouldn't let itself be resized beneath
4070 // its minimal height but avoid the display artefacts that appear if it
4071 // does happen, e.g. because there is really not enough vertical space.
4072 if ( !HasFlag(wxDV_NO_HEADER) && m_headerArea &&
4073 m_headerArea->GetSize().y <= m_headerArea->GetBestSize(). y )
4074 {
4075 m_headerArea->Refresh();
4076 }
4ed7af08
RR
4077}
4078
788432e3
RR
4079void wxDataViewCtrl::SetFocus()
4080{
4081 if (m_clientArea)
4082 m_clientArea->SetFocus();
4083}
4084
aba9bfd0 4085bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
4ed7af08
RR
4086{
4087 if (!wxDataViewCtrlBase::AssociateModel( model ))
4088 return false;
4089
aba9bfd0 4090 m_notifier = new wxGenericDataViewModelNotifier( m_clientArea );
4ed7af08 4091
f554a14b 4092 model->AddNotifier( m_notifier );
4ed7af08 4093
51bdecff 4094 m_clientArea->DestroyTree();
cfa42cb8 4095
aba9bfd0
RR
4096 m_clientArea->BuildTree(model);
4097
4b3feaa7 4098 m_clientArea->UpdateDisplay();
f554a14b 4099
4ed7af08
RR
4100 return true;
4101}
4102
9adeb77a
VZ
4103#if wxUSE_DRAG_AND_DROP
4104
821baf7d
RR
4105bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format )
4106{
4107 return m_clientArea->EnableDragSource( format );
4108}
4109
4110bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format )
4111{
4112 return m_clientArea->EnableDropTarget( format );
4113}
4114
9adeb77a
VZ
4115#endif // wxUSE_DRAG_AND_DROP
4116
4ed7af08
RR
4117bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
4118{
4119 if (!wxDataViewCtrlBase::AppendColumn(col))
4120 return false;
f554a14b 4121
afebb87b 4122 m_cols.Append( col );
d0154e3a 4123 m_colsBestWidths.push_back(0);
aef252d9 4124 OnColumnsCountChanged();
736fe67c
RR
4125 return true;
4126}
4127
4128bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
4129{
4130 if (!wxDataViewCtrlBase::PrependColumn(col))
4131 return false;
4132
4133 m_cols.Insert( col );
d0154e3a 4134 m_colsBestWidths.insert(m_colsBestWidths.begin(), 0);
aef252d9 4135 OnColumnsCountChanged();
4ed7af08
RR
4136 return true;
4137}
4138
19723525
RR
4139bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
4140{
4141 if (!wxDataViewCtrlBase::InsertColumn(pos,col))
4142 return false;
4143
4144 m_cols.Insert( pos, col );
d0154e3a 4145 m_colsBestWidths.insert(m_colsBestWidths.begin() + pos, 0);
aef252d9 4146 OnColumnsCountChanged();
19723525
RR
4147 return true;
4148}
4149
aef252d9
VZ
4150void wxDataViewCtrl::OnColumnChange(unsigned int idx)
4151{
4152 if ( m_headerArea )
4153 m_headerArea->UpdateColumn(idx);
4154
4155 m_clientArea->UpdateDisplay();
4156}
4157
4158void wxDataViewCtrl::OnColumnsCountChanged()
9861f022
RR
4159{
4160 if (m_headerArea)
e2bfe673 4161 m_headerArea->SetColumnCount(GetColumnCount());
9861f022
RR
4162
4163 m_clientArea->UpdateDisplay();
4164}
3b6280be
RR
4165
4166void wxDataViewCtrl::DoSetExpanderColumn()
4167{
4168 m_clientArea->UpdateDisplay();
4169}
4170
4171void wxDataViewCtrl::DoSetIndent()
4172{
4173 m_clientArea->UpdateDisplay();
4174}
4175
afebb87b
RR
4176unsigned int wxDataViewCtrl::GetColumnCount() const
4177{
4178 return m_cols.GetCount();
4179}
4180
bbfd4548
VZ
4181bool wxDataViewCtrl::SetRowHeight( int lineHeight )
4182{
4183 if ( !m_clientArea )
4184 return false;
4185
4186 m_clientArea->SetRowHeight(lineHeight);
4187
4188 return true;
4189}
4190
aef252d9 4191wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int idx ) const
afebb87b 4192{
aef252d9 4193 return m_cols[idx];
afebb87b
RR
4194}
4195
702f5349 4196wxDataViewColumn *wxDataViewCtrl::GetColumnAt(unsigned int pos) const
fc8c1a15 4197{
702f5349
VZ
4198 // columns can't be reordered if there is no header window which allows
4199 // to do this
4200 const unsigned idx = m_headerArea ? m_headerArea->GetColumnsOrder()[pos]
977a41ec 4201 : pos;
59e60167 4202
702f5349
VZ
4203 return GetColumn(idx);
4204}
cfa42cb8 4205
702f5349
VZ
4206int wxDataViewCtrl::GetColumnIndex(const wxDataViewColumn *column) const
4207{
4208 const unsigned count = m_cols.size();
4209 for ( unsigned n = 0; n < count; n++ )
4210 {
4211 if ( m_cols[n] == column )
4212 return n;
4213 }
4214
4215 return wxNOT_FOUND;
4216}
4217
d0154e3a
VS
4218unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
4219{
4220 if ( m_colsBestWidths[idx] != 0 )
4221 return m_colsBestWidths[idx];
4222
0645bd38 4223 const int count = m_clientArea->GetRowCount();
d0154e3a
VS
4224 wxDataViewColumn *column = GetColumn(idx);
4225 wxDataViewRenderer *renderer =
4226 const_cast<wxDataViewRenderer*>(column->GetRenderer());
4227
0645bd38
VS
4228 class MaxWidthCalculator
4229 {
4230 public:
4231 MaxWidthCalculator(wxDataViewMainWindow *clientArea,
4232 wxDataViewRenderer *renderer,
4233 const wxDataViewModel *model,
4234 unsigned column)
4235 : m_width(0),
4236 m_clientArea(clientArea),
4237 m_renderer(renderer),
4238 m_model(model),
4239 m_column(column)
4240 {
4241 }
4242
4243 void UpdateWithWidth(int width)
4244 {
4245 m_width = wxMax(m_width, width);
4246 }
4247
4248 void UpdateWithRow(int row)
4249 {
4250 wxDataViewItem item = m_clientArea->GetItemByRow(row);
4251 m_renderer->PrepareForItem(m_model, item, m_column);
4252 m_width = wxMax(m_width, m_renderer->GetSize().x);
4253 }
4254
4255 int GetMaxWidth() const { return m_width; }
4256
4257 private:
4258 int m_width;
4259 wxDataViewMainWindow *m_clientArea;
4260 wxDataViewRenderer *m_renderer;
4261 const wxDataViewModel *m_model;
4262 unsigned m_column;
4263 };
4264
4265 MaxWidthCalculator calculator(m_clientArea, renderer,
4266 GetModel(), column->GetModelColumn());
d0154e3a
VS
4267
4268 if ( m_headerArea )
4269 {
0645bd38 4270 int header_width = m_headerArea->GetTextExtent(column->GetTitle()).x;
d0154e3a 4271 // Labels on native MSW header are indented on both sides
0645bd38
VS
4272 header_width +=
4273 wxRendererNative::Get().GetHeaderButtonMargin(m_headerArea);
4274 calculator.UpdateWithWidth(header_width);
4275 }
4276
4277 // The code below deserves some explanation. For very large controls, we
4278 // simply can't afford to calculate sizes for all items, it takes too
4279 // long. So the best we can do is to check the first and the last N/2
4280 // items in the control for some sufficiently large N and calculate best
4281 // sizes from that. That can result in the calculated best width being too
4282 // small for some outliers, but it's better to get slightly imperfect
4283 // result than to wait several seconds after every update. To avoid highly
4284 // visible miscalculations, we also include all currently visible items
4285 // no matter what. Finally, the value of N is determined dynamically by
4286 // measuring how much time we spent on the determining item widths so far.
4287
4288#if wxUSE_STOPWATCH
4289 int top_part_end = count;
4290 static const long CALC_TIMEOUT = 20/*ms*/;
4291 // don't call wxStopWatch::Time() too often
4292 static const unsigned CALC_CHECK_FREQ = 100;
4293 wxStopWatch timer;
4294#else
4295 // use some hard-coded limit, that's the best we can do without timer
4296 int top_part_end = wxMin(500, count);
4297#endif // wxUSE_STOPWATCH/!wxUSE_STOPWATCH
4298
4299 int row = 0;
4300
4301 for ( row = 0; row < top_part_end; row++ )
4302 {
4303#if wxUSE_STOPWATCH
4304 if ( row % CALC_CHECK_FREQ == CALC_CHECK_FREQ-1 &&
4305 timer.Time() > CALC_TIMEOUT )
4306 break;
4307#endif // wxUSE_STOPWATCH
4308 calculator.UpdateWithRow(row);
d0154e3a
VS
4309 }
4310
40fc5b2f 4311 // row is the first unmeasured item now; that's our value of N/2
0645bd38
VS
4312
4313 if ( row < count )
d0154e3a 4314 {
0645bd38 4315 top_part_end = row;
d0154e3a 4316
0645bd38
VS
4317 // add bottom N/2 items now:
4318 const int bottom_part_start = wxMax(row, count - row);
4319 for ( row = bottom_part_start; row < count; row++ )
4320 {
4321 calculator.UpdateWithRow(row);
4322 }
86755098 4323
0645bd38
VS
4324 // finally, include currently visible items in the calculation:
4325 const wxPoint origin = CalcUnscrolledPosition(wxPoint(0, 0));
4326 int first_visible = m_clientArea->GetLineAt(origin.y);
4327 int last_visible = m_clientArea->GetLineAt(origin.y + GetClientSize().y);
4328
4329 first_visible = wxMax(first_visible, top_part_end);
4330 last_visible = wxMin(bottom_part_start, last_visible);
4331
4332 for ( row = first_visible; row < last_visible; row++ )
4333 {
4334 calculator.UpdateWithRow(row);
4335 }
4336
4337 wxLogTrace("dataview",
4338 "determined best size from %d top, %d bottom plus %d more visible items out of %d total",
4339 top_part_end,
4340 count - bottom_part_start,
4341 wxMax(0, last_visible - first_visible),
4342 count);
d0154e3a
VS
4343 }
4344
0645bd38 4345 int max_width = calculator.GetMaxWidth();
d0154e3a
VS
4346 if ( max_width > 0 )
4347 max_width += 2 * PADDING_RIGHTLEFT;
4348
4349 const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx] = max_width;
4350 return max_width;
4351}
4352
702f5349 4353void wxDataViewCtrl::ColumnMoved(wxDataViewColumn * WXUNUSED(col),
977a41ec 4354 unsigned int WXUNUSED(new_pos))
702f5349
VZ
4355{
4356 // do _not_ reorder m_cols elements here, they should always be in the
4357 // order in which columns were added, we only display the columns in
4358 // different order
fc8c1a15
RR
4359 m_clientArea->UpdateDisplay();
4360}
4361
afebb87b
RR
4362bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
4363{
b3a3c9d8 4364 wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column );
4264606e 4365 if (!ret)
afebb87b
RR
4366 return false;
4367
d0154e3a 4368 m_colsBestWidths.erase(m_colsBestWidths.begin() + GetColumnIndex(column));
b7fe2261 4369 m_cols.Erase(ret);
aef252d9 4370 OnColumnsCountChanged();
afebb87b
RR
4371
4372 return true;
4373}
4374
4375bool wxDataViewCtrl::ClearColumns()
4376{
42cbde51 4377 SetExpanderColumn(NULL);
b3a3c9d8 4378 m_cols.Clear();
d0154e3a 4379 m_colsBestWidths.clear();
aef252d9 4380 OnColumnsCountChanged();
afebb87b
RR
4381 return true;
4382}
4383
bed74e48 4384void wxDataViewCtrl::InvalidateColBestWidth(int idx)
d0154e3a
VS
4385{
4386 m_colsBestWidths[idx] = 0;
bed74e48 4387 m_colsDirty = true;
d0154e3a
VS
4388}
4389
bed74e48 4390void wxDataViewCtrl::InvalidateColBestWidths()
d0154e3a
VS
4391{
4392 m_colsBestWidths.clear();
4393 m_colsBestWidths.resize(m_cols.size());
bed74e48
VS
4394 m_colsDirty = true;
4395}
d0154e3a 4396
bed74e48
VS
4397void wxDataViewCtrl::UpdateColWidths()
4398{
4399 if ( !m_headerArea )
4400 return;
4401
76b92fa5
VS
4402 const unsigned len = m_colsBestWidths.size();
4403 for ( unsigned i = 0; i < len; i++ )
bed74e48 4404 {
76b92fa5
VS
4405 if ( m_colsBestWidths[i] == 0 )
4406 m_headerArea->UpdateColumn(i);
bed74e48
VS
4407 }
4408}
4409
4410void wxDataViewCtrl::OnInternalIdle()
4411{
4412 wxDataViewCtrlBase::OnInternalIdle();
4413
4414 if ( m_colsDirty )
d0154e3a 4415 {
bed74e48
VS
4416 m_colsDirty = false;
4417 UpdateColWidths();
d0154e3a
VS
4418 }
4419}
4420
453091c2
RR
4421int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
4422{
5d9e1605
RR
4423#if 1
4424 unsigned int len = GetColumnCount();
4425 for ( unsigned int i = 0; i < len; i++ )
4426 {
4427 wxDataViewColumn * col = GetColumnAt(i);
4428 if (column==col)
4429 return i;
4430 }
ce00f59b 4431
5d9e1605
RR
4432 return wxNOT_FOUND;
4433#else
4434 // This returns the position in pixels which is not what we want.
702f5349
VZ
4435 int ret = 0,
4436 dummy = 0;
4437 unsigned int len = GetColumnCount();
4438 for ( unsigned int i = 0; i < len; i++ )
526e19e2 4439 {
702f5349 4440 wxDataViewColumn * col = GetColumnAt(i);
526e19e2
RR
4441 if (col->IsHidden())
4442 continue;
4443 ret += col->GetWidth();
4444 if (column==col)
4445 {
702f5349 4446 CalcScrolledPosition( ret, dummy, &ret, &dummy );
526e19e2
RR
4447 break;
4448 }
4449 }
4450 return ret;
5d9e1605 4451#endif
453091c2
RR
4452}
4453
21f47fb9
RR
4454wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
4455{
46234a03 4456 return m_sortingColumnIdx == wxNOT_FOUND ? NULL
977a41ec 4457 : GetColumn(m_sortingColumnIdx);
21f47fb9
RR
4458}
4459
80ce465c
VZ
4460wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const
4461{
4462 return GetItemByRow(m_clientArea->GetCurrentRow());
4463}
4464
4465void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
4466{
4467 const int row = m_clientArea->GetRowByItem(item);
4468
4469 const unsigned oldCurrent = m_clientArea->GetCurrentRow();
4470 if ( static_cast<unsigned>(row) != oldCurrent )
4471 {
4472 m_clientArea->ChangeCurrentRow(row);
4473 m_clientArea->RefreshRow(oldCurrent);
4474 m_clientArea->RefreshRow(row);
4475 }
4476}
4477
fa93d732 4478int wxDataViewCtrl::GetSelectedItemsCount() const
66e09788 4479{
fa93d732 4480 return m_clientArea->GetSelections().size();
66e09788
RR
4481}
4482
b7e9f8b1
RR
4483int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
4484{
4485 sel.Empty();
f23b8c0d 4486 const wxDataViewSelection& selections = m_clientArea->GetSelections();
373a4816 4487
f23b8c0d 4488 const size_t len = selections.size();
eceb6af1 4489 for ( size_t i = 0; i < len; i++ )
b7e9f8b1 4490 {
f23b8c0d 4491 wxDataViewItem item = m_clientArea->GetItemByRow(selections[i]);
373a4816
VS
4492 if ( item.IsOk() )
4493 {
4494 sel.Add(item);
4495 }
4496 else
4497 {
4498 wxFAIL_MSG( "invalid item in selection - bad internal state" );
4499 }
b7e9f8b1 4500 }
373a4816
VS
4501
4502 return sel.size();
b7e9f8b1
RR
4503}
4504
4505void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel )
4506{
59e60167 4507 wxDataViewSelection selection(wxDataViewSelectionCmp);
4219d8b0
RR
4508
4509 wxDataViewItem last_parent;
4510
b7e9f8b1
RR
4511 int len = sel.GetCount();
4512 for( int i = 0; i < len; i ++ )
4513 {
4219d8b0
RR
4514 wxDataViewItem item = sel[i];
4515 wxDataViewItem parent = GetModel()->GetParent( item );
4516 if (parent)
4517 {
4518 if (parent != last_parent)
4519 ExpandAncestors(item);
4520 }
9adeb77a 4521
4219d8b0
RR
4522 last_parent = parent;
4523 int row = m_clientArea->GetRowByItem( item );
b7e9f8b1
RR
4524 if( row >= 0 )
4525 selection.Add( static_cast<unsigned int>(row) );
4526 }
9adeb77a 4527
b7e9f8b1
RR
4528 m_clientArea->SetSelections( selection );
4529}
4530
4531void wxDataViewCtrl::Select( const wxDataViewItem & item )
704c3490 4532{
4219d8b0 4533 ExpandAncestors( item );
9adeb77a 4534
b7e9f8b1
RR
4535 int row = m_clientArea->GetRowByItem( item );
4536 if( row >= 0 )
57f2a652 4537 {
bc4f1ff2 4538 // Unselect all rows before select another in the single select mode
57f2a652
RR
4539 if (m_clientArea->IsSingleSel())
4540 m_clientArea->SelectAllRows(false);
ce00f59b 4541
b7e9f8b1 4542 m_clientArea->SelectRow(row, true);
ce00f59b 4543
de67922e
RR
4544 // Also set focus to the selected item
4545 m_clientArea->ChangeCurrentRow( row );
57f2a652 4546 }
704c3490 4547}
3b6280be 4548
b7e9f8b1 4549void wxDataViewCtrl::Unselect( const wxDataViewItem & item )
6ff7eee7 4550{
b7e9f8b1
RR
4551 int row = m_clientArea->GetRowByItem( item );
4552 if( row >= 0 )
4553 m_clientArea->SelectRow(row, false);
6ff7eee7
RR
4554}
4555
b7e9f8b1 4556bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
6ff7eee7 4557{
b7e9f8b1
RR
4558 int row = m_clientArea->GetRowByItem( item );
4559 if( row >= 0 )
4560 {
4561 return m_clientArea->IsRowSelected(row);
4562 }
4563 return false;
6ff7eee7
RR
4564}
4565
b7e9f8b1 4566void wxDataViewCtrl::SelectAll()
6ff7eee7 4567{
b7e9f8b1
RR
4568 m_clientArea->SelectAllRows(true);
4569}
df387169 4570
b7e9f8b1
RR
4571void wxDataViewCtrl::UnselectAll()
4572{
4573 m_clientArea->SelectAllRows(false);
6ff7eee7 4574}
b7e9f8b1 4575
fbda518c 4576void wxDataViewCtrl::EnsureVisible( int row, int column )
b7e9f8b1 4577{
fbda518c
RR
4578 if( row < 0 )
4579 row = 0;
67be459b 4580 if( row > (int) m_clientArea->GetRowCount() )
fbda518c
RR
4581 row = m_clientArea->GetRowCount();
4582
4583 int first = m_clientArea->GetFirstVisibleRow();
4584 int last = m_clientArea->GetLastVisibleRow();
4585 if( row < first )
4586 m_clientArea->ScrollTo( row, column );
4587 else if( row > last )
4588 m_clientArea->ScrollTo( row - last + first, column );
4589 else
4590 m_clientArea->ScrollTo( first, column );
b7e9f8b1
RR
4591}
4592
fbda518c 4593void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn * column )
b7e9f8b1 4594{
4219d8b0 4595 ExpandAncestors( item );
9adeb77a 4596
13499080
RR
4597 m_clientArea->RecalculateDisplay();
4598
b7e9f8b1
RR
4599 int row = m_clientArea->GetRowByItem(item);
4600 if( row >= 0 )
fbda518c
RR
4601 {
4602 if( column == NULL )
9bcc8016 4603 EnsureVisible(row, -1);
fbda518c 4604 else
702f5349 4605 EnsureVisible( row, GetColumnIndex(column) );
fbda518c 4606 }
b7fe2261 4607
b7e9f8b1
RR
4608}
4609
4cef3873 4610void wxDataViewCtrl::HitTest( const wxPoint & point, wxDataViewItem & item,
bc4f1ff2 4611 wxDataViewColumn* &column ) const
66e09788
RR
4612{
4613 m_clientArea->HitTest(point, item, column);
4614}
4615
4cef3873 4616wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item,
bc4f1ff2 4617 const wxDataViewColumn* column ) const
66e09788
RR
4618{
4619 return m_clientArea->GetItemRect(item, column);
4620}
4621
b7e9f8b1
RR
4622wxDataViewItem wxDataViewCtrl::GetItemByRow( unsigned int row ) const
4623{
4624 return m_clientArea->GetItemByRow( row );
4625}
4626
4627int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
4628{
4629 return m_clientArea->GetRowByItem( item );
4630}
4631
afebb87b
RR
4632void wxDataViewCtrl::Expand( const wxDataViewItem & item )
4633{
e3d358bb
RR
4634 ExpandAncestors( item );
4635
afebb87b
RR
4636 int row = m_clientArea->GetRowByItem( item );
4637 if (row != -1)
4638 m_clientArea->Expand(row);
4639}
4640
4641void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
4642{
4643 int row = m_clientArea->GetRowByItem( item );
4644 if (row != -1)
b7fe2261 4645 m_clientArea->Collapse(row);
afebb87b
RR
4646}
4647
739a8399
RR
4648bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
4649{
4650 int row = m_clientArea->GetRowByItem( item );
4651 if (row != -1)
4652 return m_clientArea->IsExpanded(row);
4653 return false;
4654}
4655
c937344c
RR
4656void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column )
4657{
4658 wxDataViewColumn* col = GetColumn( column );
4659 if (!col)
4660 return;
4cef3873 4661
c937344c 4662 wxDataViewRenderer* renderer = col->GetRenderer();
2c336e24
VS
4663 if (renderer->GetMode() != wxDATAVIEW_CELL_EDITABLE)
4664 return;
4665
4666 const wxRect itemRect = GetItemRect(item, col);
4667 renderer->StartEditing(item, itemRect);
c937344c
RR
4668}
4669
4cef3873 4670#endif // !wxUSE_GENERICDATAVIEWCTRL
4ed7af08 4671
4cef3873 4672#endif // wxUSE_DATAVIEWCTRL