summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2012-12-10 18:32:46 +0000
committerNoel Power <noel.power@suse.com>2012-12-10 18:32:46 +0000
commit4a9568fc10c57df1506ee2cc7d47ebc45e077064 (patch)
treec48d13b4016e0910472d37c98c6abc347fbb3008
parent3bc88c4fdc2a05f816f29cb42b7d4f609214357c (diff)
import hyperlinks for shapes
Change-Id: I21686528616798d76c58fb3e6a6960eb52d36f23
-rw-r--r--oox/inc/oox/core/relations.hxx2
-rw-r--r--oox/source/core/relations.cxx6
-rw-r--r--oox/source/drawingml/hyperlinkcontext.cxx7
-rw-r--r--sc/source/filter/inc/worksheetbuffer.hxx4
-rw-r--r--sc/source/filter/oox/drawingfragment.cxx22
-rw-r--r--sc/source/filter/oox/worksheetbuffer.cxx19
6 files changed, 55 insertions, 5 deletions
diff --git a/oox/inc/oox/core/relations.hxx b/oox/inc/oox/core/relations.hxx
index e7d558b044ed..67f298e6dc9a 100644
--- a/oox/inc/oox/core/relations.hxx
+++ b/oox/inc/oox/core/relations.hxx
@@ -88,6 +88,8 @@ public:
/** Returns the external target of the relation with the passed relation identifier. */
::rtl::OUString getExternalTargetFromRelId( const ::rtl::OUString& rRelId ) const;
+ /** Returns the internal target of the relation with the passed relation identifier. */
+ ::rtl::OUString getInternalTargetFromRelId( const ::rtl::OUString& rRelId ) const;
/** Returns the full fragment path for the target of the passed relation. */
::rtl::OUString getFragmentPathFromRelation( const Relation& rRelation ) const;
diff --git a/oox/source/core/relations.cxx b/oox/source/core/relations.cxx
index ef9510ce54b7..ad39489671c0 100644
--- a/oox/source/core/relations.cxx
+++ b/oox/source/core/relations.cxx
@@ -92,6 +92,12 @@ OUString Relations::getExternalTargetFromRelId( const OUString& rRelId ) const
return (pRelation && pRelation->mbExternal) ? pRelation->maTarget : OUString();
}
+OUString Relations::getInternalTargetFromRelId( const OUString& rRelId ) const
+{
+ const Relation* pRelation = getRelationFromRelId( rRelId );
+ return (pRelation && !pRelation->mbExternal) ? pRelation->maTarget : OUString();
+}
+
OUString Relations::getFragmentPathFromRelation( const Relation& rRelation ) const
{
// no target, no fragment path
diff --git a/oox/source/drawingml/hyperlinkcontext.cxx b/oox/source/drawingml/hyperlinkcontext.cxx
index 06958aa13de8..15d0a29bdec9 100644
--- a/oox/source/drawingml/hyperlinkcontext.cxx
+++ b/oox/source/drawingml/hyperlinkcontext.cxx
@@ -53,11 +53,12 @@ HyperLinkContext::HyperLinkContext( ContextHandler& rParent,
if ( !aRelId.isEmpty() )
{
OSL_TRACE("OOX: URI rId %s", ::rtl::OUStringToOString (aRelId, RTL_TEXTENCODING_UTF8).pData->buffer);
- sHref = getRelations().getExternalTargetFromRelId( aRelId );
- if( !sHref.isEmpty() )
+ OUString sExtHref = getRelations().getExternalTargetFromRelId( aRelId );
+ sURL = getRelations().getInternalTargetFromRelId( aRelId );
+ if( !sExtHref.isEmpty() )
{
OSL_TRACE("OOX: URI href %s", ::rtl::OUStringToOString (sHref, RTL_TEXTENCODING_UTF8).pData->buffer);
- sURL = getFilter().getAbsoluteUrl( sHref );
+ sURL = getFilter().getAbsoluteUrl( sExtHref );
}
}
OUString sTooltip = xAttributes->getOptionalValue( R_TOKEN( tooltip ) );
diff --git a/sc/source/filter/inc/worksheetbuffer.hxx b/sc/source/filter/inc/worksheetbuffer.hxx
index e527a72e40db..3402518ae760 100644
--- a/sc/source/filter/inc/worksheetbuffer.hxx
+++ b/sc/source/filter/inc/worksheetbuffer.hxx
@@ -90,6 +90,10 @@ public:
sal_Int16 getCalcSheetIndex( const ::rtl::OUString& rWorksheetName ) const;
/** Returns the finalized name of the sheet with the passed worksheet name. */
::rtl::OUString getCalcSheetName( const ::rtl::OUString& rWorksheetName ) const;
+ /** Converts sSheetNameRef (e.g. '#SheetName!A1' to '#SheetName.A1' )
+ if sSheetNameRef doesn't start with '#' it is ignored and not modified
+ */
+ void convertSheetNameRef( ::rtl::OUString& sSheetNameRef ) const;
private:
struct SheetInfo : public SheetInfoModel
diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx
index 73e6b47eb7c1..2fcabc355c69 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -35,6 +35,9 @@
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp>
#include <rtl/strbuf.hxx>
+#include <svx/svdobj.hxx>
+#include "drwlayer.hxx"
+#include "userdat.hxx"
#include "oox/drawingml/connectorshapecontext.hxx"
#include "oox/drawingml/graphicshapecontext.hxx"
#include "oox/helper/attributelist.hxx"
@@ -45,7 +48,7 @@
#include "stylesbuffer.hxx"
#include "themebuffer.hxx"
#include "unitconverter.hxx"
-
+#include "worksheetbuffer.hxx"
namespace oox {
namespace xls {
@@ -53,7 +56,6 @@ using ::rtl::OUString;
// ============================================================================
-using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::document;
@@ -66,6 +68,10 @@ using namespace ::oox::core;
using namespace ::oox::drawingml;
using namespace ::oox::ole;
+using ::com::sun::star::awt::Size;
+using ::com::sun::star::awt::Point;
+using ::com::sun::star::awt::Rectangle;
+using ::com::sun::star::awt::XControlModel;
using ::rtl::OStringBuffer;
using ::rtl::OUString;
using ::rtl::OUStringToOString;
@@ -110,12 +116,24 @@ Shape::Shape( const WorksheetHelper& rHelper, const AttributeList& rAttribs, con
void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
{
+ rtl::OUString sURL;
+ getShapeProperties()[ PROP_URL ] >>= sURL;
+ getWorksheets().convertSheetNameRef( sURL );
if( !maMacroName.isEmpty() && mxShape.is() )
{
VbaMacroAttacherRef xAttacher( new ShapeMacroAttacher( maMacroName, mxShape ) );
getBaseFilter().getVbaProject().registerMacroAttacher( xAttacher );
}
::oox::drawingml::Shape::finalizeXShape( rFilter, rxShapes );
+ if ( !sURL.isEmpty() )
+ {
+ SdrObject* pObj = SdrObject::getSdrObjectFromXShape( mxShape );
+ if ( pObj )
+ {
+ if ( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, sal_True ) )
+ pInfo->SetHlink( sURL );
+ }
+ }
}
// ============================================================================
diff --git a/sc/source/filter/oox/worksheetbuffer.cxx b/sc/source/filter/oox/worksheetbuffer.cxx
index 8e092ac74e5e..f315eebda2f1 100644
--- a/sc/source/filter/oox/worksheetbuffer.cxx
+++ b/sc/source/filter/oox/worksheetbuffer.cxx
@@ -119,6 +119,25 @@ OUString WorksheetBuffer::getCalcSheetName( sal_Int32 nWorksheet ) const
return pSheetInfo ? pSheetInfo->maCalcName : OUString();
}
+void WorksheetBuffer::convertSheetNameRef( ::rtl::OUString& sSheetNameRef ) const
+{
+ // convert '#SheetName!A1' to '#SheetName.A1'
+ if( !sSheetNameRef.isEmpty() && (sSheetNameRef[ 0 ] == '#') )
+ {
+ sal_Int32 nSepPos = sSheetNameRef.lastIndexOf( '!' );
+ if( nSepPos > 0 )
+ {
+ // replace the exclamation mark with a period
+ sSheetNameRef = sSheetNameRef.replaceAt( nSepPos, 1, OUString( sal_Unicode( '.' ) ) );
+ // #i66592# convert sheet names that have been renamed on import
+ OUString aSheetName = sSheetNameRef.copy( 1, nSepPos - 1 );
+ OUString aCalcName = getCalcSheetName( aSheetName );
+ if( !aCalcName.isEmpty() )
+ sSheetNameRef = sSheetNameRef.replaceAt( 1, nSepPos - 1, aCalcName );
+ }
+ }
+}
+
sal_Int16 WorksheetBuffer::getCalcSheetIndex( const OUString& rWorksheetName ) const
{
const SheetInfo* pSheetInfo = maSheetInfosByName.get( rWorksheetName ).get();