Added windowing and scrolling logic to generic

implementation of wxDataViewCtrl (it runs now).


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38238 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2006-03-21 12:30:06 +00:00
parent 40cc34ec56
commit 4b3feaa75d
3 changed files with 138 additions and 21 deletions

View File

@ -21,6 +21,8 @@
// --------------------------------------------------------- // ---------------------------------------------------------
class WXDLLIMPEXP_CORE wxDataViewCtrl; class WXDLLIMPEXP_CORE wxDataViewCtrl;
class WXDLLIMPEXP_CORE wxDataViewMainWindow;
class WXDLLIMPEXP_CORE wxDataViewHeaderWindow;
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewCell // wxDataViewCell
@ -169,7 +171,11 @@ public:
virtual void SetTitle( const wxString &title ); virtual void SetTitle( const wxString &title );
void SetWidth( int width ) { m_width = width; }
int GetWidth() { return m_width; }
private: private:
int m_width;
protected: protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
@ -191,8 +197,8 @@ public:
wxDataViewCtrl( wxWindow *parent, wxWindowID id, wxDataViewCtrl( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator ) : const wxValidator& validator = wxDefaultValidator )
wxScrollHelperNative(this) : wxScrollHelperNative(this)
{ {
Create(parent, id, pos, size, style, validator ); Create(parent, id, pos, size, style, validator );
} }
@ -210,12 +216,13 @@ public:
virtual bool AppendColumn( wxDataViewColumn *col ); virtual bool AppendColumn( wxDataViewColumn *col );
private: private:
friend class wxDataViewMainWindow;
wxDataViewListModelNotifier *m_notifier; wxDataViewListModelNotifier *m_notifier;
wxWindow *m_clientArea; wxDataViewMainWindow *m_clientArea;
wxWindow *m_headerArea; wxDataViewHeaderWindow *m_headerArea;
private: private:
virtual void ScrollWindow( int dx, int dy, const wxRect *rect ); void OnSize( wxSizeEvent &event );
// we need to return a special WM_GETDLGCODE value to process just the // we need to return a special WM_GETDLGCODE value to process just the
// arrows but let the other navigation characters through // arrows but let the other navigation characters through
@ -228,6 +235,7 @@ private:
private: private:
DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
DECLARE_NO_COPY_CLASS(wxDataViewCtrl) DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
DECLARE_EVENT_TABLE()
}; };

View File

@ -381,6 +381,7 @@ wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell,
size_t model_column, int flags ) : size_t model_column, int flags ) :
wxDataViewColumnBase( title, cell, model_column, flags ) wxDataViewColumnBase( title, cell, model_column, flags )
{ {
m_width = 80;
} }
wxDataViewColumn::~wxDataViewColumn() wxDataViewColumn::~wxDataViewColumn()
@ -453,8 +454,10 @@ wxDataViewHeaderWindow::~wxDataViewHeaderWindow()
void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event ) void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event )
{ {
wxPaintDC dc; int w, h;
PrepareDC( dc ); GetClientSize( &w, &h );
wxPaintDC dc( this );
int xpix; int xpix;
m_owner->GetScrollPixelsPerUnit( &xpix, NULL ); m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
@ -467,7 +470,37 @@ void wxDataViewHeaderWindow::OnPaint( wxPaintEvent &event )
dc.SetFont( GetFont() ); 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 ) void wxDataViewHeaderWindow::OnMouse( wxMouseEvent &event )
@ -500,8 +533,15 @@ public:
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
void OnSetFocus( wxFocusEvent &event ); void OnSetFocus( wxFocusEvent &event );
void UpdateDisplay();
void RecalculateDisplay();
void OnInternalIdle();
void ScrollWindow( int dx, int dy, const wxRect *rect );
private: private:
wxDataViewCtrl *m_owner; wxDataViewCtrl *m_owner;
int m_lineHeight;
bool m_dirty;
private: private:
DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow) DECLARE_DYNAMIC_CLASS(wxDataViewMainWindow)
@ -521,20 +561,70 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i
wxWindow( parent, id, pos, size, 0, name ) wxWindow( parent, id, pos, size, 0, name )
{ {
SetOwner( parent ); SetOwner( parent );
// We need to calculate this smartly..
m_lineHeight = 20;
UpdateDisplay();
} }
wxDataViewMainWindow::~wxDataViewMainWindow() wxDataViewMainWindow::~wxDataViewMainWindow()
{ {
} }
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 ) void wxDataViewMainWindow::OnPaint( wxPaintEvent &event )
{ {
wxPaintDC dc( this ); wxPaintDC dc( this );
PrepareDC( dc ); GetOwner()->PrepareDC( dc );
int dev_x, dev_y;
m_owner->CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
dc.SetFont( GetFont() ); dc.SetFont( GetFont() );
@ -557,6 +647,10 @@ void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase) IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
BEGIN_EVENT_TABLE(wxDataViewCtrl, wxDataViewCtrlBase)
EVT_SIZE(wxDataViewCtrl::OnSize)
END_EVENT_TABLE()
wxDataViewCtrl::~wxDataViewCtrl() wxDataViewCtrl::~wxDataViewCtrl()
{ {
if (m_notifier) if (m_notifier)
@ -572,6 +666,9 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxValidator& validator ) long style, const wxValidator& validator )
{ {
if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle|wxSUNKEN_BORDER, validator))
return false;
Init(); Init();
#ifdef __WXMAC__ #ifdef __WXMAC__
@ -610,10 +707,18 @@ WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
} }
#endif #endif
void wxDataViewCtrl::ScrollWindow( int dx, int dy, const wxRect *rect ) void wxDataViewCtrl::OnSize( wxSizeEvent &event )
{ {
wxDataViewCtrlBase::ScrollWindow( dx, dy, rect ); // We need to override OnSize so that our scrolled
m_headerArea->ScrollWindow( dx, 0, rect ); // 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 ) bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model )
@ -625,6 +730,8 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model )
model->AddNotifier( m_notifier ); model->AddNotifier( m_notifier );
m_clientArea->UpdateDisplay();
return true; return true;
} }
@ -633,6 +740,8 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
if (!wxDataViewCtrlBase::AppendColumn(col)) if (!wxDataViewCtrlBase::AppendColumn(col))
return false; return false;
m_clientArea->UpdateDisplay();
return true; return true;
} }