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