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