include/vcl/weld.hxx | 5 +++-- vcl/inc/salvtables.hxx | 2 ++ vcl/source/app/salvtables.cxx | 6 ++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-)
New commits: commit 208d931861be4d5cf571c404f517fb5c26499aa0 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu May 21 12:48:34 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri May 22 20:39:36 2020 +0200 support rendering a widget snapshot to an OutputDevice Change-Id: I7beecd8f9579d5ae4b60a839f4a71c3238e0666d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94645 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index fd734309d6a9..a57f7f4321c3 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -272,6 +272,9 @@ public: virtual void connect_get_property_tree(const Link<boost::property_tree::ptree&, void>& rLink) = 0; + // render the widget to an output device + virtual void draw(VirtualDevice& rOutput) = 0; + virtual ~Widget() {} }; @@ -461,8 +464,6 @@ public: virtual void resize_to_request() = 0; - // render the dialog for a screenshot - virtual void draw(VirtualDevice& rOutput) = 0; // collect positions of widgets and their help ids for screenshot purposes virtual ScreenShotCollection collect_screenshot_data() = 0; }; diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index 6cc85731952e..86b9d0aec5bf 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -390,6 +390,8 @@ public: virtual void set_highlight_background() override; + virtual void draw(VirtualDevice& rOutput) override; + SystemWindow* getSystemWindow(); }; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index b3c9d2cfb77d..67cb4fad45e1 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1135,6 +1135,12 @@ std::unique_ptr<weld::Container> SalInstanceWidget::weld_parent() const return std::make_unique<SalInstanceContainer>(pParent, m_pBuilder, false); } +void SalInstanceWidget::draw(VirtualDevice& rOutput) +{ + rOutput.SetOutputSizePixel(m_xWidget->GetSizePixel()); + m_xWidget->PaintToDevice(&rOutput, Point()); +} + namespace { class SalInstanceBox : public SalInstanceContainer, public virtual weld::Box diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 530a115bd96b..16b2a1ae1d7c 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3065,6 +3065,46 @@ public: xRet->SetBackground(COL_TRANSPARENT); return xRet; } + + virtual void draw(VirtualDevice& rOutput) override + { + // detect if we have to manually setup its size + bool bAlreadyRealized = gtk_widget_get_realized(m_pWidget); + // has to be visible for draw to work + 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); + + 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); + cairo_t* cr = cairo_create(pSurface); + + gtk_widget_draw(m_pWidget, cr); + + cairo_destroy(cr); + + if (!bAlreadyVisible) + gtk_widget_hide(m_pWidget); + if (!bAlreadyMapped) + gtk_widget_unmap(m_pWidget); + if (!bAlreadyRealized) + gtk_widget_unrealize(m_pWidget); + } }; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits