]> git.saurik.com Git - wxWidgets.git/blob - src/generic/datavgen.cpp
Bo'd patch to make wxDataViewCtrl compile again (4th attempt
[wxWidgets.git] / src / generic / datavgen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/datavgen.cpp
3 // Purpose: wxDataViewCtrl generic implementation
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Guru Kathiresan, Otto Wyss
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
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_DATAVIEWCTRL
19
20 #include "wx/dataview.h"
21
22 #ifdef wxUSE_GENERICDATAVIEWCTRL
23
24 #ifndef WX_PRECOMP
25 #ifdef __WXMSW__
26 #include "wx/msw/private.h"
27 #include "wx/msw/wrapwin.h"
28 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
29 #endif
30 #include "wx/sizer.h"
31 #include "wx/log.h"
32 #include "wx/dcclient.h"
33 #include "wx/timer.h"
34 #include "wx/settings.h"
35 #include "wx/msgdlg.h"
36 #include "wx/dcscreen.h"
37 #endif
38
39 #include "wx/stockitem.h"
40 #include "wx/calctrl.h"
41 #include "wx/popupwin.h"
42 #include "wx/renderer.h"
43 #include "wx/dcbuffer.h"
44 #include "wx/icon.h"
45
46 //-----------------------------------------------------------------------------
47 // classes
48 //-----------------------------------------------------------------------------
49
50 class wxDataViewCtrl;
51
52 static const int SCROLL_UNIT_X = 15;
53
54 // the cell padding on the left/right
55 static const int PADDING_RIGHTLEFT = 3;
56
57 // the cell padding on the top/bottom
58 static const int PADDING_TOPBOTTOM = 1;
59
60
61 bool operator == ( const wxDataViewItem & left, const wxDataViewItem & right )
62 {
63 return left.GetID() == right.GetID();
64 }
65
66 //-----------------------------------------------------------------------------
67 // wxDataViewHeaderWindow
68 //-----------------------------------------------------------------------------
69
70 #define USE_NATIVE_HEADER_WINDOW 1
71
72 // NB: for some reason, this class must be dllexport'ed or we get warnings from
73 // MSVC in DLL build
74 class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl
75 {
76 public:
77 wxDataViewHeaderWindowBase()
78 { m_owner = NULL; }
79
80 bool Create(wxDataViewCtrl *parent, wxWindowID id,
81 const wxPoint &pos, const wxSize &size,
82 const wxString &name)
83 {
84 return wxWindow::Create(parent, id, pos, size, wxNO_BORDER, name);
85 }
86
87 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
88 wxDataViewCtrl *GetOwner() { return m_owner; }
89
90 // called on column addition/removal
91 virtual void UpdateDisplay() { /* by default, do nothing */ }
92
93 // returns the n-th column
94 virtual wxDataViewColumn *GetColumn(unsigned int n)
95 {
96 wxASSERT(m_owner);
97 wxDataViewColumn *ret = m_owner->GetColumn(n);
98 wxASSERT(ret);
99
100 return ret;
101 }
102
103 protected:
104 wxDataViewCtrl *m_owner;
105
106 // sends an event generated from the n-th wxDataViewColumn
107 void SendEvent(wxEventType type, unsigned int n);
108 };
109
110 // on wxMSW the header window (only that part however) can be made native!
111 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
112
113 #define COLUMN_WIDTH_OFFSET 2
114 #define wxDataViewHeaderWindowMSW wxDataViewHeaderWindow
115
116 class wxDataViewHeaderWindowMSW : public wxDataViewHeaderWindowBase
117 {
118 public:
119
120 wxDataViewHeaderWindowMSW( wxDataViewCtrl *parent,
121 wxWindowID id,
122 const wxPoint &pos = wxDefaultPosition,
123 const wxSize &size = wxDefaultSize,
124 const wxString &name = wxT("wxdataviewctrlheaderwindow") )
125 {
126 Create(parent, id, pos, size, name);
127 }
128
129 bool Create(wxDataViewCtrl *parent, wxWindowID id,
130 const wxPoint &pos, const wxSize &size,
131 const wxString &name);
132
133 ~wxDataViewHeaderWindowMSW();
134
135 // called when any column setting is changed and/or changed
136 // the column count
137 virtual void UpdateDisplay();
138
139 // called when the main window gets scrolled
140 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
141
142 protected:
143 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
144 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
145
146 unsigned int GetColumnIdxFromHeader(NMHEADER *nmHDR);
147
148 wxDataViewColumn *GetColumnFromHeader(NMHEADER *nmHDR)
149 { return GetColumn(GetColumnIdxFromHeader(nmHDR)); }
150
151 private:
152 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW)
153 };
154
155 #else // !defined(__WXMSW__)
156
157 #define HEADER_WINDOW_HEIGHT 25
158 #define HEADER_HORIZ_BORDER 5
159 #define HEADER_VERT_BORDER 3
160 #define wxGenericDataViewHeaderWindow wxDataViewHeaderWindow
161
162 class wxGenericDataViewHeaderWindow : public wxDataViewHeaderWindowBase
163 {
164 public:
165 wxGenericDataViewHeaderWindow( wxDataViewCtrl *parent,
166 wxWindowID id,
167 const wxPoint &pos = wxDefaultPosition,
168 const wxSize &size = wxDefaultSize,
169 const wxString &name = wxT("wxdataviewctrlheaderwindow") )
170 {
171 Init();
172 Create(parent, id, pos, size, name);
173 }
174
175 bool Create(wxDataViewCtrl *parent, wxWindowID id,
176 const wxPoint &pos, const wxSize &size,
177 const wxString &name);
178
179 ~wxGenericDataViewHeaderWindow()
180 {
181 delete m_resizeCursor;
182 }
183
184 virtual void UpdateDisplay() { Refresh(); }
185
186 // event handlers:
187
188 void OnPaint( wxPaintEvent &event );
189 void OnMouse( wxMouseEvent &event );
190 void OnSetFocus( wxFocusEvent &event );
191
192
193 protected:
194
195 // vars used for column resizing:
196
197 wxCursor *m_resizeCursor;
198 const wxCursor *m_currentCursor;
199 bool m_isDragging;
200
201 bool m_dirty; // needs refresh?
202 int m_column; // index of the column being resized
203 int m_currentX; // divider line position in logical (unscrolled) coords
204 int m_minX; // minimal position beyond which the divider line
205 // can't be dragged in logical coords
206
207 // the pen used to draw the current column width drag line
208 // when resizing the columsn
209 wxPen m_penCurrent;
210
211
212 // internal utilities:
213
214 void Init()
215 {
216 m_currentCursor = (wxCursor *) NULL;
217 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
218
219 m_isDragging = false;
220 m_dirty = false;
221
222 m_column = wxNOT_FOUND;
223 m_currentX = 0;
224 m_minX = 0;
225
226 wxColour col = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
227 m_penCurrent = wxPen(col, 1, wxSOLID);
228 }
229
230 void DrawCurrent();
231 void AdjustDC(wxDC& dc);
232
233 private:
234 DECLARE_DYNAMIC_CLASS(wxGenericDataViewHeaderWindow)
235 DECLARE_EVENT_TABLE()
236 };
237
238 #endif // defined(__WXMSW__)
239
240 //-----------------------------------------------------------------------------
241 // wxDataViewRenameTimer
242 //-----------------------------------------------------------------------------
243
244 class wxDataViewRenameTimer: public wxTimer
245 {
246 private:
247 wxDataViewMainWindow *m_owner;
248
249 public:
250 wxDataViewRenameTimer( wxDataViewMainWindow *owner );
251 void Notify();
252 };
253
254 //-----------------------------------------------------------------------------
255 // wxDataViewTreeNode
256 //-----------------------------------------------------------------------------
257 class wxDataViewTreeNode;
258 WX_DEFINE_ARRAY_PTR( wxDataViewTreeNode *, wxDataViewTreeNodes );
259
260 class wxDataViewTreeNode
261 {
262 public:
263 wxDataViewTreeNode( wxDataViewTreeNode * parent )
264 { this->parent = parent;
265 if( parent == NULL )
266 open = true;
267 else
268 open = false;
269 }
270 //I don't know what I need to do in the destructure
271 ~wxDataViewTreeNode()
272 { }
273
274 wxDataViewTreeNode * GetParent() { return parent; }
275 void SetParent( wxDataViewTreeNode * parent ) { this->parent = parent; }
276 wxDataViewTreeNodes GetChildren() { return children; }
277 void SetChildren( wxDataViewTreeNodes children ) { this->children = children; }
278
279 wxDataViewTreeNode * GetChild( unsigned int n ) { return children.Item( n ); }
280 void InsertChild( wxDataViewTreeNode * child, unsigned int n) { children.Insert( child, n); }
281 void AppendChild( wxDataViewTreeNode * child ) { children.Add( child ); }
282
283 wxDataViewItem & GetItem() { return item; }
284 void SetItem( wxDataViewItem & item ) { this->item = item; }
285
286 unsigned int GetChildrenNumber() { return children.GetCount(); }
287
288 bool IsOpen() { return open; }
289 bool HasChildren() { return children.GetCount() != 0; }
290 private:
291 wxDataViewTreeNode * parent;
292 wxDataViewTreeNodes children;
293 wxDataViewItem item;
294 bool open;
295 };
296
297 //-----------------------------------------------------------------------------
298 // wxDataViewMainWindow
299 //-----------------------------------------------------------------------------
300
301 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSelection,
302 WXDLLIMPEXP_ADV);
303
304 class wxDataViewMainWindow: public wxWindow
305 {
306 public:
307 wxDataViewMainWindow( wxDataViewCtrl *parent,
308 wxWindowID id,
309 const wxPoint &pos = wxDefaultPosition,
310 const wxSize &size = wxDefaultSize,
311 const wxString &name = wxT("wxdataviewctrlmainwindow") );
312 virtual ~wxDataViewMainWindow();
313
314 // notifications from wxDataViewModel
315 bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
316 bool ItemDeleted( const wxDataViewItem &item );
317 bool ItemChanged( const wxDataViewItem &item );
318 bool ValueChanged( const wxDataViewItem &item, unsigned int col );
319 bool Cleared();
320
321 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
322 wxDataViewCtrl *GetOwner() { return m_owner; }
323 const wxDataViewCtrl *GetOwner() const { return m_owner; }
324
325 void OnPaint( wxPaintEvent &event );
326 void OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event);
327 void OnChar( wxKeyEvent &event );
328 void OnMouse( wxMouseEvent &event );
329 void OnSetFocus( wxFocusEvent &event );
330 void OnKillFocus( wxFocusEvent &event );
331
332 void UpdateDisplay();
333 void RecalculateDisplay();
334 void OnInternalIdle();
335
336 void OnRenameTimer();
337
338 void ScrollWindow( int dx, int dy, const wxRect *rect = NULL );
339
340 bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; }
341 void ChangeCurrentRow( unsigned int row );
342
343 bool IsSingleSel() const { return !GetParent()->HasFlag(wxDV_MULTIPLE); }
344 bool IsEmpty() { return GetRowCount() == 0; }
345
346 int GetCountPerPage() const;
347 int GetEndOfLastCol() const;
348 unsigned int GetFirstVisibleRow() const;
349 unsigned int GetLastVisibleRow() const;
350 unsigned int GetRowCount() const;
351
352 void Select( const wxArrayInt& aSelections );
353 void SelectAllRows( bool on );
354 void SelectRow( unsigned int row, bool on );
355 void SelectRows( unsigned int from, unsigned int to, bool on );
356 void ReverseRowSelection( unsigned int row );
357 bool IsRowSelected( unsigned int row );
358
359 void RefreshRow( unsigned int row );
360 void RefreshRows( unsigned int from, unsigned int to );
361 void RefreshRowsAfter( unsigned int firstRow );
362
363 // returns the colour to be used for drawing the rules
364 wxColour GetRuleColour() const
365 {
366 return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT);
367 }
368
369 //void EnsureVisible( unsigned int row );
370 wxRect GetLineRect( unsigned int row ) const;
371
372 //Some useful functions for row and item mapping
373 wxDataViewItem GetItemByRow( unsigned int row );
374 unsigned int GetRowByItem( const wxDataViewItem & item );
375
376 //Methods for building the mapping tree
377 void BuildTree( wxDataViewModel * model );
378 void DestroyTree();
379
380 private:
381 wxDataViewCtrl *m_owner;
382 int m_lineHeight;
383 bool m_dirty;
384
385 wxDataViewColumn *m_currentCol;
386 unsigned int m_currentRow;
387 wxDataViewSelection m_selection;
388
389 wxDataViewRenameTimer *m_renameTimer;
390 bool m_lastOnSame;
391
392 bool m_hasFocus;
393
394 int m_dragCount;
395 wxPoint m_dragStart;
396
397 // for double click logic
398 unsigned int m_lineLastClicked,
399 m_lineBeforeLastClicked,
400 m_lineSelectSingleOnUp;
401
402 // the pen used to draw horiz/vertical rules
403 wxPen m_penRule;
404
405 //This is the tree structure of the model
406 wxDataViewTreeNode * m_root;
407 unsigned int m_count;
408 private:
409 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
410 DECLARE_EVENT_TABLE()
411 };
412
413 // ---------------------------------------------------------
414 // wxGenericDataViewModelNotifier
415 // ---------------------------------------------------------
416
417 class wxGenericDataViewModelNotifier: public wxDataViewModelNotifier
418 {
419 public:
420 wxGenericDataViewModelNotifier( wxDataViewMainWindow *mainWindow )
421 { m_mainWindow = mainWindow; }
422
423 virtual bool ItemAdded( const wxDataViewItem & parent, const wxDataViewItem & item )
424 { return m_mainWindow->ItemAdded( parent , item ); }
425 virtual bool ItemDeleted( const wxDataViewItem & item )
426 { return m_mainWindow->ItemDeleted( item ); }
427 virtual bool ItemChanged( const wxDataViewItem & item )
428 { return m_mainWindow->ItemChanged(item); }
429 virtual bool ValueChanged( const wxDataViewItem & item , unsigned int col )
430 { return m_mainWindow->ValueChanged( item, col ); }
431 virtual bool Cleared()
432 { return m_mainWindow->Cleared(); }
433
434 wxDataViewMainWindow *m_mainWindow;
435 };
436
437 // ---------------------------------------------------------
438 // wxDataViewRenderer
439 // ---------------------------------------------------------
440
441 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
442
443 wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype,
444 wxDataViewCellMode mode,
445 int align) :
446 wxDataViewRendererBase( varianttype, mode, align )
447 {
448 m_dc = NULL;
449 m_align = align;
450 m_mode = mode;
451 }
452
453 wxDataViewRenderer::~wxDataViewRenderer()
454 {
455 if (m_dc)
456 delete m_dc;
457 }
458
459 wxDC *wxDataViewRenderer::GetDC()
460 {
461 if (m_dc == NULL)
462 {
463 if (GetOwner() == NULL)
464 return NULL;
465 if (GetOwner()->GetOwner() == NULL)
466 return NULL;
467 m_dc = new wxClientDC( GetOwner()->GetOwner() );
468 }
469
470 return m_dc;
471 }
472
473 // ---------------------------------------------------------
474 // wxDataViewCustomRenderer
475 // ---------------------------------------------------------
476
477 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
478
479 wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
480 wxDataViewCellMode mode, int align ) :
481 wxDataViewRenderer( varianttype, mode, align )
482 {
483 }
484
485 // ---------------------------------------------------------
486 // wxDataViewTextRenderer
487 // ---------------------------------------------------------
488
489 IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer)
490
491 wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype,
492 wxDataViewCellMode mode, int align ) :
493 wxDataViewCustomRenderer( varianttype, mode, align )
494 {
495 }
496
497 bool wxDataViewTextRenderer::SetValue( const wxVariant &value )
498 {
499 m_text = value.GetString();
500
501 return true;
502 }
503
504 bool wxDataViewTextRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
505 {
506 return false;
507 }
508
509 bool wxDataViewTextRenderer::HasEditorCtrl()
510 {
511 return true;
512 }
513
514 wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
515 wxRect labelRect, const wxVariant &value )
516 {
517 return new wxTextCtrl( parent, wxID_ANY, value,
518 wxPoint(labelRect.x,labelRect.y),
519 wxSize(labelRect.width,labelRect.height) );
520 }
521
522 bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
523 {
524 wxTextCtrl *text = (wxTextCtrl*) editor;
525 value = text->GetValue();
526 return true;
527 }
528
529 bool wxDataViewTextRenderer::Render( wxRect cell, wxDC *dc, int state )
530 {
531 wxDataViewCtrl *view = GetOwner()->GetOwner();
532 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ?
533 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) :
534 view->GetForegroundColour();
535
536 dc->SetTextForeground(col);
537 dc->DrawText( m_text, cell.x, cell.y );
538
539 return true;
540 }
541
542 wxSize wxDataViewTextRenderer::GetSize() const
543 {
544 const wxDataViewCtrl *view = GetView();
545 if (!m_text.empty())
546 {
547 int x,y;
548 view->GetTextExtent( m_text, &x, &y );
549 return wxSize( x, y );
550 }
551 return wxSize(80,20);
552 }
553
554 // ---------------------------------------------------------
555 // wxDataViewBitmapRenderer
556 // ---------------------------------------------------------
557
558 IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer)
559
560 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
561 wxDataViewCellMode mode, int align ) :
562 wxDataViewCustomRenderer( varianttype, mode, align )
563 {
564 }
565
566 bool wxDataViewBitmapRenderer::SetValue( const wxVariant &value )
567 {
568 if (value.GetType() == wxT("wxBitmap"))
569 m_bitmap << value;
570 if (value.GetType() == wxT("wxIcon"))
571 m_icon << value;
572
573 return true;
574 }
575
576 bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const
577 {
578 return false;
579 }
580
581 bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
582 {
583 if (m_bitmap.Ok())
584 dc->DrawBitmap( m_bitmap, cell.x, cell.y );
585 else if (m_icon.Ok())
586 dc->DrawIcon( m_icon, cell.x, cell.y );
587
588 return true;
589 }
590
591 wxSize wxDataViewBitmapRenderer::GetSize() const
592 {
593 if (m_bitmap.Ok())
594 return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
595 else if (m_icon.Ok())
596 return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
597
598 return wxSize(16,16);
599 }
600
601 // ---------------------------------------------------------
602 // wxDataViewToggleRenderer
603 // ---------------------------------------------------------
604
605 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewCustomRenderer)
606
607 wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
608 wxDataViewCellMode mode, int align ) :
609 wxDataViewCustomRenderer( varianttype, mode, align )
610 {
611 m_toggle = false;
612 }
613
614 bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
615 {
616 m_toggle = value.GetBool();
617
618 return true;
619 }
620
621 bool wxDataViewToggleRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
622 {
623 return false;
624 }
625
626 bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
627 {
628 // User wxRenderer here
629
630 wxRect rect;
631 rect.x = cell.x + cell.width/2 - 10;
632 rect.width = 20;
633 rect.y = cell.y + cell.height/2 - 10;
634 rect.height = 20;
635
636 int flags = 0;
637 if (m_toggle)
638 flags |= wxCONTROL_CHECKED;
639 if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE)
640 flags |= wxCONTROL_DISABLED;
641
642 wxRendererNative::Get().DrawCheckBox(
643 GetOwner()->GetOwner(),
644 *dc,
645 rect,
646 flags );
647
648 return true;
649 }
650
651 bool wxDataViewToggleRenderer::Activate( wxRect WXUNUSED(cell),
652 wxDataViewModel *model,
653 const wxDataViewItem & item, unsigned int col)
654 {
655 bool value = !m_toggle;
656 wxVariant variant = value;
657 model->SetValue( variant, item, col);
658 model->ValueChanged( item, col );
659 return true;
660 }
661
662 wxSize wxDataViewToggleRenderer::GetSize() const
663 {
664 return wxSize(20,20);
665 }
666
667 // ---------------------------------------------------------
668 // wxDataViewProgressRenderer
669 // ---------------------------------------------------------
670
671 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
672
673 wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
674 const wxString &varianttype, wxDataViewCellMode mode, int align ) :
675 wxDataViewCustomRenderer( varianttype, mode, align )
676 {
677 m_label = label;
678 m_value = 0;
679 }
680
681 wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
682 {
683 }
684
685 bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
686 {
687 m_value = (long) value;
688
689 if (m_value < 0) m_value = 0;
690 if (m_value > 100) m_value = 100;
691
692 return true;
693 }
694
695 bool wxDataViewProgressRenderer::GetValue( wxVariant &value ) const
696 {
697 value = (long) m_value;
698 return true;
699 }
700
701 bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
702 {
703 double pct = (double)m_value / 100.0;
704 wxRect bar = cell;
705 bar.width = (int)(cell.width * pct);
706 dc->SetPen( *wxTRANSPARENT_PEN );
707 dc->SetBrush( *wxBLUE_BRUSH );
708 dc->DrawRectangle( bar );
709
710 dc->SetBrush( *wxTRANSPARENT_BRUSH );
711 dc->SetPen( *wxBLACK_PEN );
712 dc->DrawRectangle( cell );
713
714 return true;
715 }
716
717 wxSize wxDataViewProgressRenderer::GetSize() const
718 {
719 return wxSize(40,12);
720 }
721
722 // ---------------------------------------------------------
723 // wxDataViewDateRenderer
724 // ---------------------------------------------------------
725
726 #define wxUSE_DATE_RENDERER_POPUP (wxUSE_CALENDARCTRL && wxUSE_POPUPWIN)
727
728 #if wxUSE_DATE_RENDERER_POPUP
729
730 class wxDataViewDateRendererPopupTransient: public wxPopupTransientWindow
731 {
732 public:
733 wxDataViewDateRendererPopupTransient( wxWindow* parent, wxDateTime *value,
734 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col) :
735 wxPopupTransientWindow( parent, wxBORDER_SIMPLE ),
736 m_item( item )
737 {
738 m_model = model;
739 m_col = col;
740 m_cal = new wxCalendarCtrl( this, wxID_ANY, *value );
741 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
742 sizer->Add( m_cal, 1, wxGROW );
743 SetSizer( sizer );
744 sizer->Fit( this );
745 }
746
747 void OnCalendar( wxCalendarEvent &event );
748
749 wxCalendarCtrl *m_cal;
750 wxDataViewModel *m_model;
751 unsigned int m_col;
752 const wxDataViewItem & m_item;
753
754 protected:
755 virtual void OnDismiss()
756 {
757 }
758
759 private:
760 DECLARE_EVENT_TABLE()
761 };
762
763 BEGIN_EVENT_TABLE(wxDataViewDateRendererPopupTransient,wxPopupTransientWindow)
764 EVT_CALENDAR( wxID_ANY, wxDataViewDateRendererPopupTransient::OnCalendar )
765 END_EVENT_TABLE()
766
767 void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
768 {
769 wxDateTime date = event.GetDate();
770 wxVariant value = date;
771 m_model->SetValue( value, m_item, m_col );
772 m_model->ValueChanged( m_item, m_col );
773 DismissAndNotify();
774 }
775
776 #endif // wxUSE_DATE_RENDERER_POPUP
777
778 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer)
779
780 wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
781 wxDataViewCellMode mode, int align ) :
782 wxDataViewCustomRenderer( varianttype, mode, align )
783 {
784 }
785
786 bool wxDataViewDateRenderer::SetValue( const wxVariant &value )
787 {
788 m_date = value.GetDateTime();
789
790 return true;
791 }
792
793 bool wxDataViewDateRenderer::GetValue( wxVariant &value ) const
794 {
795 value = m_date;
796 return true;
797 }
798
799 bool wxDataViewDateRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
800 {
801 dc->SetFont( GetOwner()->GetOwner()->GetFont() );
802 wxString tmp = m_date.FormatDate();
803 dc->DrawText( tmp, cell.x, cell.y );
804
805 return true;
806 }
807
808 wxSize wxDataViewDateRenderer::GetSize() const
809 {
810 const wxDataViewCtrl* view = GetView();
811 wxString tmp = m_date.FormatDate();
812 wxCoord x,y,d;
813 view->GetTextExtent( tmp, &x, &y, &d );
814 return wxSize(x,y+d);
815 }
816
817 bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *model,
818 const wxDataViewItem & item, unsigned int col )
819 {
820 wxVariant variant;
821 model->GetValue( variant, item, col );
822 wxDateTime value = variant.GetDateTime();
823
824 #if wxUSE_DATE_RENDERER_POPUP
825 wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
826 GetOwner()->GetOwner()->GetParent(), &value, model, item, col);
827 wxPoint pos = wxGetMousePosition();
828 popup->Move( pos );
829 popup->Layout();
830 popup->Popup( popup->m_cal );
831 #else // !wxUSE_DATE_RENDERER_POPUP
832 wxMessageBox(value.Format());
833 #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
834 return true;
835 }
836
837 // ---------------------------------------------------------
838 // wxDataViewColumn
839 // ---------------------------------------------------------
840
841 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
842
843 wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
844 unsigned int model_column,
845 int width, wxAlignment align, int flags ) :
846 wxDataViewColumnBase( title, cell, model_column, width, align, flags )
847 {
848 SetAlignment(align);
849 SetTitle(title);
850 SetFlags(flags);
851
852 Init(width < 0 ? wxDVC_DEFAULT_WIDTH : width);
853 }
854
855 wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
856 unsigned int model_column,
857 int width, wxAlignment align, int flags ) :
858 wxDataViewColumnBase( bitmap, cell, model_column, width, align, flags )
859 {
860 SetAlignment(align);
861 SetFlags(flags);
862
863 Init(width < 0 ? wxDVC_TOGGLE_DEFAULT_WIDTH : width);
864 }
865
866 wxDataViewColumn::~wxDataViewColumn()
867 {
868 }
869
870 void wxDataViewColumn::Init( int width )
871 {
872 m_width = width;
873 m_minWidth = wxDVC_DEFAULT_MINWIDTH;
874 m_ascending = true;
875 }
876
877 void wxDataViewColumn::SetResizeable( bool resizeable )
878 {
879 if (resizeable)
880 m_flags |= wxDATAVIEW_COL_RESIZABLE;
881 else
882 m_flags &= ~wxDATAVIEW_COL_RESIZABLE;
883 }
884
885 void wxDataViewColumn::SetHidden( bool hidden )
886 {
887 if (hidden)
888 m_flags |= wxDATAVIEW_COL_HIDDEN;
889 else
890 m_flags &= ~wxDATAVIEW_COL_HIDDEN;
891
892 // tell our owner to e.g. update its scrollbars:
893 if (GetOwner())
894 GetOwner()->OnColumnChange();
895 }
896
897 void wxDataViewColumn::SetSortable( bool sortable )
898 {
899 if (sortable)
900 m_flags |= wxDATAVIEW_COL_SORTABLE;
901 else
902 m_flags &= ~wxDATAVIEW_COL_SORTABLE;
903
904 // Update header button
905 if (GetOwner())
906 GetOwner()->OnColumnChange();
907 }
908
909 void wxDataViewColumn::SetSortOrder( bool ascending )
910 {
911 m_ascending = ascending;
912
913 // Update header button
914 if (GetOwner())
915 GetOwner()->OnColumnChange();
916 }
917
918 bool wxDataViewColumn::IsSortOrderAscending() const
919 {
920 return m_ascending;
921 }
922
923 void wxDataViewColumn::SetInternalWidth( int width )
924 {
925 m_width = width;
926
927 // the scrollbars of the wxDataViewCtrl needs to be recalculated!
928 if (m_owner && m_owner->m_clientArea)
929 m_owner->m_clientArea->RecalculateDisplay();
930 }
931
932 void wxDataViewColumn::SetWidth( int width )
933 {
934 m_owner->m_headerArea->UpdateDisplay();
935
936 SetInternalWidth(width);
937 }
938
939
940 //-----------------------------------------------------------------------------
941 // wxDataViewHeaderWindowBase
942 //-----------------------------------------------------------------------------
943
944 void wxDataViewHeaderWindowBase::SendEvent(wxEventType type, unsigned int n)
945 {
946 wxWindow *parent = GetParent();
947 wxDataViewEvent le(type, parent->GetId());
948
949 le.SetEventObject(parent);
950 le.SetColumn(n);
951 le.SetDataViewColumn(GetColumn(n));
952 le.SetModel(GetOwner()->GetModel());
953
954 // for events created by wxDataViewHeaderWindow the
955 // row / value fields are not valid
956
957 parent->GetEventHandler()->ProcessEvent(le);
958 }
959
960 #if defined(__WXMSW__) && USE_NATIVE_HEADER_WINDOW
961
962 // implemented in msw/listctrl.cpp:
963 int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick);
964
965 IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindowMSW, wxWindow)
966
967 bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id,
968 const wxPoint &pos, const wxSize &size,
969 const wxString &name )
970 {
971 m_owner = parent;
972
973 if ( !CreateControl(parent, id, pos, size, 0, wxDefaultValidator, name) )
974 return false;
975
976 int x = pos.x == wxDefaultCoord ? 0 : pos.x,
977 y = pos.y == wxDefaultCoord ? 0 : pos.y,
978 w = size.x == wxDefaultCoord ? 1 : size.x,
979 h = size.y == wxDefaultCoord ? 22 : size.y;
980
981 // create the native WC_HEADER window:
982 WXHWND hwndParent = (HWND)parent->GetHandle();
983 WXDWORD msStyle = WS_CHILD | HDS_BUTTONS | HDS_HORZ | HDS_HOTTRACK | HDS_FULLDRAG;
984 m_hWnd = CreateWindowEx(0,
985 WC_HEADER,
986 (LPCTSTR) NULL,
987 msStyle,
988 x, y, w, h,
989 (HWND)hwndParent,
990 (HMENU)-1,
991 wxGetInstance(),
992 (LPVOID) NULL);
993 if (m_hWnd == NULL)
994 {
995 wxLogLastError(_T("CreateWindowEx"));
996 return false;
997 }
998
999 // we need to subclass the m_hWnd to force wxWindow::HandleNotify
1000 // to call wxDataViewHeaderWindow::MSWOnNotify
1001 SubclassWin(m_hWnd);
1002
1003 // the following is required to get the default win's font for
1004 // header windows and must be done befor sending the HDM_LAYOUT msg
1005 SetFont(GetFont());
1006
1007 RECT rcParent;
1008 HDLAYOUT hdl;
1009 WINDOWPOS wp;
1010
1011 // Retrieve the bounding rectangle of the parent window's
1012 // client area, and then request size and position values
1013 // from the header control.
1014 ::GetClientRect((HWND)hwndParent, &rcParent);
1015
1016 hdl.prc = &rcParent;
1017 hdl.pwpos = &wp;
1018 if (!SendMessage((HWND)m_hWnd, HDM_LAYOUT, 0, (LPARAM) &hdl))
1019 {
1020 wxLogLastError(_T("SendMessage"));
1021 return false;
1022 }
1023
1024 // Set the size, position, and visibility of the header control.
1025 SetWindowPos((HWND)m_hWnd,
1026 wp.hwndInsertAfter,
1027 wp.x, wp.y,
1028 wp.cx, wp.cy,
1029 wp.flags | SWP_SHOWWINDOW);
1030
1031 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1032 // a wxBoxSizer and in order to avoid super-big header windows,
1033 // we need to set our height as fixed
1034 SetMinSize(wxSize(-1, wp.cy));
1035 SetMaxSize(wxSize(-1, wp.cy));
1036
1037 return true;
1038 }
1039
1040 wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow()
1041 {
1042 UnsubclassWin();
1043 }
1044
1045 void wxDataViewHeaderWindowMSW::UpdateDisplay()
1046 {
1047 // remove old columns
1048 for (int j=0, max=Header_GetItemCount((HWND)m_hWnd); j < max; j++)
1049 Header_DeleteItem((HWND)m_hWnd, 0);
1050
1051 // add the updated array of columns to the header control
1052 unsigned int cols = GetOwner()->GetColumnCount();
1053 unsigned int added = 0;
1054 for (unsigned int i = 0; i < cols; i++)
1055 {
1056 wxDataViewColumn *col = GetColumn( i );
1057 if (col->IsHidden())
1058 continue; // don't add it!
1059
1060 HDITEM hdi;
1061 hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
1062 hdi.pszText = (wxChar *) col->GetTitle().wx_str();
1063 hdi.cxy = col->GetWidth();
1064 hdi.cchTextMax = sizeof(hdi.pszText)/sizeof(hdi.pszText[0]);
1065 hdi.fmt = HDF_LEFT | HDF_STRING;
1066
1067 // lParam is reserved for application's use:
1068 // we store there the column index to use it later in MSWOnNotify
1069 // (since columns may have been hidden)
1070 hdi.lParam = (LPARAM)i;
1071
1072 // the native wxMSW implementation of the header window
1073 // draws the column separator COLUMN_WIDTH_OFFSET pixels
1074 // on the right: to correct this effect we make the column
1075 // exactly COLUMN_WIDTH_OFFSET wider (for the first column):
1076 if (i == 0)
1077 hdi.cxy += COLUMN_WIDTH_OFFSET;
1078
1079 switch (col->GetAlignment())
1080 {
1081 case wxALIGN_LEFT:
1082 hdi.fmt |= HDF_LEFT;
1083 break;
1084 case wxALIGN_CENTER:
1085 case wxALIGN_CENTER_HORIZONTAL:
1086 hdi.fmt |= HDF_CENTER;
1087 break;
1088 case wxALIGN_RIGHT:
1089 hdi.fmt |= HDF_RIGHT;
1090 break;
1091
1092 default:
1093 // such alignment is not allowed for the column header!
1094 wxFAIL;
1095 }
1096
1097 SendMessage((HWND)m_hWnd, HDM_INSERTITEM,
1098 (WPARAM)added, (LPARAM)&hdi);
1099 added++;
1100 }
1101 }
1102
1103 unsigned int wxDataViewHeaderWindowMSW::GetColumnIdxFromHeader(NMHEADER *nmHDR)
1104 {
1105 unsigned int idx;
1106
1107 // NOTE: we don't just return nmHDR->iItem because when there are
1108 // hidden columns, nmHDR->iItem may be different from
1109 // nmHDR->pitem->lParam
1110
1111 if (nmHDR->pitem && nmHDR->pitem->mask & HDI_LPARAM)
1112 {
1113 idx = (unsigned int)nmHDR->pitem->lParam;
1114 return idx;
1115 }
1116
1117 HDITEM item;
1118 item.mask = HDI_LPARAM;
1119 Header_GetItem((HWND)m_hWnd, nmHDR->iItem, &item);
1120
1121 return (unsigned int)item.lParam;
1122 }
1123
1124 bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
1125 {
1126 NMHDR *nmhdr = (NMHDR *)lParam;
1127
1128 // is it a message from the header?
1129 if ( nmhdr->hwndFrom != (HWND)m_hWnd )
1130 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
1131
1132 NMHEADER *nmHDR = (NMHEADER *)nmhdr;
1133 switch ( nmhdr->code )
1134 {
1135 case HDN_BEGINTRACK:
1136 // user has started to resize a column:
1137 // do we need to veto it?
1138 if (!GetColumn(nmHDR->iItem)->IsResizeable())
1139 {
1140 // veto it!
1141 *result = TRUE;
1142 }
1143 break;
1144
1145 case HDN_BEGINDRAG:
1146 // user has started to reorder a column
1147 break;
1148
1149 case HDN_ITEMCHANGING:
1150 if (nmHDR->pitem != NULL &&
1151 (nmHDR->pitem->mask & HDI_WIDTH) != 0)
1152 {
1153 int minWidth = GetColumnFromHeader(nmHDR)->GetMinWidth();
1154 if (nmHDR->pitem->cxy < minWidth)
1155 {
1156 // do not allow the user to resize this column under
1157 // its minimal width:
1158 *result = TRUE;
1159 }
1160 }
1161 break;
1162
1163 case HDN_ITEMCHANGED: // user is resizing a column
1164 case HDN_ENDTRACK: // user has finished resizing a column
1165 case HDN_ENDDRAG: // user has finished reordering a column
1166
1167 // update the width of the modified column:
1168 if (nmHDR->pitem != NULL &&
1169 (nmHDR->pitem->mask & HDI_WIDTH) != 0)
1170 {
1171 unsigned int idx = GetColumnIdxFromHeader(nmHDR);
1172 unsigned int w = nmHDR->pitem->cxy;
1173 wxDataViewColumn *col = GetColumn(idx);
1174
1175 // see UpdateDisplay() for more info about COLUMN_WIDTH_OFFSET
1176 if (idx == 0 && w > COLUMN_WIDTH_OFFSET)
1177 w -= COLUMN_WIDTH_OFFSET;
1178
1179 if (w >= (unsigned)col->GetMinWidth())
1180 col->SetInternalWidth(w);
1181 }
1182 break;
1183
1184 case HDN_ITEMCLICK:
1185 {
1186 unsigned int idx = GetColumnIdxFromHeader(nmHDR);
1187 wxEventType evt = nmHDR->iButton == 0 ?
1188 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
1189 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
1190 SendEvent(evt, idx);
1191 }
1192 break;
1193
1194 case NM_RCLICK:
1195 {
1196 // NOTE: for some reason (i.e. for a bug in Windows)
1197 // the HDN_ITEMCLICK notification is not sent on
1198 // right clicks, so we need to handle NM_RCLICK
1199
1200 POINT ptClick;
1201 int column = wxMSWGetColumnClicked(nmhdr, &ptClick);
1202 if (column != wxNOT_FOUND)
1203 {
1204 HDITEM item;
1205 item.mask = HDI_LPARAM;
1206 Header_GetItem((HWND)m_hWnd, column, &item);
1207
1208 // 'idx' may be different from 'column' if there are
1209 // hidden columns...
1210 unsigned int idx = (unsigned int)item.lParam;
1211 SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK,
1212 idx);
1213 }
1214 }
1215 break;
1216
1217 case HDN_GETDISPINFOW:
1218 // see wxListCtrl::MSWOnNotify for more info!
1219 break;
1220
1221 case HDN_ITEMDBLCLICK:
1222 {
1223 unsigned int idx = GetColumnIdxFromHeader(nmHDR);
1224 int w = GetOwner()->GetBestColumnWidth(idx);
1225
1226 // update the native control:
1227 HDITEM hd;
1228 ZeroMemory(&hd, sizeof(hd));
1229 hd.mask = HDI_WIDTH;
1230 hd.cxy = w;
1231 Header_SetItem(GetHwnd(),
1232 nmHDR->iItem, // NOTE: we don't want 'idx' here!
1233 &hd);
1234
1235 // update the wxDataViewColumn class:
1236 GetColumn(idx)->SetInternalWidth(w);
1237 }
1238 break;
1239
1240 default:
1241 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
1242 }
1243
1244 return true;
1245 }
1246
1247 void wxDataViewHeaderWindowMSW::ScrollWindow(int WXUNUSED(dx), int WXUNUSED(dy),
1248 const wxRect *WXUNUSED(rect))
1249 {
1250 wxSize ourSz = GetClientSize();
1251 wxSize ownerSz = m_owner->GetClientSize();
1252
1253 // where should the (logical) origin of this window be placed?
1254 int x1 = 0, y1 = 0;
1255 m_owner->CalcUnscrolledPosition(0, 0, &x1, &y1);
1256
1257 // put this window on top of our parent and
1258 SetWindowPos((HWND)m_hWnd, HWND_TOP, -x1, 0,
1259 ownerSz.GetWidth() + x1, ourSz.GetHeight(),
1260 SWP_SHOWWINDOW);
1261 }
1262
1263 void wxDataViewHeaderWindowMSW::DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
1264 int WXUNUSED(w), int WXUNUSED(h),
1265 int WXUNUSED(f))
1266 {
1267 // the wxDataViewCtrl's internal wxBoxSizer will call this function when
1268 // the wxDataViewCtrl window gets resized: the following dummy call
1269 // to ScrollWindow() is required in order to get this header window
1270 // correctly repainted when it's (horizontally) scrolled:
1271
1272 ScrollWindow(0, 0);
1273 }
1274
1275 #else // !defined(__WXMSW__)
1276
1277 IMPLEMENT_ABSTRACT_CLASS(wxGenericDataViewHeaderWindow, wxWindow)
1278 BEGIN_EVENT_TABLE(wxGenericDataViewHeaderWindow, wxWindow)
1279 EVT_PAINT (wxGenericDataViewHeaderWindow::OnPaint)
1280 EVT_MOUSE_EVENTS (wxGenericDataViewHeaderWindow::OnMouse)
1281 EVT_SET_FOCUS (wxGenericDataViewHeaderWindow::OnSetFocus)
1282 END_EVENT_TABLE()
1283
1284 bool wxGenericDataViewHeaderWindow::Create(wxDataViewCtrl *parent, wxWindowID id,
1285 const wxPoint &pos, const wxSize &size,
1286 const wxString &name )
1287 {
1288 m_owner = parent;
1289
1290 if (!wxDataViewHeaderWindowBase::Create(parent, id, pos, size, name))
1291 return false;
1292
1293 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
1294 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1295 SetOwnForegroundColour( attr.colFg );
1296 SetOwnBackgroundColour( attr.colBg );
1297 if (!m_hasFont)
1298 SetOwnFont( attr.font );
1299
1300 // set our size hints: wxDataViewCtrl will put this wxWindow inside
1301 // a wxBoxSizer and in order to avoid super-big header windows,
1302 // we need to set our height as fixed
1303 SetMinSize(wxSize(-1, HEADER_WINDOW_HEIGHT));
1304 SetMaxSize(wxSize(-1, HEADER_WINDOW_HEIGHT));
1305
1306 return true;
1307 }
1308
1309 void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1310 {
1311 int w, h;
1312 GetClientSize( &w, &h );
1313
1314 wxAutoBufferedPaintDC dc( this );
1315
1316 dc.SetBackground(GetBackgroundColour());
1317 dc.Clear();
1318
1319 int xpix;
1320 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1321
1322 int x;
1323 m_owner->GetViewStart( &x, NULL );
1324
1325 // account for the horz scrollbar offset
1326 dc.SetDeviceOrigin( -x * xpix, 0 );
1327
1328 dc.SetFont( GetFont() );
1329
1330 unsigned int cols = GetOwner()->GetColumnCount();
1331 unsigned int i;
1332 int xpos = 0;
1333 for (i = 0; i < cols; i++)
1334 {
1335 wxDataViewColumn *col = GetColumn( i );
1336 if (col->IsHidden())
1337 continue; // skip it!
1338
1339 int cw = col->GetWidth();
1340 int ch = h;
1341
1342 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE;
1343 if (col->IsSortable())
1344 {
1345 if (col->IsSortOrderAscending())
1346 sortArrow = wxHDR_SORT_ICON_UP;
1347 else
1348 sortArrow = wxHDR_SORT_ICON_DOWN;
1349 }
1350
1351 wxRendererNative::Get().DrawHeaderButton
1352 (
1353 this,
1354 dc,
1355 wxRect(xpos, 0, cw, ch-1),
1356 m_parent->IsEnabled() ? 0
1357 : (int)wxCONTROL_DISABLED,
1358 sortArrow
1359 );
1360
1361 // align as required the column title:
1362 int x = xpos;
1363 wxSize titleSz = dc.GetTextExtent(col->GetTitle());
1364 switch (col->GetAlignment())
1365 {
1366 case wxALIGN_LEFT:
1367 x += HEADER_HORIZ_BORDER;
1368 break;
1369 case wxALIGN_CENTER:
1370 case wxALIGN_CENTER_HORIZONTAL:
1371 x += (cw - titleSz.GetWidth() - 2 * HEADER_HORIZ_BORDER)/2;
1372 break;
1373 case wxALIGN_RIGHT:
1374 x += cw - titleSz.GetWidth() - HEADER_HORIZ_BORDER;
1375 break;
1376 }
1377
1378 // always center the title vertically:
1379 int y = wxMax((ch - titleSz.GetHeight()) / 2, HEADER_VERT_BORDER);
1380
1381 dc.SetClippingRegion( xpos+HEADER_HORIZ_BORDER,
1382 HEADER_VERT_BORDER,
1383 wxMax(cw - 2 * HEADER_HORIZ_BORDER, 1), // width
1384 wxMax(ch - 2 * HEADER_VERT_BORDER, 1)); // height
1385 dc.DrawText( col->GetTitle(), x, y );
1386 dc.DestroyClippingRegion();
1387
1388 xpos += cw;
1389 }
1390 }
1391
1392 void wxGenericDataViewHeaderWindow::OnSetFocus( wxFocusEvent &event )
1393 {
1394 GetParent()->SetFocus();
1395 event.Skip();
1396 }
1397
1398 void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event )
1399 {
1400 // we want to work with logical coords
1401 int x;
1402 m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
1403 int y = event.GetY();
1404
1405 if (m_isDragging)
1406 {
1407 // we don't draw the line beyond our window,
1408 // but we allow dragging it there
1409 int w = 0;
1410 GetClientSize( &w, NULL );
1411 m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
1412 w -= 6;
1413
1414 // erase the line if it was drawn
1415 if (m_currentX < w)
1416 DrawCurrent();
1417
1418 if (event.ButtonUp())
1419 {
1420 m_isDragging = false;
1421 if (HasCapture())
1422 ReleaseMouse();
1423
1424 m_dirty = true;
1425
1426 GetColumn(m_column)->SetWidth(m_currentX - m_minX);
1427
1428 Refresh();
1429 GetOwner()->Refresh();
1430 }
1431 else
1432 {
1433 m_currentX = wxMax(m_minX + 7, x);
1434
1435 // draw in the new location
1436 if (m_currentX < w) DrawCurrent();
1437 }
1438
1439 }
1440 else // not dragging
1441 {
1442 m_minX = 0;
1443 m_column = wxNOT_FOUND;
1444
1445 bool hit_border = false;
1446
1447 // end of the current column
1448 int xpos = 0;
1449
1450 // find the column where this event occured
1451 int countCol = m_owner->GetColumnCount();
1452 for (int column = 0; column < countCol; column++)
1453 {
1454 wxDataViewColumn *p = GetColumn(column);
1455
1456 if (p->IsHidden())
1457 continue; // skip if not shown
1458
1459 xpos += p->GetWidth();
1460 m_column = column;
1461 if ((abs(x-xpos) < 3) && (y < 22))
1462 {
1463 hit_border = true;
1464 break;
1465 }
1466
1467 if (x < xpos)
1468 {
1469 // inside the column
1470 break;
1471 }
1472
1473 m_minX = xpos;
1474 }
1475
1476 if (m_column == wxNOT_FOUND)
1477 return;
1478
1479 bool resizeable = GetColumn(m_column)->IsResizeable();
1480 if (event.LeftDClick() && resizeable)
1481 {
1482 GetColumn(m_column)->SetWidth(GetOwner()->GetBestColumnWidth(m_column));
1483 Refresh();
1484 }
1485 else if (event.LeftDown() || event.RightUp())
1486 {
1487 if (hit_border && event.LeftDown() && resizeable)
1488 {
1489 m_isDragging = true;
1490 CaptureMouse();
1491 m_currentX = x;
1492 DrawCurrent();
1493 }
1494 else // click on a column
1495 {
1496 wxEventType evt = event.LeftDown() ?
1497 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK :
1498 wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK;
1499 SendEvent(evt, m_column);
1500 }
1501 }
1502 else if (event.Moving())
1503 {
1504 if (hit_border && resizeable)
1505 m_currentCursor = m_resizeCursor;
1506 else
1507 m_currentCursor = wxSTANDARD_CURSOR;
1508
1509 SetCursor(*m_currentCursor);
1510 }
1511 }
1512 }
1513
1514 void wxGenericDataViewHeaderWindow::DrawCurrent()
1515 {
1516 int x1 = m_currentX;
1517 int y1 = 0;
1518 ClientToScreen (&x1, &y1);
1519
1520 int x2 = m_currentX-1;
1521 #ifdef __WXMSW__
1522 ++x2; // but why ????
1523 #endif
1524 int y2 = 0;
1525 m_owner->GetClientSize( NULL, &y2 );
1526 m_owner->ClientToScreen( &x2, &y2 );
1527
1528 wxScreenDC dc;
1529 dc.SetLogicalFunction(wxINVERT);
1530 dc.SetPen(m_penCurrent);
1531 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1532 AdjustDC(dc);
1533 dc.DrawLine(x1, y1, x2, y2);
1534 }
1535
1536 void wxGenericDataViewHeaderWindow::AdjustDC(wxDC& dc)
1537 {
1538 int xpix, x;
1539
1540 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
1541 m_owner->GetViewStart( &x, NULL );
1542
1543 // shift the DC origin to match the position of the main window horizontal
1544 // scrollbar: this allows us to always use logical coords
1545 dc.SetDeviceOrigin( -x * xpix, 0 );
1546 }
1547
1548 #endif // defined(__WXMSW__)
1549
1550 //-----------------------------------------------------------------------------
1551 // wxDataViewRenameTimer
1552 //-----------------------------------------------------------------------------
1553
1554 wxDataViewRenameTimer::wxDataViewRenameTimer( wxDataViewMainWindow *owner )
1555 {
1556 m_owner = owner;
1557 }
1558
1559 void wxDataViewRenameTimer::Notify()
1560 {
1561 m_owner->OnRenameTimer();
1562 }
1563
1564 //-----------------------------------------------------------------------------
1565 // wxDataViewMainWindow
1566 //-----------------------------------------------------------------------------
1567
1568 int LINKAGEMODE wxDataViewSelectionCmp( unsigned int row1, unsigned int row2 )
1569 {
1570 if (row1 > row2) return 1;
1571 if (row1 == row2) return 0;
1572 return -1;
1573 }
1574
1575
1576 IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
1577
1578 BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
1579 EVT_PAINT (wxDataViewMainWindow::OnPaint)
1580 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse)
1581 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus)
1582 EVT_KILL_FOCUS (wxDataViewMainWindow::OnKillFocus)
1583 EVT_CHAR (wxDataViewMainWindow::OnChar)
1584 END_EVENT_TABLE()
1585
1586 wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id,
1587 const wxPoint &pos, const wxSize &size, const wxString &name ) :
1588 wxWindow( parent, id, pos, size, wxWANTS_CHARS, name ),
1589 m_selection( wxDataViewSelectionCmp )
1590
1591 {
1592 SetOwner( parent );
1593
1594 m_lastOnSame = false;
1595 m_renameTimer = new wxDataViewRenameTimer( this );
1596
1597 // TODO: user better initial values/nothing selected
1598 m_currentCol = NULL;
1599 m_currentRow = 0;
1600
1601 // TODO: we need to calculate this smartly
1602 m_lineHeight =
1603 #ifdef __WXMSW__
1604 17;
1605 #else
1606 20;
1607 #endif
1608 wxASSERT(m_lineHeight > 2*PADDING_TOPBOTTOM);
1609
1610 m_dragCount = 0;
1611 m_dragStart = wxPoint(0,0);
1612 m_lineLastClicked = (unsigned int) -1;
1613 m_lineBeforeLastClicked = (unsigned int) -1;
1614 m_lineSelectSingleOnUp = (unsigned int) -1;
1615
1616 m_hasFocus = false;
1617
1618 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1619 SetBackgroundColour( *wxWHITE );
1620
1621 m_penRule = wxPen(GetRuleColour(), 1, wxSOLID);
1622
1623 //Some new added code to deal with the tree structure
1624 m_root = new wxDataViewTreeNode( NULL );
1625 m_count = 0 ;
1626 UpdateDisplay();
1627 }
1628
1629 wxDataViewMainWindow::~wxDataViewMainWindow()
1630 {
1631 DestroyTree();
1632 delete m_renameTimer;
1633 }
1634
1635 void wxDataViewMainWindow::OnRenameTimer()
1636 {
1637 // We have to call this here because changes may just have
1638 // been made and no screen update taken place.
1639 if ( m_dirty )
1640 wxSafeYield();
1641
1642 int xpos = 0;
1643 unsigned int cols = GetOwner()->GetColumnCount();
1644 unsigned int i;
1645 for (i = 0; i < cols; i++)
1646 {
1647 wxDataViewColumn *c = GetOwner()->GetColumn( i );
1648 if (c->IsHidden())
1649 continue; // skip it!
1650
1651 if (c == m_currentCol)
1652 break;
1653 xpos += c->GetWidth();
1654 }
1655 wxRect labelRect( xpos, m_currentRow * m_lineHeight,
1656 m_currentCol->GetWidth(), m_lineHeight );
1657
1658 GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y,
1659 &labelRect.x, &labelRect.y);
1660
1661 m_currentCol->GetRenderer()->StartEditing( m_currentRow, labelRect );
1662 }
1663
1664 class DoJob
1665 {
1666 public:
1667 DoJob(){};
1668 virtual ~DoJob(){};
1669
1670 virtual bool operator() ( wxDataViewTreeNode * node ) = 0 ;
1671 };
1672
1673 class ItemAddJob: public DoJob
1674 {
1675 public:
1676 ItemAddJob( const wxDataViewItem & parent, const wxDataViewItem & item )
1677 { this->parent = parent ; this->item = item ; }
1678 virtual ~ItemAddJob(){};
1679
1680 virtual bool operator() ( wxDataViewTreeNode * node )
1681 {
1682 if( node->GetItem() == parent )
1683 {
1684 wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
1685 newnode->SetItem(item);
1686 node->AppendChild( newnode);
1687 return true;
1688 }
1689 return false;
1690 }
1691 private:
1692 wxDataViewItem parent, item;
1693 };
1694
1695 bool Walker( wxDataViewTreeNode * node, DoJob & func )
1696 {
1697 if( !node->HasChildren())
1698 return false;
1699
1700 wxDataViewTreeNodes nodes = node->GetChildren();
1701 int len = node->GetChildrenNumber();
1702 int i = 0 ;
1703 for( ; i < len ; i ++ )
1704 {
1705 wxDataViewTreeNode * n = nodes[i];
1706 if( func( n ) )
1707 return true;
1708 if( Walker( n , func ) )
1709 return true;
1710 }
1711 return false;
1712 }
1713
1714
1715
1716 bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
1717 {
1718 ItemAddJob job( parent, item);
1719 Walker( m_root , job);
1720 UpdateDisplay();
1721 return true;
1722 }
1723
1724 bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem & item)
1725 {
1726 UpdateDisplay();
1727 return true;
1728 }
1729
1730 bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
1731 {
1732 UpdateDisplay();
1733 return true;
1734 }
1735
1736 bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int WXUNUSED(col) )
1737 {
1738 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
1739 /*#define MAX_VIRTUAL_WIDTH 100000
1740
1741 wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
1742 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
1743 Refresh( true, &rect );
1744
1745 return true;
1746 */
1747 UpdateDisplay();
1748 return true;
1749 }
1750
1751 bool wxDataViewMainWindow::Cleared()
1752 {
1753 UpdateDisplay();
1754 return true;
1755 }
1756
1757 void wxDataViewMainWindow::UpdateDisplay()
1758 {
1759 m_dirty = true;
1760 }
1761
1762 void wxDataViewMainWindow::OnInternalIdle()
1763 {
1764 wxWindow::OnInternalIdle();
1765
1766 if (m_dirty)
1767 {
1768 RecalculateDisplay();
1769 m_dirty = false;
1770 }
1771 }
1772
1773 void wxDataViewMainWindow::RecalculateDisplay()
1774 {
1775 wxDataViewModel *model = GetOwner()->GetModel();
1776 if (!model)
1777 {
1778 Refresh();
1779 return;
1780 }
1781
1782 int width = GetEndOfLastCol();
1783 int height = GetRowCount() * m_lineHeight;
1784
1785 SetVirtualSize( width, height );
1786 GetOwner()->SetScrollRate( 10, m_lineHeight );
1787
1788 Refresh();
1789 }
1790
1791 void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
1792 {
1793 wxWindow::ScrollWindow( dx, dy, rect );
1794
1795 if (GetOwner()->m_headerArea)
1796 GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
1797 }
1798
1799 void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
1800 {
1801 wxDataViewModel *model = GetOwner()->GetModel();
1802 wxAutoBufferedPaintDC dc( this );
1803
1804 // prepare the DC
1805 dc.SetBackground(GetBackgroundColour());
1806 dc.Clear();
1807 GetOwner()->PrepareDC( dc );
1808 dc.SetFont( GetFont() );
1809
1810 wxRect update = GetUpdateRegion().GetBox();
1811 m_owner->CalcUnscrolledPosition( update.x, update.y, &update.x, &update.y );
1812
1813 // compute which items needs to be redrawn
1814 unsigned int item_start = wxMax( 0, (update.y / m_lineHeight) );
1815 unsigned int item_count =
1816 wxMin( (int)(((update.y + update.height) / m_lineHeight) - item_start + 1),
1817 (int)(m_count- item_start) );
1818 unsigned int item_last = item_start + item_count;
1819
1820 // compute which columns needs to be redrawn
1821 unsigned int cols = GetOwner()->GetColumnCount();
1822 unsigned int col_start = 0;
1823 unsigned int x_start = 0;
1824 for (x_start = 0; col_start < cols; col_start++)
1825 {
1826 wxDataViewColumn *col = GetOwner()->GetColumn(col_start);
1827 if (col->IsHidden())
1828 continue; // skip it!
1829
1830 unsigned int w = col->GetWidth();
1831 if (x_start+w >= (unsigned int)update.x)
1832 break;
1833
1834 x_start += w;
1835 }
1836
1837 unsigned int col_last = col_start;
1838 unsigned int x_last = x_start;
1839 for (; col_last < cols; col_last++)
1840 {
1841 wxDataViewColumn *col = GetOwner()->GetColumn(col_last);
1842 if (col->IsHidden())
1843 continue; // skip it!
1844
1845 if (x_last > (unsigned int)update.GetRight())
1846 break;
1847
1848 x_last += col->GetWidth();
1849 }
1850
1851 // Draw horizontal rules if required
1852 if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
1853 {
1854 dc.SetPen(m_penRule);
1855 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1856
1857 for (unsigned int i = item_start; i <= item_last+1; i++)
1858 {
1859 int y = i * m_lineHeight;
1860 dc.DrawLine(x_start, y, x_last, y);
1861 }
1862 }
1863
1864 // Draw vertical rules if required
1865 if ( m_owner->HasFlag(wxDV_VERT_RULES) )
1866 {
1867 dc.SetPen(m_penRule);
1868 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1869
1870 int x = x_start;
1871 for (unsigned int i = col_start; i < col_last; i++)
1872 {
1873 wxDataViewColumn *col = GetOwner()->GetColumn(i);
1874 if (col->IsHidden())
1875 continue; // skip it
1876
1877 dc.DrawLine(x, item_start * m_lineHeight,
1878 x, item_last * m_lineHeight);
1879
1880 x += col->GetWidth();
1881 }
1882
1883 // Draw last vertical rule
1884 dc.DrawLine(x, item_start * m_lineHeight,
1885 x, item_last * m_lineHeight);
1886 }
1887
1888 // redraw the background for the items which are selected/current
1889 for (unsigned int item = item_start; item < item_last; item++)
1890 {
1891 bool selected = m_selection.Index( item ) != wxNOT_FOUND;
1892 if (selected || item == m_currentRow)
1893 {
1894 int flags = selected ? (int)wxCONTROL_SELECTED : 0;
1895 if (item == m_currentRow)
1896 flags |= wxCONTROL_CURRENT;
1897 if (m_hasFocus)
1898 flags |= wxCONTROL_FOCUSED;
1899
1900 wxRect rect( x_start, item*m_lineHeight, x_last, m_lineHeight );
1901 wxRendererNative::Get().DrawItemSelectionRect
1902 (
1903 this,
1904 dc,
1905 rect,
1906 flags
1907 );
1908 }
1909 }
1910
1911 // redraw all cells for all rows which must be repainted and for all columns
1912 wxRect cell_rect;
1913 cell_rect.x = x_start;
1914 cell_rect.height = m_lineHeight; // -1 is for the horizontal rules
1915 for (unsigned int i = col_start; i < col_last; i++)
1916 {
1917 wxDataViewColumn *col = GetOwner()->GetColumn( i );
1918 wxDataViewRenderer *cell = col->GetRenderer();
1919 cell_rect.width = col->GetWidth();
1920
1921 if (col->IsHidden())
1922 continue; // skipt it!
1923
1924 for (unsigned int item = item_start; item < item_last; item++)
1925 {
1926 // get the cell value and set it into the renderer
1927 wxVariant value;
1928 wxDataViewItem dataitem = GetItemByRow(item);
1929 model->GetValue( value, dataitem, col->GetModelColumn());
1930 cell->SetValue( value );
1931
1932 // update the y offset
1933 cell_rect.y = item * m_lineHeight;
1934
1935 // cannot be bigger than allocated space
1936 wxSize size = cell->GetSize();
1937 size.x = wxMin( size.x + 2*PADDING_RIGHTLEFT, cell_rect.width );
1938 size.y = wxMin( size.y + 2*PADDING_TOPBOTTOM, cell_rect.height );
1939
1940 wxRect item_rect(cell_rect.GetTopLeft(), size);
1941 int align = cell->GetAlignment();
1942
1943 // horizontal alignment:
1944 item_rect.x = cell_rect.x;
1945 if (align & wxALIGN_CENTER_HORIZONTAL)
1946 item_rect.x = cell_rect.x + (cell_rect.width / 2) - (size.x / 2);
1947 else if (align & wxALIGN_RIGHT)
1948 item_rect.x = cell_rect.x + cell_rect.width - size.x;
1949 //else: wxALIGN_LEFT is the default
1950
1951 // vertical alignment:
1952 item_rect.y = cell_rect.y;
1953 if (align & wxALIGN_CENTER_VERTICAL)
1954 item_rect.y = cell_rect.y + (cell_rect.height / 2) - (size.y / 2);
1955 else if (align & wxALIGN_BOTTOM)
1956 item_rect.y = cell_rect.y + cell_rect.height - size.y;
1957 //else: wxALIGN_TOP is the default
1958
1959 // add padding
1960 item_rect.x += PADDING_RIGHTLEFT;
1961 item_rect.y += PADDING_TOPBOTTOM;
1962 item_rect.width = size.x - 2 * PADDING_RIGHTLEFT;
1963 item_rect.height = size.y - 2 * PADDING_TOPBOTTOM;
1964
1965 int state = 0;
1966 if (m_selection.Index(item) != wxNOT_FOUND)
1967 state |= wxDATAVIEW_CELL_SELECTED;
1968
1969 // TODO: it would be much more efficient to create a clipping
1970 // region for the entire column being rendered (in the OnPaint
1971 // of wxDataViewMainWindow) instead of a single clip region for
1972 // each cell. However it would mean that each renderer should
1973 // respect the given wxRect's top & bottom coords, eventually
1974 // violating only the left & right coords - however the user can
1975 // make its own renderer and thus we cannot be sure of that.
1976 dc.SetClippingRegion( item_rect );
1977 cell->Render( item_rect, &dc, state );
1978 dc.DestroyClippingRegion();
1979 }
1980
1981 cell_rect.x += cell_rect.width;
1982 }
1983 }
1984
1985 int wxDataViewMainWindow::GetCountPerPage() const
1986 {
1987 wxSize size = GetClientSize();
1988 return size.y / m_lineHeight;
1989 }
1990
1991 int wxDataViewMainWindow::GetEndOfLastCol() const
1992 {
1993 int width = 0;
1994 unsigned int i;
1995 for (i = 0; i < GetOwner()->GetColumnCount(); i++)
1996 {
1997 const wxDataViewColumn *c =
1998 wx_const_cast(wxDataViewCtrl*, GetOwner())->GetColumn( i );
1999
2000 if (!c->IsHidden())
2001 width += c->GetWidth();
2002 }
2003 return width;
2004 }
2005
2006 unsigned int wxDataViewMainWindow::GetFirstVisibleRow() const
2007 {
2008 int x = 0;
2009 int y = 0;
2010 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
2011
2012 return y / m_lineHeight;
2013 }
2014
2015 unsigned int wxDataViewMainWindow::GetLastVisibleRow() const
2016 {
2017 wxSize client_size = GetClientSize();
2018 m_owner->CalcUnscrolledPosition( client_size.x, client_size.y,
2019 &client_size.x, &client_size.y );
2020
2021 return wxMin( GetRowCount()-1, ((unsigned)client_size.y/m_lineHeight)+1 );
2022 }
2023
2024 unsigned int wxDataViewMainWindow::GetRowCount() const
2025 {
2026 return m_count;
2027 //return wx_const_cast(wxDataViewCtrl*, GetOwner())->GetModel()->GetRowCount();
2028 }
2029
2030 void wxDataViewMainWindow::ChangeCurrentRow( unsigned int row )
2031 {
2032 m_currentRow = row;
2033
2034 // send event
2035 }
2036
2037 void wxDataViewMainWindow::SelectAllRows( bool on )
2038 {
2039 if (IsEmpty())
2040 return;
2041
2042 if (on)
2043 {
2044 m_selection.Clear();
2045 for (unsigned int i = 0; i < GetRowCount(); i++)
2046 m_selection.Add( i );
2047 Refresh();
2048 }
2049 else
2050 {
2051 unsigned int first_visible = GetFirstVisibleRow();
2052 unsigned int last_visible = GetLastVisibleRow();
2053 unsigned int i;
2054 for (i = 0; i < m_selection.GetCount(); i++)
2055 {
2056 unsigned int row = m_selection[i];
2057 if ((row >= first_visible) && (row <= last_visible))
2058 RefreshRow( row );
2059 }
2060 m_selection.Clear();
2061 }
2062 }
2063
2064 void wxDataViewMainWindow::SelectRow( unsigned int row, bool on )
2065 {
2066 if (m_selection.Index( row ) == wxNOT_FOUND)
2067 {
2068 if (on)
2069 {
2070 m_selection.Add( row );
2071 RefreshRow( row );
2072 }
2073 }
2074 else
2075 {
2076 if (!on)
2077 {
2078 m_selection.Remove( row );
2079 RefreshRow( row );
2080 }
2081 }
2082 }
2083
2084 void wxDataViewMainWindow::SelectRows( unsigned int from, unsigned int to, bool on )
2085 {
2086 if (from > to)
2087 {
2088 unsigned int tmp = from;
2089 from = to;
2090 to = tmp;
2091 }
2092
2093 unsigned int i;
2094 for (i = from; i <= to; i++)
2095 {
2096 if (m_selection.Index( i ) == wxNOT_FOUND)
2097 {
2098 if (on)
2099 m_selection.Add( i );
2100 }
2101 else
2102 {
2103 if (!on)
2104 m_selection.Remove( i );
2105 }
2106 }
2107 RefreshRows( from, to );
2108 }
2109
2110 void wxDataViewMainWindow::Select( const wxArrayInt& aSelections )
2111 {
2112 for (size_t i=0; i < aSelections.GetCount(); i++)
2113 {
2114 int n = aSelections[i];
2115
2116 m_selection.Add( n );
2117 RefreshRow( n );
2118 }
2119 }
2120
2121 void wxDataViewMainWindow::ReverseRowSelection( unsigned int row )
2122 {
2123 if (m_selection.Index( row ) == wxNOT_FOUND)
2124 m_selection.Add( row );
2125 else
2126 m_selection.Remove( row );
2127 RefreshRow( row );
2128 }
2129
2130 bool wxDataViewMainWindow::IsRowSelected( unsigned int row )
2131 {
2132 return (m_selection.Index( row ) != wxNOT_FOUND);
2133 }
2134
2135 void wxDataViewMainWindow::RefreshRow( unsigned int row )
2136 {
2137 wxRect rect( 0, row*m_lineHeight, GetEndOfLastCol(), m_lineHeight );
2138 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2139
2140 wxSize client_size = GetClientSize();
2141 wxRect client_rect( 0, 0, client_size.x, client_size.y );
2142 wxRect intersect_rect = client_rect.Intersect( rect );
2143 if (intersect_rect.width > 0)
2144 Refresh( true, &intersect_rect );
2145 }
2146
2147 void wxDataViewMainWindow::RefreshRows( unsigned int from, unsigned int to )
2148 {
2149 if (from > to)
2150 {
2151 unsigned int tmp = to;
2152 to = from;
2153 from = tmp;
2154 }
2155
2156 wxRect rect( 0, from*m_lineHeight, GetEndOfLastCol(), (to-from+1) * m_lineHeight );
2157 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2158
2159 wxSize client_size = GetClientSize();
2160 wxRect client_rect( 0, 0, client_size.x, client_size.y );
2161 wxRect intersect_rect = client_rect.Intersect( rect );
2162 if (intersect_rect.width > 0)
2163 Refresh( true, &intersect_rect );
2164 }
2165
2166 void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow )
2167 {
2168 unsigned int count = GetRowCount();
2169 if (firstRow > count)
2170 return;
2171
2172 wxRect rect( 0, firstRow*m_lineHeight, GetEndOfLastCol(), count * m_lineHeight );
2173 m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
2174
2175 wxSize client_size = GetClientSize();
2176 wxRect client_rect( 0, 0, client_size.x, client_size.y );
2177 wxRect intersect_rect = client_rect.Intersect( rect );
2178 if (intersect_rect.width > 0)
2179 Refresh( true, &intersect_rect );
2180 }
2181
2182 void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event)
2183 {
2184 wxCHECK_RET( newCurrent < GetRowCount(),
2185 _T("invalid item index in OnArrowChar()") );
2186
2187 // if there is no selection, we cannot move it anywhere
2188 if (!HasCurrentRow())
2189 return;
2190
2191 unsigned int oldCurrent = m_currentRow;
2192
2193 // in single selection we just ignore Shift as we can't select several
2194 // items anyhow
2195 if ( event.ShiftDown() && !IsSingleSel() )
2196 {
2197 RefreshRow( oldCurrent );
2198
2199 ChangeCurrentRow( newCurrent );
2200
2201 // select all the items between the old and the new one
2202 if ( oldCurrent > newCurrent )
2203 {
2204 newCurrent = oldCurrent;
2205 oldCurrent = m_currentRow;
2206 }
2207
2208 SelectRows( oldCurrent, newCurrent, true );
2209 }
2210 else // !shift
2211 {
2212 RefreshRow( oldCurrent );
2213
2214 // all previously selected items are unselected unless ctrl is held
2215 if ( !event.ControlDown() )
2216 SelectAllRows(false);
2217
2218 ChangeCurrentRow( newCurrent );
2219
2220 if ( !event.ControlDown() )
2221 SelectRow( m_currentRow, true );
2222 else
2223 RefreshRow( m_currentRow );
2224 }
2225
2226 //EnsureVisible( m_currentRow );
2227 }
2228
2229 wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const
2230 {
2231 wxRect rect;
2232 rect.x = 0;
2233 rect.y = m_lineHeight * row;
2234 rect.width = GetEndOfLastCol();
2235 rect.height = m_lineHeight;
2236
2237 return rect;
2238 }
2239
2240 /*
2241 static int tree_walk_current ;
2242 wxDataViewTreeNode * TreeWalk( unsigned int row , wxDataViewTreeNode * node )
2243 {
2244 wxDataViewTreeNode * ret ;
2245 if( tree_walk_current == row )
2246 return node;
2247
2248 if( node->HasChildren() && node->IsOpen())
2249 {
2250 wxDataViewTreeNodes nodes = node->GetChildren();
2251 int len = nodes.GetCount();
2252 int i = 0 ;
2253 for( ; i < len; i ++)
2254 {
2255 tree_walk_current ++;
2256 ret = TreeWalk( row, nodes[i] );
2257 if( ret != NULL )
2258 return ret;
2259 }
2260 }
2261 return NULL;
2262 }
2263 */
2264
2265 class RowToItemJob: public DoJob
2266 {
2267 public:
2268 RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current ;}
2269 virtual ~RowToItemJob(){};
2270
2271 virtual bool operator() ( wxDataViewTreeNode * node )
2272 {
2273 if( current == row)
2274 {
2275 ret = node->GetItem() ;
2276 return true;
2277 }
2278 current ++;
2279 return false;
2280 }
2281
2282 wxDataViewItem GetResult(){ return ret; }
2283 private:
2284 unsigned int row;
2285 int current ;
2286 wxDataViewItem ret;
2287 };
2288
2289 wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row)
2290 {
2291 RowToItemJob job( row, 0 );
2292 Walker( m_root , job );
2293 return job.GetResult();
2294 }
2295
2296 class ItemToRowJob : public DoJob
2297 {
2298 public:
2299 ItemToRowJob(const wxDataViewItem & item){ this->item = item ; }
2300 virtual ~ItemToRowJob(){};
2301
2302 virtual bool operator() ( wxDataViewTreeNode * node)
2303 {
2304 ret ++;
2305 if( node->GetItem() == item )
2306 return true;
2307
2308 return false;
2309 }
2310
2311 int GetResult(){ return ret; }
2312 private:
2313 wxDataViewItem item;
2314 int ret;
2315 };
2316
2317 unsigned int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
2318 {
2319 ItemToRowJob job( item );
2320 Walker(m_root , job );
2321 return job.GetResult();
2322 }
2323
2324 unsigned int BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
2325 {
2326 int sum = 0 ;
2327 if( !model->HasChildren( item ) )
2328 return 0;
2329
2330 wxDataViewItem i = model->GetFirstChild( item );
2331 while( i.IsOk() )
2332 {
2333 wxDataViewTreeNode * n = new wxDataViewTreeNode( node );
2334 n->SetItem(i);
2335 node->AppendChild(n);
2336 int num = BuildTreeHelper( model, i, n) + 1;
2337 sum += num ;
2338 i = model->GetNextSibling( i );
2339 }
2340 return sum;
2341 }
2342
2343 void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
2344 {
2345 //First we define a invalid item to fetch the top-level elements
2346 wxDataViewItem item;
2347 m_count = BuildTreeHelper( model, item, m_root);
2348 }
2349
2350 void DestroyTreeHelper( wxDataViewTreeNode * node )
2351 {
2352 if( node->HasChildren() )
2353 {
2354 int len = node->GetChildrenNumber();
2355 int i = 0 ;
2356 wxDataViewTreeNodes nodes = node->GetChildren();
2357 for( ; i < len; i ++ )
2358 {
2359 DestroyTreeHelper(nodes[i]);
2360 }
2361 }
2362 delete node;
2363 }
2364
2365 void wxDataViewMainWindow::DestroyTree()
2366 {
2367 DestroyTreeHelper(m_root);
2368 m_count = 0 ;
2369 }
2370
2371 void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
2372 {
2373 if (event.GetKeyCode() == WXK_TAB)
2374 {
2375 wxNavigationKeyEvent nevent;
2376 nevent.SetWindowChange( event.ControlDown() );
2377 nevent.SetDirection( !event.ShiftDown() );
2378 nevent.SetEventObject( GetParent()->GetParent() );
2379 nevent.SetCurrentFocus( m_parent );
2380 if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent ))
2381 return;
2382 }
2383
2384 // no item -> nothing to do
2385 if (!HasCurrentRow())
2386 {
2387 event.Skip();
2388 return;
2389 }
2390
2391 // don't use m_linesPerPage directly as it might not be computed yet
2392 const int pageSize = GetCountPerPage();
2393 wxCHECK_RET( pageSize, _T("should have non zero page size") );
2394
2395 switch ( event.GetKeyCode() )
2396 {
2397 case WXK_UP:
2398 if ( m_currentRow > 0 )
2399 OnArrowChar( m_currentRow - 1, event );
2400 break;
2401
2402 case WXK_DOWN:
2403 if ( m_currentRow < GetRowCount() - 1 )
2404 OnArrowChar( m_currentRow + 1, event );
2405 break;
2406
2407 case WXK_END:
2408 if (!IsEmpty())
2409 OnArrowChar( GetRowCount() - 1, event );
2410 break;
2411
2412 case WXK_HOME:
2413 if (!IsEmpty())
2414 OnArrowChar( 0, event );
2415 break;
2416
2417 case WXK_PAGEUP:
2418 {
2419 int steps = pageSize - 1;
2420 int index = m_currentRow - steps;
2421 if (index < 0)
2422 index = 0;
2423
2424 OnArrowChar( index, event );
2425 }
2426 break;
2427
2428 case WXK_PAGEDOWN:
2429 {
2430 int steps = pageSize - 1;
2431 unsigned int index = m_currentRow + steps;
2432 unsigned int count = GetRowCount();
2433 if ( index >= count )
2434 index = count - 1;
2435
2436 OnArrowChar( index, event );
2437 }
2438 break;
2439
2440 default:
2441 event.Skip();
2442 }
2443 }
2444
2445 void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
2446 {
2447 if (event.GetEventType() == wxEVT_MOUSEWHEEL)
2448 {
2449 // let the base handle mouse wheel events.
2450 event.Skip();
2451 return;
2452 }
2453
2454 int x = event.GetX();
2455 int y = event.GetY();
2456 m_owner->CalcUnscrolledPosition( x, y, &x, &y );
2457
2458 wxDataViewColumn *col = NULL;
2459
2460 int xpos = 0;
2461 unsigned int cols = GetOwner()->GetColumnCount();
2462 unsigned int i;
2463 for (i = 0; i < cols; i++)
2464 {
2465 wxDataViewColumn *c = GetOwner()->GetColumn( i );
2466 if (c->IsHidden())
2467 continue; // skip it!
2468
2469 if (x < xpos + c->GetWidth())
2470 {
2471 col = c;
2472 break;
2473 }
2474 xpos += c->GetWidth();
2475 }
2476 if (!col)
2477 return;
2478 wxDataViewRenderer *cell = col->GetRenderer();
2479
2480 unsigned int current = y / m_lineHeight;
2481
2482 if ((current > GetRowCount()) || (x > GetEndOfLastCol()))
2483 {
2484 // Unselect all if below the last row ?
2485 return;
2486 }
2487
2488 wxDataViewModel *model = GetOwner()->GetModel();
2489
2490 if (event.Dragging())
2491 {
2492 if (m_dragCount == 0)
2493 {
2494 // we have to report the raw, physical coords as we want to be
2495 // able to call HitTest(event.m_pointDrag) from the user code to
2496 // get the item being dragged
2497 m_dragStart = event.GetPosition();
2498 }
2499
2500 m_dragCount++;
2501
2502 if (m_dragCount != 3)
2503 return;
2504
2505 if (event.LeftIsDown())
2506 {
2507 // Notify cell about drag
2508 }
2509 return;
2510 }
2511 else
2512 {
2513 m_dragCount = 0;
2514 }
2515
2516 bool forceClick = false;
2517
2518 if (event.ButtonDClick())
2519 {
2520 m_renameTimer->Stop();
2521 m_lastOnSame = false;
2522 }
2523
2524 if (event.LeftDClick())
2525 {
2526 if ( current == m_lineLastClicked )
2527 {
2528 if (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)
2529 {
2530 wxVariant value;
2531 model->GetValue( value, col->GetModelColumn(), current );
2532 cell->SetValue( value );
2533 wxRect cell_rect( xpos, current * m_lineHeight,
2534 col->GetWidth(), m_lineHeight );
2535 wxDataViewItem dataitem = GetItemByRow(current);
2536 cell->Activate( cell_rect, model, dataitem, col->GetModelColumn() );
2537 }
2538 return;
2539 }
2540 else
2541 {
2542 // The first click was on another item, so don't interpret this as
2543 // a double click, but as a simple click instead
2544 forceClick = true;
2545 }
2546 }
2547
2548 if (event.LeftUp())
2549 {
2550 if (m_lineSelectSingleOnUp != (unsigned int)-1)
2551 {
2552 // select single line
2553 SelectAllRows( false );
2554 SelectRow( m_lineSelectSingleOnUp, true );
2555 }
2556
2557 if (m_lastOnSame)
2558 {
2559 if ((col == m_currentCol) && (current == m_currentRow) &&
2560 (cell->GetMode() == wxDATAVIEW_CELL_EDITABLE) )
2561 {
2562 m_renameTimer->Start( 100, true );
2563 }
2564 }
2565
2566 m_lastOnSame = false;
2567 m_lineSelectSingleOnUp = (unsigned int)-1;
2568 }
2569 else
2570 {
2571 // This is necessary, because after a DnD operation in
2572 // from and to ourself, the up event is swallowed by the
2573 // DnD code. So on next non-up event (which means here and
2574 // now) m_lineSelectSingleOnUp should be reset.
2575 m_lineSelectSingleOnUp = (unsigned int)-1;
2576 }
2577
2578 if (event.RightDown())
2579 {
2580 m_lineBeforeLastClicked = m_lineLastClicked;
2581 m_lineLastClicked = current;
2582
2583 // If the item is already selected, do not update the selection.
2584 // Multi-selections should not be cleared if a selected item is clicked.
2585 if (!IsRowSelected(current))
2586 {
2587 SelectAllRows(false);
2588 ChangeCurrentRow(current);
2589 SelectRow(m_currentRow,true);
2590 }
2591
2592 // notify cell about right click
2593 // cell->...
2594
2595 // Allow generation of context menu event
2596 event.Skip();
2597 }
2598 else if (event.MiddleDown())
2599 {
2600 // notify cell about middle click
2601 // cell->...
2602 }
2603 if (event.LeftDown() || forceClick)
2604 {
2605 #ifdef __WXMSW__
2606 SetFocus();
2607 #endif
2608
2609 m_lineBeforeLastClicked = m_lineLastClicked;
2610 m_lineLastClicked = current;
2611
2612 unsigned int oldCurrentRow = m_currentRow;
2613 bool oldWasSelected = IsRowSelected(m_currentRow);
2614
2615 bool cmdModifierDown = event.CmdDown();
2616 if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
2617 {
2618 if ( IsSingleSel() || !IsRowSelected(current) )
2619 {
2620 SelectAllRows( false );
2621
2622 ChangeCurrentRow(current);
2623
2624 SelectRow(m_currentRow,true);
2625 }
2626 else // multi sel & current is highlighted & no mod keys
2627 {
2628 m_lineSelectSingleOnUp = current;
2629 ChangeCurrentRow(current); // change focus
2630 }
2631 }
2632 else // multi sel & either ctrl or shift is down
2633 {
2634 if (cmdModifierDown)
2635 {
2636 ChangeCurrentRow(current);
2637
2638 ReverseRowSelection(m_currentRow);
2639 }
2640 else if (event.ShiftDown())
2641 {
2642 ChangeCurrentRow(current);
2643
2644 unsigned int lineFrom = oldCurrentRow,
2645 lineTo = current;
2646
2647 if ( lineTo < lineFrom )
2648 {
2649 lineTo = lineFrom;
2650 lineFrom = m_currentRow;
2651 }
2652
2653 SelectRows(lineFrom, lineTo, true);
2654 }
2655 else // !ctrl, !shift
2656 {
2657 // test in the enclosing if should make it impossible
2658 wxFAIL_MSG( _T("how did we get here?") );
2659 }
2660 }
2661
2662 if (m_currentRow != oldCurrentRow)
2663 RefreshRow( oldCurrentRow );
2664
2665 wxDataViewColumn *oldCurrentCol = m_currentCol;
2666
2667 // Update selection here...
2668 m_currentCol = col;
2669
2670 m_lastOnSame = !forceClick && ((col == oldCurrentCol) &&
2671 (current == oldCurrentRow)) && oldWasSelected;
2672 }
2673 }
2674
2675 void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
2676 {
2677 m_hasFocus = true;
2678
2679 if (HasCurrentRow())
2680 Refresh();
2681
2682 event.Skip();
2683 }
2684
2685 void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event )
2686 {
2687 m_hasFocus = false;
2688
2689 if (HasCurrentRow())
2690 Refresh();
2691
2692 event.Skip();
2693 }
2694
2695 //-----------------------------------------------------------------------------
2696 // wxDataViewCtrl
2697 //-----------------------------------------------------------------------------
2698
2699 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
2700
2701 BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
2702 EVT_SIZE(wxDataViewCtrl::OnSize)
2703 END_EVENT_TABLE()
2704
2705 wxDataViewCtrl::~wxDataViewCtrl()
2706 {
2707 if (m_notifier)
2708 GetModel()->RemoveNotifier( m_notifier );
2709 }
2710
2711 void wxDataViewCtrl::Init()
2712 {
2713 m_notifier = NULL;
2714 }
2715
2716 bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
2717 const wxPoint& pos, const wxSize& size,
2718 long style, const wxValidator& validator )
2719 {
2720 if (!wxControl::Create( parent, id, pos, size,
2721 style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator))
2722 return false;
2723
2724 Init();
2725
2726 #ifdef __WXMAC__
2727 MacSetClipChildren( true ) ;
2728 #endif
2729
2730 m_clientArea = new wxDataViewMainWindow( this, wxID_ANY );
2731
2732 if (HasFlag(wxDV_NO_HEADER))
2733 m_headerArea = NULL;
2734 else
2735 m_headerArea = new wxDataViewHeaderWindow( this, wxID_ANY );
2736
2737 SetTargetWindow( m_clientArea );
2738
2739 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
2740 if (m_headerArea)
2741 sizer->Add( m_headerArea, 0, wxGROW );
2742 sizer->Add( m_clientArea, 1, wxGROW );
2743 SetSizer( sizer );
2744
2745 return true;
2746 }
2747
2748 #ifdef __WXMSW__
2749 WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
2750 WXWPARAM wParam,
2751 WXLPARAM lParam)
2752 {
2753 WXLRESULT rc = wxDataViewCtrlBase::MSWWindowProc(nMsg, wParam, lParam);
2754
2755 #ifndef __WXWINCE__
2756 // we need to process arrows ourselves for scrolling
2757 if ( nMsg == WM_GETDLGCODE )
2758 {
2759 rc |= DLGC_WANTARROWS;
2760 }
2761 #endif
2762
2763 return rc;
2764 }
2765 #endif
2766
2767 void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) )
2768 {
2769 // We need to override OnSize so that our scrolled
2770 // window a) does call Layout() to use sizers for
2771 // positioning the controls but b) does not query
2772 // the sizer for their size and use that for setting
2773 // the scrollable area as set that ourselves by
2774 // calling SetScrollbar() further down.
2775
2776 Layout();
2777
2778 AdjustScrollbars();
2779 }
2780
2781 bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
2782 {
2783 if (!wxDataViewCtrlBase::AssociateModel( model ))
2784 return false;
2785
2786 m_notifier = new wxGenericDataViewModelNotifier( m_clientArea );
2787
2788 model->AddNotifier( m_notifier );
2789
2790 m_clientArea->BuildTree(model);
2791
2792 m_clientArea->UpdateDisplay();
2793
2794 return true;
2795 }
2796
2797 bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
2798 {
2799 if (!wxDataViewCtrlBase::AppendColumn(col))
2800 return false;
2801
2802 OnColumnChange();
2803 return true;
2804 }
2805
2806 void wxDataViewCtrl::OnColumnChange()
2807 {
2808 if (m_headerArea)
2809 m_headerArea->UpdateDisplay();
2810
2811 m_clientArea->UpdateDisplay();
2812 }
2813 /********************************************************************
2814 void wxDataViewCtrl::SetSelection( int row )
2815 {
2816 m_clientArea->SelectRow(row, true);
2817 }
2818
2819 void wxDataViewCtrl::SetSelectionRange( unsigned int from, unsigned int to )
2820 {
2821 m_clientArea->SelectRows(from, to, true);
2822 }
2823
2824 void wxDataViewCtrl::SetSelections( const wxArrayInt& aSelections )
2825 {
2826 m_clientArea->Select(aSelections);
2827 }
2828
2829 void wxDataViewCtrl::Unselect( unsigned int WXUNUSED(row) )
2830 {
2831 // FIXME - TODO
2832 }
2833
2834 bool wxDataViewCtrl::IsSelected( unsigned int WXUNUSED(row) ) const
2835 {
2836 // FIXME - TODO
2837
2838 return false;
2839 }
2840
2841 int wxDataViewCtrl::GetSelection() const
2842 {
2843 // FIXME - TODO
2844
2845 return -1;
2846 }
2847
2848 int wxDataViewCtrl::GetSelections(wxArrayInt& WXUNUSED(aSelections) ) const
2849 {
2850 // FIXME - TODO
2851
2852 return 0;
2853 }
2854 *********************************************************************/
2855 #endif
2856 // !wxUSE_GENERICDATAVIEWCTRL
2857
2858 #endif
2859 // wxUSE_DATAVIEWCTRL