summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-03-28 03:24:47 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-03-28 03:35:22 +0200
commit5d8c9ef5e5945fd166a9e0793b7d31ed679742d4 (patch)
treed67d039166dea1abaabb8b17dfb49c90a03f481e /chart2
parent74b274602a5a76b949f6d1a521b343688693090b (diff)
implement the layout dumper for chart2
Diffstat (limited to 'chart2')
-rw-r--r--chart2/Library_chartview.mk4
-rw-r--r--chart2/source/model/main/ChartModel.cxx5
-rw-r--r--chart2/source/model/main/ChartModel.hxx1
-rw-r--r--chart2/source/view/main/ChartView.cxx113
-rw-r--r--chart2/source/view/main/ChartView.hxx10
5 files changed, 131 insertions, 2 deletions
diff --git a/chart2/Library_chartview.mk b/chart2/Library_chartview.mk
index f9e97038f469..24ba681c26b1 100644
--- a/chart2/Library_chartview.mk
+++ b/chart2/Library_chartview.mk
@@ -115,4 +115,8 @@ $(eval $(call gb_Library_add_exception_objects,chartview,\
chart2/source/view/main/VTitle \
))
+$(eval $(call gb_Library_use_externals,chartview,\
+ libxml2 \
+))
+
# vim: set noet sw=4 ts=4:
diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx
index c23dba72d22b..9b67d81d15c6 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -1357,6 +1357,11 @@ uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartM
rtl::OUString SAL_CALL ChartModel::dump()
throw (uno::RuntimeException)
{
+ uno::Reference< qa::XDumper > xDumper(
+ this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
+ if (xDumper.is())
+ return xDumper->dump();
+
return rtl::OUString();
}
diff --git a/chart2/source/model/main/ChartModel.hxx b/chart2/source/model/main/ChartModel.hxx
index 40b1dbdebcee..b3bc2eb06656 100644
--- a/chart2/source/model/main/ChartModel.hxx
+++ b/chart2/source/model/main/ChartModel.hxx
@@ -51,6 +51,7 @@
#include <com/sun/star/chart2/data/XDataSource.hpp>
#include <com/sun/star/chart2/XChartTypeTemplate.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/qa/XDumper.hpp>
// public API
#include <com/sun/star/chart2/data/XDataProvider.hpp>
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 9297cef1b779..250f1c8bcddc 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -97,6 +97,9 @@
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/util/XRefreshable.hpp>
#include <com/sun/star/util/NumberFormat.hpp>
+#include <com/sun/star/awt/Size.hpp>
+#include <com/sun/star/awt/Point.hpp>
+#include <com/sun/star/drawing/XShapeDescriptor.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
@@ -106,6 +109,13 @@
#include <svl/languageoptions.hxx>
#include <sot/clsids.hxx>
+#include <rtl/strbuf.hxx>
+#include <rtl/oustringostreaminserter.hxx>
+
+//libxml2 for dumping
+#include <libxml/xmlwriter.h>
+
+
//.............................................................................
namespace chart
{
@@ -3015,6 +3025,109 @@ uno::Sequence< ::rtl::OUString > ChartView::getAvailableServiceNames() throw (un
return aServiceNames;
}
+namespace {
+
+#define DEBUG_DUMPER 0
+
+int writeCallback(void* pContext, const char* sBuffer, int nLen)
+{
+ rtl::OStringBuffer* pBuffer = static_cast<rtl::OStringBuffer*>(pContext);
+ pBuffer->append(sBuffer);
+ return nLen;
+}
+
+int closeCallback(void* )
+{
+ return 0;
+}
+
+void dumpPositionAsAttribute(const awt::Point& rPoint, xmlTextWriterPtr xmlWriter)
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("position"), "%i,%i", rPoint.X, rPoint.Y);
+}
+
+void dumpSizeAsAttribute(const awt::Size& rSize, xmlTextWriterPtr xmlWriter)
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("size"), "%ix%i", rSize.Width, rSize.Height);
+}
+
+void dumpShapeDescriptorAsAttribute( uno::Reference< drawing::XShapeDescriptor > xDescr, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("type"), "%s", rtl::OUStringToOString(xDescr->getShapeType(), RTL_TEXTENCODING_UTF8).getStr());
+}
+
+void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter );
+
+void dumpXShape( uno::Reference< drawing::XShape > xShape, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShape" ) );
+
+ dumpPositionAsAttribute(xShape->getPosition(), xmlWriter);
+ dumpSizeAsAttribute(xShape->getSize(), xmlWriter);
+ uno::Reference< drawing::XShapeDescriptor > xDescr(xShape, uno::UNO_QUERY_THROW);
+ dumpShapeDescriptorAsAttribute(xDescr, xmlWriter);
+
+ uno::Reference< lang::XServiceInfo > xServiceInfo( xShape, uno::UNO_QUERY_THROW );
+ uno::Sequence< rtl::OUString > aServiceNames = xServiceInfo->getSupportedServiceNames();
+ sal_Int32 nServices = aServiceNames.getLength();
+ for (sal_Int32 i = 0; i < nServices; ++i)
+ {
+ if (aServiceNames[i].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GroupShape")))
+ {
+ uno::Reference< drawing::XShapes > xShapes(xShape, uno::UNO_QUERY_THROW);
+ dumpXShapes(xShapes, xmlWriter);
+ }
+#if DEBUG_DUMPER
+ xmlTextWriterStartElement(xmlWriter, BAD_CAST( "ServiceName" ));
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST( "name" ), "%s", rtl::OUStringToOString(aServiceNames[i], RTL_TEXTENCODING_UTF8).getStr());
+ xmlTextWriterEndElement( xmlWriter );
+#endif
+ }
+
+ xmlTextWriterEndElement( xmlWriter );
+}
+
+void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShapes" ) );
+ uno::Reference< container::XIndexAccess > xIA( xShapes, uno::UNO_QUERY_THROW);
+ sal_Int32 nLength = xIA->getCount();
+ for (sal_Int32 i = 0; i < nLength; ++i)
+ {
+ uno::Reference< drawing::XShape > xShape( xIA->getByIndex( i ), uno::UNO_QUERY_THROW );
+ dumpXShape( xShape, xmlWriter );
+ }
+
+ xmlTextWriterEndElement( xmlWriter );
+}
+
+}
+
+rtl::OUString ChartView::dump() throw (uno::RuntimeException)
+{
+ impl_updateView();
+ uno::Reference<drawing::XShapes> xPageShapes( ShapeFactory(m_xShapeFactory)
+ .getOrCreateChartRootShape( m_xDrawPage ) );
+
+ if (!xPageShapes.is())
+ return rtl::OUString();
+
+ rtl::OStringBuffer aString;
+ xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO( writeCallback, closeCallback, &aString, NULL );
+ xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer );
+ xmlTextWriterSetIndent( xmlWriter, 1 );
+
+ xmlTextWriterStartDocument( xmlWriter, NULL, NULL, NULL );
+
+ dumpXShapes( xPageShapes, xmlWriter );
+
+ xmlTextWriterEndDocument( xmlWriter );
+ xmlFreeTextWriter( xmlWriter );
+
+
+ return OStringToOUString(aString.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
+}
+
//.............................................................................
} //namespace chart
//.............................................................................
diff --git a/chart2/source/view/main/ChartView.hxx b/chart2/source/view/main/ChartView.hxx
index 32beb467e791..8321c038f0d7 100644
--- a/chart2/source/view/main/ChartView.hxx
+++ b/chart2/source/view/main/ChartView.hxx
@@ -30,7 +30,7 @@
#include "chartview/ExplicitValueProvider.hxx"
#include "ServiceMacros.hxx"
-#include <cppuhelper/implbase9.hxx>
+#include <cppuhelper/implbase10.hxx>
#include <cppuhelper/interfacecontainer.hxx>
// header for class SfxListener
@@ -47,6 +47,7 @@
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/util/XModeChangeBroadcaster.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
+#include <com/sun/star/qa/XDumper.hpp>
#include <vector>
#include <boost/shared_ptr.hpp>
@@ -70,7 +71,7 @@ The view than changes to state dirty. The view can be updated with call 'update'
The View is not responsible to handle single user events (that is instead done by the ChartWindow).
*/
-class ChartView : public ::cppu::WeakImplHelper9<
+class ChartView : public ::cppu::WeakImplHelper10<
::com::sun::star::lang::XInitialization
, ::com::sun::star::lang::XServiceInfo
, ::com::sun::star::datatransfer::XTransferable
@@ -84,6 +85,7 @@ class ChartView : public ::cppu::WeakImplHelper9<
,::com::sun::star::util::XUpdatable
,::com::sun::star::beans::XPropertySet
,::com::sun::star::lang::XMultiServiceFactory
+ ,::com::sun::star::qa::XDumper
>
, public ExplicitValueProvider
, private SfxListener
@@ -182,6 +184,10 @@ public:
virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier )
throw (::com::sun::star::uno::RuntimeException);
+ // XDumper
+ virtual rtl::OUString SAL_CALL dump()
+ throw(::com::sun::star::uno::RuntimeException);
+
private: //methods
ChartView();