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