[Libreoffice-commits] .: 2 commits - sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed May 25 11:40:03 PDT 2011
sc/inc/externalrefmgr.hxx | 7 +
sc/source/ui/app/transobj.cxx | 4 -
sc/source/ui/docshell/externalrefmgr.cxx | 4 +
sc/source/ui/docshell/impex.cxx | 16 ++--
sc/source/ui/inc/viewfunc.hxx | 4 -
sc/source/ui/undo/undoblk.cxx | 3
sc/source/ui/view/cellsh3.cxx | 6 +
sc/source/ui/view/gridwin.cxx | 2
sc/source/ui/view/viewfun5.cxx | 115 ++++++++++++++++++-------------
sc/source/ui/view/viewfunc.cxx | 7 +
10 files changed, 106 insertions(+), 62 deletions(-)
New commits:
commit 9aa5c0fe84edd8d043602de419573a1ca49fe2bd
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Apr 20 17:07:41 2011 -0400
Paste link from another calc doc as external reference instead of DDE.
DDE is deprecated, and it relies on platform dependent file paths which
are non-portable. Better use external references for paste link
operations.
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index b94987f..a0b8246 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -304,7 +304,7 @@ sal_Bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor )
// if this transfer object was used to create a DDE link, filtered rows
// have to be included for subsequent calls (to be consistent with link data)
if ( nFormat == SOT_FORMATSTR_ID_LINK )
- bUsedForLink = sal_True;
+ bUsedForLink = true;
sal_Bool bIncludeFiltered = pDoc->IsCutMode() || bUsedForLink;
@@ -395,7 +395,7 @@ sal_Bool ScTransferObj::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObj
{
// called from SetObject, put data into stream
- sal_Bool bRet = false;
+ bool bRet = false;
switch (nUserObjectId)
{
case SCTRANS_TYPE_IMPEX:
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 21becd5..5b9ed57 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -475,21 +475,27 @@ sal_Bool ScImportExport::ExportStream( SvStream& rStrm, const String& rBaseURL,
DBG_ASSERT( aDocName.Len(), "ClipBoard document has no name! :-/" );
if( aDocName.Len() )
{
+ // Always use Calc A1 syntax for paste link.
String aRefName;
sal_uInt16 nFlags = SCA_VALID | SCA_TAB_3D;
if( bSingle )
- aRange.aStart.Format( aRefName, nFlags, pDoc, pDoc->GetAddressConvention() );
+ aRange.aStart.Format( aRefName, nFlags, pDoc, formula::FormulaGrammar::CONV_OOO );
else
{
if( aRange.aStart.Tab() != aRange.aEnd.Tab() )
nFlags |= SCA_TAB2_3D;
- aRange.Format( aRefName, nFlags, pDoc );
+ aRange.Format( aRefName, nFlags, pDoc, formula::FormulaGrammar::CONV_OOO );
}
String aAppName = Application::GetAppName();
- WriteUnicodeOrByteString( rStrm, aAppName, sal_True );
- WriteUnicodeOrByteString( rStrm, aDocName, sal_True );
- WriteUnicodeOrByteString( rStrm, aRefName, sal_True );
+ // extra bits are used to tell the client to prefer external
+ // reference link.
+ ::rtl::OUString aExtraBits(RTL_CONSTASCII_USTRINGPARAM("calc:extref"));
+
+ WriteUnicodeOrByteString( rStrm, aAppName, true );
+ WriteUnicodeOrByteString( rStrm, aDocName, true );
+ WriteUnicodeOrByteString( rStrm, aRefName, true );
+ WriteUnicodeOrByteString( rStrm, aExtraBits, true );
if ( rStrm.GetStreamCharSet() == RTL_TEXTENCODING_UNICODE )
rStrm << sal_Unicode(0);
else
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index deca468..08cc60e 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -100,7 +100,7 @@ public:
void EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, const EditTextObject* pData,
sal_Bool bRecord = sal_True, sal_Bool bTestSimple = false );
- void EnterMatrix( const String& rString );
+ void EnterMatrix( const String& rString, ::formula::FormulaGrammar::Grammar eGram );
void EnterBlock( const String& rString, const EditTextObject* pData );
void EnterDataAtCursor( const String& rString ); //! nicht benutzt ?
@@ -149,7 +149,7 @@ public:
const ::com::sun::star::uno::Reference<
::com::sun::star::datatransfer::XTransferable >& rxTransferable,
SCCOL nPosX, SCROW nPosY );
- sal_Bool PasteDDE( const ::com::sun::star::uno::Reference<
+ bool PasteLink( const ::com::sun::star::uno::Reference<
::com::sun::star::datatransfer::XTransferable >& rxTransferable );
sal_Bool ApplyGraphicToObject( SdrObject* pObject, const Graphic& rGraphic );
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 868ecad..06f8446 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1768,7 +1768,8 @@ void ScUndoEnterMatrix::Repeat(SfxRepeatTarget& rTarget)
if (rTarget.ISA(ScTabViewTarget))
{
String aTemp = aFormula;
- ((ScTabViewTarget&)rTarget).GetViewShell()->EnterMatrix(aTemp);
+ ScDocument* pDoc = pDocShell->GetDocument();
+ ((ScTabViewTarget&)rTarget).GetViewShell()->EnterMatrix(aTemp, pDoc->GetGrammar());
}
}
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 9ea2068..7c6f7d7 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -219,7 +219,8 @@ void ScCellShell::Execute( SfxRequest& rReq )
{
String aStr = ((const SfxStringItem&)pReqArgs->
Get( SID_INSERT_MATRIX )).GetValue();
- pTabViewShell->EnterMatrix( aStr );
+ ScDocument* pDoc = GetViewData()->GetDocument();
+ pTabViewShell->EnterMatrix( aStr, pDoc->GetGrammar() );
rReq.Done();
}
}
@@ -288,7 +289,8 @@ void ScCellShell::Execute( SfxRequest& rReq )
}
else
{
- pTabViewShell->EnterMatrix( aString );
+ ScDocument* pDoc = GetViewData()->GetDocument();
+ pTabViewShell->EnterMatrix( aString, pDoc->GetGrammar() );
rReq.Done();
}
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index cd75842..d2f864f 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -4033,7 +4033,7 @@ sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPos
pView->MarkCursor( nDestPosX + nSizeX - 1,
nDestPosY + nSizeY - 1, nThisTab );
- pView->EnterMatrix( aFormula );
+ pView->EnterMatrix( aFormula, ::formula::FormulaGrammar::GRAM_NATIVE );
pView->MarkRange( aDest, false, false );
pView->SetCursor( aDest.aStart.Col(), aDest.aStart.Row() );
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index a2e3c30..9ba12c1 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -288,7 +288,7 @@ sal_Bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
}
else if ( nFormatId == SOT_FORMATSTR_ID_LINK ) // LINK is also in ScImportExport
{
- bRet = PasteDDE( rxTransferable );
+ bRet = PasteLink( rxTransferable );
}
else if ( ScImportExport::IsFormatSupported( nFormatId ) || nFormatId == SOT_FORMAT_RTF )
{
@@ -630,17 +630,7 @@ sal_Bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
return bRet;
}
-ByteString lcl_GetSubString( sal_Char* pData, long nStart, long nDataSize )
-{
- if ( nDataSize <= nStart /* || pData[nDataSize] != 0 */ )
- {
- OSL_FAIL("DDE Data: invalid data");
- return ByteString();
- }
- return ByteString( pData + nStart );
-}
-
-sal_Bool ScViewFunc::PasteDDE( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
+bool ScViewFunc::PasteLink( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
{
TransferableDataHelper aDataHelper( rxTransferable );
@@ -682,37 +672,76 @@ sal_Bool ScViewFunc::PasteDDE( const uno::Reference<datatransfer::XTransferable>
// create formula
- long nSeqLen = aSequence.getLength();
- sal_Char* pData = (sal_Char*)aSequence.getConstArray();
+ sal_Int32 nSeqLen = aSequence.getLength();
+ const char* p = reinterpret_cast<const char*>(aSequence.getConstArray());
rtl_TextEncoding eSysEnc = gsl_getSystemTextEncoding();
- ByteString aByteApp = lcl_GetSubString( pData, 0, nSeqLen );
- ByteString aByteTopic = lcl_GetSubString( pData, aByteApp.Len() + 1, nSeqLen );
- ByteString aByteItem = lcl_GetSubString( pData, aByteApp.Len() + aByteTopic.Len() + 2, nSeqLen );
-
- String aApp( aByteApp, eSysEnc );
- String aTopic( aByteTopic, eSysEnc );
- String aItem( aByteItem, eSysEnc );
-
- // TODO: we could define ocQuote for "
- const String aQuote( '"' );
- const String& sSep = ScCompiler::GetNativeSymbol( ocSep);
- String aFormula( '=' );
- aFormula += ScCompiler::GetNativeSymbol( ocDde);
- aFormula += ScCompiler::GetNativeSymbol( ocOpen);
- aFormula += aQuote;
- aFormula += aApp;
- aFormula += aQuote;
- aFormula += sSep;
- aFormula += aQuote;
- aFormula += aTopic;
- aFormula += aQuote;
- aFormula += sSep;
- aFormula += aQuote;
- aFormula += aItem;
- aFormula += aQuote;
- aFormula += ScCompiler::GetNativeSymbol( ocClose);
+ // char array delimited by \0.
+ // app \0 topic \0 item \0 (extra \0) where the extra is optional.
+ ::std::vector<rtl::OUString> aStrs;
+ const char* pStart = p;
+ sal_Int32 nStart = 0;
+ for (sal_Int32 i = 0; i < nSeqLen; ++i, ++p)
+ {
+ if (*p == '\0')
+ {
+ sal_Int32 nLen = i - nStart;
+ aStrs.push_back(rtl::OUString(pStart, nLen, eSysEnc));
+ nStart = ++i;
+ pStart = ++p;
+ }
+ }
+
+ if (aStrs.size() < 3)
+ return false;
+
+ const rtl::OUString* pApp = &aStrs[0];
+ const rtl::OUString* pTopic = &aStrs[1];
+ const rtl::OUString* pItem = &aStrs[2];
+ const rtl::OUString* pExtra = NULL;
+ if (aStrs.size() > 3)
+ pExtra = &aStrs[3];
+
+ if (pExtra && pExtra->equalsAscii("calc:extref"))
+ {
+ // Paste this as an external reference. Note that paste link always
+ // uses Calc A1 syntax even when another formula syntax is specified
+ // in the UI.
+ rtl::OUStringBuffer aBuf;
+ aBuf.appendAscii("='");
+ rtl::OUString aPath = ScGlobal::GetAbsDocName(
+ *pTopic, GetViewData()->GetDocument()->GetDocumentShell());
+ aBuf.append(aPath);
+ aBuf.appendAscii("'#");
+ aBuf.append(*pItem);
+ EnterMatrix(aBuf.makeStringAndClear(), ::formula::FormulaGrammar::GRAM_NATIVE);
+ return true;
+ }
+ else
+ {
+ // DDE in all other cases.
+
+ // TODO: we could define ocQuote for "
+ rtl::OUStringBuffer aBuf;
+ aBuf.append(sal_Unicode('='));
+ aBuf.append(ScCompiler::GetNativeSymbol(ocDde));
+ aBuf.append(ScCompiler::GetNativeSymbol(ocOpen));
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(*pApp);
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(ScCompiler::GetNativeSymbol(ocSep));
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(*pTopic);
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(ScCompiler::GetNativeSymbol(ocSep));
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(*pItem);
+ aBuf.append(sal_Unicode('"'));
+ aBuf.append(ScCompiler::GetNativeSymbol(ocClose));
+
+ EnterMatrix(aBuf.makeStringAndClear(), ::formula::FormulaGrammar::GRAM_NATIVE);
+ }
// mark range
@@ -724,13 +753,9 @@ sal_Bool ScViewFunc::PasteDDE( const uno::Reference<datatransfer::XTransferable>
InitBlockMode( nCurX, nCurY, nTab );
MarkCursor( nCurX+static_cast<SCCOL>(nCols)-1, nCurY+static_cast<SCROW>(nRows)-1, nTab );
ShowAllCursors();
-
- // enter formula
-
- EnterMatrix( aFormula );
CursorPosChanged();
- return sal_True;
+ return true;
}
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index eea615a..1c7af99 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -899,7 +899,7 @@ void ScViewFunc::EnterDataAtCursor( const String& rString )
EnterData( nPosX, nPosY, nTab, rString );
}
-void ScViewFunc::EnterMatrix( const String& rString )
+void ScViewFunc::EnterMatrix( const String& rString, ::formula::FormulaGrammar::Grammar eGram )
{
ScViewData* pData = GetViewData();
const ScMarkData& rMark = pData->GetMarkData();
@@ -912,7 +912,7 @@ void ScViewFunc::EnterMatrix( const String& rString )
SCCOL nCol = pData->GetCurX();
SCROW nRow = pData->GetCurY();
SCTAB nTab = pData->GetTabNo();
- ScFormulaCell aFormCell( pDoc, ScAddress(nCol,nRow,nTab), rString,formula::FormulaGrammar::GRAM_DEFAULT, MM_FORMULA );
+ ScFormulaCell aFormCell( pDoc, ScAddress(nCol,nRow,nTab), rString, eGram, MM_FORMULA );
SCSIZE nSizeX;
SCSIZE nSizeY;
@@ -932,7 +932,8 @@ void ScViewFunc::EnterMatrix( const String& rString )
if (pData->GetSimpleArea(aRange) == SC_MARK_SIMPLE)
{
ScDocShell* pDocSh = pData->GetDocShell();
- sal_Bool bSuccess = pDocSh->GetDocFunc().EnterMatrix( aRange, &rMark, NULL, rString, false, false, EMPTY_STRING, formula::FormulaGrammar::GRAM_DEFAULT );
+ bool bSuccess = pDocSh->GetDocFunc().EnterMatrix(
+ aRange, &rMark, NULL, rString, false, false, EMPTY_STRING, eGram );
if (bSuccess)
pDocSh->UpdateOle(GetViewData());
}
commit 4a5aee05126c90f0383c585e5685d6655138e7f6
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Apr 20 15:47:55 2011 -0400
Check if the referenced file is loadable, and if not, don't update.
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 834a4fe..13cbeae 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -672,6 +672,12 @@ public:
*/
void notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdateType eType);
+ /**
+ * Check if the file specified by the path is a legitimate file that
+ * exists & can be loaded.
+ */
+ bool isFileLoadable(const String& rFile) const;
+
private:
ScExternalRefManager();
ScExternalRefManager(const ScExternalRefManager&);
@@ -722,7 +728,6 @@ private:
const ScDocument* getInMemorySrcDocument(sal_uInt16 nFileId);
const ScDocument* getSrcDocument(sal_uInt16 nFileId);
SfxObjectShellRef loadSrcDocument(sal_uInt16 nFileId, String& rFilter);
- bool isFileLoadable(const String& rFile) const;
void maybeLinkExternalFile(sal_uInt16 nFileId);
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 1bfdc8b..6d39d73 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1272,6 +1272,10 @@ void ScExternalRefLink::DataChanged(const String& /*rMimeType*/, const Any& /*rV
String aFile, aFilter;
mpDoc->GetLinkManager()->GetDisplayNames(this, NULL, &aFile, NULL, &aFilter);
ScExternalRefManager* pMgr = mpDoc->GetExternalRefManager();
+
+ if (!pMgr->isFileLoadable(aFile))
+ return;
+
const String* pCurFile = pMgr->getExternalFileName(mnFileId);
if (!pCurFile)
return;
More information about the Libreoffice-commits
mailing list