diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-03-15 09:49:02 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-03-15 02:50:31 +0100 |
commit | 043273e721ade64e4fb42f969cf22b4202c6b80d (patch) | |
tree | 668158b4e7cd04e1264f9121f2cacedfb92d9ebc /xmlscript/source/xmldlg_imexp | |
parent | 90cb743a69ad4b7cb3466b7ce5b2bbed6353d792 (diff) |
xmlscript: change import/export to not use GraphicObject URL
Change-Id: Ic81bf1a5ce45394e098366d0f4af53845ba0da87
Reviewed-on: https://gerrit.libreoffice.org/51307
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmlscript/source/xmldlg_imexp')
-rw-r--r-- | xmlscript/source/xmldlg_imexp/common.hxx | 1 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/exp_share.hxx | 8 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/imp_share.hxx | 2 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx | 11 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 33 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx | 12 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_import.cxx | 25 |
7 files changed, 52 insertions, 40 deletions
diff --git a/xmlscript/source/xmldlg_imexp/common.hxx b/xmlscript/source/xmldlg_imexp/common.hxx index ecfa439d4c00..1737c3cf1330 100644 --- a/xmlscript/source/xmldlg_imexp/common.hxx +++ b/xmlscript/source/xmldlg_imexp/common.hxx @@ -40,7 +40,6 @@ extern StringTriple const * const g_pEventTranslations; } -#define XMLSCRIPT_GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:" #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlscript/source/xmldlg_imexp/exp_share.hxx b/xmlscript/source/xmldlg_imexp/exp_share.hxx index e58a2c215640..39dc1fc3b9ef 100644 --- a/xmlscript/source/xmldlg_imexp/exp_share.hxx +++ b/xmlscript/source/xmldlg_imexp/exp_share.hxx @@ -140,8 +140,6 @@ public: OUString const & rPropName, OUString const & rAttrName ); void readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName ); - void readImageURLAttr( - OUString const & rPropName, OUString const & rAttrName ); void readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName ); void readImagePositionAttr( @@ -164,8 +162,10 @@ public: OUString const & rPropName, OUString const & rAttrName ); void readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName ); - void readDataAwareAttr( - OUString const & rAttrName ); + + void readDataAwareAttr(OUString const & rAttrName ); + void readImageOrGraphicAttr(OUString const & rAttrName ); + void addBoolAttr( OUString const & rAttrName, bool bValue ) { addAttribute( rAttrName, OUString::boolean(bValue) ); } diff --git a/xmlscript/source/xmldlg_imexp/imp_share.hxx b/xmlscript/source/xmldlg_imexp/imp_share.hxx index 8f41b29172c9..c93bd905d363 100644 --- a/xmlscript/source/xmldlg_imexp/imp_share.hxx +++ b/xmlscript/source/xmldlg_imexp/imp_share.hxx @@ -421,7 +421,7 @@ public: bool importVerticalAlignProperty( OUString const & rPropName, OUString const & rAttrName, css::uno::Reference<css::xml::input::XAttributes> const & xAttributes ); - bool importImageURLProperty( OUString const & rPropName, OUString const & rAttrName, + bool importGraphicOrImageProperty(OUString const & rAttrName, css::uno::Reference< css::xml::input::XAttributes > const & xAttributes ); bool importImageAlignProperty( OUString const & rPropName, OUString const & rAttrName, diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx index 764cdb892d77..9c0e71610112 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_expmodels.cxx @@ -187,8 +187,7 @@ void ElementDescriptor::readButtonModel( StyleBag * all_styles ) readAlignAttr( "Align", XMLNS_DIALOGS_PREFIX ":align" ); readVerticalAlignAttr( "VerticalAlign", XMLNS_DIALOGS_PREFIX ":valign" ); readButtonTypeAttr( "PushButtonType", XMLNS_DIALOGS_PREFIX ":button-type" ); - readImageURLAttr( "ImageURL", XMLNS_DIALOGS_PREFIX ":image-src" ); - + readImageOrGraphicAttr(XMLNS_DIALOGS_PREFIX ":image-src"); readImagePositionAttr( "ImagePosition", XMLNS_DIALOGS_PREFIX ":image-position" ); readImageAlignAttr( "ImageAlign", XMLNS_DIALOGS_PREFIX ":image-align" ); @@ -247,7 +246,7 @@ void ElementDescriptor::readCheckBoxModel( StyleBag * all_styles ) readStringAttr( "Label", XMLNS_DIALOGS_PREFIX ":value" ); readAlignAttr( "Align", XMLNS_DIALOGS_PREFIX ":align" ); readVerticalAlignAttr( "VerticalAlign", XMLNS_DIALOGS_PREFIX ":valign" ); - readImageURLAttr( "ImageURL", XMLNS_DIALOGS_PREFIX ":image-src" ); + readImageOrGraphicAttr(XMLNS_DIALOGS_PREFIX ":image-src"); readImagePositionAttr( "ImagePosition", XMLNS_DIALOGS_PREFIX ":image-position" ); readBoolAttr( "MultiLine", XMLNS_DIALOGS_PREFIX ":multiline" ); @@ -417,7 +416,7 @@ void ElementDescriptor::readRadioButtonModel( StyleBag * all_styles ) readStringAttr( "Label", XMLNS_DIALOGS_PREFIX ":value" ); readAlignAttr( "Align", XMLNS_DIALOGS_PREFIX ":align" ); readVerticalAlignAttr( "VerticalAlign", XMLNS_DIALOGS_PREFIX ":valign" ); - readImageURLAttr( "ImageURL", XMLNS_DIALOGS_PREFIX ":image-src" ); + readImageOrGraphicAttr(XMLNS_DIALOGS_PREFIX ":image-src"); readImagePositionAttr( "ImagePosition", XMLNS_DIALOGS_PREFIX ":image-position" ); readBoolAttr( "MultiLine", XMLNS_DIALOGS_PREFIX ":multiline" ); readStringAttr( "GroupName", XMLNS_DIALOGS_PREFIX ":group-name" ); @@ -594,7 +593,7 @@ void ElementDescriptor::readImageControlModel( StyleBag * all_styles ) readBoolAttr( "ScaleImage", XMLNS_DIALOGS_PREFIX ":scale-image" ); readImageScaleModeAttr( "ScaleMode", XMLNS_DIALOGS_PREFIX ":scale-mode" ); readBoolAttr( "Tabstop", XMLNS_DIALOGS_PREFIX ":tabstop" ); - readImageURLAttr( "ImageURL", XMLNS_DIALOGS_PREFIX ":src" ); + readImageOrGraphicAttr(XMLNS_DIALOGS_PREFIX ":src"); readEvents(); } @@ -1042,7 +1041,7 @@ void ElementDescriptor::readDialogModel( StyleBag * all_styles ) bool bDecoration = false; if ( (aDecorationAny >>= bDecoration) && !bDecoration ) addAttribute( XMLNS_DIALOGS_PREFIX ":withtitlebar", "false" ); - readImageURLAttr( "ImageURL", XMLNS_DIALOGS_PREFIX ":image-src" ); + readImageOrGraphicAttr(XMLNS_DIALOGS_PREFIX ":image-src"); readEvents(); } diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index fad368c04117..5de38569aeca 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -64,6 +64,8 @@ #include <com/sun/star/table/CellRangeAddress.hpp> #include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/document/GraphicObjectResolver.hpp> +#include <com/sun/star/document/XGraphicStorageHandler.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <comphelper/processfactory.hxx> #include <i18nlangtag/languagetag.hxx> @@ -716,27 +718,36 @@ void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUStr } } -void ElementDescriptor::readImageURLAttr( OUString const & rPropName, OUString const & rAttrName ) +void ElementDescriptor::readImageOrGraphicAttr(OUString const & rAttrName) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + OUString sURL; + if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("Graphic")) { - OUString sURL; - _xProps->getPropertyValue( rPropName ) >>= sURL; - - if ( sURL.startsWith( XMLSCRIPT_GRAPHOBJ_URLPREFIX ) ) + uno::Reference<graphic::XGraphic> xGraphic; + _xProps->getPropertyValue("Graphic") >>= xGraphic; + if (xGraphic.is()) { Reference< document::XStorageBasedDocument > xDocStorage( _xDocument, UNO_QUERY ); if ( xDocStorage.is() ) { Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext(); - uno::Reference< document::XGraphicObjectResolver > xGraphicResolver = - document::GraphicObjectResolver::createWithStorage( xContext, xDocStorage->getDocumentStorage() ); - sURL = xGraphicResolver->resolveGraphicObjectURL( sURL ); + uno::Reference<document::XGraphicObjectResolver> xGraphicResolver; + xGraphicResolver.set(document::GraphicObjectResolver::createWithStorage(xContext, xDocStorage->getDocumentStorage())); + uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler; + xGraphicStorageHandler.set(xGraphicResolver, uno::UNO_QUERY); + if (xGraphicStorageHandler.is()) + { + sURL = xGraphicStorageHandler->saveGraphic(xGraphic); + } } } - if ( !sURL.isEmpty() ) - addAttribute( rAttrName, sURL ); } + else if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState("ImageURL")) + { + _xProps->getPropertyValue("ImageURL") >>= sURL; + } + if (!sURL.isEmpty()) + addAttribute(rAttrName, sURL); } void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName ) diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx index b1a53e7ba9bd..7af6c0abbe65 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx @@ -893,7 +893,7 @@ void ImageControlElement::endElement() ctx.importDefaults( _nBasePosX, _nBasePosY, _xAttributes ); ctx.importBooleanProperty( "ScaleImage", "scale-image", _xAttributes ); ctx.importImageScaleModeProperty( "ScaleMode" , "scale-mode" , _xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "src" , _xAttributes ); + ctx.importGraphicOrImageProperty("src" , _xAttributes); ctx.importBooleanProperty( "Tabstop", "tabstop", _xAttributes ); ctx.importEvents( _events ); // avoid ring-reference: @@ -1150,7 +1150,7 @@ void TitledBoxElement::endElement() ctx.importStringProperty( "Label", "value", xAttributes ); ctx.importAlignProperty( "Align", "align", xAttributes ); ctx.importVerticalAlignProperty( "VerticalAlign", "valign", xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "image-src" , _xAttributes ); + ctx.importGraphicOrImageProperty("image-src" , _xAttributes); ctx.importImagePositionProperty( "ImagePosition", "image-position", xAttributes ); ctx.importBooleanProperty( "MultiLine", "multiline", xAttributes ); ctx.importStringProperty( "GroupName", "group-name", xAttributes ); @@ -1241,7 +1241,7 @@ void RadioGroupElement::endElement() ctx.importStringProperty( "Label", "value", xAttributes ); ctx.importAlignProperty( "Align", "align", xAttributes ); ctx.importVerticalAlignProperty( "VerticalAlign", "valign", xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "image-src" , xAttributes ); + ctx.importGraphicOrImageProperty("image-src" , _xAttributes); ctx.importImagePositionProperty( "ImagePosition", "image-position", xAttributes ); ctx.importBooleanProperty( "MultiLine", "multiline", xAttributes ); ctx.importStringProperty( "GroupName", "group-name", xAttributes ); @@ -1491,7 +1491,7 @@ void CheckBoxElement::endElement() ctx.importStringProperty( "Label", "value", _xAttributes ); ctx.importAlignProperty( "Align", "align", _xAttributes ); ctx.importVerticalAlignProperty( "VerticalAlign", "valign", _xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "image-src" , _xAttributes ); + ctx.importGraphicOrImageProperty("image-src" , _xAttributes); ctx.importImagePositionProperty( "ImagePosition", "image-position", _xAttributes ); ctx.importBooleanProperty( "MultiLine", "multiline", _xAttributes ); @@ -1557,7 +1557,7 @@ void ButtonElement::endElement() ctx.importVerticalAlignProperty( "VerticalAlign", "valign", _xAttributes ); ctx.importBooleanProperty( "DefaultButton", "default", _xAttributes ); ctx.importButtonTypeProperty( "PushButtonType", "button-type", _xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "image-src" , _xAttributes ); + ctx.importGraphicOrImageProperty("image-src" , _xAttributes); ctx.importImagePositionProperty( "ImagePosition", "image-position", _xAttributes ); ctx.importImageAlignProperty( "ImageAlign", "image-align", _xAttributes ); if (ctx.importLongProperty( "RepeatDelay", "repeat", _xAttributes )) @@ -1832,7 +1832,7 @@ void WindowElement::endElement() ctx.importBooleanProperty("Sizeable", "resizeable", _xAttributes ); ctx.importStringProperty("Title", "title", _xAttributes ); ctx.importBooleanProperty("Decoration", "withtitlebar", _xAttributes ); - ctx.importImageURLProperty( "ImageURL" , "image-src" , _xAttributes ); + ctx.importGraphicOrImageProperty("image-src" , _xAttributes); ctx.importScollableSettings( _xAttributes ); ctx.importEvents( _events ); // avoid ring-reference: diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx index 0abf8453843a..8949234d6d94 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx @@ -54,7 +54,9 @@ #include <com/sun/star/table/CellAddress.hpp> #include <com/sun/star/table/CellRangeAddress.hpp> #include <com/sun/star/document/XGraphicObjectResolver.hpp> +#include <com/sun/star/document/XGraphicStorageHandler.hpp> #include <com/sun/star/document/XStorageBasedDocument.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/util/NumberFormatsSupplier.hpp> using namespace ::com::sun::star; @@ -840,8 +842,8 @@ bool ImportContext::importVerticalAlignProperty( return false; } -bool ImportContext::importImageURLProperty( - OUString const & rPropName, OUString const & rAttrName, +bool ImportContext::importGraphicOrImageProperty( + OUString const & rAttrName, Reference< xml::input::XAttributes > const & xAttributes ) { OUString sURL = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, rAttrName ); @@ -849,6 +851,8 @@ bool ImportContext::importImageURLProperty( { Reference< document::XStorageBasedDocument > xDocStorage( _pImport->getDocOwner(), UNO_QUERY ); + uno::Reference<graphic::XGraphic> xGraphic; + uno::Reference< document::XGraphicObjectResolver > xGraphicResolver; if ( xDocStorage.is() ) { @@ -857,29 +861,28 @@ bool ImportContext::importImageURLProperty( xGraphicResolver.set( _pImport->getComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext( "com.sun.star.comp.Svx.GraphicImportHelper" , aArgs, _pImport->getComponentContext() ), UNO_QUERY ); - if ( xGraphicResolver.is() ) + uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler; + xGraphicStorageHandler.set(xGraphicResolver, uno::UNO_QUERY); + if (xGraphicStorageHandler.is()) { OUString aTmp("vnd.sun.star.Package:"); aTmp += sURL; try { - aTmp = xGraphicResolver->resolveGraphicObjectURL( aTmp ); - if ( !aTmp.isEmpty() ) - sURL = aTmp; + xGraphic = xGraphicStorageHandler->loadGraphic(sURL); } catch( const uno::Exception& ) { return false; } - } } - if ( !sURL.isEmpty() ) + if (xGraphic.is()) { - Reference< beans::XPropertySet > xProps( getControlModel(), UNO_QUERY ); - if ( xProps.is() ) + Reference<beans::XPropertySet> xProps( getControlModel(), UNO_QUERY ); + if (xProps.is()) { - xProps->setPropertyValue( rPropName, makeAny( sURL ) ); + xProps->setPropertyValue("Graphic", makeAny(xGraphic)); return true; } } |