]> git.saurik.com Git - wxWidgets.git/blame - src/generic/datavgen.cpp
Don't centre the frame on WinCE
[wxWidgets.git] / src / generic / datavgen.cpp
CommitLineData
4ed7af08
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: datavgen.cpp
3// Purpose: wxDataViewCtrl generic implementation
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#include "wx/defs.h"
14
15#if wxUSE_DATAVIEWCTRL
16
17#include "wx/dataview.h"
18
19#ifdef wxUSE_GENERICDATAVIEWCTRL
20
21#include "wx/stockitem.h"
22#include "wx/dcclient.h"
23#include "wx/calctrl.h"
24#include "wx/popupwin.h"
25#include "wx/sizer.h"
26#include "wx/log.h"
27#include "wx/renderer.h"
28
29#ifdef __WXMSW__
30 #include <windows.h> // for DLGC_WANTARROWS
31 #include "wx/msw/winundef.h"
32#endif
33
34//-----------------------------------------------------------------------------
35// classes
36//-----------------------------------------------------------------------------
37
38class wxDataViewCtrl;
39
a0f3af5f
RR
40//-----------------------------------------------------------------------------
41// wxDataViewHeaderWindow
42//-----------------------------------------------------------------------------
4ed7af08 43
a0f3af5f 44class wxDataViewHeaderWindow: public wxWindow
4ed7af08
RR
45{
46public:
a0f3af5f
RR
47 wxDataViewHeaderWindow( wxDataViewCtrl *parent,
48 wxWindowID id,
49 const wxPoint &pos = wxDefaultPosition,
50 const wxSize &size = wxDefaultSize,
51 const wxString &name = wxT("wxdataviewctrlheaderwindow") );
52 ~wxDataViewHeaderWindow();
4ed7af08 53
a0f3af5f
RR
54 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
55 wxDataViewCtrl *GetOwner() { return m_owner; }
4ed7af08 56
a0f3af5f
RR
57 void OnPaint( wxPaintEvent &event );
58 void OnMouse( wxMouseEvent &event );
59 void OnSetFocus( wxFocusEvent &event );
4ed7af08 60
a0f3af5f
RR
61private:
62 wxDataViewCtrl *m_owner;
63 wxCursor *m_resizeCursor;
4ed7af08 64
a0f3af5f
RR
65private:
66 DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindow)
67 DECLARE_EVENT_TABLE()
68};
4ed7af08 69
a0f3af5f
RR
70//-----------------------------------------------------------------------------
71// wxDataViewMainWindow
72//-----------------------------------------------------------------------------
4ed7af08 73
a0f3af5f 74class wxDataViewMainWindow: public wxWindow
4ed7af08 75{
a0f3af5f
RR
76public:
77 wxDataViewMainWindow( wxDataViewCtrl *parent,
78 wxWindowID id,
79 const wxPoint &pos = wxDefaultPosition,
80 const wxSize &size = wxDefaultSize,
81 const wxString &name = wxT("wxdataviewctrlmainwindow") );
82 ~wxDataViewMainWindow();
4ed7af08 83
a0f3af5f
RR
84 // notifications from wxDataViewListModel
85 bool RowAppended();
86 bool RowPrepended();
87 bool RowInserted( size_t before );
88 bool RowDeleted( size_t row );
89 bool RowChanged( size_t row );
90 bool ValueChanged( size_t col, size_t row );
91 bool RowsReordered( size_t *new_order );
92 bool Cleared();
4ed7af08 93
a0f3af5f
RR
94 void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
95 wxDataViewCtrl *GetOwner() { return m_owner; }
4ed7af08 96
a0f3af5f
RR
97 void OnPaint( wxPaintEvent &event );
98 void OnMouse( wxMouseEvent &event );
99 void OnSetFocus( wxFocusEvent &event );
4ed7af08 100
a0f3af5f
RR
101 void UpdateDisplay();
102 void RecalculateDisplay();
103 void OnInternalIdle();
4ed7af08 104
a0f3af5f
RR
105 void ScrollWindow( int dx, int dy, const wxRect *rect );
106private:
107 wxDataViewCtrl *m_owner;
108 int m_lineHeight;
109 bool m_dirty;
110
111private:
112 DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
113 DECLARE_EVENT_TABLE()
114};
4ed7af08 115
a0f3af5f
RR
116// ---------------------------------------------------------
117// wxGenericDataViewListModelNotifier
118// ---------------------------------------------------------
119
120class wxGenericDataViewListModelNotifier: public wxDataViewListModelNotifier
4ed7af08 121{
a0f3af5f
RR
122public:
123 wxGenericDataViewListModelNotifier( wxDataViewMainWindow *mainWindow )
124 { m_mainWindow = mainWindow; }
125
126 virtual bool RowAppended()
127 { return m_mainWindow->RowAppended(); }
128 virtual bool RowPrepended()
129 { return m_mainWindow->RowPrepended(); }
130 virtual bool RowInserted( size_t before )
131 { return m_mainWindow->RowInserted( before ); }
132 virtual bool RowDeleted( size_t row )
133 { return m_mainWindow->RowDeleted( row ); }
134 virtual bool RowChanged( size_t row )
135 { return m_mainWindow->RowChanged( row ); }
136 virtual bool ValueChanged( size_t col, size_t row )
137 { return m_mainWindow->ValueChanged( col, row ); }
138 virtual bool RowsReordered( size_t *new_order )
139 { return m_mainWindow->RowsReordered( new_order ); }
140 virtual bool Cleared()
141 { return m_mainWindow->Cleared(); }
142
143 wxDataViewMainWindow *m_mainWindow;
144};
4ed7af08
RR
145
146// ---------------------------------------------------------
147// wxDataViewCell
148// ---------------------------------------------------------
149
150IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell, wxDataViewCellBase)
151
152wxDataViewCell::wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode ) :
153 wxDataViewCellBase( varianttype, mode )
154{
3d9d7cc4 155 m_dc = NULL;
4ed7af08
RR
156}
157
3d9d7cc4
RR
158wxDataViewCell::~wxDataViewCell()
159{
160 if (m_dc)
161 delete m_dc;
162}
163
164wxDC *wxDataViewCell::GetDC()
165{
166 if (m_dc == NULL)
167 {
168 if (GetOwner() == NULL)
169 return NULL;
170 if (GetOwner()->GetOwner() == NULL)
171 return NULL;
172 m_dc = new wxClientDC( GetOwner()->GetOwner() );
173 }
174
175 return m_dc;
176}
177
178// ---------------------------------------------------------
179// wxDataViewCustomCell
180// ---------------------------------------------------------
181
182IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell)
183
184wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype,
185 wxDataViewCellMode mode ) :
186 wxDataViewCell( varianttype, mode )
187{
188}
189
190
4ed7af08
RR
191// ---------------------------------------------------------
192// wxDataViewTextCell
193// ---------------------------------------------------------
194
3d9d7cc4 195IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCustomCell)
4ed7af08
RR
196
197wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) :
3d9d7cc4 198 wxDataViewCustomCell( varianttype, mode )
4ed7af08
RR
199{
200}
201
202bool wxDataViewTextCell::SetValue( const wxVariant &value )
203{
90675b95
RR
204 m_text = value.GetString();
205
206 return true;
4ed7af08
RR
207}
208
209bool wxDataViewTextCell::GetValue( wxVariant &value )
210{
211 return false;
212}
213
3d9d7cc4
RR
214bool wxDataViewTextCell::Render( wxRect cell, wxDC *dc, int state )
215{
90675b95
RR
216 dc->DrawText( m_text, cell.x, cell.y );
217
218 return true;
3d9d7cc4
RR
219}
220
221wxSize wxDataViewTextCell::GetSize()
222{
223 return wxSize(80,20);
224}
225
4ed7af08
RR
226// ---------------------------------------------------------
227// wxDataViewToggleCell
228// ---------------------------------------------------------
229
3d9d7cc4 230IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCustomCell)
4ed7af08
RR
231
232wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype,
233 wxDataViewCellMode mode ) :
3d9d7cc4 234 wxDataViewCustomCell( varianttype, mode )
4ed7af08 235{
90675b95 236 m_toggle = false;
4ed7af08
RR
237}
238
239bool wxDataViewToggleCell::SetValue( const wxVariant &value )
240{
90675b95
RR
241 m_toggle = value.GetBool();
242
243 return true;;
4ed7af08
RR
244}
245
246bool wxDataViewToggleCell::GetValue( wxVariant &value )
247{
248 return false;
249}
250
3d9d7cc4 251bool wxDataViewToggleCell::Render( wxRect cell, wxDC *dc, int state )
4ed7af08 252{
90675b95
RR
253 // User wxRenderer here
254
255 dc->SetPen( *wxBLACK_PEN );
256 dc->SetBrush( *wxTRANSPARENT_BRUSH );
257 wxRect rect;
258 rect.x = cell.x + cell.width/2 - 10;
259 rect.width = 20;
260 rect.y = cell.y + cell.height/2 - 10;
261 rect.height = 20;
262 dc->DrawRectangle( rect );
263 if (m_toggle)
264 {
265 rect.x += 2;
266 rect.y += 2;
267 rect.width -= 4;
268 rect.height -= 4;
269 dc->DrawLine( rect.x, rect.y, rect.x+rect.width, rect.y+rect.height );
270 dc->DrawLine( rect.x+rect.width, rect.y, rect.x, rect.y+rect.height );
271 }
272
273 return true;
4ed7af08
RR
274}
275
3d9d7cc4 276wxSize wxDataViewToggleCell::GetSize()
4ed7af08 277{
3d9d7cc4 278 return wxSize(20,20);
4ed7af08
RR
279}
280
4ed7af08
RR
281// ---------------------------------------------------------
282// wxDataViewProgressCell
283// ---------------------------------------------------------
284
285IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell)
286
287wxDataViewProgressCell::wxDataViewProgressCell( const wxString &label,
288 const wxString &varianttype, wxDataViewCellMode mode ) :
289 wxDataViewCustomCell( varianttype, mode )
290{
291 m_label = label;
292 m_value = 0;
293}
294
295wxDataViewProgressCell::~wxDataViewProgressCell()
296{
297}
298
299bool wxDataViewProgressCell::SetValue( const wxVariant &value )
300{
301 m_value = (long) value;
302
303 if (m_value < 0) m_value = 0;
304 if (m_value > 100) m_value = 100;
305
306 return true;
307}
308
309bool wxDataViewProgressCell::Render( wxRect cell, wxDC *dc, int state )
310{
311 double pct = (double)m_value / 100.0;
312 wxRect bar = cell;
313 bar.width = (int)(cell.width * pct);
314 dc->SetPen( *wxTRANSPARENT_PEN );
315 dc->SetBrush( *wxBLUE_BRUSH );
316 dc->DrawRectangle( bar );
317
318 dc->SetBrush( *wxTRANSPARENT_BRUSH );
319 dc->SetPen( *wxBLACK_PEN );
320 dc->DrawRectangle( cell );
321
322 return true;
323}
324
325wxSize wxDataViewProgressCell::GetSize()
326{
327 return wxSize(40,12);
328}
329
330// ---------------------------------------------------------
331// wxDataViewDateCell
332// ---------------------------------------------------------
333
334class wxDataViewDateCellPopupTransient: public wxPopupTransientWindow
335{
336public:
337 wxDataViewDateCellPopupTransient( wxWindow* parent, wxDateTime *value,
338 wxDataViewListModel *model, size_t col, size_t row ) :
339 wxPopupTransientWindow( parent, wxBORDER_SIMPLE )
340 {
341 m_model = model;
342 m_col = col;
343 m_row = row;
344 m_cal = new wxCalendarCtrl( this, -1, *value );
345 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
346 sizer->Add( m_cal, 1, wxGROW );
347 SetSizer( sizer );
348 sizer->Fit( this );
349 }
350
351 virtual void OnDismiss()
352 {
353 }
354
355 void OnCalendar( wxCalendarEvent &event );
356
357 wxCalendarCtrl *m_cal;
358 wxDataViewListModel *m_model;
359 size_t m_col;
360 size_t m_row;
361
362private:
363 DECLARE_EVENT_TABLE()
364};
365
366BEGIN_EVENT_TABLE(wxDataViewDateCellPopupTransient,wxPopupTransientWindow)
367 EVT_CALENDAR( -1, wxDataViewDateCellPopupTransient::OnCalendar )
368END_EVENT_TABLE()
369
370void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent &event )
371{
372 wxDateTime date = event.GetDate();
373 wxVariant value = date;
374 m_model->SetValue( value, m_col, m_row );
375 m_model->ValueChanged( m_col, m_row );
376 DismissAndNotify();
377}
378
379IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell, wxDataViewCustomCell)
380
381wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype,
382 wxDataViewCellMode mode ) :
383 wxDataViewCustomCell( varianttype, mode )
384{
385}
386
387bool wxDataViewDateCell::SetValue( const wxVariant &value )
388{
389 m_date = value.GetDateTime();
390
391 return true;
392}
393
394bool wxDataViewDateCell::Render( wxRect cell, wxDC *dc, int state )
395{
396 dc->SetFont( GetOwner()->GetOwner()->GetFont() );
397 wxString tmp = m_date.FormatDate();
398 dc->DrawText( tmp, cell.x, cell.y );
399
400 return true;
401}
402
403wxSize wxDataViewDateCell::GetSize()
404{
405 wxDataViewCtrl* view = GetOwner()->GetOwner();
406 wxString tmp = m_date.FormatDate();
407 wxCoord x,y,d;
408 view->GetTextExtent( tmp, &x, &y, &d );
409 return wxSize(x,y+d);
410}
411
412bool wxDataViewDateCell::Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row )
413{
414 wxVariant variant;
415 model->GetValue( variant, col, row );
416 wxDateTime value = variant.GetDateTime();
417
418 wxDataViewDateCellPopupTransient *popup = new wxDataViewDateCellPopupTransient(
419 GetOwner()->GetOwner()->GetParent(), &value, model, col, row );
420 wxPoint pos = wxGetMousePosition();
421 popup->Move( pos );
422 popup->Layout();
423 popup->Popup( popup->m_cal );
424
425 return true;
426}
427
428// ---------------------------------------------------------
429// wxDataViewColumn
430// ---------------------------------------------------------
431
432IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
433
434wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell,
435 size_t model_column, int flags ) :
436 wxDataViewColumnBase( title, cell, model_column, flags )
437{
4b3feaa7 438 m_width = 80;
4ed7af08
RR
439}
440
441wxDataViewColumn::~wxDataViewColumn()
442{
443}
444
445void wxDataViewColumn::SetTitle( const wxString &title )
446{
447 wxDataViewColumnBase::SetTitle( title );
448
449}
450
451//-----------------------------------------------------------------------------
452// wxDataViewHeaderWindow
453//-----------------------------------------------------------------------------
454
45778c96 455IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindow, wxWindow)
4ed7af08
RR
456
457BEGIN_EVENT_TABLE(wxDataViewHeaderWindow,wxWindow)
458 EVT_PAINT (wxDataViewHeaderWindow::OnPaint)
459 EVT_MOUSE_EVENTS (wxDataViewHeaderWindow::OnMouse)
460 EVT_SET_FOCUS (wxDataViewHeaderWindow::OnSetFocus)
461END_EVENT_TABLE()
462
463wxDataViewHeaderWindow::wxDataViewHeaderWindow( wxDataViewCtrl *parent, wxWindowID id,
464 const wxPoint &pos, const wxSize &size, const wxString &name ) :
465 wxWindow( parent, id, pos, size, 0, name )
466{
467 SetOwner( parent );
4b3feaa7 468
4ed7af08
RR
469 m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
470
471 wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
472 SetOwnForegroundColour( attr.colFg );
473 SetOwnBackgroundColour( attr.colBg );
474 if (!m_hasFont)
475 SetOwnFont( attr.font );
476}
477
478wxDataViewHeaderWindow::~wxDataViewHeaderWindow()
479{
480 delete m_resizeCursor;
481}
482
483void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event )
484{
4b3feaa7
RR
485 int w, h;
486 GetClientSize( &w, &h );
487
488 wxPaintDC dc( this );
4ed7af08
RR
489
490 int xpix;
491 m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
492
493 int x;
494 m_owner->GetViewStart( &x, NULL );
495
496 // account for the horz scrollbar offset
497 dc.SetDeviceOrigin( -x * xpix, 0 );
498
499 dc.SetFont( GetFont() );
500
4b3feaa7
RR
501 size_t cols = GetOwner()->GetNumberOfColumns();
502 size_t i;
503 int xpos = 0;
504 for (i = 0; i < cols; i++)
505 {
506 wxDataViewColumn *col = GetOwner()->GetColumn( i );
507 int width = col->GetWidth();
508
509 // the width of the rect to draw: make it smaller to fit entirely
510 // inside the column rect
511#ifdef __WXMAC__
512 int cw = width;
513 int ch = h;
514#else
515 int cw = width - 2;
516 int ch = h - 2;
517#endif
518
519 wxRendererNative::Get().DrawHeaderButton
520 (
521 this,
522 dc,
523 wxRect(xpos, 0, cw, ch),
524 m_parent->IsEnabled() ? 0
525 : (int)wxCONTROL_DISABLED
526 );
527
528 dc.DrawText( col->GetTitle(), xpos+3, 3 );
529
530 xpos += width;
531 }
4ed7af08
RR
532}
533
534void wxDataViewHeaderWindow::OnMouse( wxMouseEvent &event )
535{
536}
537
538void wxDataViewHeaderWindow::OnSetFocus( wxFocusEvent &event )
539{
540 event.Skip();
541}
542
543//-----------------------------------------------------------------------------
544// wxDataViewMainWindow
545//-----------------------------------------------------------------------------
546
45778c96 547IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
4ed7af08
RR
548
549BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
550 EVT_PAINT (wxDataViewMainWindow::OnPaint)
551 EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse)
552 EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus)
553END_EVENT_TABLE()
554
555wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id,
556 const wxPoint &pos, const wxSize &size, const wxString &name ) :
557 wxWindow( parent, id, pos, size, 0, name )
558{
559 SetOwner( parent );
4b3feaa7
RR
560
561 // We need to calculate this smartly..
562 m_lineHeight = 20;
563
564 UpdateDisplay();
4ed7af08
RR
565}
566
567wxDataViewMainWindow::~wxDataViewMainWindow()
568{
569}
570
a0f3af5f
RR
571bool wxDataViewMainWindow::RowAppended()
572{
573 return false;
574}
575
576bool wxDataViewMainWindow::RowPrepended()
577{
578 return false;
579}
580
581bool wxDataViewMainWindow::RowInserted( size_t before )
582{
583 return false;
584}
585
586bool wxDataViewMainWindow::RowDeleted( size_t row )
587{
588 return false;
589}
590
591bool wxDataViewMainWindow::RowChanged( size_t row )
592{
593 return false;
594}
595
596bool wxDataViewMainWindow::ValueChanged( size_t col, size_t row )
597{
598 return false;
599}
600
601bool wxDataViewMainWindow::RowsReordered( size_t *new_order )
602{
603 return false;
604}
605
606bool wxDataViewMainWindow::Cleared()
607{
608 return false;
609}
610
4b3feaa7
RR
611void wxDataViewMainWindow::UpdateDisplay()
612{
613 m_dirty = true;
614}
615
616void wxDataViewMainWindow::OnInternalIdle()
617{
618 wxWindow::OnInternalIdle();
619
620 if (m_dirty)
621 {
622 RecalculateDisplay();
623 m_dirty = false;
624 }
625}
626
627void wxDataViewMainWindow::RecalculateDisplay()
628{
629 wxDataViewListModel *model = GetOwner()->GetModel();
630 if (!model)
631 {
632 Refresh();
633 return;
634 }
635
636 int width = 0;
637 size_t cols = GetOwner()->GetNumberOfColumns();
638 size_t i;
639 for (i = 0; i < cols; i++)
640 {
641 wxDataViewColumn *col = GetOwner()->GetColumn( i );
642 width += col->GetWidth();
643 }
644
645 int height = model->GetNumberOfRows() * m_lineHeight;
646
647 SetVirtualSize( width, height );
648 GetOwner()->SetScrollRate( 10, m_lineHeight );
649
650 Refresh();
651}
652
653void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
654{
655 wxWindow::ScrollWindow( dx, dy, rect );
656 GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
657}
658
4ed7af08
RR
659void wxDataViewMainWindow::OnPaint( wxPaintEvent &event )
660{
661 wxPaintDC dc( this );
662
4b3feaa7 663 GetOwner()->PrepareDC( dc );
4ed7af08
RR
664
665 dc.SetFont( GetFont() );
90675b95
RR
666
667 wxRect update = GetUpdateRegion().GetBox();
668 m_owner->CalcUnscrolledPosition( update.x, update.y, &update.x, &update.y );
4ed7af08 669
90675b95
RR
670 wxDataViewListModel *model = GetOwner()->GetModel();
671
672 size_t item_start = update.y / m_lineHeight;
673 size_t item_count = (update.height / m_lineHeight) + 1;
674
675 wxRect cell_rect;
676 cell_rect.x = 0;
677 cell_rect.height = m_lineHeight;
678 size_t cols = GetOwner()->GetNumberOfColumns();
679 size_t i;
680 for (i = 0; i < cols; i++)
681 {
682 wxDataViewColumn *col = GetOwner()->GetColumn( i );
683 wxDataViewCell *cell = col->GetCell();
684 cell_rect.width = col->GetWidth();
685
686 size_t item;
687 for (item = item_start; item <= item_start+item_count; item++)
688 {
689 cell_rect.y = item*m_lineHeight;
690 wxVariant value;
691 model->GetValue( value, col->GetModelColumn(), item );
692 cell->SetValue( value );
693 cell->Render( cell_rect, &dc, 0 );
694 }
695
696 cell_rect.x += cell_rect.width;
697 }
4ed7af08
RR
698}
699
700void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
701{
702 event.Skip();
703}
704
705void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
706{
707 event.Skip();
708}
709
710//-----------------------------------------------------------------------------
711// wxDataViewCtrl
712//-----------------------------------------------------------------------------
713
714IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
715
4b3feaa7
RR
716BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
717 EVT_SIZE(wxDataViewCtrl::OnSize)
718END_EVENT_TABLE()
719
4ed7af08
RR
720wxDataViewCtrl::~wxDataViewCtrl()
721{
722 if (m_notifier)
723 GetModel()->RemoveNotifier( m_notifier );
724}
725
726void wxDataViewCtrl::Init()
727{
728 m_notifier = NULL;
729}
730
731bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
732 const wxPoint& pos, const wxSize& size,
733 long style, const wxValidator& validator )
734{
4b3feaa7
RR
735 if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator))
736 return false;
737
4ed7af08
RR
738 Init();
739
740#ifdef __WXMAC__
741 MacSetClipChildren( true ) ;
742#endif
743
744 m_clientArea = new wxDataViewMainWindow( this, -1 );
745 m_headerArea = new wxDataViewHeaderWindow( this, -1, wxDefaultPosition, wxSize(-1,25) );
746
747 SetTargetWindow( m_clientArea );
748
749 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
750 sizer->Add( m_headerArea, 0, wxGROW );
751 sizer->Add( m_clientArea, 1, wxGROW );
752 SetSizer( sizer );
753
754 return true;
755}
756
757#ifdef __WXMSW__
758WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
759 WXWPARAM wParam,
760 WXLPARAM lParam)
761{
762 WXLRESULT rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam);
763
764#ifndef __WXWINCE__
765 // we need to process arrows ourselves for scrolling
766 if ( nMsg == WM_GETDLGCODE )
767 {
768 rc |= DLGC_WANTARROWS;
769 }
770#endif
771
772 return rc;
773}
774#endif
775
4b3feaa7 776void wxDataViewCtrl::OnSize( wxSizeEvent &event )
4ed7af08 777{
4b3feaa7
RR
778 // We need to override OnSize so that our scrolled
779 // window a) does call Layout() to use sizers for
780 // positioning the controls but b) does not query
781 // the sizer for their size and use that for setting
782 // the scrollable area as set that ourselves by
783 // calling SetScrollbar() further down.
784
785 Layout();
786
787 AdjustScrollbars();
4ed7af08
RR
788}
789
790bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model )
791{
792 if (!wxDataViewCtrlBase::AssociateModel( model ))
793 return false;
794
a0f3af5f 795 m_notifier = new wxGenericDataViewListModelNotifier( m_clientArea );
4ed7af08
RR
796
797 model->AddNotifier( m_notifier );
798
4b3feaa7
RR
799 m_clientArea->UpdateDisplay();
800
4ed7af08
RR
801 return true;
802}
803
804bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
805{
806 if (!wxDataViewCtrlBase::AppendColumn(col))
807 return false;
4b3feaa7
RR
808
809 m_clientArea->UpdateDisplay();
810
4ed7af08
RR
811 return true;
812}
813
814#endif
815 // !wxUSE_GENERICDATAVIEWCTRL
816
817#endif
818 // wxUSE_DATAVIEWCTRL
819