#i102261# OLE control event handler support

This commit is contained in:
Andreas Bregas 2009-06-17 13:32:41 +00:00
parent 3027f5a947
commit 179cb343c8
9 changed files with 130 additions and 5 deletions

View file

@ -287,6 +287,7 @@ private:
::std::auto_ptr<ScExternalRefManager> pExternalRefMgr;
String aDocName; // opt: Dokumentname
String aDocCodeName; // opt: Dokumentname
ScRangePairListRef xColNameRanges;
ScRangePairListRef xRowNameRanges;
@ -433,6 +434,8 @@ public:
SC_DLLPUBLIC const String& GetName() const { return aDocName; }
void SetName( const String& r ) { aDocName = r; }
const String& GetCodeName() const { return aDocCodeName; }
void SetCodeName( const String& r ) { aDocCodeName = r; }
void GetDocStat( ScDocStat& rDocStat );
@ -523,6 +526,8 @@ public:
SC_DLLPUBLIC BOOL HasTable( SCTAB nTab ) const;
SC_DLLPUBLIC BOOL GetName( SCTAB nTab, String& rName ) const;
SC_DLLPUBLIC BOOL GetCodeName( SCTAB nTab, String& rName ) const;
SC_DLLPUBLIC BOOL SetCodeName( SCTAB nTab, String& rName );
SC_DLLPUBLIC BOOL GetTable( const String& rName, SCTAB& rTab ) const;
SC_DLLPUBLIC inline SCTAB GetTableCount() const { return nMaxTableNumber; }
SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }

View file

@ -126,6 +126,8 @@ public:
const String& GetCodeName( size_t nIdx ) const;
/** Appends a codename for a sheet. */
void AppendCodeName( const String& rCodeName );
void SetCodeName( const String& rCodeName, size_t nIdx );
void DeleteCodeName( size_t nIdx );
private:
::std::auto_ptr< ScExtDocOptionsImpl > mxImpl;

View file

@ -93,8 +93,9 @@ class ScDocShell;
#define SC_SERVICE_FORMULAPARS 38
#define SC_SERVICE_OPCODEMAPPER 39
#define SC_SERVICE_VBACODENAMEPROVIDER 40
#define SC_SERVICE_COUNT 40
#define SC_SERVICE_COUNT 41
#define SC_SERVICE_INVALID USHRT_MAX

View file

@ -81,6 +81,7 @@ private:
ScColumn aCol[MAXCOLCOUNT];
String aName;
String aCodeName;
String aComment;
BOOL bScenario;
BOOL bLayoutRTL;
@ -212,6 +213,9 @@ public:
void GetName( String& rName ) const;
void SetName( const String& rNewName );
void GetCodeName( String& rName ) const { rName = aCodeName; }
void SetCodeName( const String& rNewName ) { aCodeName = rNewName; }
const String& GetUpperName() const;
const String& GetPageStyle() const { return aPageStyle; }

View file

@ -150,6 +150,32 @@ BOOL ScDocument::GetName( SCTAB nTab, String& rName ) const
return FALSE;
}
BOOL ScDocument::SetCodeName( SCTAB nTab, String& rName )
{
if (VALIDTAB(nTab))
{
if (pTab[nTab])
{
pTab[nTab]->SetCodeName( rName );
return TRUE;
}
}
OSL_TRACE( "**** can't set code name %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() );
return FALSE;
}
BOOL ScDocument::GetCodeName( SCTAB nTab, String& rName ) const
{
if (VALIDTAB(nTab))
if (pTab[nTab])
{
pTab[nTab]->GetCodeName( rName );
return TRUE;
}
rName.Erase();
return FALSE;
}
BOOL ScDocument::GetTable( const String& rName, SCTAB& rTab ) const
{
@ -289,6 +315,7 @@ BOOL ScDocument::InsertTab( SCTAB nPos, const String& rName,
if (nPos == SC_TAB_APPEND || nPos == nTabCount)
{
pTab[nTabCount] = new ScTable(this, nTabCount, rName);
pTab[nTabCount]->SetCodeName( rName );
++nMaxTableNumber;
if ( bExternalDocument )
pTab[nTabCount]->SetVisible( FALSE );
@ -321,10 +348,16 @@ BOOL ScDocument::InsertTab( SCTAB nPos, const String& rName,
for (i = 0; i <= MAXTAB; i++)
if (pTab[i])
pTab[i]->UpdateInsertTab(nPos);
for (i = nTabCount; i > nPos; i--)
{
pTab[i] = pTab[i - 1];
}
pTab[nPos] = new ScTable(this, nPos, rName);
pTab[nPos]->SetCodeName( rName );
++nMaxTableNumber;
for (i = 0; i <= MAXTAB; i++)
if (pTab[i])
pTab[i]->UpdateCompile();

View file

@ -124,6 +124,7 @@ extern BOOL bIsOlk, bOderSo;
ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const String& rNewName,
BOOL bColInfo, BOOL bRowInfo ) :
aName( rNewName ),
aCodeName( rNewName ),
bScenario( FALSE ),
bLayoutRTL( FALSE ),
bLoadingRTL( FALSE ),

View file

@ -113,7 +113,7 @@ using namespace com::sun::star;
ImportExcel8::ImportExcel8( XclImpRootData& rImpData, SvStream& rStrm ) :
ImportExcel( rImpData, rStrm )
ImportExcel( rImpData, rStrm ), mnTab(0)
{
delete pFormConv;
@ -242,9 +242,15 @@ void ImportExcel8::Codename( BOOL bWorkbookGlobals )
if( aName.Len() )
{
if( bWorkbookGlobals )
{
GetExtDocOptions().GetDocSettings().maGlobCodeName = aName;
GetDoc().SetCodeName( aName );
}
else
{
GetExtDocOptions().AppendCodeName( aName );
GetDoc().SetCodeName( mnTab++, aName );
}
}
}
}

View file

@ -52,6 +52,7 @@ class XclImpStream;
class ImportExcel8 : public ImportExcel
{
SCTAB mnTab;
protected:
ExcScenarioList aScenList;

View file

@ -60,9 +60,65 @@
// #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
#include <svx/xmleohlp.hxx>
#include <svx/xmlgrhlp.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/document/XCodeNameQuery.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/form/XFormsSupplier.hpp>
using namespace ::com::sun::star;
class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
{
ScDocShell* mpDocShell;
public:
ScVbaCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell ) {}
// XCodeNameQuery
rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
{
rtl::OUString sCodeName;
if ( mpDocShell )
{
OSL_TRACE( "*** In ScVbaCodeNameProvider::getCodeNameForObject");
// need to find the page ( and index ) for this control
uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mpDocShell->GetModel(), uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
sal_Int32 nLen = xIndex->getCount();
bool bMatched = false;
uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
for ( sal_Int32 index = 0; index < nLen; ++index )
{
try
{
uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
// get the www-standard container
uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
sal_Int32 nCntrls = xFormControls->getCount();
for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
{
uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
bMatched = ( xControl == xIf );
if ( bMatched )
{
String sName;
mpDocShell->GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
sCodeName = sName;
}
}
}
catch( uno::Exception& ) {}
if ( bMatched )
break;
}
}
// Probably should throw here ( if !bMatched )
return sCodeName;
}
};
//------------------------------------------------------------------------
@ -112,7 +168,8 @@ static const sal_Char* __FAR_DATA aProvNames[SC_SERVICE_COUNT] =
SC_SERVICENAME_CHDATAPROV, // SC_SERVICE_CHDATAPROV
SC_SERVICENAME_FORMULAPARS, // SC_SERVICE_FORMULAPARS
SC_SERVICENAME_OPCODEMAPPER // SC_SERVICE_OPCODEMAPPER
SC_SERVICENAME_OPCODEMAPPER, // SC_SERVICE_OPCODEMAPPER
"ooo.vba.VBACodeNameProvider", // SC_SERVICE_OPCODEMAPPER
};
//
@ -164,7 +221,8 @@ static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
"", // SC_SERVICE_SHEETDOCSET
"", // SC_SERVICE_CHDATAPROV
"", // SC_SERVICE_FORMULAPARS
"" // SC_SERVICE_OPCODEMAPPER
"", // SC_SERVICE_OPCODEMAPPER
"", // SC_SERVICE_VBACODENAMEPROVIDER
};
@ -361,9 +419,23 @@ uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
pComp->SetGrammar( pDoc->GetGrammar() );
xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
break;
}
break;
case SC_SERVICE_VBACODENAMEPROVIDER:
{
// Only create the excel faking service for excel docs
const SfxFilter *pFilt = pDocShell->GetMedium()->GetFilter();
if ( pFilt && pFilt->IsAlienFormat() )
{
// application/vnd.ms-excel is the mime type for Excel
static const rtl::OUString sExcelMimeType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.ms-excel" ) );
if ( sExcelMimeType.equals( pFilt->GetMimeType() ) )
xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider( pDocShell )));
}
break;
}
}
return xRet;
}