summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2014-12-12 17:09:45 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-01-07 13:31:00 +0000
commit40ec3aa2d5f9ecf713cce0fd7c89fdd5f830f664 (patch)
tree8f8431c3fac6a7c1ad7f7972f145d2b60efe10d9
parentd210265a1b6c4d7b405ef6e79fd30395ca1bc0aa (diff)
rhbz#1116534 crash when pasting over a formula
When pasting CSV data into existing document, we cannot use the ScImportExport optimization for insertion, because the cells can already have content (a grouped formula in this case). So use appropriate ScDocument functions, even if that means the import is slower. This is a regression from commit 93959db4d8846cfdfb87ab647c4d457fb09bb869 "use DocumentImport for csv import, related fdo#69006". (cherry picked from commit bf97980c8d5d5fbc63a08b8834c10fe903152b75) Conflicts: sc/source/ui/view/viewfun5.cxx Change-Id: I92f70abca0542d796e3aa674b28a31053fff00d0 Reviewed-on: https://gerrit.libreoffice.org/13456 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/source/ui/docshell/impex.cxx69
-rw-r--r--sc/source/ui/inc/impex.hxx4
-rw-r--r--sc/source/ui/view/viewfun5.cxx6
3 files changed, 54 insertions, 25 deletions
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 9882966a1992..feba39cfea14 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -85,7 +85,8 @@ ScImportExport::ScImportExport( ScDocument* p )
bFormulas( false ), bIncludeFiltered( true ),
bAll( true ), bSingle( true ), bUndo( false ),
bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ),
- mbApi( true ), mbImportBroadcast(false), mExportTextOptions()
+ mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ),
+ mExportTextOptions()
{
pUndoDoc = NULL;
pExtOptions = NULL;
@@ -99,7 +100,8 @@ ScImportExport::ScImportExport( ScDocument* p, const ScAddress& rPt )
bFormulas( false ), bIncludeFiltered( true ),
bAll( false ), bSingle( true ), bUndo( pDocSh != NULL ),
bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ),
- mbApi( true ), mbImportBroadcast(false), mExportTextOptions()
+ mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ),
+ mExportTextOptions()
{
pUndoDoc = NULL;
pExtOptions = NULL;
@@ -114,7 +116,8 @@ ScImportExport::ScImportExport( ScDocument* p, const ScRange& r )
bFormulas( false ), bIncludeFiltered( true ),
bAll( false ), bSingle( false ), bUndo( pDocSh != NULL ),
bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ),
- mbApi( true ), mbImportBroadcast(false), mExportTextOptions()
+ mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ),
+ mExportTextOptions()
{
pUndoDoc = NULL;
pExtOptions = NULL;
@@ -130,7 +133,8 @@ ScImportExport::ScImportExport( ScDocument* p, const OUString& rPos )
bFormulas( false ), bIncludeFiltered( true ),
bAll( false ), bSingle( true ), bUndo( pDocSh != NULL ),
bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ),
- mbApi( true ), mbImportBroadcast(false), mExportTextOptions()
+ mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ),
+ mExportTextOptions()
{
pUndoDoc = NULL;
pExtOptions = NULL;
@@ -928,7 +932,8 @@ bool ScImportExport::Text2Doc( SvStream& rStrm )
// Extended Ascii-Import
static bool lcl_PutString(
- ScDocumentImport& rDocImport, SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rStr, sal_uInt8 nColFormat,
+ ScDocumentImport& rDocImport, bool bUseDocImport,
+ SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rStr, sal_uInt8 nColFormat,
SvNumberFormatter* pFormatter, bool bDetectNumFormat,
::utl::TransliterationWrapper& rTransliteration, CalendarWrapper& rCalendar,
::utl::TransliterationWrapper* pSecondTransliteration, CalendarWrapper* pSecondCalendar )
@@ -952,17 +957,24 @@ static bool lcl_PutString(
pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs);
}
- if(ScStringUtil::isMultiline(rStr))
+ if ( bUseDocImport )
{
- ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
- rEngine.SetText(rStr);
- rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject());
- return true;
- }
- else
+ if(ScStringUtil::isMultiline(rStr))
+ {
+ ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
+ rEngine.SetText(rStr);
+ rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject());
+ return true;
+ }
+ else
+ {
+ rDocImport.setStringCell(ScAddress(nCol, nRow, nTab), rStr);
+ return false;
+ }
+ } else
{
- rDocImport.setStringCell(ScAddress(nCol, nRow, nTab), rStr);
- return false;
+ pDoc->SetTextCell(ScAddress(nCol, nRow, nTab), rStr);
+ return bMultiLine;
}
}
@@ -976,7 +988,10 @@ static bool lcl_PutString(
if ( pDocFormatter->IsNumberFormat( rStr, nEnglish, fVal ) )
{
// Numberformat will not be set to English
- rDocImport.setNumericCell( ScAddress( nCol, nRow, nTab ), fVal );
+ if ( bUseDocImport )
+ rDocImport.setNumericCell( ScAddress( nCol, nRow, nTab ), fVal );
+ else
+ pDoc->SetValue( nCol, nRow, nTab, fVal );
return bMultiLine;
}
// else, continue with SetString
@@ -1165,7 +1180,10 @@ static bool lcl_PutString(
nFormat = pDocFormatter->GetStandardFormat( fDays, nFormat, nType, eDocLang);
ScAddress aPos(nCol,nRow,nTab);
- rDocImport.setNumericCell(aPos, fDays);
+ if ( bUseDocImport )
+ rDocImport.setNumericCell(aPos, fDays);
+ else
+ pDoc->SetValue( aPos, fDays );
pDoc->SetNumberFormat(aPos, nFormat);
return bMultiLine; // success
@@ -1182,14 +1200,20 @@ static bool lcl_PutString(
aParam.mbDetectNumberFormat = bDetectNumFormat;
aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly;
aParam.mbHandleApostrophe = false;
- rDocImport.setAutoInput(ScAddress(nCol, nRow, nTab), rStr, &aParam);
+ if ( bUseDocImport )
+ rDocImport.setAutoInput(ScAddress(nCol, nRow, nTab), rStr, &aParam);
+ else
+ pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
}
else
{
bMultiLine = true;
ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
rEngine.SetText(rStr);
- rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject());
+ if ( bUseDocImport )
+ rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject());
+ else
+ pDoc->SetEditText( ScAddress( nCol, nRow, nTab ), rEngine.CreateTextObject() );
}
return bMultiLine;
}
@@ -1347,7 +1371,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
nFmt = SC_COL_TEXT;
bMultiLine |= lcl_PutString(
- aDocImport, nCol, nRow, nTab, aCell, nFmt,
+ aDocImport, !mbOverwriting, nCol, nRow, nTab, aCell, nFmt,
&aNumFormatter, bDetectNumFormat, aTransliteration, aCalendar,
pEnglishTransliteration.get(), pEnglishCalendar.get());
}
@@ -1390,7 +1414,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
nFmt = SC_COL_TEXT;
bMultiLine |= lcl_PutString(
- aDocImport, nCol, nRow, nTab, aCell, nFmt,
+ aDocImport, !mbOverwriting, nCol, nRow, nTab, aCell, nFmt,
&aNumFormatter, bDetectNumFormat, aTransliteration,
aCalendar, pEnglishTransliteration.get(), pEnglishCalendar.get());
}
@@ -1448,13 +1472,14 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
bDetermineRange = !bDetermineRange; // toggle
} while (!bDetermineRange);
- aDocImport.finalize();
+ if ( !mbOverwriting )
+ aDocImport.finalize();
xProgress.reset(); // make room for AdjustRowHeight progress
if (bRangeIsDetermined)
EndPaste(false);
- if (mbImportBroadcast)
+ if (mbImportBroadcast && !mbOverwriting)
{
pDoc->BroadcastCells(aRange, SC_HINT_DATACHANGED);
pDocSh->PostDataChanged();
diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx
index 9faa1a69ac52..0db2234d742d 100644
--- a/sc/source/ui/inc/impex.hxx
+++ b/sc/source/ui/inc/impex.hxx
@@ -67,6 +67,9 @@ class ScImportExport
bool bOverflowCell; // too much data for a cell
bool mbApi;
bool mbImportBroadcast; // whether or not to broadcast after data import.
+ bool mbOverwriting; // Whether we could be overwriting existing values (paste).
+ // In this case we cannot use the insert optimization, but we
+ // do not need to broadcast after the import.
ScExportTextOptions mExportTextOptions;
ScAsciiOptions* pExtOptions; // extended options
@@ -155,6 +158,7 @@ public:
bool IsApi() const { return mbApi; }
void SetApi( bool bApi ) { mbApi = bApi; }
void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
+ void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
};
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 9d398119e296..6803808c2c19 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -294,9 +294,9 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
}
else
{
- ScAddress aCellPos( nPosX, nPosY, GetViewData()->GetTabNo() );
- ScImportExport aObj( GetViewData()->GetDocument(), aCellPos );
- aObj.SetImportBroadcast(true);
+ ScAddress aCellPos( nPosX, nPosY, GetViewData().GetTabNo() );
+ ScImportExport aObj( GetViewData().GetDocument(), aCellPos );
+ aObj.SetOverwriting( true );
OUString aStr;
SotStorageStreamRef xStream;