[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - editeng/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Wed Mar 20 12:50:35 PDT 2013
editeng/inc/editeng/editobj.hxx | 2
sc/source/ui/collab/sendfunc.cxx | 30 +++++++
sc/source/ui/collab/sendfunc.hxx | 25 ++++++
sc/source/ui/docshell/docfunc.cxx | 148 ++++++++++++++++++++++++++------------
sc/source/ui/inc/docfunc.hxx | 2
sc/source/ui/view/viewfunc.cxx | 8 +-
6 files changed, 165 insertions(+), 50 deletions(-)
New commits:
commit ab44be5a64262942f6f2842dd5adf8366d644c59
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Mar 20 15:52:14 2013 -0400
Add SetStringCell() and SetEditCell() to ScDocFunc.
More on averting the use of PutCell().
Change-Id: I3881d7d468780eefe8016c754a053eb42ad3c5ad
diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index 4b96934..60b1f0f 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 4684148..6b17a2e 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 90482fb..b3df393 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 2b31f46..962697a 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 932a594..b253ff8 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
{
commit 9862d2bd6b9c0b87dd16964a464285d4be904261
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Mar 20 15:51:29 2013 -0400
Make EditTextObject copyable. Its Clone() method uses that anyway...
Change-Id: I9c9ce4ddbf4849e3b237f037d8f1232b4ae84387
diff --git a/editeng/inc/editeng/editobj.hxx b/editeng/inc/editeng/editobj.hxx
index bfce8fd..93a590c 100644
--- a/editeng/inc/editeng/editobj.hxx
+++ b/editeng/inc/editeng/editobj.hxx
@@ -62,12 +62,12 @@ class EDITENG_DLLPUBLIC EditTextObject : public SfxItemPoolUser
EditTextObject(); // disabled
EditTextObject( SfxItemPool* pPool );
- EditTextObject( const EditTextObject& r );
void StoreData( SvStream& rStrm ) const;
void CreateData( SvStream& rStrm );
public:
+ EditTextObject( const EditTextObject& r );
virtual ~EditTextObject();
sal_uInt16 GetUserType() const; // For OutlinerMode, it can however not save in compatible format
More information about the Libreoffice-commits
mailing list