render pages in print preview at idle time, not from OnPaint, to make the UI appear more responsive when preview takes long time to create
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54133 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
7c748f5e5e
commit
b88bf07395
@ -338,6 +338,8 @@ public:
|
||||
const wxString& name = wxT("canvas"));
|
||||
virtual ~wxPreviewCanvas();
|
||||
|
||||
void SetPreview(wxPrintPreviewBase *preview) { m_printPreview = preview; }
|
||||
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnChar(wxKeyEvent &event);
|
||||
// Responds to colour changes
|
||||
@ -347,6 +349,7 @@ private:
|
||||
#if wxUSE_MOUSEWHEEL
|
||||
void OnMouseWheel(wxMouseEvent& event);
|
||||
#endif // wxUSE_MOUSEWHEEL
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
|
||||
wxPrintPreviewBase* m_printPreview;
|
||||
|
||||
@ -519,6 +522,10 @@ public:
|
||||
// The preview canvas should call this from OnPaint
|
||||
virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
|
||||
|
||||
// Updates rendered page by calling RenderPage() if needed, returns true
|
||||
// if there was some change. Preview canvas should call it at idle time
|
||||
virtual bool UpdatePageRendering();
|
||||
|
||||
// This draws a blank page onto the preview canvas
|
||||
virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
|
||||
|
||||
@ -608,6 +615,7 @@ public:
|
||||
virtual wxFrame *GetFrame() const;
|
||||
virtual wxPreviewCanvas *GetCanvas() const;
|
||||
virtual bool PaintPage(wxPreviewCanvas *canvas, wxDC& dc);
|
||||
virtual bool UpdatePageRendering();
|
||||
virtual bool DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc);
|
||||
virtual void AdjustScrollbars(wxPreviewCanvas *canvas);
|
||||
virtual bool RenderPage(int pageNum);
|
||||
|
@ -808,6 +808,7 @@ IMPLEMENT_CLASS(wxPreviewCanvas, wxWindow)
|
||||
BEGIN_EVENT_TABLE(wxPreviewCanvas, wxScrolledWindow)
|
||||
EVT_PAINT(wxPreviewCanvas::OnPaint)
|
||||
EVT_CHAR(wxPreviewCanvas::OnChar)
|
||||
EVT_IDLE(wxPreviewCanvas::OnIdle)
|
||||
EVT_SYS_COLOUR_CHANGED(wxPreviewCanvas::OnSysColourChanged)
|
||||
#if wxUSE_MOUSEWHEEL
|
||||
EVT_MOUSEWHEEL(wxPreviewCanvas::OnMouseWheel)
|
||||
@ -859,6 +860,16 @@ void wxPreviewCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||
}
|
||||
}
|
||||
|
||||
void wxPreviewCanvas::OnIdle(wxIdleEvent& event)
|
||||
{
|
||||
if ( m_printPreview )
|
||||
{
|
||||
if ( m_printPreview->UpdatePageRendering() )
|
||||
Refresh();
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
// Responds to colour changes, and passes event on to children.
|
||||
void wxPreviewCanvas::OnSysColourChanged(wxSysColourChangedEvent& event)
|
||||
{
|
||||
@ -1272,7 +1283,9 @@ void wxPreviewFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
||||
m_printPreview->SetCanvas(NULL);
|
||||
m_printPreview->SetFrame(NULL);
|
||||
}
|
||||
delete m_printPreview;
|
||||
|
||||
m_previewCanvas->SetPreview(NULL);
|
||||
wxDELETE(m_printPreview);
|
||||
|
||||
Destroy();
|
||||
}
|
||||
@ -1396,8 +1409,6 @@ bool wxPrintPreviewBase::SetCurrentPage(int pageNum)
|
||||
{
|
||||
AdjustScrollbars(m_previewCanvas);
|
||||
|
||||
if (!RenderPage(pageNum))
|
||||
return false;
|
||||
m_previewCanvas->Refresh();
|
||||
m_previewCanvas->SetFocus();
|
||||
}
|
||||
@ -1454,13 +1465,21 @@ void wxPrintPreviewBase::CalcRects(wxPreviewCanvas *canvas, wxRect& pageRect, wx
|
||||
}
|
||||
|
||||
|
||||
bool wxPrintPreviewBase::UpdatePageRendering()
|
||||
{
|
||||
if ( m_previewBitmap )
|
||||
return false;
|
||||
|
||||
if ( !RenderPage(m_currentPage) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxPrintPreviewBase::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
|
||||
{
|
||||
DrawBlankPage(canvas, dc);
|
||||
|
||||
if (!m_previewBitmap)
|
||||
if (!RenderPage(m_currentPage))
|
||||
return false;
|
||||
if (!m_previewBitmap)
|
||||
return false;
|
||||
if (!canvas)
|
||||
@ -1616,7 +1635,6 @@ void wxPrintPreviewBase::SetZoom(int percent)
|
||||
if (m_previewCanvas)
|
||||
{
|
||||
AdjustScrollbars(m_previewCanvas);
|
||||
RenderPage(m_currentPage);
|
||||
((wxScrolledWindow *) m_previewCanvas)->Scroll(0, 0);
|
||||
m_previewCanvas->ClearBackground();
|
||||
m_previewCanvas->Refresh();
|
||||
@ -1724,6 +1742,11 @@ bool wxPrintPreview::PaintPage(wxPreviewCanvas *canvas, wxDC& dc)
|
||||
return m_pimpl->PaintPage( canvas, dc );
|
||||
}
|
||||
|
||||
bool wxPrintPreview::UpdatePageRendering()
|
||||
{
|
||||
return m_pimpl->UpdatePageRendering();
|
||||
}
|
||||
|
||||
bool wxPrintPreview::DrawBlankPage(wxPreviewCanvas *canvas, wxDC& dc)
|
||||
{
|
||||
return m_pimpl->DrawBlankPage( canvas, dc );
|
||||
|
Loading…
Reference in New Issue
Block a user