]>
Commit | Line | Data |
---|---|---|
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 | ||
38 | class wxDataViewCtrl; | |
39 | ||
a0f3af5f RR |
40 | //----------------------------------------------------------------------------- |
41 | // wxDataViewHeaderWindow | |
42 | //----------------------------------------------------------------------------- | |
4ed7af08 | 43 | |
a0f3af5f | 44 | class wxDataViewHeaderWindow: public wxWindow |
4ed7af08 RR |
45 | { |
46 | public: | |
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 |
61 | private: |
62 | wxDataViewCtrl *m_owner; | |
63 | wxCursor *m_resizeCursor; | |
4ed7af08 | 64 | |
a0f3af5f RR |
65 | private: |
66 | DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindow) | |
67 | DECLARE_EVENT_TABLE() | |
68 | }; | |
4ed7af08 | 69 | |
a0f3af5f RR |
70 | //----------------------------------------------------------------------------- |
71 | // wxDataViewMainWindow | |
72 | //----------------------------------------------------------------------------- | |
4ed7af08 | 73 | |
a0f3af5f | 74 | class wxDataViewMainWindow: public wxWindow |
4ed7af08 | 75 | { |
a0f3af5f RR |
76 | public: |
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 ); |
106 | private: | |
107 | wxDataViewCtrl *m_owner; | |
108 | int m_lineHeight; | |
109 | bool m_dirty; | |
110 | ||
111 | private: | |
112 | DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow) | |
113 | DECLARE_EVENT_TABLE() | |
114 | }; | |
4ed7af08 | 115 | |
a0f3af5f RR |
116 | // --------------------------------------------------------- |
117 | // wxGenericDataViewListModelNotifier | |
118 | // --------------------------------------------------------- | |
119 | ||
120 | class wxGenericDataViewListModelNotifier: public wxDataViewListModelNotifier | |
4ed7af08 | 121 | { |
a0f3af5f RR |
122 | public: |
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 | ||
150 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell, wxDataViewCellBase) | |
151 | ||
152 | wxDataViewCell::wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode ) : | |
153 | wxDataViewCellBase( varianttype, mode ) | |
154 | { | |
3d9d7cc4 | 155 | m_dc = NULL; |
4ed7af08 RR |
156 | } |
157 | ||
3d9d7cc4 RR |
158 | wxDataViewCell::~wxDataViewCell() |
159 | { | |
160 | if (m_dc) | |
161 | delete m_dc; | |
162 | } | |
163 | ||
164 | wxDC *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 | ||
182 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell) | |
183 | ||
184 | wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype, | |
185 | wxDataViewCellMode mode ) : | |
186 | wxDataViewCell( varianttype, mode ) | |
187 | { | |
188 | } | |
189 | ||
190 | ||
4ed7af08 RR |
191 | // --------------------------------------------------------- |
192 | // wxDataViewTextCell | |
193 | // --------------------------------------------------------- | |
194 | ||
3d9d7cc4 | 195 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCustomCell) |
4ed7af08 RR |
196 | |
197 | wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) : | |
3d9d7cc4 | 198 | wxDataViewCustomCell( varianttype, mode ) |
4ed7af08 RR |
199 | { |
200 | } | |
201 | ||
202 | bool wxDataViewTextCell::SetValue( const wxVariant &value ) | |
203 | { | |
204 | return false; | |
205 | } | |
206 | ||
207 | bool wxDataViewTextCell::GetValue( wxVariant &value ) | |
208 | { | |
209 | return false; | |
210 | } | |
211 | ||
3d9d7cc4 RR |
212 | bool wxDataViewTextCell::Render( wxRect cell, wxDC *dc, int state ) |
213 | { | |
214 | return false; | |
215 | } | |
216 | ||
217 | wxSize wxDataViewTextCell::GetSize() | |
218 | { | |
219 | return wxSize(80,20); | |
220 | } | |
221 | ||
4ed7af08 RR |
222 | // --------------------------------------------------------- |
223 | // wxDataViewToggleCell | |
224 | // --------------------------------------------------------- | |
225 | ||
3d9d7cc4 | 226 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCustomCell) |
4ed7af08 RR |
227 | |
228 | wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype, | |
229 | wxDataViewCellMode mode ) : | |
3d9d7cc4 | 230 | wxDataViewCustomCell( varianttype, mode ) |
4ed7af08 RR |
231 | { |
232 | } | |
233 | ||
234 | bool wxDataViewToggleCell::SetValue( const wxVariant &value ) | |
235 | { | |
236 | return false; | |
237 | } | |
238 | ||
239 | bool wxDataViewToggleCell::GetValue( wxVariant &value ) | |
240 | { | |
241 | return false; | |
242 | } | |
243 | ||
3d9d7cc4 | 244 | bool wxDataViewToggleCell::Render( wxRect cell, wxDC *dc, int state ) |
4ed7af08 RR |
245 | { |
246 | return false; | |
247 | } | |
248 | ||
3d9d7cc4 | 249 | wxSize wxDataViewToggleCell::GetSize() |
4ed7af08 | 250 | { |
3d9d7cc4 | 251 | return wxSize(20,20); |
4ed7af08 RR |
252 | } |
253 | ||
4ed7af08 RR |
254 | // --------------------------------------------------------- |
255 | // wxDataViewProgressCell | |
256 | // --------------------------------------------------------- | |
257 | ||
258 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell) | |
259 | ||
260 | wxDataViewProgressCell::wxDataViewProgressCell( const wxString &label, | |
261 | const wxString &varianttype, wxDataViewCellMode mode ) : | |
262 | wxDataViewCustomCell( varianttype, mode ) | |
263 | { | |
264 | m_label = label; | |
265 | m_value = 0; | |
266 | } | |
267 | ||
268 | wxDataViewProgressCell::~wxDataViewProgressCell() | |
269 | { | |
270 | } | |
271 | ||
272 | bool wxDataViewProgressCell::SetValue( const wxVariant &value ) | |
273 | { | |
274 | m_value = (long) value; | |
275 | ||
276 | if (m_value < 0) m_value = 0; | |
277 | if (m_value > 100) m_value = 100; | |
278 | ||
279 | return true; | |
280 | } | |
281 | ||
282 | bool wxDataViewProgressCell::Render( wxRect cell, wxDC *dc, int state ) | |
283 | { | |
284 | double pct = (double)m_value / 100.0; | |
285 | wxRect bar = cell; | |
286 | bar.width = (int)(cell.width * pct); | |
287 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
288 | dc->SetBrush( *wxBLUE_BRUSH ); | |
289 | dc->DrawRectangle( bar ); | |
290 | ||
291 | dc->SetBrush( *wxTRANSPARENT_BRUSH ); | |
292 | dc->SetPen( *wxBLACK_PEN ); | |
293 | dc->DrawRectangle( cell ); | |
294 | ||
295 | return true; | |
296 | } | |
297 | ||
298 | wxSize wxDataViewProgressCell::GetSize() | |
299 | { | |
300 | return wxSize(40,12); | |
301 | } | |
302 | ||
303 | // --------------------------------------------------------- | |
304 | // wxDataViewDateCell | |
305 | // --------------------------------------------------------- | |
306 | ||
307 | class wxDataViewDateCellPopupTransient: public wxPopupTransientWindow | |
308 | { | |
309 | public: | |
310 | wxDataViewDateCellPopupTransient( wxWindow* parent, wxDateTime *value, | |
311 | wxDataViewListModel *model, size_t col, size_t row ) : | |
312 | wxPopupTransientWindow( parent, wxBORDER_SIMPLE ) | |
313 | { | |
314 | m_model = model; | |
315 | m_col = col; | |
316 | m_row = row; | |
317 | m_cal = new wxCalendarCtrl( this, -1, *value ); | |
318 | wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); | |
319 | sizer->Add( m_cal, 1, wxGROW ); | |
320 | SetSizer( sizer ); | |
321 | sizer->Fit( this ); | |
322 | } | |
323 | ||
324 | virtual void OnDismiss() | |
325 | { | |
326 | } | |
327 | ||
328 | void OnCalendar( wxCalendarEvent &event ); | |
329 | ||
330 | wxCalendarCtrl *m_cal; | |
331 | wxDataViewListModel *m_model; | |
332 | size_t m_col; | |
333 | size_t m_row; | |
334 | ||
335 | private: | |
336 | DECLARE_EVENT_TABLE() | |
337 | }; | |
338 | ||
339 | BEGIN_EVENT_TABLE(wxDataViewDateCellPopupTransient,wxPopupTransientWindow) | |
340 | EVT_CALENDAR( -1, wxDataViewDateCellPopupTransient::OnCalendar ) | |
341 | END_EVENT_TABLE() | |
342 | ||
343 | void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent &event ) | |
344 | { | |
345 | wxDateTime date = event.GetDate(); | |
346 | wxVariant value = date; | |
347 | m_model->SetValue( value, m_col, m_row ); | |
348 | m_model->ValueChanged( m_col, m_row ); | |
349 | DismissAndNotify(); | |
350 | } | |
351 | ||
352 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell, wxDataViewCustomCell) | |
353 | ||
354 | wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype, | |
355 | wxDataViewCellMode mode ) : | |
356 | wxDataViewCustomCell( varianttype, mode ) | |
357 | { | |
358 | } | |
359 | ||
360 | bool wxDataViewDateCell::SetValue( const wxVariant &value ) | |
361 | { | |
362 | m_date = value.GetDateTime(); | |
363 | ||
364 | return true; | |
365 | } | |
366 | ||
367 | bool wxDataViewDateCell::Render( wxRect cell, wxDC *dc, int state ) | |
368 | { | |
369 | dc->SetFont( GetOwner()->GetOwner()->GetFont() ); | |
370 | wxString tmp = m_date.FormatDate(); | |
371 | dc->DrawText( tmp, cell.x, cell.y ); | |
372 | ||
373 | return true; | |
374 | } | |
375 | ||
376 | wxSize wxDataViewDateCell::GetSize() | |
377 | { | |
378 | wxDataViewCtrl* view = GetOwner()->GetOwner(); | |
379 | wxString tmp = m_date.FormatDate(); | |
380 | wxCoord x,y,d; | |
381 | view->GetTextExtent( tmp, &x, &y, &d ); | |
382 | return wxSize(x,y+d); | |
383 | } | |
384 | ||
385 | bool wxDataViewDateCell::Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row ) | |
386 | { | |
387 | wxVariant variant; | |
388 | model->GetValue( variant, col, row ); | |
389 | wxDateTime value = variant.GetDateTime(); | |
390 | ||
391 | wxDataViewDateCellPopupTransient *popup = new wxDataViewDateCellPopupTransient( | |
392 | GetOwner()->GetOwner()->GetParent(), &value, model, col, row ); | |
393 | wxPoint pos = wxGetMousePosition(); | |
394 | popup->Move( pos ); | |
395 | popup->Layout(); | |
396 | popup->Popup( popup->m_cal ); | |
397 | ||
398 | return true; | |
399 | } | |
400 | ||
401 | // --------------------------------------------------------- | |
402 | // wxDataViewColumn | |
403 | // --------------------------------------------------------- | |
404 | ||
405 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) | |
406 | ||
407 | wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, | |
408 | size_t model_column, int flags ) : | |
409 | wxDataViewColumnBase( title, cell, model_column, flags ) | |
410 | { | |
4b3feaa7 | 411 | m_width = 80; |
4ed7af08 RR |
412 | } |
413 | ||
414 | wxDataViewColumn::~wxDataViewColumn() | |
415 | { | |
416 | } | |
417 | ||
418 | void wxDataViewColumn::SetTitle( const wxString &title ) | |
419 | { | |
420 | wxDataViewColumnBase::SetTitle( title ); | |
421 | ||
422 | } | |
423 | ||
424 | //----------------------------------------------------------------------------- | |
425 | // wxDataViewHeaderWindow | |
426 | //----------------------------------------------------------------------------- | |
427 | ||
45778c96 | 428 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindow, wxWindow) |
4ed7af08 RR |
429 | |
430 | BEGIN_EVENT_TABLE(wxDataViewHeaderWindow,wxWindow) | |
431 | EVT_PAINT (wxDataViewHeaderWindow::OnPaint) | |
432 | EVT_MOUSE_EVENTS (wxDataViewHeaderWindow::OnMouse) | |
433 | EVT_SET_FOCUS (wxDataViewHeaderWindow::OnSetFocus) | |
434 | END_EVENT_TABLE() | |
435 | ||
436 | wxDataViewHeaderWindow::wxDataViewHeaderWindow( wxDataViewCtrl *parent, wxWindowID id, | |
437 | const wxPoint &pos, const wxSize &size, const wxString &name ) : | |
438 | wxWindow( parent, id, pos, size, 0, name ) | |
439 | { | |
440 | SetOwner( parent ); | |
4b3feaa7 | 441 | |
4ed7af08 RR |
442 | m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); |
443 | ||
444 | wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); | |
445 | SetOwnForegroundColour( attr.colFg ); | |
446 | SetOwnBackgroundColour( attr.colBg ); | |
447 | if (!m_hasFont) | |
448 | SetOwnFont( attr.font ); | |
449 | } | |
450 | ||
451 | wxDataViewHeaderWindow::~wxDataViewHeaderWindow() | |
452 | { | |
453 | delete m_resizeCursor; | |
454 | } | |
455 | ||
456 | void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event ) | |
457 | { | |
4b3feaa7 RR |
458 | int w, h; |
459 | GetClientSize( &w, &h ); | |
460 | ||
461 | wxPaintDC dc( this ); | |
4ed7af08 RR |
462 | |
463 | int xpix; | |
464 | m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); | |
465 | ||
466 | int x; | |
467 | m_owner->GetViewStart( &x, NULL ); | |
468 | ||
469 | // account for the horz scrollbar offset | |
470 | dc.SetDeviceOrigin( -x * xpix, 0 ); | |
471 | ||
472 | dc.SetFont( GetFont() ); | |
473 | ||
4b3feaa7 RR |
474 | size_t cols = GetOwner()->GetNumberOfColumns(); |
475 | size_t i; | |
476 | int xpos = 0; | |
477 | for (i = 0; i < cols; i++) | |
478 | { | |
479 | wxDataViewColumn *col = GetOwner()->GetColumn( i ); | |
480 | int width = col->GetWidth(); | |
481 | ||
482 | // the width of the rect to draw: make it smaller to fit entirely | |
483 | // inside the column rect | |
484 | #ifdef __WXMAC__ | |
485 | int cw = width; | |
486 | int ch = h; | |
487 | #else | |
488 | int cw = width - 2; | |
489 | int ch = h - 2; | |
490 | #endif | |
491 | ||
492 | wxRendererNative::Get().DrawHeaderButton | |
493 | ( | |
494 | this, | |
495 | dc, | |
496 | wxRect(xpos, 0, cw, ch), | |
497 | m_parent->IsEnabled() ? 0 | |
498 | : (int)wxCONTROL_DISABLED | |
499 | ); | |
500 | ||
501 | dc.DrawText( col->GetTitle(), xpos+3, 3 ); | |
502 | ||
503 | xpos += width; | |
504 | } | |
4ed7af08 RR |
505 | } |
506 | ||
507 | void wxDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) | |
508 | { | |
509 | } | |
510 | ||
511 | void wxDataViewHeaderWindow::OnSetFocus( wxFocusEvent &event ) | |
512 | { | |
513 | event.Skip(); | |
514 | } | |
515 | ||
516 | //----------------------------------------------------------------------------- | |
517 | // wxDataViewMainWindow | |
518 | //----------------------------------------------------------------------------- | |
519 | ||
45778c96 | 520 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow) |
4ed7af08 RR |
521 | |
522 | BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow) | |
523 | EVT_PAINT (wxDataViewMainWindow::OnPaint) | |
524 | EVT_MOUSE_EVENTS (wxDataViewMainWindow::OnMouse) | |
525 | EVT_SET_FOCUS (wxDataViewMainWindow::OnSetFocus) | |
526 | END_EVENT_TABLE() | |
527 | ||
528 | wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID id, | |
529 | const wxPoint &pos, const wxSize &size, const wxString &name ) : | |
530 | wxWindow( parent, id, pos, size, 0, name ) | |
531 | { | |
532 | SetOwner( parent ); | |
4b3feaa7 RR |
533 | |
534 | // We need to calculate this smartly.. | |
535 | m_lineHeight = 20; | |
536 | ||
537 | UpdateDisplay(); | |
4ed7af08 RR |
538 | } |
539 | ||
540 | wxDataViewMainWindow::~wxDataViewMainWindow() | |
541 | { | |
542 | } | |
543 | ||
a0f3af5f RR |
544 | bool wxDataViewMainWindow::RowAppended() |
545 | { | |
546 | return false; | |
547 | } | |
548 | ||
549 | bool wxDataViewMainWindow::RowPrepended() | |
550 | { | |
551 | return false; | |
552 | } | |
553 | ||
554 | bool wxDataViewMainWindow::RowInserted( size_t before ) | |
555 | { | |
556 | return false; | |
557 | } | |
558 | ||
559 | bool wxDataViewMainWindow::RowDeleted( size_t row ) | |
560 | { | |
561 | return false; | |
562 | } | |
563 | ||
564 | bool wxDataViewMainWindow::RowChanged( size_t row ) | |
565 | { | |
566 | return false; | |
567 | } | |
568 | ||
569 | bool wxDataViewMainWindow::ValueChanged( size_t col, size_t row ) | |
570 | { | |
571 | return false; | |
572 | } | |
573 | ||
574 | bool wxDataViewMainWindow::RowsReordered( size_t *new_order ) | |
575 | { | |
576 | return false; | |
577 | } | |
578 | ||
579 | bool wxDataViewMainWindow::Cleared() | |
580 | { | |
581 | return false; | |
582 | } | |
583 | ||
4b3feaa7 RR |
584 | void wxDataViewMainWindow::UpdateDisplay() |
585 | { | |
586 | m_dirty = true; | |
587 | } | |
588 | ||
589 | void wxDataViewMainWindow::OnInternalIdle() | |
590 | { | |
591 | wxWindow::OnInternalIdle(); | |
592 | ||
593 | if (m_dirty) | |
594 | { | |
595 | RecalculateDisplay(); | |
596 | m_dirty = false; | |
597 | } | |
598 | } | |
599 | ||
600 | void wxDataViewMainWindow::RecalculateDisplay() | |
601 | { | |
602 | wxDataViewListModel *model = GetOwner()->GetModel(); | |
603 | if (!model) | |
604 | { | |
605 | Refresh(); | |
606 | return; | |
607 | } | |
608 | ||
609 | int width = 0; | |
610 | size_t cols = GetOwner()->GetNumberOfColumns(); | |
611 | size_t i; | |
612 | for (i = 0; i < cols; i++) | |
613 | { | |
614 | wxDataViewColumn *col = GetOwner()->GetColumn( i ); | |
615 | width += col->GetWidth(); | |
616 | } | |
617 | ||
618 | int height = model->GetNumberOfRows() * m_lineHeight; | |
619 | ||
620 | SetVirtualSize( width, height ); | |
621 | GetOwner()->SetScrollRate( 10, m_lineHeight ); | |
622 | ||
623 | Refresh(); | |
624 | } | |
625 | ||
626 | void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) | |
627 | { | |
628 | wxWindow::ScrollWindow( dx, dy, rect ); | |
629 | GetOwner()->m_headerArea->ScrollWindow( dx, 0 ); | |
630 | } | |
631 | ||
4ed7af08 RR |
632 | void wxDataViewMainWindow::OnPaint( wxPaintEvent &event ) |
633 | { | |
634 | wxPaintDC dc( this ); | |
635 | ||
4b3feaa7 | 636 | GetOwner()->PrepareDC( dc ); |
4ed7af08 RR |
637 | |
638 | dc.SetFont( GetFont() ); | |
639 | ||
640 | dc.DrawText( wxT("main window"), 5, 5 ); | |
641 | } | |
642 | ||
643 | void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) | |
644 | { | |
645 | event.Skip(); | |
646 | } | |
647 | ||
648 | void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event ) | |
649 | { | |
650 | event.Skip(); | |
651 | } | |
652 | ||
653 | //----------------------------------------------------------------------------- | |
654 | // wxDataViewCtrl | |
655 | //----------------------------------------------------------------------------- | |
656 | ||
657 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) | |
658 | ||
4b3feaa7 RR |
659 | BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase) |
660 | EVT_SIZE(wxDataViewCtrl::OnSize) | |
661 | END_EVENT_TABLE() | |
662 | ||
4ed7af08 RR |
663 | wxDataViewCtrl::~wxDataViewCtrl() |
664 | { | |
665 | if (m_notifier) | |
666 | GetModel()->RemoveNotifier( m_notifier ); | |
667 | } | |
668 | ||
669 | void wxDataViewCtrl::Init() | |
670 | { | |
671 | m_notifier = NULL; | |
672 | } | |
673 | ||
674 | bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, | |
675 | const wxPoint& pos, const wxSize& size, | |
676 | long style, const wxValidator& validator ) | |
677 | { | |
4b3feaa7 RR |
678 | if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator)) |
679 | return false; | |
680 | ||
4ed7af08 RR |
681 | Init(); |
682 | ||
683 | #ifdef __WXMAC__ | |
684 | MacSetClipChildren( true ) ; | |
685 | #endif | |
686 | ||
687 | m_clientArea = new wxDataViewMainWindow( this, -1 ); | |
688 | m_headerArea = new wxDataViewHeaderWindow( this, -1, wxDefaultPosition, wxSize(-1,25) ); | |
689 | ||
690 | SetTargetWindow( m_clientArea ); | |
691 | ||
692 | wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); | |
693 | sizer->Add( m_headerArea, 0, wxGROW ); | |
694 | sizer->Add( m_clientArea, 1, wxGROW ); | |
695 | SetSizer( sizer ); | |
696 | ||
697 | return true; | |
698 | } | |
699 | ||
700 | #ifdef __WXMSW__ | |
701 | WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg, | |
702 | WXWPARAM wParam, | |
703 | WXLPARAM lParam) | |
704 | { | |
705 | WXLRESULT rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam); | |
706 | ||
707 | #ifndef __WXWINCE__ | |
708 | // we need to process arrows ourselves for scrolling | |
709 | if ( nMsg == WM_GETDLGCODE ) | |
710 | { | |
711 | rc |= DLGC_WANTARROWS; | |
712 | } | |
713 | #endif | |
714 | ||
715 | return rc; | |
716 | } | |
717 | #endif | |
718 | ||
4b3feaa7 | 719 | void wxDataViewCtrl::OnSize( wxSizeEvent &event ) |
4ed7af08 | 720 | { |
4b3feaa7 RR |
721 | // We need to override OnSize so that our scrolled |
722 | // window a) does call Layout() to use sizers for | |
723 | // positioning the controls but b) does not query | |
724 | // the sizer for their size and use that for setting | |
725 | // the scrollable area as set that ourselves by | |
726 | // calling SetScrollbar() further down. | |
727 | ||
728 | Layout(); | |
729 | ||
730 | AdjustScrollbars(); | |
4ed7af08 RR |
731 | } |
732 | ||
733 | bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model ) | |
734 | { | |
735 | if (!wxDataViewCtrlBase::AssociateModel( model )) | |
736 | return false; | |
737 | ||
a0f3af5f | 738 | m_notifier = new wxGenericDataViewListModelNotifier( m_clientArea ); |
4ed7af08 RR |
739 | |
740 | model->AddNotifier( m_notifier ); | |
741 | ||
4b3feaa7 RR |
742 | m_clientArea->UpdateDisplay(); |
743 | ||
4ed7af08 RR |
744 | return true; |
745 | } | |
746 | ||
747 | bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) | |
748 | { | |
749 | if (!wxDataViewCtrlBase::AppendColumn(col)) | |
750 | return false; | |
4b3feaa7 RR |
751 | |
752 | m_clientArea->UpdateDisplay(); | |
753 | ||
4ed7af08 RR |
754 | return true; |
755 | } | |
756 | ||
757 | #endif | |
758 | // !wxUSE_GENERICDATAVIEWCTRL | |
759 | ||
760 | #endif | |
761 | // wxUSE_DATAVIEWCTRL | |
762 |