summaryrefslogtreecommitdiff
path: root/vcl/unx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-06-04 11:34:28 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-06-06 09:57:53 +0200
commita30a5d1b8af18d19526f1980df41857f455cc8ef (patch)
treee8add75abca3c336cbc46936a7d19028ba4251aa /vcl/unx
parent7665246ac8addc002f74e3a9b22d1baeda448af3 (diff)
weld AboutDialog
use a native GtkAboutDialog on that platform and refactor the current cui about dialog body to form the body of a vcl AboutDialog use add_button to add the buttons to whichever is preferred of the headerbar or action-area Change-Id: I67e0b36dcb8d3fa08ec4f0397b0f6185b0778675 Reviewed-on: https://gerrit.libreoffice.org/73439 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r--vcl/unx/gtk3/gtk3gtkinst.cxx173
1 files changed, 170 insertions, 3 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index bd1f8a6f3abe..c7459a81a1f4 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1817,6 +1817,13 @@ public:
return gtk_widget_get_vexpand(m_pWidget);
}
+ virtual void set_secondary(bool bSecondary) override
+ {
+ GtkWidget* pParent = gtk_widget_get_parent(m_pWidget);
+ if (pParent && GTK_IS_BUTTON_BOX(pParent))
+ gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(pParent), m_pWidget, bSecondary);
+ }
+
virtual void set_margin_top(int nMargin) override
{
gtk_widget_set_margin_top(m_pWidget, nMargin);
@@ -2288,10 +2295,31 @@ namespace
GdkPixbuf* getPixbuf(const VirtualDevice& rDevice)
{
Size aSize(rDevice.GetOutputSizePixel());
- cairo_surface_t* surface = get_underlying_cairo_surface(rDevice);
+ cairo_surface_t* orig_surface = get_underlying_cairo_surface(rDevice);
double m_fXScale, m_fYScale;
- dl_cairo_surface_get_device_scale(surface, &m_fXScale, &m_fYScale);
- return gdk_pixbuf_get_from_surface(surface, 0, 0, aSize.Width() * m_fXScale, aSize.Height() * m_fYScale);
+ dl_cairo_surface_get_device_scale(orig_surface, &m_fXScale, &m_fYScale);
+
+ cairo_surface_t* surface;
+ if (m_fXScale != 1.0 || m_fYScale != -1)
+ {
+ surface = cairo_surface_create_similar_image(orig_surface,
+ CAIRO_FORMAT_ARGB32,
+ aSize.Width(),
+ aSize.Height());
+ cairo_t* cr = cairo_create(surface);
+ cairo_set_source_surface(cr, orig_surface, 0, 0);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ }
+ else
+ surface = orig_surface;
+
+ GdkPixbuf* pRet = gdk_pixbuf_get_from_surface(surface, 0, 0, aSize.Width(), aSize.Height());
+
+ if (surface != orig_surface)
+ cairo_surface_destroy(surface);
+
+ return pRet;
}
GtkWidget* image_new_from_virtual_device(const VirtualDevice& rImageSurface)
@@ -3349,6 +3377,118 @@ public:
}
};
+class GtkInstanceAboutDialog : public GtkInstanceDialog, public virtual weld::AboutDialog
+{
+private:
+ GtkAboutDialog* m_pAboutDialog;
+ GtkCssProvider* m_pCssProvider;
+ std::unique_ptr<utl::TempFile> mxBackgroundImage;
+public:
+ GtkInstanceAboutDialog(GtkAboutDialog* pAboutDialog, GtkInstanceBuilder* pBuilder, bool bTakeOwnership)
+ : GtkInstanceDialog(GTK_DIALOG(pAboutDialog), pBuilder, bTakeOwnership)
+ , m_pAboutDialog(pAboutDialog)
+ , m_pCssProvider(nullptr)
+ {
+ }
+
+ virtual void set_version(const OUString& rVersion) override
+ {
+ gtk_about_dialog_set_version(m_pAboutDialog, OUStringToOString(rVersion, RTL_TEXTENCODING_UTF8).getStr());
+ }
+
+ virtual void set_copyright(const OUString& rCopyright) override
+ {
+ gtk_about_dialog_set_copyright(m_pAboutDialog, OUStringToOString(rCopyright, RTL_TEXTENCODING_UTF8).getStr());
+ }
+
+ virtual void set_website(const OUString& rURL) override
+ {
+ OString sURL(OUStringToOString(rURL, RTL_TEXTENCODING_UTF8));
+ gtk_about_dialog_set_website(m_pAboutDialog, sURL.isEmpty() ? nullptr : sURL.getStr());
+ }
+
+ virtual void set_website_label(const OUString& rLabel) override
+ {
+ OString sLabel(OUStringToOString(rLabel, RTL_TEXTENCODING_UTF8));
+ gtk_about_dialog_set_website_label(m_pAboutDialog, sLabel.isEmpty() ? nullptr : sLabel.getStr());
+ }
+
+ virtual OUString get_website_label() const override
+ {
+ const gchar* pText = gtk_about_dialog_get_website_label(m_pAboutDialog);
+ return OUString(pText, pText ? strlen(pText) : 0, RTL_TEXTENCODING_UTF8);
+ }
+
+ virtual void set_logo(VirtualDevice* pDevice) override
+ {
+ GdkPixbuf* pixbuf = pDevice ? getPixbuf(*pDevice) : nullptr;
+ if (!pixbuf)
+ gtk_about_dialog_set_logo(m_pAboutDialog, nullptr);
+ else
+ {
+ gtk_about_dialog_set_logo(m_pAboutDialog, pixbuf);
+ g_object_unref(pixbuf);
+ }
+ }
+
+ virtual void set_background(VirtualDevice* pDevice) override
+ {
+ GtkStyleContext *pStyleContext = gtk_widget_get_style_context(GTK_WIDGET(m_pAboutDialog));
+ if (m_pCssProvider)
+ {
+ gtk_style_context_remove_provider(pStyleContext, GTK_STYLE_PROVIDER(m_pCssProvider));
+ m_pCssProvider= nullptr;
+ }
+
+ mxBackgroundImage.reset();
+
+ if (pDevice)
+ {
+ mxBackgroundImage.reset(new utl::TempFile());
+ mxBackgroundImage->EnableKillingFile(true);
+
+ OString sOutput = mxBackgroundImage->GetFileName().toUtf8();
+
+ cairo_surface_t* orig_surface = get_underlying_cairo_surface(*pDevice);
+ double m_fXScale, m_fYScale;
+ dl_cairo_surface_get_device_scale(orig_surface, &m_fXScale, &m_fYScale);
+
+ cairo_surface_t* surface;
+ if (m_fXScale != 1.0 || m_fYScale != -1)
+ {
+ Size aSize(pDevice->GetOutputSizePixel());
+ surface = cairo_surface_create_similar_image(orig_surface,
+ CAIRO_FORMAT_ARGB32,
+ aSize.Width(),
+ aSize.Height());
+ cairo_t* cr = cairo_create(surface);
+ cairo_set_source_surface(cr, orig_surface, 0, 0);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ }
+ else
+ surface = orig_surface;
+
+ cairo_surface_write_to_png(surface, sOutput.getStr());
+
+ if (surface != orig_surface)
+ cairo_surface_destroy(surface);
+
+ m_pCssProvider = gtk_css_provider_new();
+ OUString aBuffer = "* { background-image: url(\"" + mxBackgroundImage->GetURL() + "\"); }";
+ OString aResult = OUStringToOString(aBuffer, RTL_TEXTENCODING_UTF8);
+ gtk_css_provider_load_from_data(m_pCssProvider, aResult.getStr(), aResult.getLength(), nullptr);
+ gtk_style_context_add_provider(pStyleContext, GTK_STYLE_PROVIDER(m_pCssProvider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+ }
+
+ virtual ~GtkInstanceAboutDialog() override
+ {
+ set_background(nullptr);
+ }
+};
+
class GtkInstanceFrame : public GtkInstanceContainer, public virtual weld::Frame
{
private:
@@ -10057,6 +10197,24 @@ private:
set_primary_text(pMessageDialog, (*m_pStringReplace)(get_primary_text(pMessageDialog)));
set_secondary_text(pMessageDialog, (*m_pStringReplace)(get_secondary_text(pMessageDialog)));
}
+ else if (GTK_IS_ABOUT_DIALOG(pWindow))
+ {
+ GtkAboutDialog* pAboutDialog = GTK_ABOUT_DIALOG(pWindow);
+ const gchar *pComments = gtk_about_dialog_get_comments(pAboutDialog);
+ if (pComments)
+ {
+ OUString sComments(pComments, strlen(pComments), RTL_TEXTENCODING_UTF8);
+ sComments = (*m_pStringReplace)(sComments);
+ gtk_about_dialog_set_comments(pAboutDialog, OUStringToOString(sComments, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ const gchar *pProgramName = gtk_about_dialog_get_program_name(pAboutDialog);
+ if (pProgramName)
+ {
+ OUString sProgramName(pProgramName, strlen(pProgramName), RTL_TEXTENCODING_UTF8);
+ sProgramName = (*m_pStringReplace)(sProgramName);
+ gtk_about_dialog_set_program_name(pAboutDialog, OUStringToOString(sProgramName, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ }
}
}
}
@@ -10176,6 +10334,15 @@ public:
return std::make_unique<GtkInstanceMessageDialog>(pMessageDialog, this, bTakeOwnership);
}
+ virtual std::unique_ptr<weld::AboutDialog> weld_about_dialog(const OString &id, bool bTakeOwnership) override
+ {
+ GtkAboutDialog* pAboutDialog = GTK_ABOUT_DIALOG(gtk_builder_get_object(m_pBuilder, id.getStr()));
+ if (!pAboutDialog)
+ return nullptr;
+ gtk_window_set_transient_for(GTK_WINDOW(pAboutDialog), GTK_WINDOW(gtk_widget_get_toplevel(m_pParentWidget)));
+ return std::make_unique<GtkInstanceAboutDialog>(pAboutDialog, this, bTakeOwnership);
+ }
+
virtual std::unique_ptr<weld::Dialog> weld_dialog(const OString &id, bool bTakeOwnership) override
{
GtkDialog* pDialog = GTK_DIALOG(gtk_builder_get_object(m_pBuilder, id.getStr()));