summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Repository.mk1
-rw-r--r--vcl/Executable_ui-previewer.mk58
-rw-r--r--vcl/Library_vcl.mk2
-rw-r--r--vcl/Module_vcl.mk1
-rw-r--r--vcl/Package_inc.mk1
-rw-r--r--vcl/inc/vcl/builder.hxx53
-rw-r--r--vcl/qa/cppunit/builder/demo.ui72
-rw-r--r--vcl/source/uipreviewer/previewer.cxx66
-rw-r--r--vcl/source/window/builder.cxx208
9 files changed, 462 insertions, 0 deletions
diff --git a/Repository.mk b/Repository.mk
index 68ddbfcd0a9e..62ca8c6467c7 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -99,6 +99,7 @@ $(eval $(call gb_Helper_register_executables,OOO, \
$(if $(filter $(GUIBASE)$(ENABLE_KDE),unxTRUE), \
kdefilepicker \
) \
+ ui-previewer \
))
ifeq ($(OS),WNT)
diff --git a/vcl/Executable_ui-previewer.mk b/vcl/Executable_ui-previewer.mk
new file mode 100644
index 000000000000..0bad66574ebf
--- /dev/null
+++ b/vcl/Executable_ui-previewer.mk
@@ -0,0 +1,58 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# Major Contributor(s):
+# Copyright (C) 2012 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
+# (initial developer)
+#
+# All Rights Reserved.
+#
+# For minor contributions see the git repository.
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+$(eval $(call gb_Executable_Executable,ui-previewer))
+
+$(eval $(call gb_Executable_set_include,ui-previewer,\
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_Executable_add_api,ui-previewer,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_Executable_add_linked_static_libs,ui-previewer,\
+ vclmain \
+))
+
+$(eval $(call gb_Executable_add_linked_libs,ui-previewer,\
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ tl \
+ ucbhelper \
+ vcl \
+ $(gb_STDLIBS) \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,ui-previewer,\
+ vcl/source/uipreviewer/previewer \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 02f52320b04d..86435a2ba352 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -83,6 +83,7 @@ $(eval $(call gb_Library_use_libraries,vcl,\
i18nutil \
cppu \
sal \
+ xmlreader \
$(gb_STDLIBS) \
))
@@ -250,6 +251,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/window/arrange \
vcl/source/window/brdwin \
vcl/source/window/btndlg \
+ vcl/source/window/builder \
vcl/source/window/cmdevt \
vcl/source/window/cursor \
vcl/source/window/decoview \
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 8789813084f5..bcf039cd6910 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -35,6 +35,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
Library_vcl \
Package_inc \
StaticLibrary_vclmain \
+ Executable_ui-previewer \
))
ifeq ($(GUIBASE),unx)
diff --git a/vcl/Package_inc.mk b/vcl/Package_inc.mk
index cbdeb36234bc..c9868e3c44b2 100644
--- a/vcl/Package_inc.mk
+++ b/vcl/Package_inc.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/bitmapex.hxx,vcl/bitmapex.hxx)
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/bitmap.hxx,vcl/bitmap.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/bmpacc.hxx,vcl/bmpacc.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/btndlg.hxx,vcl/btndlg.hxx))
+$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/builder.hxx,vcl/builder.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/button.hxx,vcl/button.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/canvastools.hxx,vcl/canvastools.hxx))
$(eval $(call gb_Package_add_file,vcl_inc,inc/vcl/cmdevt.h,vcl/cmdevt.h))
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
new file mode 100644
index 000000000000..4c2ce32d4158
--- /dev/null
+++ b/vcl/inc/vcl/builder.hxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Caolán McNamara <caolanm@redhat.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _VCLBUILDER_HXX
+#define _VCLBUILDER_HXX
+
+#include <vcl/dllapi.h>
+#include <vcl/window.hxx>
+#include <xmlreader/xmlreader.hxx>
+#include <vector>
+
+class VCL_DLLPUBLIC VclBuilder
+{
+private:
+ std::vector<Window*> m_aChildren;
+public:
+ VclBuilder(Window *pParent, rtl::OUString sUIFile);
+ ~VclBuilder();
+ Window *get_widget_root();
+private:
+ Window *makeObject(Window *pParent, xmlreader::Span &name);
+
+ void handleObject(Window *pParent, xmlreader::XmlReader &reader);
+ void handleProperty(Window *pWindow, xmlreader::XmlReader &reader);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/builder/demo.ui b/vcl/qa/cppunit/builder/demo.ui
new file mode 100644
index 000000000000..d6bd41b8eac0
--- /dev/null
+++ b/vcl/qa/cppunit/builder/demo.ui
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkDialog" id="dialog1">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label">Hello</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label">World</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Hello World</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button2</action-widget>
+ <action-widget response="0">button1</action-widget>
+ </action-widgets>
+ </object>
+</interface>
diff --git a/vcl/source/uipreviewer/previewer.cxx b/vcl/source/uipreviewer/previewer.cxx
new file mode 100644
index 000000000000..9b5fa912ed8c
--- /dev/null
+++ b/vcl/source/uipreviewer/previewer.cxx
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <ucbhelper/configurationkeys.hxx>
+#include <ucbhelper/contentbroker.hxx>
+#include <vcl/builder.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/svapp.hxx>
+
+class UIPreviewApp : public Application
+{
+public:
+ virtual int Main();
+};
+
+using namespace com::sun::star;
+
+int UIPreviewApp::Main()
+{
+ std::vector<rtl::OUString> uifiles;
+ for (sal_uInt16 i = 0; i < GetCommandLineParamCount(); ++i)
+ uifiles.push_back(GetCommandLineParam(i));
+
+ if (uifiles.empty())
+ {
+ fprintf(stderr, "Usage: ui-previewer file.ui\n");
+ return EXIT_FAILURE;
+ }
+
+ uno::Reference<uno::XComponentContext> xContext =
+ cppu::defaultBootstrap_InitialComponentContext();
+ uno::Reference<lang::XMultiComponentFactory> xFactory =
+ xContext->getServiceManager();
+ uno::Reference<lang::XMultiServiceFactory> xSFactory =
+ uno::Reference<lang::XMultiServiceFactory> (xFactory, uno::UNO_QUERY_THROW);
+ comphelper::setProcessServiceFactory(xSFactory);
+
+ // Create UCB.
+ uno::Sequence< uno::Any > aArgs(2);
+ aArgs[ 0 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UCB_CONFIGURATION_KEY1_LOCAL));
+ aArgs[ 1 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UCB_CONFIGURATION_KEY2_OFFICE));
+ ::ucbhelper::ContentBroker::initialize(xSFactory, aArgs);
+
+ VclBuilder aBuilder(NULL, uifiles[0]);
+ Window *pWindow = aBuilder.get_widget_root();
+ Dialog *pDialog = dynamic_cast<Dialog*>(pWindow);
+ if (pDialog)
+ {
+ pDialog->Execute();
+ }
+ else
+ {
+ fprintf(stderr, "to-do: no toplevel dialog, make one\n");
+ }
+
+ ::ucbhelper::ContentBroker::deinitialize();
+
+ return EXIT_SUCCESS;
+}
+
+UIPreviewApp aApp;
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
new file mode 100644
index 000000000000..0378ea9ba9b0
--- /dev/null
+++ b/vcl/source/window/builder.cxx
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Caolán McNamara <caolanm@redhat.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <vcl/builder.hxx>
+#include <vcl/button.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/fixed.hxx>
+#include <vcl/layout.hxx>
+
+VclBuilder::VclBuilder(Window *pParent, rtl::OUString sUri)
+{
+ xmlreader::XmlReader reader(sUri);
+
+ while(1)
+ {
+ xmlreader::Span name;
+ int nsId;
+ xmlreader::XmlReader::Result res = reader.nextItem(
+ xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
+
+ if (res == xmlreader::XmlReader::RESULT_BEGIN &&
+ name.equals(RTL_CONSTASCII_STRINGPARAM("object")))
+ {
+ handleObject(pParent, reader);
+ }
+
+ rtl::OString sFoo(name.begin, name.length);
+ fprintf(stderr, "interface level is %s\n", sFoo.getStr());
+ if (res == xmlreader::XmlReader::RESULT_DONE)
+ break;
+ }
+
+ for (std::vector<Window*>::iterator aI = m_aChildren.begin(),
+ aEnd = m_aChildren.end(); aI != aEnd; ++aI)
+ {
+ Window *pWindow = *aI;
+ if (pWindow)
+ {
+ pWindow->Show();
+ }
+ }
+}
+
+VclBuilder::~VclBuilder()
+{
+ for (std::vector<Window*>::reverse_iterator aI = m_aChildren.rbegin(),
+ aEnd = m_aChildren.rend(); aI != aEnd; ++aI)
+ {
+ Window *pWindow = *aI;
+ delete pWindow;
+ }
+}
+
+Window *VclBuilder::makeObject(Window *pParent, xmlreader::Span &name)
+{
+ Window *pWindow = NULL;
+ if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkDialog")))
+ {
+ pWindow = new Dialog(pParent, WB_SIZEMOVE);
+ }
+ else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkBox")))
+ {
+ pWindow = new VclHBox(pParent);
+ }
+ else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkButton")))
+ {
+ pWindow = new PushButton(pParent);
+ }
+ else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkLabel")))
+ {
+ pWindow = new FixedText(pParent);
+ }
+ else
+ {
+ fprintf(stderr, "TO-DO, implement %s\n",
+ rtl::OString(name.begin, name.length).getStr());
+ }
+ fprintf(stderr, "created %p child of %p\n", pWindow, pParent);
+ return pWindow;
+}
+
+void VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader)
+{
+ Window *pCurrentChild = NULL;
+
+ xmlreader::Span name;
+ int nsId;
+
+ while (reader.nextAttribute(&nsId, &name)) {
+ rtl::OString sFoo(name.begin, name.length);
+ fprintf(stderr, "objectlevel attribute: is %s\n", sFoo.getStr());
+
+ if (name.equals(RTL_CONSTASCII_STRINGPARAM("class")))
+ {
+ name = reader.getAttributeValue(false);
+ pCurrentChild = makeObject(pParent, name);
+ if (!pCurrentChild)
+ {
+ fprintf(stderr, "missing object!\n");
+ }
+
+ if (pCurrentChild)
+ m_aChildren.push_back(pCurrentChild);
+ }
+ }
+
+ if (!pCurrentChild)
+ {
+ fprintf(stderr, "missing object!\n");
+ pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back();
+ }
+
+ int nLevel = 1;
+
+ while(1)
+ {
+ xmlreader::XmlReader::Result res = reader.nextItem(
+ xmlreader::XmlReader::TEXT_NONE, &name, &nsId);
+
+ if (res == xmlreader::XmlReader::RESULT_DONE)
+ break;
+
+ rtl::OString sFoo(name.begin, name.length);
+ fprintf(stderr, "objectlevel: is %s %d\n", sFoo.getStr(),
+ res);
+
+ if (res == xmlreader::XmlReader::RESULT_BEGIN)
+ ++nLevel;
+
+ if (res == xmlreader::XmlReader::RESULT_BEGIN &&
+ name.equals(RTL_CONSTASCII_STRINGPARAM("object")))
+ {
+ handleObject(pCurrentChild, reader);
+ }
+
+ if (res == xmlreader::XmlReader::RESULT_BEGIN &&
+ name.equals(RTL_CONSTASCII_STRINGPARAM("property")))
+ {
+ handleProperty(pCurrentChild, reader);
+ }
+
+ if (res == xmlreader::XmlReader::RESULT_END)
+ {
+ --nLevel;
+ }
+
+ if (!nLevel)
+ break;
+ }
+}
+
+void VclBuilder::handleProperty(Window *pWindow, xmlreader::XmlReader &reader)
+{
+ if (!pWindow)
+ return;
+
+ xmlreader::Span name;
+ int nsId;
+
+ while (reader.nextAttribute(&nsId, &name)) {
+ rtl::OString sFoo(name.begin, name.length);
+ fprintf(stderr, "property attribute: is %s\n", sFoo.getStr());
+
+ if (name.equals(RTL_CONSTASCII_STRINGPARAM("name")))
+ {
+ name = reader.getAttributeValue(false);
+ if (name.equals(RTL_CONSTASCII_STRINGPARAM("label")))
+ {
+ reader.nextItem(
+ xmlreader::XmlReader::TEXT_NORMALIZED, &name, &nsId);
+ pWindow->SetText(rtl::OUString(name.begin, name.length, RTL_TEXTENCODING_UTF8));
+ }
+ }
+ }
+}
+
+
+Window *VclBuilder::get_widget_root()
+{
+ return m_aChildren.empty() ? NULL : m_aChildren[0];
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */