summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/source/ui/collab/sendfunc.cxx189
-rw-r--r--sc/source/ui/view/viewfunc.cxx3
2 files changed, 156 insertions, 36 deletions
diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index ccc785d725b0..0de59bfa9c2a 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -27,45 +27,172 @@
*/
#include "sal/config.h"
+
+#include <vector>
+
#include "cell.hxx"
#include "docsh.hxx"
#include "docfunc.hxx"
namespace {
-// Ye noddy protocol !
-// method name ',' then arguments comma separated
-class ScChangeOp
+// Ye noddy mangling - needs improvement ...
+// method name ';' then arguments ; separated
+class ScChangeOpWriter
{
rtl::OUStringBuffer aMessage;
+ void appendSeparator()
+ {
+ aMessage.append( sal_Unicode( ';' ) );
+ }
public:
- ScChangeOp( const char *pName )
+
+ ScChangeOpWriter( const char *pName )
+ {
+ aMessage.appendAscii( pName );
+ appendSeparator();
+ }
+
+ void appendString( const rtl::OUString &rStr )
{
- aMessage.appendAscii( pName );
- aMessage.append( sal_Unicode( ',' ) );
+ aMessage.append( rStr );
+ appendSeparator();
}
- void appendString( const ScAddress &rPos )
+ void appendString( const String &rStr )
{
- rtl::OUString aStr;
- rPos.Format( aStr );
- aMessage.append( aStr );
+ aMessage.append( rStr );
+ appendSeparator();
}
void appendAddress( const ScAddress &rPos )
{
- (void)rPos;
+ rtl::OUString aStr;
+ rPos.Format( aStr, SCA_VALID );
+ aMessage.append( aStr );
+ appendSeparator();
+ }
+
+ void appendInt( sal_Int32 i )
+ {
+ aMessage.append( i );
+ appendSeparator();
+ }
+
+ void appendBool( sal_Bool b )
+ {
+ aMessage.appendAscii( b ? "true" : "false" );
+ appendSeparator();
+ }
+
+ rtl::OString toString()
+ {
+ return rtl::OUStringToOString( aMessage.toString(), RTL_TEXTENCODING_UTF8 );
}
};
-class ScDocFuncIntercept : public ScDocFunc
+struct ProtocolError {
+ const char *message;
+};
+
+class ScChangeOpReader {
+ std::vector< rtl::OString > maArgs;
+
+public:
+
+ ScChangeOpReader( const rtl::OString &rString)
+ {
+ // will need to handle escaping etc.
+ for (sal_Int32 n = 0; n >= 0 && n < rString.getLength();)
+ maArgs.push_back( rString.getToken( 0, ';', n ) );
+ }
+ ~ScChangeOpReader() {}
+
+ rtl::OString getMethod()
+ {
+ return maArgs[0];
+ }
+
+ size_t getArgCount() { return maArgs.size(); }
+
+ rtl::OUString getString( sal_Int32 n )
+ {
+ if (n > 0 && (size_t)n < getArgCount() )
+ return rtl::OUString( maArgs[n].getStr(), maArgs[n].getLength(),
+ RTL_TEXTENCODING_UTF8 );
+ else
+ return rtl::OUString();
+ }
+
+ ScAddress getAddress( sal_Int32 n )
+ {
+ ScAddress aAddr;
+ rtl::OUString aToken( getString( n ) );
+ aAddr.Parse( aToken );
+ return aAddr;
+ }
+
+ bool getBool( sal_Int32 n )
+ {
+ if (n > 0 && (size_t)n < getArgCount() )
+ return maArgs[n].equalsIgnoreAsciiCase( "true" );
+ else
+ return false;
+ }
+};
+
+
+class ScDocFuncRecv : public ScDocFunc
{
+ ScDocFunc *mpChain;
public:
- ScDocFuncIntercept( ScDocShell& rDocSh ) : ScDocFunc( rDocSh )
+ // FIXME: really ScDocFunc should be an abstract base
+ ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain )
+ : ScDocFunc( rDocSh ),
+ mpChain( pChain )
{
- fprintf( stderr, "Interceptor created !\n" );
+ fprintf( stderr, "Receiver created !\n" );
}
- virtual ~ScDocFuncIntercept() {}
+ virtual ~ScDocFuncRecv() {}
+
+ void RecvMessage( const rtl::OString &rString )
+ {
+ try {
+ ScChangeOpReader aReader( rString );
+ // FIXME: have some hash to enumeration mapping here
+ if ( aReader.getMethod() == "setNormalString" )
+ mpChain->SetNormalString( aReader.getAddress( 1 ), aReader.getString( 2 ),
+ aReader.getBool( 3 ) );
+ else
+ fprintf( stderr, "Error: unknown message '%s' (%d)\n",
+ rString.getStr(), (int)aReader.getArgCount() );
+ } catch (const ProtocolError &e) {
+ fprintf( stderr, "Error: protocol twisting '%s'\n", e.message );
+ }
+ }
+};
+
+class ScDocFuncSend : public ScDocFunc
+{
+ ScDocFuncRecv *mpChain;
+
+ void SendMessage( ScChangeOpWriter &rOp )
+ {
+ fprintf( stderr, "Op: '%s'\n", rOp.toString().getStr() );
+ mpChain->RecvMessage( rOp.toString() );
+ }
+
+public:
+ // FIXME: really ScDocFunc should be an abstract base, so
+ // we don't need the rDocSh hack/pointer
+ ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain )
+ : ScDocFunc( rDocSh ),
+ mpChain( pChain )
+ {
+ fprintf( stderr, "Sender created !\n" );
+ }
+ virtual ~ScDocFuncSend() {}
+
virtual void EnterListAction( sal_uInt16 nNameResId )
{
// Want to group these operations for the other side ...
@@ -74,34 +201,29 @@ public:
virtual void EndListAction()
{
}
- virtual ScBaseCell* InterpretEnglishString( const ScAddress& rPos, const String& rText,
- const String& rFormulaNmsp,
- const formula::FormulaGrammar::Grammar eGrammar,
- short* pRetFormatType )
- {
- fprintf( stderr, "interp. english string '%s'\n",
- rtl::OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ).getStr() );
- return ScDocFunc::InterpretEnglishString( rPos, rText, rFormulaNmsp,
- eGrammar, pRetFormatType );
- }
+
virtual sal_Bool SetNormalString( const ScAddress& rPos, const String& rText, sal_Bool bApi )
{
- fprintf( stderr, "set normal string '%s'\n",
- rtl::OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ).getStr() );
- return ScDocFunc::SetNormalString( rPos, rText, bApi );
+ ScChangeOpWriter aOp( "setNormalString" );
+ aOp.appendAddress( rPos );
+ aOp.appendString( rText );
+ aOp.appendBool( bApi );
+ SendMessage( aOp );
+ // return mpChain->SetNormalString( rPos, rText, bApi );
+ return true; // needs some code auditing action
}
virtual sal_Bool PutCell( const ScAddress& rPos, ScBaseCell* pNewCell, sal_Bool bApi )
{
fprintf( stderr, "put cell '%p' type %d %d\n", pNewCell, pNewCell->GetCellType(), bApi );
- return ScDocFunc::PutCell( rPos, pNewCell, bApi );
+ return mpChain->PutCell( rPos, pNewCell, bApi );
}
virtual sal_Bool PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine,
sal_Bool bInterpret, sal_Bool bApi )
{
fprintf( stderr, "put data\n" );
- return ScDocFunc::PutData( rPos, rEngine, bInterpret, bApi );
+ return mpChain->PutData( rPos, rEngine, bInterpret, bApi );
}
virtual sal_Bool SetCellText( const ScAddress& rPos, const String& rText,
@@ -111,13 +233,13 @@ public:
{
fprintf( stderr, "set cell text '%s'\n",
rtl::OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ).getStr() );
- return ScDocFunc::SetCellText( rPos, rText, bInterpret, bEnglish, bApi, rFormulaNmsp, eGrammar );
+ return mpChain->SetCellText( rPos, rText, bInterpret, bEnglish, bApi, rFormulaNmsp, eGrammar );
}
virtual bool ShowNote( const ScAddress& rPos, bool bShow = true )
{
fprintf( stderr, "%s note\n", bShow ? "show" : "hide" );
- return ScDocFunc::ShowNote( rPos, bShow );
+ return mpChain->ShowNote( rPos, bShow );
}
};
@@ -125,8 +247,9 @@ public:
SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
{
+ // FIXME: the chains should be auto-ptrs.
if (getenv ("INTERCEPT"))
- return new ScDocFuncIntercept( *this );
+ return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) );
else
return new ScDocFuncDirect( *this );
}
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 443a02f3a2b2..cbd7bb76aefa 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -342,9 +342,6 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
bool bRecord = pDoc->IsUndoEnabled();
SCTAB i;
- fprintf( stderr, "EnterData '%s'\n",
- rtl::OUStringToOString( rString, RTL_TEXTENCODING_UTF8 ).getStr() );
-
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScDocFunc &rFunc = GetViewData()->GetDocFunc();
ScDocShellModificator aModificator( *pDocSh );