Files
libreoffice/basctl/source/basicide/basobj2.cxx

414 lines
16 KiB
C++
Raw Normal View History

2000-09-29 10:02:42 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-29 10:02:42 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-29 10:02:42 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-29 10:02:42 +00:00
*
* This file is part of OpenOffice.org.
2000-09-29 10:02:42 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-29 10:02:42 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-29 10:02:42 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-29 10:02:42 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_basctl.hxx"
2000-09-29 10:02:42 +00:00
#include <ide_pch.hxx>
#include <vector>
#include <algorithm>
#include <basic/sbx.hxx>
#include <unotools/moduleoptions.hxx>
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
2000-09-29 10:02:42 +00:00
#include <basobj.hxx>
#include <iderdll.hxx>
#include <iderdll2.hxx>
#include <iderid.hxx>
#include <macrodlg.hxx>
#include <moduldlg.hxx>
#include <basidesh.hxx>
2001-08-03 14:14:56 +00:00
#include <basidesh.hrc>
#include <baside2.hxx>
2001-07-20 09:49:36 +00:00
#include <basicmod.hxx>
#include <basdoc.hxx>
2001-08-03 14:14:56 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
2001-08-03 14:14:56 +00:00
2001-07-25 06:23:37 +00:00
//----------------------------------------------------------------------------
extern "C" {
CWS-TOOLING: integrate CWS sb102 2008-12-11 16:18:12 +0100 sb r265332 : #i95065# cleanup, to make Windows linking work 2008-12-11 16:16:03 +0100 sb r265331 : #i95065# missing SAL_DLLPUBLIC_EXPORT 2008-12-09 17:40:28 +0100 sb r265122 : #i94469# move CJK specific configuration data to brand layer 2008-12-09 16:09:08 +0100 sb r265112 : #i96959# use PTHREAD_MUTEX_RECURSIVE on all platforms 2008-12-09 15:54:31 +0100 sb r265110 : #i95065# do not derive apphelper::LifeTimeGuard from osl::ResettableMutexGuard to avoid problems with VISIBILITY_HIDDEN=TRUE on MSC 2008-12-09 15:40:51 +0100 sb r265104 : #i95065# add VISIBILITY_HIDDEN=TRUE to connectivity/source/drivers/mozab 2008-12-09 15:36:21 +0100 sb r265102 : #i95501# updated SDK_HOME 2008-12-09 15:31:46 +0100 sb r265099 : typo (temppath vs. tmppath) 2008-12-08 11:48:08 +0100 sb r264979 : #i95065# removed spurious ExplicitCategoriesProvider.obj (ExplicitCategoriesProvider.cxx is not in this directory) 2008-12-07 19:41:07 +0100 sb r264960 : #i96994# erroneously doubled backslash caused visibility feature to be disabled for all GCC versions on Mac OS X 2008-12-06 23:54:49 +0100 sb r264948 : changes from trunk that CWS-TOOLING's rebase to DEV300:m37 (r264891) had missed, as files had been moved around on this CWS 2008-12-05 20:29:23 +0100 sb r264919 : #i85508# versions of flex apparently differ in whether input() resp. yyinput() returns zero or EOF upon end of file 2008-12-05 15:37:23 +0100 sb r264908 : #i95315# removed obsolete jut 2008-12-05 15:34:59 +0100 sb r264907 : #i95531# removed empty obsolete directories 2008-12-05 10:09:23 +0100 sb r264891 : CWS-TOOLING: rebase CWS sb102 to trunk@264807 (milestone: DEV300:m37) 2008-12-04 14:50:20 +0100 sb r264845 : #i95065# introduced VISIBILITY_HIDDEN makefile flag to reduce duplications; made additional libraries use VISIBILITY_HIDDEN=TRUE to avoid warnings with recent GCC 4 versions (had to split certain code directories to make changes that would otherwise erroneously affect multiple libraries built in the same makefile); changed connectivity::ORefVector to no longer derive from std::vector, as that caused problems with the MSC implementation of VISIBILITY_HIDDEN=TRUE; replaced uses of JNIEXPORT with SAL_DLLPUBLIC_EXPORT, as the former does not expand to visibility attributes on some platforms where the latter does 2008-12-03 11:29:38 +0100 sb r264759 : #i94583# remove unnecessary (and wrong) assertion check for rtl_getAppCommandArg return value (which is guaranteed to return osl_Process_E_None or not return at all) 2008-12-02 17:18:31 +0100 sb r264724 : #i96809# silenced GCC 4.3.2 warning 2008-12-02 13:29:34 +0100 sb r264695 : #i96797# make get_tmp_dir fail less often 2008-11-28 17:19:24 +0100 sb r264566 : #i95691# inadvertently missing from -c 264564 2008-11-28 17:07:50 +0100 sb r264564 : #i95691# only structs of exactly 1, 2, 4, or 8 bytes are returned through registers 2008-11-25 13:28:08 +0100 sb r264291 : #i96427# support for SAL_EXCEPTION_DLLPUBLIC_EXPORT (patch by np) 2008-11-21 14:45:22 +0100 sb r264140 : #i95428# added SAL_EXCEPTION_DLLPUBLIC_EXPORT and SAL_EXCEPTION_DLLPRIVATE 2008-11-19 13:19:37 +0100 sb r263984 : #i95525# removed erroneous application/octet-stream svn:mime-type properties
2008-12-30 13:32:01 +00:00
SAL_DLLPUBLIC_EXPORT rtl_uString* basicide_choose_macro( void* pOnlyInDocument_AsXModel, BOOL bChooseOnly, rtl_uString* pMacroDesc )
2001-07-25 06:23:37 +00:00
{
::rtl::OUString aMacroDesc( pMacroDesc );
Reference< frame::XModel > aDocument( static_cast< frame::XModel* >( pOnlyInDocument_AsXModel ) );
::rtl::OUString aScriptURL = BasicIDE::ChooseMacro( aDocument, bChooseOnly, aMacroDesc );
2001-08-03 14:14:56 +00:00
rtl_uString* pScriptURL = aScriptURL.pData;
rtl_uString_acquire( pScriptURL );
2001-07-25 06:23:37 +00:00
2001-08-03 14:14:56 +00:00
return pScriptURL;
2001-07-25 06:23:37 +00:00
}
CWS-TOOLING: integrate CWS sb102 2008-12-11 16:18:12 +0100 sb r265332 : #i95065# cleanup, to make Windows linking work 2008-12-11 16:16:03 +0100 sb r265331 : #i95065# missing SAL_DLLPUBLIC_EXPORT 2008-12-09 17:40:28 +0100 sb r265122 : #i94469# move CJK specific configuration data to brand layer 2008-12-09 16:09:08 +0100 sb r265112 : #i96959# use PTHREAD_MUTEX_RECURSIVE on all platforms 2008-12-09 15:54:31 +0100 sb r265110 : #i95065# do not derive apphelper::LifeTimeGuard from osl::ResettableMutexGuard to avoid problems with VISIBILITY_HIDDEN=TRUE on MSC 2008-12-09 15:40:51 +0100 sb r265104 : #i95065# add VISIBILITY_HIDDEN=TRUE to connectivity/source/drivers/mozab 2008-12-09 15:36:21 +0100 sb r265102 : #i95501# updated SDK_HOME 2008-12-09 15:31:46 +0100 sb r265099 : typo (temppath vs. tmppath) 2008-12-08 11:48:08 +0100 sb r264979 : #i95065# removed spurious ExplicitCategoriesProvider.obj (ExplicitCategoriesProvider.cxx is not in this directory) 2008-12-07 19:41:07 +0100 sb r264960 : #i96994# erroneously doubled backslash caused visibility feature to be disabled for all GCC versions on Mac OS X 2008-12-06 23:54:49 +0100 sb r264948 : changes from trunk that CWS-TOOLING's rebase to DEV300:m37 (r264891) had missed, as files had been moved around on this CWS 2008-12-05 20:29:23 +0100 sb r264919 : #i85508# versions of flex apparently differ in whether input() resp. yyinput() returns zero or EOF upon end of file 2008-12-05 15:37:23 +0100 sb r264908 : #i95315# removed obsolete jut 2008-12-05 15:34:59 +0100 sb r264907 : #i95531# removed empty obsolete directories 2008-12-05 10:09:23 +0100 sb r264891 : CWS-TOOLING: rebase CWS sb102 to trunk@264807 (milestone: DEV300:m37) 2008-12-04 14:50:20 +0100 sb r264845 : #i95065# introduced VISIBILITY_HIDDEN makefile flag to reduce duplications; made additional libraries use VISIBILITY_HIDDEN=TRUE to avoid warnings with recent GCC 4 versions (had to split certain code directories to make changes that would otherwise erroneously affect multiple libraries built in the same makefile); changed connectivity::ORefVector to no longer derive from std::vector, as that caused problems with the MSC implementation of VISIBILITY_HIDDEN=TRUE; replaced uses of JNIEXPORT with SAL_DLLPUBLIC_EXPORT, as the former does not expand to visibility attributes on some platforms where the latter does 2008-12-03 11:29:38 +0100 sb r264759 : #i94583# remove unnecessary (and wrong) assertion check for rtl_getAppCommandArg return value (which is guaranteed to return osl_Process_E_None or not return at all) 2008-12-02 17:18:31 +0100 sb r264724 : #i96809# silenced GCC 4.3.2 warning 2008-12-02 13:29:34 +0100 sb r264695 : #i96797# make get_tmp_dir fail less often 2008-11-28 17:19:24 +0100 sb r264566 : #i95691# inadvertently missing from -c 264564 2008-11-28 17:07:50 +0100 sb r264564 : #i95691# only structs of exactly 1, 2, 4, or 8 bytes are returned through registers 2008-11-25 13:28:08 +0100 sb r264291 : #i96427# support for SAL_EXCEPTION_DLLPUBLIC_EXPORT (patch by np) 2008-11-21 14:45:22 +0100 sb r264140 : #i95428# added SAL_EXCEPTION_DLLPUBLIC_EXPORT and SAL_EXCEPTION_DLLPRIVATE 2008-11-19 13:19:37 +0100 sb r263984 : #i95525# removed erroneous application/octet-stream svn:mime-type properties
2008-12-30 13:32:01 +00:00
SAL_DLLPUBLIC_EXPORT void basicide_macro_organizer( INT16 nTabId )
{
OSL_TRACE("in basicide_macro_organizer");
BasicIDE::Organize( nTabId );
}
2001-07-25 06:23:37 +00:00
}
namespace BasicIDE
{
//----------------------------------------------------------------------------
void Organize( INT16 tabId )
2000-09-29 10:02:42 +00:00
{
BasicIDEDLL::Init();
BasicEntryDescriptor aDesc;
BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
if ( pIDEShell )
2000-09-29 10:02:42 +00:00
{
IDEBaseWindow* pCurWin = pIDEShell->GetCurWindow();
if ( pCurWin )
aDesc = pCurWin->CreateEntryDescriptor();
2000-09-29 10:02:42 +00:00
}
Window* pParent = Application::GetDefDialogParent();
OrganizeDialog* pDlg = new OrganizeDialog( pParent, tabId, aDesc );
2000-09-29 10:02:42 +00:00
pDlg->Execute();
delete pDlg;
}
//----------------------------------------------------------------------------
2000-09-29 10:02:42 +00:00
BOOL IsValidSbxName( const String& rName )
2000-09-29 10:02:42 +00:00
{
for ( USHORT nChar = 0; nChar < rName.Len(); nChar++ )
{
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 TRUE;
}
static BOOL StringCompareLessThan( const String& rStr1, const String& rStr2 )
2000-09-29 10:02:42 +00:00
{
return (rStr1.CompareIgnoreCaseToAscii( rStr2 ) == COMPARE_LESS);
2000-09-29 10:02:42 +00:00
}
//----------------------------------------------------------------------------
Sequence< ::rtl::OUString > GetMergedLibraryNames( const Reference< script::XLibraryContainer >& xModLibContainer, const Reference< script::XLibraryContainer >& xDlgLibContainer )
{
// create a sorted list of module library names
::std::vector<String> aModLibList;
if ( xModLibContainer.is() )
{
Sequence< ::rtl::OUString > aModLibNames = xModLibContainer->getElementNames();
sal_Int32 nModLibCount = aModLibNames.getLength();
const ::rtl::OUString* pModLibNames = aModLibNames.getConstArray();
for ( sal_Int32 i = 0 ; i < nModLibCount ; i++ )
aModLibList.push_back( pModLibNames[ i ] );
::std::sort( aModLibList.begin() , aModLibList.end() , StringCompareLessThan );
}
// create a sorted list of dialog library names
::std::vector<String> aDlgLibList;
if ( xDlgLibContainer.is() )
{
Sequence< ::rtl::OUString > aDlgLibNames = xDlgLibContainer->getElementNames();
sal_Int32 nDlgLibCount = aDlgLibNames.getLength();
const ::rtl::OUString* pDlgLibNames = aDlgLibNames.getConstArray();
for ( sal_Int32 i = 0 ; i < nDlgLibCount ; i++ )
aDlgLibList.push_back( pDlgLibNames[ i ] );
::std::sort( aDlgLibList.begin() , aDlgLibList.end() , StringCompareLessThan );
}
// merge both lists
::std::vector<String> aLibList( aModLibList.size() + aDlgLibList.size() );
::std::merge( aModLibList.begin(), aModLibList.end(), aDlgLibList.begin(), aDlgLibList.end(), aLibList.begin(), StringCompareLessThan );
::std::vector<String>::iterator aIterEnd = ::std::unique( aLibList.begin(), aLibList.end() ); // move unique elements to the front
aLibList.erase( aIterEnd, aLibList.end() ); // remove duplicates
// copy to sequence
sal_Int32 nLibCount = aLibList.size();
Sequence< ::rtl::OUString > aSeqLibNames( nLibCount );
for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
aSeqLibNames.getArray()[ i ] = aLibList[ i ];
return aSeqLibNames;
}
//----------------------------------------------------------------------------
bool RenameModule( Window* pErrorParent, const ScriptDocument& rDocument, const String& rLibName, const String& rOldName, const String& rNewName )
{
if ( !rDocument.hasModule( rLibName, rOldName ) )
{
OSL_ENSURE( false, "BasicIDE::RenameModule: old module name is invalid!" );
return false;
}
if ( rDocument.hasModule( rLibName, rNewName ) )
{
ErrorBox aError( pErrorParent, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) );
aError.Execute();
return false;
}
// #i74440
if ( rNewName.Len() == 0 )
{
ErrorBox aError( pErrorParent, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) );
aError.Execute();
return false;
}
if ( !rDocument.renameModule( rLibName, rOldName, rNewName ) )
return false;
BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
if ( pIDEShell )
{
IDEBaseWindow* pWin = pIDEShell->FindWindow( rDocument, rLibName, rNewName, BASICIDE_TYPE_MODULE, TRUE );
if ( pWin )
{
2001-09-25 08:14:46 +00:00
// set new name in window
pWin->SetName( rNewName );
// set new module in module window
2001-09-25 08:14:46 +00:00
ModulWindow* pModWin = (ModulWindow*)pWin;
pModWin->SetSbModule( (SbModule*)pModWin->GetBasic()->FindModule( rNewName ) );
// update tabwriter
USHORT nId = (USHORT)(pIDEShell->GetIDEWindowTable()).GetKey( pWin );
DBG_ASSERT( nId, "No entry in Tabbar!" );
if ( nId )
{
BasicIDETabBar* pTabBar = (BasicIDETabBar*)pIDEShell->GetTabBar();
pTabBar->SetPageText( nId, rNewName );
pTabBar->Sort();
pTabBar->MakeVisible( pTabBar->GetCurPageId() );
}
}
}
return true;
}
//----------------------------------------------------------------------------
::rtl::OUString ChooseMacro( const uno::Reference< frame::XModel >& rxLimitToDocument, BOOL bChooseOnly, const ::rtl::OUString& rMacroDesc )
{
(void)rMacroDesc;
BasicIDEDLL::Init();
IDE_DLL()->GetExtraData()->ChoosingMacro() = TRUE;
SFX_APP()->EnterBasicCall();
String aScriptURL;
BOOL bError = FALSE;
SbMethod* pMethod = NULL;
MacroChooser* pChooser = new MacroChooser( NULL, TRUE );
if ( bChooseOnly || !SvtModuleOptions().IsBasicIDE() )
pChooser->SetMode( MACROCHOOSER_CHOOSEONLY );
if ( !bChooseOnly && rxLimitToDocument.is() )
// Hack!
pChooser->SetMode( MACROCHOOSER_RECORDING );
short nRetValue = pChooser->Execute();
IDE_DLL()->GetExtraData()->ChoosingMacro() = FALSE;
switch ( nRetValue )
{
case MACRO_OK_RUN:
{
pMethod = pChooser->GetMacro();
if ( !pMethod && pChooser->GetMode() == MACROCHOOSER_RECORDING )
pMethod = pChooser->CreateMacro();
if ( pMethod )
{
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");
}
// 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() )
{
pMethod->AddRef(); // festhalten, bis Event abgearbeitet.
Application::PostUserEvent( LINK( IDE_DLL()->GetExtraData(), BasicIDEData, ExecuteMacroEvent ), pMethod );
}
}
break;
}
delete pChooser;
SFX_APP()->LeaveBasicCall();
return ::rtl::OUString( aScriptURL );
}
//----------------------------------------------------------------------------
Sequence< ::rtl::OUString > GetMethodNames( const ScriptDocument& rDocument, const String& rLibName, const String& rModName )
throw(NoSuchElementException )
{
Sequence< ::rtl::OUString > aSeqMethods;
// get module
::rtl::OUString aOUSource;
if ( rDocument.getModule( rLibName, rModName, aOUSource ) )
{
SbModuleRef xModule = new SbModule( rModName );
xModule->SetSource32( aOUSource );
USHORT nCount = xModule->GetMethods()->Count();
2010-08-06 09:35:51 +02:00
USHORT nRealCount = nCount;
for ( USHORT i = 0; i < nCount; i++ )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( i );
2010-08-06 09:35:51 +02:00
if( pMethod->IsHidden() )
--nRealCount;
}
aSeqMethods.realloc( nRealCount );
USHORT iTarget = 0;
for ( USHORT i = 0 ; i < nCount; ++i )
{
SbMethod* pMethod = (SbMethod*)xModule->GetMethods()->Get( i );
if( pMethod->IsHidden() )
continue;
DBG_ASSERT( pMethod, "Method not found! (NULL)" );
2010-08-06 09:35:51 +02:00
aSeqMethods.getArray()[ iTarget++ ] = pMethod->GetName();
}
}
return aSeqMethods;
}
//----------------------------------------------------------------------------
BOOL HasMethod( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, const String& rMethName )
{
BOOL bHasMethod = FALSE;
::rtl::OUString aOUSource;
if ( rDocument.hasModule( rLibName, rModName ) && rDocument.getModule( rLibName, rModName, aOUSource ) )
{
SbModuleRef xModule = new SbModule( rModName );
xModule->SetSource32( aOUSource );
SbxArray* pMethods = xModule->GetMethods();
if ( pMethods )
{
SbMethod* pMethod = (SbMethod*)pMethods->Find( rMethName, SbxCLASS_METHOD );
2010-08-06 09:35:51 +02:00
if ( pMethod && !pMethod->IsHidden() )
bHasMethod = TRUE;
}
}
return bHasMethod;
}
} //namespace BasicIDE
//----------------------------------------------------------------------------