summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/basobj2.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basctl/source/basicide/basobj2.cxx')
-rw-r--r--basctl/source/basicide/basobj2.cxx286
1 files changed, 164 insertions, 122 deletions
diff --git a/basctl/source/basicide/basobj2.cxx b/basctl/source/basicide/basobj2.cxx
index a5b441cdb1ab..7a578f20f186 100644
--- a/basctl/source/basicide/basobj2.cxx
+++ b/basctl/source/basicide/basobj2.cxx
@@ -31,23 +31,29 @@
#include <ide_pch.hxx>
-#include <vector>
-#include <algorithm>
-#include <basic/sbx.hxx>
-#include <unotools/moduleoptions.hxx>
+#include "basobj.hxx"
+#include "iderdll.hxx"
+#include "iderdll2.hxx"
+#include "iderid.hxx"
+#include "macrodlg.hxx"
+#include "moduldlg.hxx"
+#include "basidesh.hxx"
+#include "basidesh.hrc"
+#include "baside2.hxx"
+#include "basicmod.hxx"
+#include "basdoc.hxx"
+
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
-#include <basobj.hxx>
-#include <iderdll.hxx>
-#include <iderdll2.hxx>
-#include <iderid.hxx>
-#include <macrodlg.hxx>
-#include <moduldlg.hxx>
-#include <basidesh.hxx>
-#include <basidesh.hrc>
-#include <baside2.hxx>
-#include <basicmod.hxx>
-#include <basdoc.hxx>
+
+#include <basic/sbx.hxx>
+#include <framework/documentundoguard.hxx>
+#include <tools/diagnose_ex.h>
+#include <unotools/moduleoptions.hxx>
+
+#include <vector>
+#include <algorithm>
+#include <memory>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -57,7 +63,7 @@ using namespace ::com::sun::star::container;
//----------------------------------------------------------------------------
extern "C" {
- SAL_DLLPUBLIC_EXPORT rtl_uString* basicide_choose_macro( void* pOnlyInDocument_AsXModel, BOOL bChooseOnly, rtl_uString* pMacroDesc )
+ SAL_DLLPUBLIC_EXPORT rtl_uString* basicide_choose_macro( void* pOnlyInDocument_AsXModel, sal_Bool bChooseOnly, rtl_uString* pMacroDesc )
{
::rtl::OUString aMacroDesc( pMacroDesc );
Reference< frame::XModel > aDocument( static_cast< frame::XModel* >( pOnlyInDocument_AsXModel ) );
@@ -67,7 +73,7 @@ extern "C" {
return pScriptURL;
}
- SAL_DLLPUBLIC_EXPORT void basicide_macro_organizer( INT16 nTabId )
+ SAL_DLLPUBLIC_EXPORT void basicide_macro_organizer( sal_Int16 nTabId )
{
OSL_TRACE("in basicide_macro_organizer");
BasicIDE::Organize( nTabId );
@@ -78,7 +84,7 @@ namespace BasicIDE
{
//----------------------------------------------------------------------------
-void Organize( INT16 tabId )
+void Organize( sal_Int16 tabId )
{
BasicIDEDLL::Init();
@@ -99,21 +105,21 @@ void Organize( INT16 tabId )
//----------------------------------------------------------------------------
-BOOL IsValidSbxName( const String& rName )
+sal_Bool IsValidSbxName( const String& rName )
{
- for ( USHORT nChar = 0; nChar < rName.Len(); nChar++ )
+ for ( sal_uInt16 nChar = 0; nChar < rName.Len(); nChar++ )
{
- BOOL bValid = ( ( rName.GetChar(nChar) >= 'A' && rName.GetChar(nChar) <= 'Z' ) ||
+ sal_Bool bValid = ( ( rName.GetChar(nChar) >= 'A' && rName.GetChar(nChar) <= 'Z' ) ||
( rName.GetChar(nChar) >= 'a' && rName.GetChar(nChar) <= 'z' ) ||
( rName.GetChar(nChar) >= '0' && rName.GetChar(nChar) <= '9' && nChar ) ||
( rName.GetChar(nChar) == '_' ) );
if ( !bValid )
- return FALSE;
+ return sal_False;
}
- return TRUE;
+ return sal_True;
}
-static BOOL StringCompareLessThan( const String& rStr1, const String& rStr2 )
+static sal_Bool StringCompareLessThan( const String& rStr1, const String& rStr2 )
{
return (rStr1.CompareIgnoreCaseToAscii( rStr2 ) == COMPARE_LESS);
}
@@ -192,7 +198,7 @@ bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const
BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
if ( pIDEShell )
{
- IDEBaseWindow* pWin = pIDEShell->FindWindow( rDocument, rLibName, rNewName, BASICIDE_TYPE_MODULE, TRUE );
+ IDEBaseWindow* pWin = pIDEShell->FindWindow( rDocument, rLibName, rNewName, BASICIDE_TYPE_MODULE, sal_True );
if ( pWin )
{
// set new name in window
@@ -203,7 +209,7 @@ bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const
pModWin->SetSbModule( (SbModule*)pModWin->GetBasic()->FindModule( rNewName ) );
// update tabwriter
- USHORT nId = (USHORT)(pIDEShell->GetIDEWindowTable()).GetKey( pWin );
+ sal_uInt16 nId = (sal_uInt16)(pIDEShell->GetIDEWindowTable()).GetKey( pWin );
DBG_ASSERT( nId, "No entry in Tabbar!" );
if ( nId )
{
@@ -217,22 +223,66 @@ bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const
return true;
}
+
+//----------------------------------------------------------------------------
+
+namespace
+{
+ struct MacroExecutionData
+ {
+ ScriptDocument aDocument;
+ SbMethodRef xMethod;
+
+ MacroExecutionData()
+ :aDocument( ScriptDocument::NoDocument )
+ ,xMethod( NULL )
+ {
+ }
+ };
+
+ class MacroExecution
+ {
+ public:
+ DECL_STATIC_LINK( MacroExecution, ExecuteMacroEvent, MacroExecutionData* );
+ };
+
+
+ IMPL_STATIC_LINK( MacroExecution, ExecuteMacroEvent, MacroExecutionData*, i_pData )
+ {
+ (void)pThis;
+ ENSURE_OR_RETURN( i_pData, "wrong MacroExecutionData", 0L );
+ // take ownership of the data
+ ::std::auto_ptr< MacroExecutionData > pData( i_pData );
+
+ DBG_ASSERT( pData->xMethod->GetParent()->GetFlags() & SBX_EXTSEARCH, "Kein EXTSEARCH!" );
+
+ // in case this is a document-local macro, try to protect the document's Undo Manager from
+ // flawed scripts
+ ::std::auto_ptr< ::framework::DocumentUndoGuard > pUndoGuard;
+ if ( pData->aDocument.isDocument() )
+ pUndoGuard.reset( new ::framework::DocumentUndoGuard( pData->aDocument.getDocument() ) );
+
+ BasicIDE::RunMethod( pData->xMethod );
+
+ return 1L;
+ }
+}
+
//----------------------------------------------------------------------------
-::rtl::OUString ChooseMacro( const uno::Reference< frame::XModel >& rxLimitToDocument, BOOL bChooseOnly, const ::rtl::OUString& rMacroDesc )
+::rtl::OUString ChooseMacro( const uno::Reference< frame::XModel >& rxLimitToDocument, sal_Bool bChooseOnly, const ::rtl::OUString& rMacroDesc )
{
(void)rMacroDesc;
BasicIDEDLL::Init();
- IDE_DLL()->GetExtraData()->ChoosingMacro() = TRUE;
- SFX_APP()->EnterBasicCall();
+ IDE_DLL()->GetExtraData()->ChoosingMacro() = sal_True;
String aScriptURL;
- BOOL bError = FALSE;
+ sal_Bool bError = sal_False;
SbMethod* pMethod = NULL;
- MacroChooser* pChooser = new MacroChooser( NULL, TRUE );
+ ::std::auto_ptr< MacroChooser > pChooser( new MacroChooser( NULL, sal_True ) );
if ( bChooseOnly || !SvtModuleOptions().IsBasicIDE() )
pChooser->SetMode( MACROCHOOSER_CHOOSEONLY );
@@ -242,7 +292,7 @@ bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const
short nRetValue = pChooser->Execute();
- IDE_DLL()->GetExtraData()->ChoosingMacro() = FALSE;
+ IDE_DLL()->GetExtraData()->ChoosingMacro() = sal_False;
switch ( nRetValue )
{
@@ -252,103 +302,95 @@ bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const
if ( !pMethod && pChooser->GetMode() == MACROCHOOSER_RECORDING )
pMethod = pChooser->CreateMacro();
- if ( pMethod )
+ if ( !pMethod )
+ break;
+
+ SbModule* pModule = pMethod->GetModule();
+ ENSURE_OR_BREAK( pModule, "BasicIDE::ChooseMacro: No Module found!" );
+
+ StarBASIC* pBasic = (StarBASIC*)pModule->GetParent();
+ ENSURE_OR_BREAK( pBasic, "BasicIDE::ChooseMacro: No Basic found!" );
+
+ BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic );
+ ENSURE_OR_BREAK( pBasMgr, "BasicIDE::ChooseMacro: No BasicManager found!" );
+
+ // name
+ String aName;
+ aName += pBasic->GetName();
+ aName += '.';
+ aName += pModule->GetName();
+ aName += '.';
+ aName += pMethod->GetName();
+
+ // language
+ String aLanguage = String::CreateFromAscii("Basic");
+
+ // location
+ String aLocation;
+ ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
+ if ( aDocument.isDocument() )
{
- SbModule* pModule = pMethod->GetModule();
- DBG_ASSERT(pModule, "BasicIDE::ChooseMacro: No Module found!");
- if ( pModule )
- {
- StarBASIC* pBasic = (StarBASIC*)pModule->GetParent();
- DBG_ASSERT(pBasic, "BasicIDE::ChooseMacro: No Basic found!");
- if ( pBasic )
- {
- BasicManager* pBasMgr = BasicIDE::FindBasicManager( pBasic );
- DBG_ASSERT(pBasMgr, "BasicIDE::ChooseMacro: No BasicManager found!");
- if ( pBasMgr )
- {
- // name
- String aName;
- aName += pBasic->GetName();
- aName += '.';
- aName += pModule->GetName();
- aName += '.';
- aName += pMethod->GetName();
-
- // language
- String aLanguage = String::CreateFromAscii("Basic");
-
- // location
- String aLocation;
- ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
- if ( aDocument.isDocument() )
- {
- // document basic
- aLocation = String::CreateFromAscii("document");
-
- if ( rxLimitToDocument.is() )
- {
- uno::Reference< frame::XModel > xLimitToDocument( rxLimitToDocument );
-
- uno::Reference< document::XEmbeddedScripts > xScripts( rxLimitToDocument, UNO_QUERY );
- if ( !xScripts.is() )
- { // the document itself does not support embedding scripts
- uno::Reference< document::XScriptInvocationContext > xContext( rxLimitToDocument, UNO_QUERY );
- if ( xContext.is() )
- xScripts = xContext->getScriptContainer();
- if ( xScripts.is() )
- { // but it is able to refer to a document which actually does support this
- xLimitToDocument.set( xScripts, UNO_QUERY );
- if ( !xLimitToDocument.is() )
- {
- OSL_ENSURE( false, "BasicIDE::ChooseMacro: a script container which is no document!?" );
- xLimitToDocument = rxLimitToDocument;
- }
- }
- }
-
- if ( xLimitToDocument != aDocument.getDocument() )
- {
- // error
- bError = TRUE;
- ErrorBox( NULL, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_ERRORCHOOSEMACRO ) ) ).Execute();
- }
- }
- }
- else
- {
- // application basic
- aLocation = String::CreateFromAscii("application");
- }
+ // document basic
+ aLocation = String::CreateFromAscii("document");
- // script URL
- if ( !bError )
+ if ( rxLimitToDocument.is() )
+ {
+ uno::Reference< frame::XModel > xLimitToDocument( rxLimitToDocument );
+
+ uno::Reference< document::XEmbeddedScripts > xScripts( rxLimitToDocument, UNO_QUERY );
+ if ( !xScripts.is() )
+ { // the document itself does not support embedding scripts
+ uno::Reference< document::XScriptInvocationContext > xContext( rxLimitToDocument, UNO_QUERY );
+ if ( xContext.is() )
+ xScripts = xContext->getScriptContainer();
+ if ( xScripts.is() )
+ { // but it is able to refer to a document which actually does support this
+ xLimitToDocument.set( xScripts, UNO_QUERY );
+ if ( !xLimitToDocument.is() )
{
- aScriptURL = String::CreateFromAscii("vnd.sun.star.script:");
- aScriptURL += aName;
- aScriptURL += String::CreateFromAscii("?language=");
- aScriptURL += aLanguage;
- aScriptURL += String::CreateFromAscii("&location=");
- aScriptURL += aLocation;
+ OSL_ENSURE( false, "BasicIDE::ChooseMacro: a script container which is no document!?" );
+ xLimitToDocument = rxLimitToDocument;
}
}
}
+
+ if ( xLimitToDocument != aDocument.getDocument() )
+ {
+ // error
+ bError = sal_True;
+ ErrorBox( NULL, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_ERRORCHOOSEMACRO ) ) ).Execute();
+ }
}
}
+ else
+ {
+ // application basic
+ aLocation = String::CreateFromAscii("application");
+ }
+
+ // script URL
+ if ( !bError )
+ {
+ aScriptURL = String::CreateFromAscii("vnd.sun.star.script:");
+ aScriptURL += aName;
+ aScriptURL += String::CreateFromAscii("?language=");
+ aScriptURL += aLanguage;
+ aScriptURL += String::CreateFromAscii("&location=");
+ aScriptURL += aLocation;
+ }
- if ( pMethod && !rxLimitToDocument.is() )
+ if ( !rxLimitToDocument.is() )
{
- pMethod->AddRef(); // festhalten, bis Event abgearbeitet.
- Application::PostUserEvent( LINK( IDE_DLL()->GetExtraData(), BasicIDEData, ExecuteMacroEvent ), pMethod );
+ MacroExecutionData* pExecData = new MacroExecutionData;
+ pExecData->aDocument = aDocument;
+ pExecData->xMethod = pMethod; // keep alive until the event has been processed
+ Application::PostUserEvent( STATIC_LINK( NULL, MacroExecution, ExecuteMacroEvent ), pExecData );
}
}
break;
}
- delete pChooser;
-
- SFX_APP()->LeaveBasicCall();
-
- return ::rtl::OUString( aScriptURL );
+ return aScriptURL;
}
//----------------------------------------------------------------------------
@@ -364,9 +406,9 @@ Sequence< ::rtl::OUString > GetMethodNames( const ScriptDocument& rDocument, con
{
SbModuleRef xModule = new SbModule( rModName );
xModule->SetSource32( aOUSource );
- USHORT nCount = xModule->GetMethods()->Count();
- USHORT nRealCount = nCount;
- for ( USHORT i = 0; i < nCount; i++ )
+ sal_uInt16 nCount = xModule->GetMethods()->Count();
+ sal_uInt16 nRealCount = nCount;
+ for ( sal_uInt16 i = 0; i < nCount; i++ )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( i );
if( pMethod->IsHidden() )
@@ -374,8 +416,8 @@ Sequence< ::rtl::OUString > GetMethodNames( const ScriptDocument& rDocument, con
}
aSeqMethods.realloc( nRealCount );
- USHORT iTarget = 0;
- for ( USHORT i = 0 ; i < nCount; ++i )
+ sal_uInt16 iTarget = 0;
+ for ( sal_uInt16 i = 0 ; i < nCount; ++i )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( i );
if( pMethod->IsHidden() )
@@ -390,9 +432,9 @@ Sequence< ::rtl::OUString > GetMethodNames( const ScriptDocument& rDocument, con
//----------------------------------------------------------------------------
-BOOL HasMethod( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, const String& rMethName )
+sal_Bool HasMethod( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, const String& rMethName )
{
- BOOL bHasMethod = FALSE;
+ sal_Bool bHasMethod = sal_False;
::rtl::OUString aOUSource;
if ( rDocument.hasModule( rLibName, rModName ) && rDocument.getModule( rLibName, rModName, aOUSource ) )
@@ -404,7 +446,7 @@ BOOL HasMethod( const ScriptDocument& rDocument, const String& rLibName, const S
{
SbMethod* pMethod = (SbMethod*)pMethods->Find( rMethName, SbxCLASS_METHOD );
if ( pMethod && !pMethod->IsHidden() )
- bHasMethod = TRUE;
+ bHasMethod = sal_True;
}
}