diff options
author | Noel Power <noel.power@suse.com> | 2013-01-08 10:56:44 +0000 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-01-08 11:01:04 +0000 |
commit | 92afb61d8bb1b264a945371065115981ecaed0f1 (patch) | |
tree | 454f19151a53e096740b1d5af032240679dc6bc9 /sc/source | |
parent | eb54843c8556cd39efb4ade347652ad118c5de66 (diff) |
support new hyperlink cell attribute
Allows a hyperlink attribute to be set for a cell, allows for import of say a
hyperlink associated with a formula cell. Since this patch does not add
any file format support it is not possible to save such an imported hyperlink
to ods. Note: such a hyperlink would not have been imported in the past so this
should not be an issue
Change-Id: Ieb234bb6e98e4a2630b596a90972a75be12a92d4
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/cell.cxx | 17 | ||||
-rw-r--r-- | sc/source/core/data/docpool.cxx | 23 | ||||
-rw-r--r-- | sc/source/filter/excel/xicontent.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/oox/worksheethelper.cxx | 29 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 40 |
5 files changed, 90 insertions, 35 deletions
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx index 371897686baa..ce073e2e29eb 100644 --- a/sc/source/core/data/cell.cxx +++ b/sc/source/core/data/cell.cxx @@ -610,6 +610,16 @@ bool ScBaseCell::CellEqual( const ScBaseCell* pCell1, const ScBaseCell* pCell2 ) return false; } +EditTextObject* ScBaseCell::CreateURLObjectFromURL( ScDocument& rDoc, const OUString& rURL, const OUString& rText ) +{ + SvxURLField aUrlField( rURL, rText, SVXURLFORMAT_APPDEFAULT); + EditEngine& rEE = rDoc.GetEditEngine(); + rEE.SetText( EMPTY_STRING ); + rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection( 0xFFFF, 0xFFFF ) ); + + return rEE.CreateTextObject(); +} + // ============================================================================ ScNoteCell::ScNoteCell( SvtBroadcaster* pBC ) : @@ -1979,12 +1989,7 @@ EditTextObject* ScFormulaCell::CreateURLObject() rtl::OUString aURL; GetURLResult( aURL, aCellText ); - SvxURLField aUrlField( aURL, aCellText, SVXURLFORMAT_APPDEFAULT); - EditEngine& rEE = pDocument->GetEditEngine(); - rEE.SetText( EMPTY_STRING ); - rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection( 0xFFFF, 0xFFFF ) ); - - return rEE.CreateTextObject(); + return CreateURLObjectFromURL( *pDocument, aURL, aCellText ); } // ============================================================================ diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx index 20044fea2825..7e422db10115 100644 --- a/sc/source/core/data/docpool.cxx +++ b/sc/source/core/data/docpool.cxx @@ -24,6 +24,7 @@ #include <vcl/outdev.hxx> #include <svl/aeitem.hxx> #include <svl/itemiter.hxx> +#include <svl/stritem.hxx> #include <svx/algitem.hxx> #include <editeng/boxitem.hxx> #include <editeng/bolnitem.hxx> @@ -81,6 +82,7 @@ sal_uInt16* ScDocumentPool::pVersionMap8 = 0; sal_uInt16* ScDocumentPool::pVersionMap9 = 0; sal_uInt16* ScDocumentPool::pVersionMap10 = 0; sal_uInt16* ScDocumentPool::pVersionMap11 = 0; +sal_uInt16* ScDocumentPool::pVersionMap12 = 0; // ATTR_FONT_TWOLINES (not used) was changed to ATTR_USERDEF (not saved in binary format) in 641c @@ -141,6 +143,7 @@ static SfxItemInfo const aItemInfos[] = { SID_ATTR_BORDER_SHADOW, SFX_ITEM_POOLABLE }, // ATTR_SHADOW { 0, SFX_ITEM_POOLABLE }, // ATTR_VALIDDATA { 0, SFX_ITEM_POOLABLE }, // ATTR_CONDITIONAL + { 0, SFX_ITEM_POOLABLE }, // ATTR_HYPERLINK { 0, SFX_ITEM_POOLABLE }, // ATTR_PATTERN { SID_ATTR_LRSPACE, SFX_ITEM_POOLABLE }, // ATTR_LRSPACE { SID_ATTR_ULSPACE, SFX_ITEM_POOLABLE }, // ATTR_ULSPACE @@ -279,6 +282,7 @@ ScDocumentPool::ScDocumentPool( SfxItemPool* pSecPool, sal_Bool bLoadRefCounts ) ppPoolDefaults[ ATTR_SHADOW - ATTR_STARTINDEX ] = new SvxShadowItem( ATTR_SHADOW ); ppPoolDefaults[ ATTR_VALIDDATA - ATTR_STARTINDEX ] = new SfxUInt32Item( ATTR_VALIDDATA, 0 ); ppPoolDefaults[ ATTR_CONDITIONAL - ATTR_STARTINDEX ] = new ScCondFormatItem; + ppPoolDefaults[ ATTR_HYPERLINK - ATTR_STARTINDEX ] = new SfxStringItem( ATTR_HYPERLINK, rtl::OUString() ) ; // GetRscString funktioniert erst nach ScGlobal::Init, zu erkennen am EmptyBrushItem //! zusaetzliche Methode ScGlobal::IsInit() oder so... @@ -366,6 +370,8 @@ ScDocumentPool::ScDocumentPool( SfxItemPool* pSecPool, sal_Bool bLoadRefCounts ) // ATTR_FONT_OVERLINE added in DEV300/overline2 SetVersionMap( 11, 100, 187, pVersionMap11 ); + // ATTR_HYERLINK added + SetVersionMap( 12, 100, 192, pVersionMap12 ); } ScDocumentPool::~ScDocumentPool() @@ -389,7 +395,7 @@ void ScDocumentPool::InitVersionMaps() !pVersionMap5 && !pVersionMap6 && !pVersionMap7 && !pVersionMap8 && !pVersionMap9 && !pVersionMap10 && - !pVersionMap11, "InitVersionMaps call multiple times" ); + !pVersionMap11 && !pVersionMap12 , "InitVersionMaps call multiple times" ); // alte WhichId's mappen // nicht mit ATTR_* zaehlen, falls die sich nochmal aendern @@ -539,6 +545,17 @@ void ScDocumentPool::InitVersionMaps() // 1 entry inserted for ( i=nMap11New, j=nMap11Start+nMap11New+1; i < nMap11Count; i++, j++ ) pVersionMap11[i] = j; + + const sal_uInt16 nMap12Start = 100; // ATTR_STARTINDEX + const sal_uInt16 nMap12End = 192; // ATTR_ENDINDEX + const sal_uInt16 nMap12Count = nMap12End - nMap12Start + 1; + const sal_uInt16 nMap12New = 55; // ATTR_HYPERLINK - ATTR_STARTINDEX + pVersionMap12 = new sal_uInt16 [ nMap12Count ]; + for ( i=0, j=nMap12Start; i < nMap12New; i++, j++ ) + pVersionMap12[i] = j; + // 1 entry inserted + for ( i=nMap12New, j=nMap12Start+nMap12New+1; i < nMap12Count; i++, j++ ) + pVersionMap12[i] = j; } void ScDocumentPool::DeleteVersionMaps() @@ -548,8 +565,10 @@ void ScDocumentPool::DeleteVersionMaps() pVersionMap5 && pVersionMap6 && pVersionMap7 && pVersionMap8 && pVersionMap9 && pVersionMap10 && - pVersionMap11, "DeleteVersionMaps without maps" ); + pVersionMap11 && pVersionMap12 , "DeleteVersionMaps without maps" ); + delete[] pVersionMap12; + pVersionMap12 = 0; delete[] pVersionMap11; pVersionMap11 = 0; delete[] pVersionMap10; diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index 7e09fb4decce..2a7b5ff43e7c 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -205,7 +205,21 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC } break; - default:; + default: + // Handle other cell types e.g. formulas ( and ? ) that have associated + // hyperlinks. + // Ideally all hyperlinks should be treated as below. For the moment, + // given the current absence of ods support lets just handle what we + // previously didn't handle the new way. + // Unfortunately we won't be able to preserve such hyperlinks when + // saving to ods. Note: when we are able to save such hyperlinks to ods + // we should handle *all* imported hyperlinks as below ( e.g. as cell + // attribute ) for better interoperability. + { + SfxStringItem aItem( ATTR_HYPERLINK, rUrl ); + rDoc.ApplyAttr( nScCol, nScRow, nScTab, aItem ); + break; + } } } diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index fbb4dd223ddd..449306ad8967 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -66,6 +66,8 @@ #include "worksheetbuffer.hxx" #include "worksheetsettings.hxx" #include "formulabuffer.hxx" +#include "scitems.hxx" +#include <svl/stritem.hxx> namespace oox { namespace xls { @@ -1039,22 +1041,21 @@ void WorksheetGlobals::insertHyperlink( const CellAddress& rAddress, const OUStr } } break; - - // fix for #i31050# disabled, HYPERLINK is not able to return numeric value (#i91351#) -#if 0 - // #i31050# replace number with HYPERLINK function - case CellContentType_VALUE: + // Handle other cell types e.g. formulas ( and ? ) that have associated + // hyperlinks. + // Ideally all hyperlinks should be treated as below. For the moment, + // given the current absence of ods support lets just handle what we + // previously didn't handle the new way. + // Unfortunately we won't be able to preserve such hyperlinks when + // saving to ods. Note: when we are able to save such hyperlinks to ods + // we should handle *all* imported hyperlinks as below ( e.g. as cell + // attribute ) for better interoperability. + default: { - Reference< XFormulaTokens > xTokens( xCell, UNO_QUERY ); - ApiTokenSequence aTokens = getFormulaParser().convertNumberToHyperlink( rUrl, xCell->getValue() ); - OSL_ENSURE( xTokens.is(), "WorksheetHelper::insertHyperlink - missing formula token interface" ); - if( xTokens.is() && aTokens.hasElements() ) - xTokens->setTokens( aTokens ); + SfxStringItem aItem( ATTR_HYPERLINK, rUrl ); + getScDocument().ApplyAttr( static_cast< SCCOL >( rAddress.Column ), static_cast< SCROW >( rAddress.Row ), static_cast< SCTAB >( rAddress.Sheet ), aItem ); + break; } - break; -#endif - - default:; } } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 620d625f8dfc..96edbcbac3a2 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -378,7 +378,7 @@ static void lcl_UnLockComment( ScDrawView* pView, SdrPageView* pPV, SdrModel* pD } } -static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell ) +static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell, OUString& rURL ) { sal_Bool bFound = false; do @@ -391,13 +391,22 @@ static sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPos else --rPosX; // weitersuchen } - else if ( rpCell->GetCellType() == CELLTYPE_EDIT) - bFound = sal_True; - else if (rpCell->GetCellType() == CELLTYPE_FORMULA && - static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell()) - bFound = sal_True; else - return false; // andere Zelle + { + const ScPatternAttr* pPattern = pDoc->GetPattern( rPosX, rPosY, nTab ); + if ( ((SfxStringItem&)pPattern->GetItem(ATTR_HYPERLINK)).GetValue().Len() > 0 ) + { + rURL = ((SfxStringItem&)pPattern->GetItem(ATTR_HYPERLINK)).GetValue(); + bFound = true; + } + else if ( rpCell->GetCellType() == CELLTYPE_EDIT) + bFound = sal_True; + else if (rpCell->GetCellType() == CELLTYPE_FORMULA && + static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell()) + bFound = sal_True; + else + return false; // andere Zelle + } } while ( !bFound ); @@ -2305,7 +2314,8 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt ) SCTAB nTab = pViewData->GetTabNo(); pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY ); ScBaseCell* pCell = NULL; - if( lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell ) ) + OUString sURL; + if( lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell, sURL ) ) { ScAddress aCellPos( nPosX, nPosY, nTab ); uno::Reference< table::XCell > xCell( new ScCellObj( pViewData->GetDocShell(), aCellPos ) ); @@ -5016,8 +5026,8 @@ bool ScGridWindow::GetEditUrlOrError( bool bSpellErr, const Point& rPos, ScDocShell* pDocSh = pViewData->GetDocShell(); ScDocument* pDoc = pDocSh->GetDocument(); ScBaseCell* pCell = NULL; - - sal_Bool bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell ); + OUString sURL; + sal_Bool bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell, sURL ); if( !bFound ) return false; @@ -5094,9 +5104,15 @@ bool ScGridWindow::GetEditUrlOrError( bool bSpellErr, const Point& rPos, if (pData) aEngine.SetText(*pData); } - else // HyperLink Formula cell + else // Not an Edit cell and is a formula cell with 'Hyperlink' + // function if we have no URL, otherwise it could be a formula + // cell ( or other type ? ) with a hyperlink associated with it. { - pTextObj.reset((static_cast<ScFormulaCell*>(pCell))->CreateURLObject()); + if ( sURL.isEmpty() ) + pTextObj.reset((static_cast<ScFormulaCell*>(pCell))->CreateURLObject()); + else + pTextObj.reset( ScBaseCell::CreateURLObjectFromURL( *pDoc, sURL, sURL ) ); + if (pTextObj.get()) aEngine.SetText(*pTextObj); } |