diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2013-08-24 01:23:36 +0200 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-08-26 14:47:28 +0200 |
commit | 1eecb8df22b77a6982601bf877067a685d913a7d (patch) | |
tree | 20c697c765595d555afb84a9bf1f1f95dd17c5c2 /sd | |
parent | f78db7cb1c973bd3c8f74fe4a226fb78ad7fbaff (diff) |
Some cleanup and consolidation of the Impress layout work.
Also make unit test work again after Mac-app like path changes.
Change-Id: I13eae20141650e1d1d826a794d1f19baaef5f561
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/drawdoc.hxx | 6 | ||||
-rw-r--r-- | sd/source/core/drawdoc.cxx | 89 | ||||
-rw-r--r-- | sd/source/core/sdpage.cxx | 110 | ||||
-rw-r--r-- | sd/xml/layoutlist.xml | 9 |
4 files changed, 87 insertions, 127 deletions
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index 88d11c92793d..6ef4c27ab0c9 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -264,8 +264,10 @@ public: bool IsExitAfterPresenting() const; void SetExitAfterPresenting( bool bExitAfterPresenting ); - void SetLayoutVector(); - std::vector<com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode>> &GetLayoutVector() { return maLayoutInfo; } + /// load xml-based impress layout definitions into document + void InitLayoutVector(); + /// return reference to vector of Impress layout definitions + const std::vector<com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode>>& GetLayoutVector() const { return maLayoutInfo; } /** Insert pages into this document diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx index a4089cbf91d5..2295c97d07b6 100644 --- a/sd/source/core/drawdoc.cxx +++ b/sd/source/core/drawdoc.cxx @@ -29,6 +29,7 @@ #include <editeng/scriptspaceitem.hxx> #include <unotools/useroptions.hxx> +#include <officecfg/Office/Impress.hxx> #include <sfx2/printer.hxx> #include <sfx2/app.hxx> @@ -71,9 +72,6 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/util/theMacroExpander.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/configuration/theDefaultProvider.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> #include <rtl/ustring.hxx> #include <rtl/uri.hxx> #include <osl/file.h> @@ -192,7 +190,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh) mpMasterPageListWatcher = ::std::auto_ptr<ImpMasterPageListWatcher>( new ImpMasterPageListWatcher(*this)); - SetLayoutVector(); + InitLayoutVector(); SetObjectShell(pDrDocSh); // for VCDrawModel if (mpDocSh) @@ -1012,66 +1010,53 @@ sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const OUString& rAuthor ) return idx; } -// to get the root element of the xml file -Reference<XElement> getRoot() +void SdDrawDocument::InitLayoutVector() { - const Reference<css::uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() ); - Reference< XMultiServiceFactory > xServiceFactory( xContext->getServiceManager() , UNO_QUERY_THROW ); - Reference< util::XMacroExpander > xMacroExpander = util::theMacroExpander::get( xContext ); - Reference< XMultiServiceFactory > xConfigProvider = configuration::theDefaultProvider::get( xContext ); - - Any propValue = uno::makeAny( - beans::PropertyValue( - "nodepath", -1, - uno::makeAny( OUString( "/org.openoffice.Office.Impress/Misc" )), - beans::PropertyState_DIRECT_VALUE ) ); - - Reference<container::XNameAccess> xNameAccess( - xConfigProvider->createInstanceWithArguments( - "com.sun.star.configuration.ConfigurationAccess", - Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW ); - - Sequence< rtl::OUString > aFiles; - xNameAccess->getByName( "LayoutListFiles" ) >>= aFiles; - rtl::OUString aURL; + const Reference<css::uno::XComponentContext> xContext( + ::comphelper::getProcessComponentContext() ); + Reference< util::XMacroExpander > xMacroExpander( + util::theMacroExpander::get( xContext ) ); + // get file list from configuration + Sequence< rtl::OUString > aFiles( + officecfg::Office::Impress::Misc::LayoutListFiles::get(xContext) ); + + // loop over each file in sequence + rtl::OUString aFilename; for( sal_Int32 i=0; i < aFiles.getLength(); ++i ) { - aURL = aFiles[i]; - if( aURL.startsWith( "vnd.sun.star.expand:" ) ) + aFilename = aFiles[i]; + if( aFilename.startsWith( "vnd.sun.star.expand:" ) ) { // cut protocol - rtl::OUString aMacro( aURL.copy( sizeof ( "vnd.sun.star.expand:" ) -1 ) ); + rtl::OUString aMacro( aFilename.copy( sizeof ( "vnd.sun.star.expand:" ) -1 ) ); + // decode uric class chars aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); + // expand macro string - aURL = xMacroExpander->expandMacros( aMacro ); + aFilename = xMacroExpander->expandMacros( aMacro ); } - } - - if( aURL.startsWith( "file://" ) ) - { - rtl::OUString aSysPath; - if( osl_getSystemPathFromFileURL( aURL.pData, &aSysPath.pData ) == osl_File_E_None ) - aURL = aSysPath; - } - const Reference<XDocumentBuilder> xDocBuilder( DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) )); - const Reference<XDocument> xDoc = xDocBuilder->parseURI( aURL ); - const Reference<XElement> xRoot = xDoc->getDocumentElement(); - return xRoot; //this loops seems to work only once,so returning the root element -} + if( aFilename.startsWith( "file://" ) ) + { + rtl::OUString aSysPath; + if( osl_getSystemPathFromFileURL( aFilename.pData, &aSysPath.pData ) == osl_File_E_None ) + aFilename = aSysPath; + } -void SdDrawDocument::SetLayoutVector() -{ - int layoutlistsize; - const Reference<XElement> root = getRoot(); //get the root element of my xml file - const Reference<XNodeList> layoutlist = root->getElementsByTagName("layout"); - layoutlistsize=layoutlist->getLength(); - for(int index=0; index < layoutlistsize; index++) - { - Reference<XNode> layoutnode = layoutlist->item(index); //get i'th layout element - maLayoutInfo.push_back(layoutnode); + // load layout file into DOM + Reference< XMultiServiceFactory > xServiceFactory( + xContext->getServiceManager() , UNO_QUERY_THROW ); + const Reference<XDocumentBuilder> xDocBuilder( + DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) )); + + // loop over every layout entry in current file + const Reference<XDocument> xDoc = xDocBuilder->parseURI( aFilename ); + const Reference<XNodeList> layoutlist = xDoc->getElementsByTagName("layout"); + const int nElements = layoutlist->getLength(); + for(int index=0; index < nElements; index++) + maLayoutInfo.push_back( layoutlist->item(index) ); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index 64dbefd31363..7be55e1b920c 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -48,25 +48,11 @@ #include <editeng/flditem.hxx> #include <svx/sdr/contact/displayinfo.hxx> #include <svx/svditer.hxx> -#include <com/sun/star/xml/dom/XDocumentBuilder.hpp> -#include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/xml/dom/XNode.hpp> #include <com/sun/star/xml/dom/XNodeList.hpp> #include <com/sun/star/xml/dom/XNamedNodeMap.hpp> -#include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <rtl/ustring.hxx> -#include <comphelper/processfactory.hxx> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/util/theMacroExpander.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/configuration/theDefaultProvider.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <unotools/streamwrap.hxx> -#include <rtl/uri.hxx> -#include <unotools/ucbstreamhelper.hxx> -#include <osl/file.h> +#include <basegfx/tools/tools.hxx> #include "../ui/inc/DrawDocShell.hxx" #include "Outliner.hxx" @@ -95,12 +81,6 @@ using namespace ::com::sun::star::uno; using namespace com::sun::star::xml::dom; using ::com::sun::star::uno::Reference; -using ::com::sun::star::io::XInputStream; -using ::com::sun::star::lang::XMultiServiceFactory; -using ::com::sun::star::container::XNameAccess; -using ::com::sun::star::beans::PropertyValue; - - TYPEINIT2( SdPage, FmFormPage, SdrObjUserCall ); /************************************************************************* @@ -1116,7 +1096,6 @@ Rectangle SdPage::GetLayoutRect() const const int MAX_PRESOBJS = 7; // maximum number of presentation objects per layout const int VERTICAL = 0x8000; -const int PRESOBJPROP = 4; struct LayoutDescriptor { @@ -1247,14 +1226,10 @@ rtl::OUString enumtoString(AutoLayout aut) return retstr; } -static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const rtl::OUString& autolayout) +static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const rtl::OUString& sLayoutType ) { Rectangle aTitleRect; Rectangle aLayoutRect; - int presobjsize; - rtl::OUString sLayoutAttName; - rtl::OUString sPresObjKindAttName; - double propvalue[4]; if( rPage.GetPageKind() != PK_HANDOUT ) { @@ -1278,42 +1253,39 @@ static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const } rRectangle[0] = aTitleRect; - - int i; - for( i = 1; i < MAX_PRESOBJS; i++ ) + for( int i = 1; i < MAX_PRESOBJS; i++ ) rRectangle[i] = aLayoutRect; - i=0; - for(i=0; i< PRESOBJPROP; i++) - propvalue[i]=0; - Point aTitlePos( aTitleRect.TopLeft() ); - Size aLayoutSize( aLayoutRect.GetSize() ); - Point aLayoutPos( aLayoutRect.TopLeft() ); - Size aTempSize; - Point aTempPnt; - aTempSize = aLayoutSize; - aTempPnt = aLayoutPos; + const Point aTitlePos( aTitleRect.TopLeft() ); + const Size aLayoutSize( aLayoutRect.GetSize() ); + const Point aLayoutPos( aLayoutRect.TopLeft() ); + double propvalue[] = {0,0,0,0}; - const std::vector<Reference<XNode>> &layoutinfo = static_cast< SdDrawDocument* >( rPage.GetModel() )->GetLayoutVector(); //getting vector from "SdDrawDocument" ,not sure about the correct mechanism - for(size_t y=0; y < layoutinfo.size(); y++) //loop through vector of Xnodes + const std::vector< Reference<XNode> >& layoutInfo = static_cast<const SdDrawDocument*>(rPage.GetModel())->GetLayoutVector(); + for( std::vector< Reference<XNode> >::const_iterator aIter=layoutInfo.begin(); aIter != layoutInfo.end(); ++aIter ) { - Reference<XNode> layoutnode = layoutinfo[y]; //get i'th layout element - Reference<XNamedNodeMap> layoutattrlist =layoutnode->getAttributes(); - Reference<XNode> layoutattr = layoutattrlist->getNamedItem("type"); - sLayoutAttName=layoutattr->getNodeValue(); //get the attribute value of layout(i.e it's type) - rtl::OUString sLayoutType = autolayout; + Reference<XNode> layoutNode = *aIter; + Reference<XNamedNodeMap> layoutAttrList =layoutNode->getAttributes(); - if(sLayoutAttName==sLayoutType) + // get the attribute value of layout (i.e it's type) + rtl::OUString sLayoutAttName = + layoutAttrList->getNamedItem("type")->getNodeValue(); + if(sLayoutAttName == sLayoutType) { int count=0; - Reference<XNodeList> layoutchildrens = layoutnode->getChildNodes(); - presobjsize = layoutchildrens->getLength(); //get the length of that of the layout(number of pres objects) + Reference<XNodeList> layoutChildren = layoutNode->getChildNodes(); + const int presobjsize = layoutChildren->getLength(); for( int j=0; j< presobjsize ; j++) { + // TODO: rework sd to permit arbitrary number of presentation objects + OSL_ASSERT(count < MAX_PRESOBJS); + rtl::OUString nodename; - Reference<XNode> presobj = layoutchildrens->item(j); //get the j'th presobj for that layout + Reference<XNode> presobj = layoutChildren->item(j); nodename=presobj->getNodeName(); - if(nodename=="presobj")//check whether children is blank 'text-node' or 'presobj' node + + //check whether children is blank 'text-node' or 'presobj' node + if(nodename == "presobj") { Reference<XNamedNodeMap> presObjAttributes = presobj->getAttributes(); @@ -1333,26 +1305,24 @@ static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const sValue = presObjPosY->getNodeValue(); propvalue[3] = sValue.toDouble(); - if(count==0) + if(count == 0) { - Size aTitleSize ( aTitleRect.GetSize() ); - aTitleSize.Height() = sal_Int32(aTitleSize.Height() * propvalue[0]); - aTitleSize.Width() = sal_Int32(aTitleSize.Width() * propvalue[1]); - aTitlePos.X() = sal_Int32(aTitlePos.X() +(aTitleSize.Width() * propvalue[2])); - aTitlePos.Y() = sal_Int32(aTitlePos.Y() + (aTitleSize.Height() * propvalue[3])); - rRectangle[count] = Rectangle (aTitlePos, aTitleSize); + Size aSize ( aTitleRect.GetSize() ); + aSize.Height() = basegfx::fround(aSize.Height() * propvalue[0]); + aSize.Width() = basegfx::fround(aSize.Width() * propvalue[1]); + Point aPos( basegfx::fround(aTitlePos.X() +(aSize.Width() * propvalue[2])), + basegfx::fround(aTitlePos.Y() + (aSize.Height() * propvalue[3])) ); + rRectangle[count] = Rectangle(aPos, aSize); count = count+1; } else { - aLayoutSize = aTempSize; //to re-gain fixed layout size - aLayoutPos = aTempPnt; //to re-gain fixed layout pos - aLayoutSize.Height() = sal_Int32(aLayoutSize.Height() * propvalue[0]); - aLayoutSize.Width() = sal_Int32(aLayoutSize.Width() * propvalue[1]); - aLayoutPos.X() = sal_Int32(aLayoutPos.X() +(aLayoutSize.Width() * propvalue[2])); - aLayoutPos.Y() = sal_Int32(aLayoutPos.Y() + (aLayoutSize.Height() * propvalue[3])); - rRectangle[count] = Rectangle (aLayoutPos, aLayoutSize); - count=count+1; + Size aSize( basegfx::fround(aLayoutSize.Width() * propvalue[1]), + basegfx::fround(aLayoutSize.Height() * propvalue[0]) ); + Point aPos( basegfx::fround(aLayoutPos.X() +(aLayoutSize.Width() * propvalue[2])), + basegfx::fround(aLayoutPos.Y() + (aLayoutSize.Height() * propvalue[3])) ); + rRectangle[count] = Rectangle (aPos, aSize); + count = count+1; } } } @@ -1525,7 +1495,6 @@ void findAutoLayoutShapesImpl( SdPage& rPage, const LayoutDescriptor& rDescripto void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate ) { - rtl::OUString autolayout; sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement ); const bool bSwitchLayout = eLayout != GetAutoLayout(); @@ -1546,12 +1515,11 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate Rectangle aRectangle[MAX_PRESOBJS]; const LayoutDescriptor& aDescriptor = GetLayoutDescriptor( meAutoLayout ); - autolayout=enumtoString(meAutoLayout); - CalcAutoLayoutRectangles( *this, aRectangle, autolayout); + rtl::OUString sLayoutName( enumtoString(meAutoLayout) ); + CalcAutoLayoutRectangles( *this, aRectangle, sLayoutName); std::set< SdrObject* > aUsedPresentationObjects; - std::vector< SdrObject* > aLayoutShapes(PRESOBJ_MAX, 0); findAutoLayoutShapesImpl( *this, aDescriptor, aLayoutShapes, bInit, bSwitchLayout ); diff --git a/sd/xml/layoutlist.xml b/sd/xml/layoutlist.xml index d7338ad38ccf..c5f8d5ef3ecf 100644 --- a/sd/xml/layoutlist.xml +++ b/sd/xml/layoutlist.xml @@ -1,5 +1,10 @@ <?xml version="1.0"?> -<!-- At present I am not sure about corect XML namespace,so once I am aware of it.I am ready to add it. +<!-- Configurable definitions of Impress slide layouts. + + Currently the layout type name needs to match a set of predefined strings. + Per entry, you can declare up to one Title object, and up to four + Outline objects. All values are relative to Impress' 'layout + rect', which is roughly 90% of the available slide area. --> <layout-list> <layout type="AUTOLAYOUT_TITLE_CONTENT"> @@ -78,4 +83,4 @@ <presobj kind="PRESOBJ_OUTLINE1" relative-height="1" relative-width="0.488" relative-posX="0" relative-posY="0"/> <presobj kind="PRESOBJ_OUTLINE2" relative-height="1" relative-width="0.488" relative-posX="1.05" relative-posY="0"/> </layout> -</layout-list>
\ No newline at end of file +</layout-list> |