[Libreoffice-commits] .: 4 commits - sc/inc sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Mon Dec 19 14:41:37 PST 2011
sc/inc/externalrefmgr.hxx | 29 ++++++++++++++++-
sc/source/core/data/cell.cxx | 2 +
sc/source/core/data/documen2.cxx | 24 +++++++++-----
sc/source/core/data/document.cxx | 28 ++++++++++++++--
sc/source/core/tool/token.cxx | 2 +
sc/source/ui/docshell/docsh.cxx | 16 +--------
sc/source/ui/docshell/externalrefmgr.cxx | 52 ++++++++++++++++++++++++++++++-
sc/source/ui/inc/namemgrtable.hxx | 2 -
sc/source/ui/namedlg/namemgrtable.cxx | 7 ++--
sc/source/ui/view/viewfun2.cxx | 5 ++
10 files changed, 137 insertions(+), 30 deletions(-)
New commits:
commit 8a9aea09d274419f924b17084137eaf6c0b92fc1
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Dec 19 23:22:55 2011 +0100
Copy absolute sheet refs between different docs: Part IV
Handle Move Sheet correctly
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index cfa027e..e2c950c 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -89,6 +89,7 @@
#include "docuno.hxx"
#include "charthelper.hxx"
#include "tabbgcolor.hxx"
+#include "clipparam.hxx"
#include <basic/sbstar.hxx>
#include <com/sun/star/container/XNameContainer.hpp>
@@ -2562,6 +2563,7 @@ void ScViewFunc::MoveTable(
if(nDestTab==SC_TAB_APPEND)
nDestTab=pDestDoc->GetTableCount();
SCTAB nDestTab1=nDestTab;
+ ScClipParam aParam;
for( sal_uInt16 j=0; j<TheTabs.size(); ++j, ++nDestTab1 )
{ // insert sheets first and update all references
rtl::OUString aName;
@@ -2576,7 +2578,10 @@ void ScViewFunc::MoveTable(
nErrVal = 0; // total error
break; // for
}
+ ScRange aRange( 0, 0, TheTabs[j], MAXCOL, MAXROW, TheTabs[j] );
+ aParam.maRanges.Append(aRange);
}
+ pDoc->SetClipParam(aParam);
if ( nErrVal > 0 )
{
nDestTab1 = nDestTab;
commit a0a1a34622e3c36c4e28561aba3a19ea8b6d51f6
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Dec 19 22:23:44 2011 +0100
Copy absolute refs between different docs: Part III
support copying from an unsaved document and some improvements
still problems with MoveTab and missing dialog box if we have external
refs to unsaved docs while we save
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index e39ac2e..b3a640e 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -33,9 +33,11 @@
#include "address.hxx"
#include "sfx2/objsh.hxx"
#include "sfx2/lnkbase.hxx"
+#include "sfx2/event.hxx"
#include "tools/time.hxx"
#include "vcl/timer.hxx"
#include "svl/zforlist.hxx"
+#include "svl/lstner.hxx"
#include "scmatrix.hxx"
#include "rangelst.hxx"
#include "formula/token.hxx"
@@ -46,6 +48,7 @@
#include <vector>
#include <list>
#include <set>
+#include <iostream>
#include <formula/ExternalReferenceHelper.hxx>
class ScDocument;
@@ -353,7 +356,7 @@ private:
mutable DocDataType maDocs;
};
-class SC_DLLPUBLIC ScExternalRefManager : public formula::ExternalReferenceHelper
+class SC_DLLPUBLIC ScExternalRefManager : public formula::ExternalReferenceHelper, SfxListener
{
public:
@@ -426,6 +429,7 @@ public:
::rtl::OUString maRelativeName;
::rtl::OUString maFilterName;
::rtl::OUString maFilterOptions;
+ bool bUnsaved;
void maybeCreateRealFileName(const String& rOwnDocName);
};
@@ -673,6 +677,16 @@ public:
*/
bool isFileLoadable(const ::rtl::OUString& rFile) const;
+ /**
+ * If in maUnsavedDocShells move it to maDocShells and create a correct
+ * external reference entry
+ *
+ * @param Pointer to the newly saved DocumentShell
+ */
+ void transformUnsavedRefToSavedRef( SfxObjectShell* pShell );
+
+ virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
+
private:
ScExternalRefManager();
ScExternalRefManager(const ScExternalRefManager&);
@@ -749,6 +763,13 @@ private:
sal_uInt32 getMappedNumberFormat(sal_uInt16 nFileId, sal_uInt32 nNumFmt, const ScDocument* pSrcDoc);
+ /**
+ * If we still contain unsaved files we should warn the user before saving
+ *
+ * @return true if the document still contains references to an unsaved file
+ */
+ bool containsUnsavedReferences() { return !maUnsavedDocShells.empty(); }
+
private:
/** cache of referenced ranges and names from source documents. */
ScExternalRefCache maRefCache;
@@ -761,6 +782,12 @@ private:
*/
DocShellMap maDocShells;
+ /**
+ * DocShells to unsaved but referenced documents. If not empty ask before saving!
+ * Move to maDocShells if document referenced here is saved
+ */
+ DocShellMap maUnsavedDocShells;
+
/** list of source documents that are managed by the link manager. */
LinkedDocMap maLinkedDocs;
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 37005ee..aa99070 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -41,6 +41,7 @@
#include <svx/svdobj.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/objsh.hxx>
+#include <sfx2/docfile.hxx>
#include <sfx2/printer.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
@@ -48,6 +49,7 @@
#include <comphelper/processfactory.hxx>
#include <svl/PasswordHelper.hxx>
#include <tools/tenccvt.hxx>
+#include <tools/urlobj.hxx>
#include <rtl/crc.h>
#include <basic/basmgr.hxx>
@@ -920,8 +922,21 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
bool bResultsOnly )
{
sal_uLong nRetVal = 1; // 0 => Fehler 1 = ok
- // 2 => RefBox, 3 => NameBox
+ // 3 => NameBox
// 4 => beides
+
+ if (pSrcDoc->pShell->GetMedium())
+ {
+ pSrcDoc->maFileURL = pSrcDoc->pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI);
+ // for unsaved files use the title name and adjust during save of file
+ if (pSrcDoc->maFileURL.isEmpty())
+ pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
+ }
+ else
+ {
+ pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
+ }
+
bool bValid = true;
if (bInsertNew) // neu einfuegen
{
@@ -1046,15 +1061,8 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
maTabs[nDestPos]->UpdateReference(URM_COPY, 0, 0, nDestPos,
MAXCOL, MAXROW, nDestPos,
0, 0, nDz, NULL);
- // Test for outside absolute references for info box
- bool bIsAbsRef = pSrcDoc->maTabs[nSrcPos]->TestTabRefAbs(nSrcPos);
// Readjust self-contained absolute references to this sheet
maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
- if (bIsAbsRef)
- {
- nRetVal += 1;
- // InfoBox AbsoluteRefs sind moeglicherweise nicht mehr korrekt!!
- }
if (bNamesLost)
{
nRetVal += 2;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index d12601f..9796ceb 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1919,9 +1919,6 @@ void ScDocument::CopyToClip(const ScClipParam& rClipParam,
// for unsaved files use the title name and adjust during save of file
if (pClipDoc->maFileURL.isEmpty())
pClipDoc->maFileURL = pShell->GetName();
-
- std::cout << pClipDoc->maFileURL << std::endl;
- std::cout << "GetName: " << rtl::OUString(pShell->GetName()) << std::endl;
}
else
{
@@ -1991,6 +1988,31 @@ void ScDocument::CopyTabToClip(SCCOL nCol1, SCROW nRow1,
{
if (!bIsClip)
{
+ if (pShell->GetMedium())
+ {
+ pClipDoc->maFileURL = pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI);
+ // for unsaved files use the title name and adjust during save of file
+ if (pClipDoc->maFileURL.isEmpty())
+ pClipDoc->maFileURL = pShell->GetName();
+ }
+ else
+ {
+ pClipDoc->maFileURL = pShell->GetName();
+ }
+
+ //init maTabNames
+ for (TableContainer::iterator itr = maTabs.begin(); itr != maTabs.end(); ++itr)
+ {
+ if( *itr )
+ {
+ rtl::OUString aTabName;
+ (*itr)->GetName(aTabName);
+ pClipDoc->maTabNames.push_back(aTabName);
+ }
+ else
+ pClipDoc->maTabNames.push_back(rtl::OUString());
+ }
+
PutInOrder( nCol1, nCol2 );
PutInOrder( nRow1, nRow2 );
if (!pClipDoc)
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 0e54338..35d6358 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1829,6 +1829,8 @@ void GetExternalTableData(const ScDocument* pOldDoc, const ScDocument* pNewDoc,
std::cout << aFileName << std::endl;
rFileId = pNewDoc->GetExternalRefManager()->getExternalFileId(aFileName);
rTabName = pOldDoc->GetCopyTabName(nTab);
+ if (rTabName.isEmpty())
+ pOldDoc->GetName(nTab, rTabName);
std::cout << "TabName: " << rTabName << std::endl;
}
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 9fa5769..26cea14 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -926,21 +926,11 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
pSheetSaveData->SetInSupportedSave(true);
break;
case SFX_EVENT_SAVEDOCDONE:
+ case SFX_EVENT_SAVEASDOCDONE:
{
- if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() )
- {
- }
+ // new positions are used after "save" and "save as", but not "save to"
UseSheetSaveEntries(); // use positions from saved file for next saving
- if (pSheetSaveData)
- pSheetSaveData->SetInSupportedSave(false);
- }
- break;
- case SFX_EVENT_SAVEASDOCDONE:
- // new positions are used after "save" and "save as", but not "save to"
- UseSheetSaveEntries(); // use positions from saved file for next saving
- if (pSheetSaveData)
- pSheetSaveData->SetInSupportedSave(false);
- break;
+ } // fall through
case SFX_EVENT_SAVETODOCDONE:
// only reset the flag, don't use the new positions
if (pSheetSaveData)
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 6d23ab9..bec7700 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2092,7 +2092,7 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI
while (pShell)
{
SfxMedium* pMedium = pShell->GetMedium();
- if (pMedium)
+ if (pMedium && pMedium->GetName().Len())
{
OUString aName = pMedium->GetName();
// TODO: We should make the case sensitivity platform dependent.
@@ -2103,6 +2103,21 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI
break;
}
}
+ else
+ {
+ // handle unsaved documents here
+ OUString aName = pShell->GetName();
+ if (pFileName->equalsIgnoreAsciiCase(aName))
+ {
+ // Found !
+ SrcShell aSrcDoc;
+ aSrcDoc.maShell = pShell;
+ maUnsavedDocShells.insert(DocShellMap::value_type(nFileId, aSrcDoc));
+ StartListening(*pShell);
+ pSrcDoc = pShell->GetDocument();
+ break;
+ }
+ }
pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, &aType, false));
}
@@ -2644,6 +2659,41 @@ sal_uInt32 ScExternalRefManager::getMappedNumberFormat(sal_uInt16 nFileId, sal_u
return nNumFmt;
}
+void ScExternalRefManager::transformUnsavedRefToSavedRef( SfxObjectShell* pShell )
+{
+ for(DocShellMap::iterator itr = maUnsavedDocShells.begin();
+ itr != maUnsavedDocShells.end(); ++itr)
+ {
+ if (&(itr->second.maShell) == pShell)
+ {
+ // found that the shell is marked as unsaved
+ rtl::OUString aFileURL = pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI);
+ switchSrcFile(itr->first, aFileURL, rtl::OUString());
+ EndListening(*pShell);
+ }
+ }
+}
+
+void ScExternalRefManager::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ if ( rHint.ISA( SfxEventHint ) )
+ {
+ sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
+ switch ( nEventId )
+ {
+ case SFX_EVENT_SAVEDOCDONE:
+ case SFX_EVENT_SAVEASDOCDONE:
+ {
+ SfxObjectShell* pObjShell = static_cast<const SfxEventHint&>( rHint ).GetObjShell();
+ transformUnsavedRefToSavedRef(pObjShell);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
IMPL_LINK(ScExternalRefManager, TimeOutHdl, AutoTimer*, pTimer)
{
if (pTimer == &maSrcDocTimer)
commit 2119f46497ab92218c8bf3a60dc54c7da78a94dd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Dec 19 01:39:34 2011 +0100
don't set current entry for every entry during init
diff --git a/sc/source/ui/inc/namemgrtable.hxx b/sc/source/ui/inc/namemgrtable.hxx
index 69bc102..3023e29 100644
--- a/sc/source/ui/inc/namemgrtable.hxx
+++ b/sc/source/ui/inc/namemgrtable.hxx
@@ -81,7 +81,7 @@ public:
ScRangeManagerTable( Window* pParent, boost::ptr_map<rtl::OUString, ScRangeName>& aTabRangeNames );
virtual ~ScRangeManagerTable();
- void addEntry( const ScRangeNameLine& rLine );
+ void addEntry( const ScRangeNameLine& rLine, bool bSetCurEntry = true );
void DeleteSelectedEntries();
void SetEntry( const ScRangeNameLine& rLine );
diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx
index 99b1ea0..7f8eb6b 100644
--- a/sc/source/ui/namedlg/namemgrtable.cxx
+++ b/sc/source/ui/namedlg/namemgrtable.cxx
@@ -104,10 +104,11 @@ ScRangeManagerTable::~ScRangeManagerTable()
Clear();
}
-void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine)
+void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine, bool bSetCurEntry)
{
SvLBoxEntry* pEntry = InsertEntryToColumn( createEntryString(rLine), LIST_APPEND, 0xffff);
- SetCurEntry(pEntry);
+ if (bSetCurEntry)
+ SetCurEntry(pEntry);
}
void ScRangeManagerTable::GetCurrentLine(ScRangeNameLine& rLine)
@@ -141,7 +142,7 @@ void ScRangeManagerTable::Init()
if (!it->second->HasType(RT_DATABASE) && !it->second->HasType(RT_SHARED))
{
aLine.aName = it->second->GetName();
- addEntry(aLine);
+ addEntry(aLine, false);
}
}
}
commit 2cc7b083386dec73b353c0bd187dfe3a58906c10
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Sun Dec 18 04:19:31 2011 +0100
Copy Absolute Formulas between Documents: Part II
adjust named ranges formulas too
little problem here:
tab absolute and col/row relative is tricky, the col/row is calculated
relative to the cell where the range name is used but we don't know in
which cells the range name is used
The other office solves that by making only references pointing to
sheets that are not copied external (this solution is not perfect)
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx
index f86d898..e85d984 100644
--- a/sc/source/core/data/cell.cxx
+++ b/sc/source/core/data/cell.cxx
@@ -179,6 +179,8 @@ void adjustRangeName(ScToken* pToken, ScDocument& rNewDoc, const ScDocument* pOl
{
bNewGlobal = bOldGlobal;
pRangeData = new ScRangeData(*pOldRangeData, &rNewDoc);
+ ScTokenArray* pRangeNameToken = pRangeData->GetCode();
+ pRangeNameToken->ReadjusteAbsolute3DReferences(pOldDoc, &rNewDoc, pRangeData->GetPos());
bool bInserted;
if (bNewGlobal)
bInserted = rNewDoc.GetRangeName()->insert(pRangeData);
More information about the Libreoffice-commits
mailing list