class wxDataViewCtrl;
-// ---------------------------------------------------------
-// wxGenericDataViewListModelNotifier
-// ---------------------------------------------------------
+//-----------------------------------------------------------------------------
+// wxDataViewHeaderWindow
+//-----------------------------------------------------------------------------
-class wxGenericDataViewListModelNotifier: public wxDataViewListModelNotifier
+class wxDataViewHeaderWindow: public wxWindow
{
public:
- wxGenericDataViewListModelNotifier( wxDataViewListModel *wx_model );
-
- virtual bool RowAppended();
- virtual bool RowPrepended();
- virtual bool RowInserted( size_t before );
- virtual bool RowDeleted( size_t row );
- virtual bool RowChanged( size_t row );
- virtual bool ValueChanged( size_t col, size_t row );
- virtual bool RowsReordered( size_t *new_order );
- virtual bool Cleared();
-
- wxDataViewListModel *m_wx_model;
+ wxDataViewHeaderWindow( wxDataViewCtrl *parent,
+ wxWindowID id,
+ const wxPoint &pos = wxDefaultPosition,
+ const wxSize &size = wxDefaultSize,
+ const wxString &name = wxT("wxdataviewctrlheaderwindow") );
+ ~wxDataViewHeaderWindow();
+
+ void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
+ wxDataViewCtrl *GetOwner() { return m_owner; }
+
+ void OnPaint( wxPaintEvent &event );
+ void OnMouse( wxMouseEvent &event );
+ void OnSetFocus( wxFocusEvent &event );
+
+private:
+ wxDataViewCtrl *m_owner;
+ wxCursor *m_resizeCursor;
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindow)
+ DECLARE_EVENT_TABLE()
};
-// ---------------------------------------------------------
-// wxGenericDataViewListModelNotifier
-// ---------------------------------------------------------
+//-----------------------------------------------------------------------------
+// wxDataViewMainWindow
+//-----------------------------------------------------------------------------
-wxGenericDataViewListModelNotifier::wxGenericDataViewListModelNotifier(
- wxDataViewListModel *wx_model )
+class wxDataViewMainWindow: public wxWindow
{
- m_wx_model = wx_model;
-}
+public:
+ wxDataViewMainWindow( wxDataViewCtrl *parent,
+ wxWindowID id,
+ const wxPoint &pos = wxDefaultPosition,
+ const wxSize &size = wxDefaultSize,
+ const wxString &name = wxT("wxdataviewctrlmainwindow") );
+ ~wxDataViewMainWindow();
+
+ // notifications from wxDataViewListModel
+ bool RowAppended();
+ bool RowPrepended();
+ bool RowInserted( size_t before );
+ bool RowDeleted( size_t row );
+ bool RowChanged( size_t row );
+ bool ValueChanged( size_t col, size_t row );
+ bool RowsReordered( size_t *new_order );
+ bool Cleared();
+
+ void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
+ wxDataViewCtrl *GetOwner() { return m_owner; }
+
+ void OnPaint( wxPaintEvent &event );
+ void OnMouse( wxMouseEvent &event );
+ void OnSetFocus( wxFocusEvent &event );
-bool wxGenericDataViewListModelNotifier::RowAppended()
-{
- size_t pos = m_wx_model->GetNumberOfRows()-1;
+ void UpdateDisplay();
+ void RecalculateDisplay();
+ void OnInternalIdle();
- return false;
-}
+ void ScrollWindow( int dx, int dy, const wxRect *rect );
+private:
+ wxDataViewCtrl *m_owner;
+ int m_lineHeight;
+ bool m_dirty;
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
+ DECLARE_EVENT_TABLE()
+};
-bool wxGenericDataViewListModelNotifier::RowPrepended()
-{
- return false;
-}
+// ---------------------------------------------------------
+// wxGenericDataViewListModelNotifier
+// ---------------------------------------------------------
-bool wxGenericDataViewListModelNotifier::RowInserted( size_t before )
+class wxGenericDataViewListModelNotifier: public wxDataViewListModelNotifier
{
- return false;
-}
+public:
+ wxGenericDataViewListModelNotifier( wxDataViewMainWindow *mainWindow )
+ { m_mainWindow = mainWindow; }
+
+ virtual bool RowAppended()
+ { return m_mainWindow->RowAppended(); }
+ virtual bool RowPrepended()
+ { return m_mainWindow->RowPrepended(); }
+ virtual bool RowInserted( size_t before )
+ { return m_mainWindow->RowInserted( before ); }
+ virtual bool RowDeleted( size_t row )
+ { return m_mainWindow->RowDeleted( row ); }
+ virtual bool RowChanged( size_t row )
+ { return m_mainWindow->RowChanged( row ); }
+ virtual bool ValueChanged( size_t col, size_t row )
+ { return m_mainWindow->ValueChanged( col, row ); }
+ virtual bool RowsReordered( size_t *new_order )
+ { return m_mainWindow->RowsReordered( new_order ); }
+ virtual bool Cleared()
+ { return m_mainWindow->Cleared(); }
+
+ wxDataViewMainWindow *m_mainWindow;
+};
-bool wxGenericDataViewListModelNotifier::RowDeleted( size_t row )
-{
- return false;
-}
+// ---------------------------------------------------------
+// wxDataViewCell
+// ---------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell, wxDataViewCellBase)
-bool wxGenericDataViewListModelNotifier::RowChanged( size_t row )
+wxDataViewCell::wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode ) :
+ wxDataViewCellBase( varianttype, mode )
{
- return true;
+ m_dc = NULL;
}
-bool wxGenericDataViewListModelNotifier::ValueChanged( size_t model_col, size_t model_row )
+wxDataViewCell::~wxDataViewCell()
{
- wxNode *node = GetOwner()->m_viewingColumns.GetFirst();
- while (node)
- {
- wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
- if (viewing_column->m_modelColumn == model_col)
- {
-
- }
-
- node = node->GetNext();
- }
-
- return false;
+ if (m_dc)
+ delete m_dc;
}
-bool wxGenericDataViewListModelNotifier::RowsReordered( size_t *new_order )
+wxDC *wxDataViewCell::GetDC()
{
- wxNode *node = GetOwner()->m_viewingColumns.GetFirst();
- while (node)
+ if (m_dc == NULL)
{
- wxDataViewViewingColumn* viewing_column = (wxDataViewViewingColumn*) node->GetData();
-
- node = node->GetNext();
+ if (GetOwner() == NULL)
+ return NULL;
+ if (GetOwner()->GetOwner() == NULL)
+ return NULL;
+ m_dc = new wxClientDC( GetOwner()->GetOwner() );
}
-
- return false;
-}
-
-bool wxGenericDataViewListModelNotifier::Cleared()
-{
- return false;
+
+ return m_dc;
}
// ---------------------------------------------------------
-// wxDataViewCell
+// wxDataViewCustomCell
// ---------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell, wxDataViewCellBase)
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell)
-wxDataViewCell::wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode ) :
- wxDataViewCellBase( varianttype, mode )
+wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype,
+ wxDataViewCellMode mode ) :
+ wxDataViewCell( varianttype, mode )
{
}
+
// ---------------------------------------------------------
// wxDataViewTextCell
// ---------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCell)
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCustomCell)
wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) :
- wxDataViewCell( varianttype, mode )
+ wxDataViewCustomCell( varianttype, mode )
{
}
return false;
}
+bool wxDataViewTextCell::Render( wxRect cell, wxDC *dc, int state )
+{
+ return false;
+}
+
+wxSize wxDataViewTextCell::GetSize()
+{
+ return wxSize(80,20);
+}
+
// ---------------------------------------------------------
// wxDataViewToggleCell
// ---------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCell)
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCustomCell)
wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype,
wxDataViewCellMode mode ) :
- wxDataViewCell( varianttype, mode )
+ wxDataViewCustomCell( varianttype, mode )
{
}
return false;
}
-// ---------------------------------------------------------
-// wxDataViewCustomCell
-// ---------------------------------------------------------
-
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell)
-
-wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype,
- wxDataViewCellMode mode ) :
- wxDataViewCell( varianttype, mode )
-{
- m_dc = NULL;
-
- Init();
-}
-
-bool wxDataViewCustomCell::Init()
+bool wxDataViewToggleCell::Render( wxRect cell, wxDC *dc, int state )
{
return false;
}
-wxDataViewCustomCell::~wxDataViewCustomCell()
+wxSize wxDataViewToggleCell::GetSize()
{
- if (m_dc)
- delete m_dc;
+ return wxSize(20,20);
}
-wxDC *wxDataViewCustomCell::GetDC()
-{
- if (m_dc == NULL)
- {
- if (GetOwner() == NULL)
- return NULL;
- if (GetOwner()->GetOwner() == NULL)
- return NULL;
- m_dc = new wxClientDC( GetOwner()->GetOwner() );
- }
-
- return m_dc;
-}
-
// ---------------------------------------------------------
// wxDataViewProgressCell
// ---------------------------------------------------------
size_t model_column, int flags ) :
wxDataViewColumnBase( title, cell, model_column, flags )
{
+ m_width = 80;
}
wxDataViewColumn::~wxDataViewColumn()
// wxDataViewHeaderWindow
//-----------------------------------------------------------------------------
-class wxDataViewHeaderWindow: public wxWindow
-{
-public:
- wxDataViewHeaderWindow( wxDataViewCtrl *parent,
- wxWindowID id,
- const wxPoint &pos = wxDefaultPosition,
- const wxSize &size = wxDefaultSize,
- const wxString &name = wxT("wxdataviewctrlheaderwindow") );
- ~wxDataViewHeaderWindow();
-
- void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
- wxDataViewCtrl *GetOwner() { return m_owner; }
-
- void OnPaint( wxPaintEvent &event );
- void OnMouse( wxMouseEvent &event );
- void OnSetFocus( wxFocusEvent &event );
-
-private:
- wxDataViewCtrl *m_owner;
- wxCursor *m_resizeCursor;
-
-private:
- DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindow)
- DECLARE_EVENT_TABLE()
-}
-
-IMPLEMENT_DYNAMIC_CLASS(wxDataViewHeaderWindow, wxWindow)
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewHeaderWindow, wxWindow)
BEGIN_EVENT_TABLE(wxDataViewHeaderWindow,wxWindow)
EVT_PAINT (wxDataViewHeaderWindow::OnPaint)
wxWindow( parent, id, pos, size, 0, name )
{
SetOwner( parent );
-
+
m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event )
{
- wxPaintDC dc;
- PrepareDC( dc );
+ int w, h;
+ GetClientSize( &w, &h );
+
+ wxPaintDC dc( this );
int xpix;
m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
dc.SetFont( GetFont() );
- dc.DrawText( wxT("This is the header..", 5, 5 );
+ size_t cols = GetOwner()->GetNumberOfColumns();
+ size_t i;
+ int xpos = 0;
+ for (i = 0; i < cols; i++)
+ {
+ wxDataViewColumn *col = GetOwner()->GetColumn( i );
+ int width = col->GetWidth();
+
+ // the width of the rect to draw: make it smaller to fit entirely
+ // inside the column rect
+#ifdef __WXMAC__
+ int cw = width;
+ int ch = h;
+#else
+ int cw = width - 2;
+ int ch = h - 2;
+#endif
+
+ wxRendererNative::Get().DrawHeaderButton
+ (
+ this,
+ dc,
+ wxRect(xpos, 0, cw, ch),
+ m_parent->IsEnabled() ? 0
+ : (int)wxCONTROL_DISABLED
+ );
+
+ dc.DrawText( col->GetTitle(), xpos+3, 3 );
+
+ xpos += width;
+ }
}
void wxDataViewHeaderWindow::OnMouse( wxMouseEvent &event )
// wxDataViewMainWindow
//-----------------------------------------------------------------------------
-class wxDataViewMainWindow: public wxWindow
-{
-public:
- wxDataViewMainWindow( wxDataViewCtrl *parent,
- wxWindowID id,
- const wxPoint &pos = wxDefaultPosition,
- const wxSize &size = wxDefaultSize,
- const wxString &name = wxT("wxdataviewctrlmainwindow") );
- ~wxDataViewMainWindow();
-
- void SetOwner( wxDataViewCtrl* owner ) { m_owner = owner; }
- wxDataViewCtrl *GetOwner() { return m_owner; }
-
- void OnPaint( wxPaintEvent &event );
- void OnMouse( wxMouseEvent &event );
- void OnSetFocus( wxFocusEvent &event );
-
-private:
- wxDataViewCtrl *m_owner;
-
-private:
- DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
- DECLARE_EVENT_TABLE()
-}
-
-IMPLEMENT_DYNAMIC_CLASS(wxDataViewMainWindow, wxWindow)
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewMainWindow, wxWindow)
BEGIN_EVENT_TABLE(wxDataViewMainWindow,wxWindow)
EVT_PAINT (wxDataViewMainWindow::OnPaint)
wxWindow( parent, id, pos, size, 0, name )
{
SetOwner( parent );
+
+ // We need to calculate this smartly..
+ m_lineHeight = 20;
+
+ UpdateDisplay();
}
wxDataViewMainWindow::~wxDataViewMainWindow()
{
}
+bool wxDataViewMainWindow::RowAppended()
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::RowPrepended()
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::RowInserted( size_t before )
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::RowDeleted( size_t row )
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::RowChanged( size_t row )
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::ValueChanged( size_t col, size_t row )
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::RowsReordered( size_t *new_order )
+{
+ return false;
+}
+
+bool wxDataViewMainWindow::Cleared()
+{
+ return false;
+}
+
+void wxDataViewMainWindow::UpdateDisplay()
+{
+ m_dirty = true;
+}
+
+void wxDataViewMainWindow::OnInternalIdle()
+{
+ wxWindow::OnInternalIdle();
+
+ if (m_dirty)
+ {
+ RecalculateDisplay();
+ m_dirty = false;
+ }
+}
+
+void wxDataViewMainWindow::RecalculateDisplay()
+{
+ wxDataViewListModel *model = GetOwner()->GetModel();
+ if (!model)
+ {
+ Refresh();
+ return;
+ }
+
+ int width = 0;
+ size_t cols = GetOwner()->GetNumberOfColumns();
+ size_t i;
+ for (i = 0; i < cols; i++)
+ {
+ wxDataViewColumn *col = GetOwner()->GetColumn( i );
+ width += col->GetWidth();
+ }
+
+ int height = model->GetNumberOfRows() * m_lineHeight;
+
+ SetVirtualSize( width, height );
+ GetOwner()->SetScrollRate( 10, m_lineHeight );
+
+ Refresh();
+}
+
+void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
+{
+ wxWindow::ScrollWindow( dx, dy, rect );
+ GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
+}
+
void wxDataViewMainWindow::OnPaint( wxPaintEvent &event )
{
wxPaintDC dc( this );
- PrepareDC( dc );
-
- int dev_x, dev_y;
- CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
+ GetOwner()->PrepareDC( dc );
dc.SetFont( GetFont() );
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
+BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
+ EVT_SIZE(wxDataViewCtrl::OnSize)
+END_EVENT_TABLE()
+
wxDataViewCtrl::~wxDataViewCtrl()
{
if (m_notifier)
const wxPoint& pos, const wxSize& size,
long style, const wxValidator& validator )
{
+ if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator))
+ return false;
+
Init();
#ifdef __WXMAC__
}
#endif
-void wxDataViewCtrl::ScrollWindow( int dx, int dy, const wxRect *rect )
+void wxDataViewCtrl::OnSize( wxSizeEvent &event )
{
- wxDataViewCtrlBase::ScrollWindow( dx, dy, rect );
- m_headerArea->ScrollWindow( dx, 0, rect );
+ // We need to override OnSize so that our scrolled
+ // window a) does call Layout() to use sizers for
+ // positioning the controls but b) does not query
+ // the sizer for their size and use that for setting
+ // the scrollable area as set that ourselves by
+ // calling SetScrollbar() further down.
+
+ Layout();
+
+ AdjustScrollbars();
}
bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model )
if (!wxDataViewCtrlBase::AssociateModel( model ))
return false;
- m_notifier = new wxGenericDataViewListModelNotifier( model );
+ m_notifier = new wxGenericDataViewListModelNotifier( m_clientArea );
model->AddNotifier( m_notifier );
+ m_clientArea->UpdateDisplay();
+
return true;
}
{
if (!wxDataViewCtrlBase::AppendColumn(col))
return false;
-
+
+ m_clientArea->UpdateDisplay();
+
return true;
}