diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-07 20:27:51 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-08 13:39:11 +0200 |
commit | 19fd82ac6e08896bd17169d1b6ea090458fc18da (patch) | |
tree | a179a2651dc58d4574833ac39ab0ea70f1dd8110 /vcl | |
parent | 2d8e2813ddc87f7ce03b97e4d603df11613461f0 (diff) |
distinguish between dialog screenshoting and rendering a widget
Change-Id: I43ee0c68d72c97a15d26e2ffea577c2a44ba91e8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98326
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/salvtables.hxx | 6 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 12 | ||||
-rw-r--r-- | vcl/source/window/syswin.cxx | 12 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 40 |
4 files changed, 46 insertions, 24 deletions
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 377653c291ec..062bf9bd66ee 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -387,7 +387,7 @@ public: virtual void set_highlight_background() override; - virtual void draw(VirtualDevice& rOutput) override; + virtual void draw(OutputDevice& rOutput, const tools::Rectangle& rRect) override; SystemWindow* getSystemWindow(); }; @@ -486,10 +486,10 @@ public: virtual void HandleEventListener(VclWindowEvent& rEvent) override; - virtual void draw(VirtualDevice& rOutput) override; - virtual weld::ScreenShotCollection collect_screenshot_data() override; + virtual VclPtr<VirtualDevice> screenshot() override; + virtual ~SalInstanceWindow() override; }; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index f3778f91340c..81c2e38085c3 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1133,10 +1133,12 @@ std::unique_ptr<weld::Container> SalInstanceWidget::weld_parent() const return std::make_unique<SalInstanceContainer>(pParent, m_pBuilder, false); } -void SalInstanceWidget::draw(VirtualDevice& rOutput) +void SalInstanceWidget::draw(OutputDevice& rOutput, const tools::Rectangle& rRect) { - rOutput.SetOutputSizePixel(m_xWidget->GetSizePixel()); - m_xWidget->PaintToDevice(&rOutput, Point()); + Size aOrigSize(m_xWidget->GetSizePixel()); + m_xWidget->SetSizePixel(rRect.GetSize()); + m_xWidget->Draw(&rOutput, rRect.TopLeft(), DrawFlags::NONE); + m_xWidget->SetSizePixel(aOrigSize); } namespace @@ -1321,11 +1323,11 @@ void SalInstanceWindow::HandleEventListener(VclWindowEvent& rEvent) SalInstanceContainer::HandleEventListener(rEvent); } -void SalInstanceWindow::draw(VirtualDevice& rOutput) +VclPtr<VirtualDevice> SalInstanceWindow::screenshot() { SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(m_xWindow.get()); assert(pSysWin); - pSysWin->createScreenshot(rOutput); + return pSysWin->createScreenshot(); } weld::ScreenShotCollection SalInstanceWindow::collect_screenshot_data() diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index 3c154dd228c7..a3f5a2a933fd 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -1156,7 +1156,7 @@ void SystemWindow::doDeferredInit(WinBits /*nBits*/) SAL_WARN("vcl.layout", "SystemWindow in layout without doDeferredInit impl"); } -void SystemWindow::createScreenshot(VirtualDevice& rOutput) +VclPtr<VirtualDevice> SystemWindow::createScreenshot() { // same prerequisites as in Execute() setDeferredProperties(); @@ -1165,11 +1165,15 @@ void SystemWindow::createScreenshot(VirtualDevice& rOutput) ToTop(); ensureRepaint(); - Point aPos; Size aSize(GetOutputSizePixel()); - rOutput.SetOutputSizePixel(aSize); - rOutput.DrawOutDev(aPos, aSize, aPos, aSize, *this); + VclPtr<VirtualDevice> xOutput(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT)); + xOutput->SetOutputSizePixel(aSize); + + Point aPos; + xOutput->DrawOutDev(aPos, aSize, aPos, aSize, *this); + + return xOutput; } void SystemWindow::PrePaint(vcl::RenderContext& rRenderContext) diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 7ff4005af8b3..cba5c662baff 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3038,7 +3038,7 @@ public: return xRet; } - virtual void draw(VirtualDevice& rOutput) override + virtual void draw(OutputDevice& rOutput, const tools::Rectangle& rRect) override { // detect if we have to manually setup its size bool bAlreadyRealized = gtk_widget_get_realized(m_pWidget); @@ -3046,30 +3046,43 @@ public: bool bAlreadyVisible = gtk_widget_get_visible(m_pWidget); // has to be mapped for draw to work bool bAlreadyMapped = gtk_widget_get_mapped(m_pWidget); + if (!bAlreadyVisible) gtk_widget_show(m_pWidget); - - GtkAllocation allocation; - if (!bAlreadyRealized) gtk_widget_realize(m_pWidget); - if (!bAlreadyMapped) gtk_widget_map(m_pWidget); + assert(gtk_widget_is_drawable(m_pWidget)); // all that should result in this holding + + Size aSize(rRect.GetSize()); + + GtkAllocation aOrigAllocation; + gtk_widget_get_allocation(m_pWidget, &aOrigAllocation); + + GtkAllocation aNewAllocation {aOrigAllocation.x, + aOrigAllocation.y, + static_cast<int>(aSize.Width()), + static_cast<int>(aSize.Height()) }; + gtk_widget_set_allocation(m_pWidget, &aNewAllocation); + if (GTK_IS_CONTAINER(m_pWidget)) gtk_container_resize_children(GTK_CONTAINER(m_pWidget)); - gtk_widget_get_allocation(m_pWidget, &allocation); - - rOutput.SetOutputSizePixel(Size(allocation.width, allocation.height)); - cairo_surface_t* pSurface = get_underlying_cairo_surface(rOutput); + VclPtr<VirtualDevice> xOutput(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT)); + xOutput->SetOutputSizePixel(aSize); + cairo_surface_t* pSurface = get_underlying_cairo_surface(*xOutput); cairo_t* cr = cairo_create(pSurface); gtk_widget_draw(m_pWidget, cr); cairo_destroy(cr); + gtk_widget_set_allocation(m_pWidget, &aOrigAllocation); + + rOutput.DrawOutDev(rRect.TopLeft(), aSize, Point(), aSize, *xOutput); + if (!bAlreadyVisible) gtk_widget_hide(m_pWidget); if (!bAlreadyMapped) @@ -4066,7 +4079,7 @@ public: g_signal_handler_unblock(m_pWidget, m_nToplevelFocusChangedSignalId); } - virtual void draw(VirtualDevice& rOutput) override + virtual VclPtr<VirtualDevice> screenshot() override { // detect if we have to manually setup its size bool bAlreadyRealized = gtk_widget_get_realized(GTK_WIDGET(m_pWindow)); @@ -4087,8 +4100,9 @@ public: gtk_widget_size_allocate(GTK_WIDGET(m_pWindow), &allocation); } - rOutput.SetOutputSizePixel(get_size()); - cairo_surface_t* pSurface = get_underlying_cairo_surface(rOutput); + VclPtr<VirtualDevice> xOutput(VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT)); + xOutput->SetOutputSizePixel(get_size()); + cairo_surface_t* pSurface = get_underlying_cairo_surface(*xOutput); cairo_t* cr = cairo_create(pSurface); Point aOffset = get_csd_offset(GTK_WIDGET(m_pWindow)); @@ -4109,6 +4123,8 @@ public: gtk_widget_hide(GTK_WIDGET(m_pWindow)); if (!bAlreadyRealized) gtk_widget_unrealize(GTK_WIDGET(m_pWindow)); + + return xOutput; } virtual weld::ScreenShotCollection collect_screenshot_data() override |