summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-20 15:52:14 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-22 21:49:17 -0400
commitbcf5b54b47eda4e39b4f5f4813cb43e1f52f0201 (patch)
tree0c32ff51267e7aaaa4bf1927ac5fb40260c70743 /sc
parente3504ca6b84f5f38ded12e279d3b3ee36f9ffa33 (diff)
Add SetStringCell() and SetEditCell() to ScDocFunc.
More on averting the use of PutCell(). Change-Id: I3881d7d468780eefe8016c754a053eb42ad3c5ad
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/collab/sendfunc.cxx30
-rw-r--r--sc/source/ui/collab/sendfunc.hxx25
-rw-r--r--sc/source/ui/docshell/docfunc.cxx148
-rw-r--r--sc/source/ui/inc/docfunc.hxx2
-rw-r--r--sc/source/ui/view/viewfunc.cxx8
5 files changed, 164 insertions, 49 deletions
diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index 4b969346f5e4..60b1f0f24ec6 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -58,6 +58,16 @@ void ScDocFuncSend::RecvMessage( const rtl::OString &rString )
mpDirect->SetValueCell(
aReader.getAddress(1), aReader.getDouble(2), aReader.getBool(3));
}
+ else if (aReader.getMethod() == "setStringCell")
+ {
+ mpDirect->SetStringCell(
+ aReader.getAddress(1), aReader.getString(2), aReader.getBool(3));
+ }
+ else if (aReader.getMethod() == "setEditCell")
+ {
+ mpDirect->SetEditCell(
+ aReader.getAddress(1), aReader.getEdit(2), aReader.getBool(3));
+ }
else if ( aReader.getMethod() == "enterListAction" )
mpDirect->EnterListAction( aReader.getInt( 1 ) );
else if ( aReader.getMethod() == "endListAction" )
@@ -141,6 +151,26 @@ bool ScDocFuncSend::SetValueCell( const ScAddress& rPos, double fVal, bool bInte
return true; // needs some code auditing action
}
+bool ScDocFuncSend::SetStringCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction )
+{
+ ScChangeOpWriter aOp("setStringCell");
+ aOp.appendAddress( rPos );
+ aOp.appendString( rStr );
+ aOp.appendBool( bInteraction );
+ SendMessage( aOp );
+ return true; // needs some code auditing action
+}
+
+bool ScDocFuncSend::SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, bool bInteraction )
+{
+ ScChangeOpWriter aOp("setEditCell");
+ aOp.appendAddress( rPos );
+ aOp.appendEditText( rStr );
+ aOp.appendBool( bInteraction );
+ SendMessage( aOp );
+ return true; // needs some code auditing action
+}
+
sal_Bool ScDocFuncSend::PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, sal_Bool bApi )
{
ScChangeOpWriter aOp( "putCell" );
diff --git a/sc/source/ui/collab/sendfunc.hxx b/sc/source/ui/collab/sendfunc.hxx
index 468414861850..6b17a2e5bb0d 100644
--- a/sc/source/ui/collab/sendfunc.hxx
+++ b/sc/source/ui/collab/sendfunc.hxx
@@ -24,6 +24,18 @@ rtl::OUString cellToString( ScBaseCell *pCell )
return rtl::OUString();
}
+OUString editToString( const EditTextObject& /*rEditText*/ )
+{
+ // FIXME: implement me.
+ return OUString();
+}
+
+EditTextObject stringToEdit( const OUString& rStr )
+{
+ // FIXME: implement me.
+ return EditTextObject();
+}
+
ScBaseCell *stringToCell( const rtl::OUString &rString )
{
(void)rString; // FIXME: implement me
@@ -86,6 +98,11 @@ public:
appendString( cellToString( pCell ) );
}
+ void appendEditText( const EditTextObject& rStr )
+ {
+ appendString( editToString(rStr) );
+ }
+
void appendDouble( double fVal )
{
aMessage.append(fVal);
@@ -206,6 +223,12 @@ public:
{
return getString(n).toDouble();
}
+
+ EditTextObject getEdit( sal_Int32 n )
+ {
+ return stringToEdit(getString(n));
+ }
+
};
} // anonymous namespace
@@ -229,6 +252,8 @@ public:
virtual sal_Bool SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, const String& rText, sal_Bool bApi );
virtual bool SetValueCell( const ScAddress& rPos, double fVal, bool bInteraction );
+ virtual bool SetStringCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction );
+ virtual bool SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, bool bInteraction );
virtual sal_Bool PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, sal_Bool bApi );
virtual sal_Bool PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine,
sal_Bool bInterpret, sal_Bool bApi );
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 90482fbaeed8..b3df393c6380 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -80,6 +80,7 @@
#include "undorangename.hxx"
#include "progress.hxx"
#include "dpobject.hxx"
+#include "stringutil.hxx"
#include <memory>
#include <basic/basmgr.hxx>
@@ -808,59 +809,118 @@ sal_Bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos,
return sal_True;
}
+namespace {
+
+void pushUndoSetCell( ScDocShell& rDocShell, ScDocument* pDoc, const ScAddress& rPos, const ScUndoSetCell::Value& rNewVal )
+{
+ svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
+ switch (pDoc->GetCellType(rPos))
+ {
+ case CELLTYPE_NONE:
+ case CELLTYPE_NOTE:
+ // Empty cell.
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, rNewVal));
+ break;
+ case CELLTYPE_VALUE:
+ {
+ double fOldVal = pDoc->GetValue(rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, fOldVal, rNewVal));
+ }
+ break;
+ case CELLTYPE_STRING:
+ {
+ OUString aOldStr = pDoc->GetString(rPos);
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldStr, rNewVal));
+ }
+ break;
+ case CELLTYPE_EDIT:
+ {
+ const EditTextObject* pOldText = pDoc->GetEditText(rPos);
+ if (pOldText)
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pOldText, rNewVal));
+ }
+ break;
+ case CELLTYPE_FORMULA:
+ {
+ const ScTokenArray* pTokens = pDoc->GetFormula(rPos);
+ if (pTokens)
+ pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pTokens, rNewVal));
+ }
+ break;
+ default:
+ ;
+ }
+}
+
+}
+
bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool bInteraction )
{
ScDocShellModificator aModificator( rDocShell );
ScDocument* pDoc = rDocShell.GetDocument();
bool bUndo = pDoc->IsUndoEnabled();
- bool bHeight = pDoc->HasAttrib(ScRange(rPos), HASATTR_NEEDHEIGHT);
+ bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
if (bUndo)
- {
- svl::IUndoManager* pUndoMgr = rDocShell.GetUndoManager();
- switch (pDoc->GetCellType(rPos))
- {
- case CELLTYPE_NONE:
- case CELLTYPE_NOTE:
- // Empty cell.
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, fVal));
- break;
- case CELLTYPE_VALUE:
- {
- double fOldVal = pDoc->GetValue(rPos);
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, fOldVal, fVal));
- }
- break;
- case CELLTYPE_STRING:
- {
- OUString aOldStr = pDoc->GetString(rPos);
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, aOldStr, fVal));
- }
- break;
- case CELLTYPE_EDIT:
- {
- const EditTextObject* pOldText = pDoc->GetEditText(rPos);
- if (pOldText)
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pOldText, fVal));
- }
- break;
- case CELLTYPE_FORMULA:
- {
- const ScTokenArray* pTokens = pDoc->GetFormula(rPos);
- if (pTokens)
- pUndoMgr->AddUndoAction(new ScUndoSetCell(&rDocShell, rPos, *pTokens, fVal));
- }
- break;
- default:
- ;
- }
- }
+ pushUndoSetCell(rDocShell, pDoc, rPos, fVal);
pDoc->SetValue(rPos, fVal);
if (bHeight)
- AdjustRowHeight( ScRange(rPos) );
+ AdjustRowHeight(rPos);
+
+ aModificator.SetDocumentModified();
+
+ // #103934#; notify editline and cell in edit mode
+ if (!bInteraction)
+ NotifyInputHandler( rPos );
+
+ return true;
+}
+
+bool ScDocFunc::SetStringCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction )
+{
+ ScDocShellModificator aModificator( rDocShell );
+ ScDocument* pDoc = rDocShell.GetDocument();
+ bool bUndo = pDoc->IsUndoEnabled();
+
+ bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+
+ if (bUndo)
+ pushUndoSetCell(rDocShell, pDoc, rPos, rStr);
+
+ ScSetStringParam aParam;
+ aParam.setTextInput();
+ pDoc->SetString(rPos, rStr, &aParam);
+
+ if (bHeight)
+ AdjustRowHeight(rPos);
+
+ aModificator.SetDocumentModified();
+
+ // #103934#; notify editline and cell in edit mode
+ if (!bInteraction)
+ NotifyInputHandler( rPos );
+
+ return true;
+}
+
+bool ScDocFunc::SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, bool bInteraction )
+{
+ ScDocShellModificator aModificator( rDocShell );
+ ScDocument* pDoc = rDocShell.GetDocument();
+ bool bUndo = pDoc->IsUndoEnabled();
+
+ bool bHeight = pDoc->HasAttrib(rPos, HASATTR_NEEDHEIGHT);
+
+ if (bUndo)
+ pushUndoSetCell(rDocShell, pDoc, rPos, rStr);
+
+ pDoc->SetEditText(rPos, rStr.Clone());
+
+ if (bHeight)
+ AdjustRowHeight(rPos);
aModificator.SetDocumentModified();
@@ -1009,9 +1069,7 @@ sal_Bool ScDocFunc::PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngi
// A copy of pNewData will be stored in the cell.
boost::scoped_ptr<EditTextObject> pNewData(rEngine.CreateTextObject());
- bRet = PutCell( rPos,
- new ScEditCell(*pNewData, pDoc, rEngine.GetEditTextObjectPool()),
- bApi );
+ bRet = SetEditCell(rPos, *pNewData, !bApi);
// Set the paragraph attributes back to the EditEngine.
if (!aRememberItems.empty())
@@ -1040,7 +1098,7 @@ sal_Bool ScDocFunc::PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngi
bRet = SetNormalString( bNumFmtSet, rPos, aText, bApi );
}
else
- bRet = PutCell( rPos, new ScStringCell( aText ), bApi );
+ bRet = SetStringCell(rPos, aText, !bApi);
}
if ( bRet && aTester.NeedsCellAttr() )
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 2b31f46ef3ce..962697a3df00 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -89,6 +89,8 @@ public:
virtual sal_Bool SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, const String& rText, sal_Bool bApi );
virtual bool SetValueCell( const ScAddress& rPos, double fVal, bool bInteraction );
+ virtual bool SetStringCell( const ScAddress& rPos, const OUString& rStr, bool bInteraction );
+ virtual bool SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, bool bInteraction );
virtual sal_Bool PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, sal_Bool bApi );
virtual sal_Bool PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine,
sal_Bool bInterpret, sal_Bool bApi );
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 932a59474ba2..b253ff8aea41 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -502,13 +502,13 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
if ( pFormatter->GetType( nIndex ) == NUMBERFORMAT_TEXT ||
( ( rString.GetChar(0) == '+' || rString.GetChar(0) == '-' ) && nError && rString.Equals( aFormula ) ) )
{
- ScBaseCell *pCell;
if ( pData )
+ {
// A clone of pData will be stored in the cell.
- pCell = new ScEditCell(*pData, pDoc, NULL);
+ rFunc.SetEditCell(aPos, *pData, true);
+ }
else
- pCell = new ScStringCell( aFormula );
- rFunc.PutCell( aPos, pCell, sal_False );
+ rFunc.SetStringCell(aPos, aFormula, true);
}
else
{