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