1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macrconf.cxx,v $
10 * $Revision: 1.25.142.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <basic/sbstar.hxx>
34 #include <basic/basmgr.hxx>
35 #ifndef _SBX_HXX //autogen
36 #include <basic/sbx.hxx>
38 #include <svtools/intitem.hxx>
39 #include <basic/sbmeth.hxx>
40 #include <basic/sbmod.hxx>
41 #ifndef _BASIC_SBUNO_HXX
42 #include <basic/sbuno.hxx>
45 #include <osl/mutex.hxx>
47 #include <com/sun/star/script/XEngine.hpp>
48 #include <com/sun/star/document/MacroExecMode.hpp>
53 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
54 #include <comphelper/processfactory.hxx>
56 #include <unotools/intlwrapper.hxx>
58 #include <sfx2/msgpool.hxx>
59 #include <sfx2/macrconf.hxx>
60 #include "sfxbasic.hxx"
61 #include <sfx2/sfx.hrc>
62 #include <sfx2/app.hxx>
63 #include <sfx2/objsh.hxx>
64 #include <sfx2/dispatch.hxx>
65 #include "minfitem.hxx"
67 #include <sfx2/evntconf.hxx>
68 #include <sfx2/docfile.hxx>
69 #include <sfx2/genlink.hxx>
70 #include <sfx2/viewfrm.hxx>
71 #include <appdata.hxx>
72 #include "objshimp.hxx"
73 #include <sfx2/request.hxx>
75 static const sal_uInt16 nCompatVersion
= 2;
76 static const sal_uInt16 nVersion
= 3;
79 SfxMacroConfig
* SfxMacroConfig::pMacroConfig
= NULL
;
81 SfxMacroConfig
* SfxMacroConfig::GetOrCreate()
83 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
85 pMacroConfig
= new SfxMacroConfig
;
89 void SfxMacroConfig::Release_Impl()
91 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
92 DELETEZ( pMacroConfig
);
95 //==========================================================================
97 struct SfxMacroConfig_Impl
99 SfxMacroInfoArr_Impl aArr
;
101 sal_Bool bWaitingForCallback
;
103 SfxMacroConfig_Impl()
105 , bWaitingForCallback( sal_False
)
109 //==========================================================================
111 SbMethod
* SfxQueryMacro_Impl( BasicManager
* pMgr
, const String
& rMacro
,
112 const String
&rLibName
, const String
& rModule
)
114 IntlWrapper
aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
115 const CollatorWrapper
* pCollator
= aIntlWrapper
.getCollator();
116 sal_uInt16 nLibCount
= pMgr
->GetLibCount();
117 for ( sal_uInt16 nLib
= 0; nLib
< nLibCount
; ++nLib
)
119 if ( COMPARE_EQUAL
== pCollator
->compareString( pMgr
->GetLibName( nLib
), rLibName
) )
121 StarBASIC
* pLib
= pMgr
->GetLib( nLib
);
124 pMgr
->LoadLib( nLib
);
125 pLib
= pMgr
->GetLib( nLib
);
130 sal_uInt16 nModCount
= pLib
->GetModules()->Count();
131 for( sal_uInt16 nMod
= 0; nMod
< nModCount
; ++nMod
)
133 SbModule
* pMod
= (SbModule
*)pLib
->GetModules()->Get( nMod
);
134 if ( pMod
&& COMPARE_EQUAL
== pCollator
->compareString( pMod
->GetName(), rModule
) )
136 SbMethod
* pMethod
= (SbMethod
*)pMod
->Find( rMacro
, SbxCLASS_METHOD
);
147 SbMethod
* SfxQueryMacro( BasicManager
* pMgr
, const String
& rMacro
)
149 sal_uInt16 nLast
= 0;
150 String aMacro
= rMacro
;
151 String aLibName
= aMacro
.GetToken( 0, '.', nLast
);
152 String aModule
= aMacro
.GetToken( 0, '.', nLast
);
153 aMacro
.Erase( 0, nLast
);
155 return SfxQueryMacro_Impl( pMgr
, aMacro
, aLibName
, aModule
);
158 ErrCode
SfxCallMacro( BasicManager
* pMgr
, const String
& rCode
,
159 SbxArray
*pArgs
, SbxValue
*pRet
)
162 SfxApplication
*pApp
= SFX_APP();
163 pApp
->EnterBasicCall();
164 SbMethod
* pMethod
= SfxQueryMacro( pMgr
, rCode
);
168 pMethod
->SetParameters( pArgs
);
169 nErr
= pMethod
->Call( pRet
);
172 nErr
= ERRCODE_BASIC_PROC_UNDEFINED
;
174 pApp
->LeaveBasicCall();
178 //==========================================================================
180 SfxMacroInfo::SfxMacroInfo( const String
& rURL
) :
187 if ( rURL
.CompareToAscii( "macro:", 6 ) == COMPARE_EQUAL
)
189 String aTmp
= rURL
.Copy( 6 );
190 if ( aTmp
.GetTokenCount('/') > 3 )
192 // 'macro:///lib.mod.proc(args)' => Macro via App-BASIC-Mgr
193 // 'macro://[docname|.]/lib.mod.proc(args)' => Macro via zugehoerigen Doc-BASIC-Mgr
194 if ( aTmp
.CompareToAscii("///", 3 ) != COMPARE_EQUAL
)
196 aTmp
= rURL
.GetToken( 3, '/' );
197 if ( aTmp
.GetTokenCount('.') == 3 )
199 aLibName
= aTmp
.GetToken( 0, '.' );
200 aModuleName
= aTmp
.GetToken( 1, '.' );
201 aMethodName
= aTmp
.GetToken( 2, '.' );
203 // Remove arguments to be compatible
204 aMethodName
.SearchAndReplaceAscii( "()", String(), sal::static_int_cast
< xub_StrLen
>(std::max( aMethodName
.Len()-2, 0 )));
208 DBG_ASSERT( aLibName
.Len() && aModuleName
.Len() && aMethodName
.Len(), "Wrong macro URL!" );
214 SfxMacroInfo::SfxMacroInfo( bool _bAppBasic
) :
217 bAppBasic(_bAppBasic
),
222 //==========================================================================
224 SfxMacroInfo::SfxMacroInfo(bool _bAppBasic
, const String
& rLibName
,
225 const String
& rModuleName
, const String
& rMethodName
) :
228 bAppBasic(_bAppBasic
),
230 aModuleName(rModuleName
),
231 aMethodName(rMethodName
),
237 //==========================================================================
239 SfxMacroInfo::SfxMacroInfo(bool _bAppBasic
, const String
& rQualifiedName
)
242 bAppBasic(_bAppBasic
),
246 sal_uInt16 nCount
= rQualifiedName
.GetTokenCount('.');
247 aMethodName
= rQualifiedName
.GetToken( nCount
-1, '.' );
249 aModuleName
= rQualifiedName
.GetToken( nCount
-2, '.' );
251 aLibName
= rQualifiedName
.GetToken( 0, '.' );
254 //==========================================================================
256 SfxMacroInfo::SfxMacroInfo(SfxMacroInfo
& rOther
) :
259 bAppBasic(rOther
.bAppBasic
),
260 aLibName(rOther
.aLibName
),
261 aModuleName(rOther
.aModuleName
),
262 aMethodName(rOther
.aMethodName
),
263 nSlotId(rOther
.nSlotId
),
267 //==========================================================================
269 SfxMacroInfo::~SfxMacroInfo()
275 //==========================================================================
277 sal_Bool
SfxMacroInfo::operator==(const SfxMacroInfo
& rOther
) const
279 if ( GetQualifiedName() == rOther
.GetQualifiedName() &&
280 bAppBasic
== rOther
.bAppBasic
)
286 //==========================================================================
288 String
SfxMacroInfo::GetMacroName() const
290 String aMacroName
= aMethodName
;
292 aMacroName
+= aLibName
;
294 aMacroName
+= aModuleName
;
299 //==========================================================================
301 String
SfxMacroInfo::GetQualifiedName() const
304 if( aMacroName
.Len() || aLibName
.Len() )
307 aMacroName
= aLibName
;
309 aMacroName
+= aModuleName
;
313 // Wg. ::com::sun::star::script::JavaScript kein Zerlegen des Strings mehr
314 aMacroName
+= aMethodName
;
318 String
SfxMacroInfo::GetFullQualifiedName() const
320 // Liefert nur Unsinn, wenn f"ur ein ::com::sun::star::script::JavaScript aufgerufen !
323 aRet
= SFX_APP()->GetName();
325 aRet
+= GetQualifiedName();
329 String
SfxMacroInfo::GetURL() const
331 if ( !aLibName
.Len() )
334 // 'macro:///lib.mod.proc(args)' => Macro via App-BASIC-Mgr
335 // 'macro://[docname|.]/lib.mod.proc(args)' => Macro via zugehoerigen Doc-BASIC-Mgr
336 // 'macro://obj.method(args)' => Object via App-BASIC-Mgr
337 String
aURL( String::CreateFromAscii("macro://") );
346 aURL
+= String::CreateFromAscii("()");
351 //==========================================================================
353 BasicManager
* SfxMacroInfo::GetBasicManager() const
357 return SFX_APP()->GetBasicManager();
361 SfxObjectShell
*pCurrDocShell
= SfxObjectShell::Current();
362 return pCurrDocShell
? pCurrDocShell
->GetBasicManager() :
363 SFX_APP()->GetBasicManager();
367 //==========================================================================
369 String
SfxMacroInfo::GetBasicName() const
373 return SFX_APP()->GetName();
377 SfxObjectShell
*pCurrDocShell
= SfxObjectShell::Current();
379 return pCurrDocShell
->GetTitle();
381 return SFX_APP()->GetName();
385 String
SfxMacroInfo::GetHelpText() const
392 String
SfxMacroConfig::RequestHelp( sal_uInt16 nId
)
394 SfxMacroInfo
*pInfo
= SFX_APP()->GetMacroConfig()->GetMacroInfo( nId
);
398 if ( !pInfo
->pHelpText
)
401 SfxQueryMacro_Impl( pInfo
->GetBasicManager(), pInfo
->aMethodName
,
402 pInfo
->aLibName
, pInfo
->aModuleName
);
403 if ( pMethod
&& pMethod
->GetInfo() )
404 pInfo
->pHelpText
= new String( pMethod
->GetInfo()->GetComment() );
407 return pInfo
->GetHelpText();
410 void SfxMacroInfo::SetHelpText( const String
& rName
)
413 pHelpText
= new String
;
417 //==========================================================================
419 SvStream
& operator >> (SvStream
& rStream
, SfxMacroInfo
& rInfo
)
421 sal_uInt16 nAppBasic
, nFileVersion
;
424 rStream
>> nFileVersion
;
425 if ( nVersion
< nCompatVersion
)
427 // In der 1.Version ohne Versionskennung
428 nAppBasic
= nVersion
;
430 rStream
.ReadByteString(aDocName
,RTL_TEXTENCODING_UTF8
);
431 rStream
.ReadByteString(rInfo
.aLibName
,RTL_TEXTENCODING_UTF8
);
432 rStream
.ReadByteString(rInfo
.aModuleName
,RTL_TEXTENCODING_UTF8
);
433 rStream
.ReadByteString(rInfo
.aMethodName
,RTL_TEXTENCODING_UTF8
);
438 rStream
>> nAppBasic
;
439 rStream
.ReadByteString(aDocName
,RTL_TEXTENCODING_UTF8
); // Vorsicht: kann bei AppName Unsinn sein!
440 rStream
.ReadByteString(rInfo
.aLibName
,RTL_TEXTENCODING_UTF8
);
441 rStream
.ReadByteString(rInfo
.aModuleName
,RTL_TEXTENCODING_UTF8
);
442 rStream
.ReadByteString(aInput
,RTL_TEXTENCODING_UTF8
);
444 if ( nFileVersion
== nCompatVersion
)
445 rInfo
.aMethodName
= aInput
;
448 sal_uInt16 nCount
= aInput
.GetTokenCount('.');
449 rInfo
.aMethodName
= aInput
.GetToken( nCount
-1, '.' );
451 rInfo
.aModuleName
= aInput
.GetToken( nCount
-2, '.' );
453 rInfo
.aLibName
= aInput
.GetToken( 0, '.' );
457 rInfo
.bAppBasic
= (sal_Bool
) nAppBasic
;
461 int SfxMacroInfo::Load( SvStream
& rStream
)
464 nSlotId
= SFX_APP()->GetMacroConfig()->GetSlotId(this);
468 //==========================================================================
470 SvStream
& operator << (SvStream
& rStream
, const SfxMacroInfo
& rInfo
)
472 if ( rInfo
.bAppBasic
)
475 << (sal_uInt16
) rInfo
.bAppBasic
;
476 rStream
.WriteByteString(rInfo
.GetBasicName(),RTL_TEXTENCODING_UTF8
);
477 rStream
.WriteByteString(rInfo
.aLibName
,RTL_TEXTENCODING_UTF8
);
478 rStream
.WriteByteString(rInfo
.aModuleName
,RTL_TEXTENCODING_UTF8
);
479 rStream
.WriteByteString(rInfo
.aMethodName
,RTL_TEXTENCODING_UTF8
);
484 << (sal_uInt16
) rInfo
.bAppBasic
;
485 rStream
.WriteByteString(SFX_APP()->GetName(),RTL_TEXTENCODING_UTF8
);
486 rStream
.WriteByteString(rInfo
.aLibName
,RTL_TEXTENCODING_UTF8
);
487 rStream
.WriteByteString(rInfo
.aModuleName
,RTL_TEXTENCODING_UTF8
);
488 rStream
.WriteByteString(rInfo
.aMethodName
,RTL_TEXTENCODING_UTF8
);
494 sal_Bool
SfxMacroInfo::Compare( const SvxMacro
& rMacro
) const
496 String aName
= rMacro
.GetLibName();
498 aName
+= rMacro
.GetMacName();
499 if ( GetFullQualifiedName() == aName
)
504 //==========================================================================
506 SfxMacroConfig::SfxMacroConfig()
508 pImp
= new SfxMacroConfig_Impl
;
511 //==========================================================================
513 SfxMacroConfig::~SfxMacroConfig()
515 if ( pImp
->nEventId
)
516 Application::RemoveUserEvent( pImp
->nEventId
);
520 //==========================================================================
522 SFX_STATE_STUB( SfxApplication
, MacroState_Impl
)
523 SFX_EXEC_STUB( SfxApplication
, MacroExec_Impl
)
525 sal_uInt16
SfxMacroConfig::GetSlotId(SfxMacroInfoPtr pInfo
)
527 sal_uInt16 nCount
= pImp
->aArr
.Count(); // Macro suchen
529 for (i
=0; i
<nCount
; i
++)
530 if ((*(pImp
->aArr
)[i
]) == (*pInfo
))
534 { // Macro noch unbekannt
535 nCount
= aIdArray
.Count();
537 for (n
=0; n
<nCount
; n
++) // freie SlotId suchen
538 if (aIdArray
[n
] > SID_MACRO_START
+ n
)
541 sal_uInt16 nNewSlotId
= SID_MACRO_START
+ n
;
542 if ( nNewSlotId
> SID_MACRO_END
)
544 aIdArray
.Insert( SID_MACRO_START
+ n
, n
);
546 SfxSlot
*pNewSlot
= new SfxSlot
;
547 pNewSlot
->nSlotId
= SID_MACRO_START
+ n
;
548 pNewSlot
->nGroupId
= 0;
549 pNewSlot
->nFlags
= SFX_SLOT_ASYNCHRON
;
550 pNewSlot
->nMasterSlotId
= 0;
551 pNewSlot
->nValue
= 0;
552 pNewSlot
->fnExec
= SFX_STUB_PTR(SfxApplication
,MacroExec_Impl
);
553 pNewSlot
->fnState
= SFX_STUB_PTR(SfxApplication
,MacroState_Impl
);
554 pNewSlot
->pType
= 0; HACK(SFX_TYPE(SfxVoidItem
))
555 pNewSlot
->pName
= pNewSlot
->pMethodName
= U2S(pInfo
->aMethodName
).getStr();
556 pNewSlot
->pLinkedSlot
= 0;
557 pNewSlot
->nArgDefCount
= 0;
558 pNewSlot
->pFirstArgDef
= 0;
559 pNewSlot
->pUnoName
= 0;
563 SfxSlot
*pSlot
= (pImp
->aArr
)[0]->pSlot
;
564 pNewSlot
->pNextSlot
= pSlot
->pNextSlot
;
565 pSlot
->pNextSlot
= pNewSlot
;
568 pNewSlot
->pNextSlot
= pNewSlot
;
571 SfxMacroInfoPtr pNewInfo
= new SfxMacroInfo(*pInfo
);
572 pNewInfo
->nSlotId
= SID_MACRO_START
+ n
;
573 pImp
->aArr
.Insert(pNewInfo
,n
);
574 pNewInfo
->pSlot
= pNewSlot
;
575 pInfo
->nSlotId
= pNewInfo
->nSlotId
;
580 pInfo
->nSlotId
= (pImp
->aArr
)[i
]->nSlotId
;
581 (pImp
->aArr
)[i
]->nRefCnt
++;
584 return pInfo
->nSlotId
;
587 //==========================================================================
589 void SfxMacroConfig::ReleaseSlotId(sal_uInt16 nId
)
591 DBG_ASSERT( IsMacroSlot( nId
), "SlotId ist kein Macro!");
593 sal_uInt16 nCount
= pImp
->aArr
.Count();
594 for (sal_uInt16 i
=0; i
<nCount
; i
++)
596 SfxMacroInfo
*pInfo
= (pImp
->aArr
)[i
];
597 if (pInfo
->nSlotId
== nId
)
600 if (pInfo
->nRefCnt
== 0)
602 // Slot wird nicht mehr referenziert, also holen
603 SfxSlot
*pSlot
= pInfo
->pSlot
;
605 // Slot aus der Verkettung rausnehmen
606 while (pSlot
->pNextSlot
!= pInfo
->pSlot
)
607 pSlot
= (SfxSlot
*) pSlot
->pNextSlot
;
608 pSlot
->pNextSlot
= pInfo
->pSlot
->pNextSlot
;
610 // Slot selbst kurz schlie\sen
611 pSlot
= pInfo
->pSlot
;
612 pSlot
->pNextSlot
= pSlot
;
614 // MacroInfo aus Array entfernen, damit sie kein Unheil
616 pImp
->aArr
.Remove(i
);
618 // SlotId wieder freigeben
619 sal_uInt16 nIdCount
= aIdArray
.Count();
620 for (sal_uInt16 n
=0; n
<nIdCount
; n
++)
622 if (aIdArray
[n
] == nId
)
629 // Sofern nicht die Applikation heruntergefahren wird, mu\s
630 // der Slot asynchron gel"oscht werden, falls er in seinem
631 // eigenen Execute abgeschossen wird!
632 if ( !SFX_APP()->Get_Impl()->bInQuit
)
633 pImp
->nEventId
= Application::PostUserEvent( LINK(this, SfxMacroConfig
, EventHdl_Impl
), pInfo
);
635 EventHdl_Impl( pInfo
);
641 DBG_ERROR("Macro-SlotId nicht gefunden!");
644 //==========================================================================
646 void SfxMacroConfig::RegisterSlotId(sal_uInt16 nId
)
648 DBG_ASSERT( IsMacroSlot( nId
), "SlotId ist kein Macro!");
650 sal_uInt16 nCount
= pImp
->aArr
.Count();
651 for (sal_uInt16 i
=0; i
<nCount
; i
++)
653 if ((pImp
->aArr
)[i
]->nSlotId
== nId
)
655 (pImp
->aArr
)[i
]->nRefCnt
++;
660 DBG_ERROR("Macro-SlotId nicht gefunden!");
663 //==========================================================================
665 SfxMacroInfo
* SfxMacroConfig::GetMacroInfo(sal_uInt16 nId
) const
667 sal_uInt16 nCount
= pImp
->aArr
.Count();
668 for (sal_uInt16 i
=0; i
<nCount
; i
++)
669 if ((pImp
->aArr
)[i
]->nSlotId
== nId
)
670 return (pImp
->aArr
)[i
];
675 //==========================================================================
677 const SfxMacroInfo
* SfxMacroConfig::GetMacroInfo_Impl( const SvxMacro
*pMacro
) const
679 sal_uInt16 nCount
= pImp
->aArr
.Count();
680 for (sal_uInt16 i
=0; i
<nCount
; i
++)
681 if ((pImp
->aArr
)[i
]->Compare(*pMacro
) )
682 return (pImp
->aArr
)[i
];
686 //==========================================================================
688 sal_Bool
SfxMacroConfig::ExecuteMacro( sal_uInt16 nId
, const String
& rArgs
) const
690 const SfxMacroInfo
* pInfo
= GetMacroInfo( nId
);
694 SfxObjectShell
* pSh
= SfxObjectShell::Current();
696 SvxMacro
aMacro( pInfo
->GetQualifiedName(), pInfo
->GetBasicName(), STARBASIC
);
697 sal_Bool bRet
= ExecuteMacro( pSh
, &aMacro
, rArgs
);
699 // Release, da im Dispatcher-Execute ein Register gemacht wurde
700 ((SfxMacroConfig
*)this)->ReleaseSlotId( nId
);
704 sal_Bool
SfxMacroConfig::ExecuteMacro( SfxObjectShell
*pSh
, const SvxMacro
* pMacro
, const String
& /*rArgs*/ ) const
706 SfxApplication
*pApp
= SFX_APP();
708 // Name des Macros oder Scripts bzw. ScriptCode
709 String
aCode( pMacro
->GetMacName() );
710 ErrCode nErr
= ERRCODE_NONE
;
712 // Ist es ein Basic-Macro ?
713 ScriptType eSType
= pMacro
->GetScriptType();
714 sal_Bool bIsBasic
= eSType
== STARBASIC
;
715 sal_Bool bIsStarScript
= ( eSType
== EXTENDED_STYPE
&& pMacro
->GetLibName().SearchAscii( "StarScript" ) != STRING_NOTFOUND
);
716 sal_Bool bIsBasicLibBased
= bIsBasic
|| bIsStarScript
|| !pSh
;
718 if ( bIsBasicLibBased
)
720 pApp
->EnterBasicCall();
721 BasicManager
*pAppMgr
= SFX_APP()->GetBasicManager();
724 // BasicManager von Document?
725 BasicManager
*pMgr
= pSh
? pSh
->GetBasicManager() : NULL
;
727 // Da leider der Name zwischendurch h"aufig gewechselt hat ...
728 if( SFX_APP()->GetName() == pMacro
->GetLibName() ||
729 pMacro
->GetLibName().EqualsAscii("StarDesktop") )
731 else if ( pMgr
== pAppMgr
)
734 if ( pSh
&& pMgr
&& pMgr
!= pAppMgr
)
736 if ( !pSh
->AdjustMacroMode( String() ) )
740 if ( pSh
&& pMgr
&& pMgr
== pAppMgr
)
742 ::com::sun::star::uno::Any aOldThisComponent
= pAppMgr
->SetGlobalUNOConstant( "ThisComponent", makeAny( pSh
->GetModel() ) );
743 nErr
= Call( 0, aCode
, pMgr
);
744 pAppMgr
->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent
);
747 nErr
= Call( 0, aCode
, pMgr
);
749 nErr
= SbxERR_NO_METHOD
;
753 pApp
->LeaveBasicCall();
757 nErr
= SbxERR_NO_METHOD
;
760 return ( nErr
== ERRCODE_NONE
);
763 sal_Bool
SfxMacroConfig::CheckMacro( SfxObjectShell
*pSh
, const SvxMacro
* pMacro
) const
765 SfxApplication
*pApp
= SFX_APP();
767 // Name des Macros oder Scripts bzw. ScriptCode
768 String
aCode( pMacro
->GetMacName() );
769 ErrCode nErr
= ERRCODE_NONE
;
771 // BasicManager von Document oder Application
772 pApp
->EnterBasicCall();
773 BasicManager
*pAppMgr
= SFX_APP()->GetBasicManager();
774 BasicManager
*pMgr
= pSh
? pSh
->GetBasicManager() : NULL
;
776 // Da leider der Name zwischendurch h"aufig gewechselt hat ...
777 if( SFX_APP()->GetName() == pMacro
->GetLibName() ||
778 pMacro
->GetLibName().EqualsAscii("StarDesktop") )
780 else if ( pMgr
== pAppMgr
)
783 if ( !pMgr
|| !SfxQueryMacro( pMgr
, aCode
) )
784 nErr
= SbxERR_NO_METHOD
;
785 pApp
->LeaveBasicCall();
786 return ( nErr
== ERRCODE_NONE
);
789 //==========================================================================
791 sal_Bool
SfxMacroConfig::CheckMacro( sal_uInt16 nId
) const
793 const SfxMacroInfo
* pInfo
= GetMacroInfo( nId
);
797 // Basic nur initialisieren, wenn default nicht ::com::sun::star::script::JavaScript; dann mu\s
798 // in IsBasic() sowieso das Basic angelegt werden
799 SfxObjectShell
* pSh
= SfxObjectShell::Current();
801 SfxApplication
*pApp
= SFX_APP();
802 pApp
->EnterBasicCall();
804 // BasicManager von Document oder Application
805 BasicManager
*pAppMgr
= SFX_APP()->GetBasicManager();
806 BasicManager
*pMgr
= pSh
? pSh
->GetBasicManager() : NULL
;
808 if( SFX_APP()->GetName() == pInfo
->GetBasicName() )
809 pMgr
= SFX_APP()->GetBasicManager();
810 else if ( pMgr
== pAppMgr
)
813 String
aFull( pInfo
->GetQualifiedName() );
814 sal_Bool bIsBasic
= pMgr
? IsBasic( 0, aFull
, pMgr
) : sal_False
;
815 pApp
->LeaveBasicCall();
819 //==========================================================================
821 IMPL_LINK( SfxMacroConfig
, CallbackHdl_Impl
, SfxMacroConfig
*, pConfig
)
823 (void)pConfig
; // unused
824 pImp
->bWaitingForCallback
= sal_False
;
828 IMPL_LINK( SfxMacroConfig
, EventHdl_Impl
, SfxMacroInfo
*, pInfo
)
835 sal_Bool
SfxMacroConfig::IsBasic(
836 SbxObject
* /*pVCtrl*/,
841 SFX_APP()->EnterBasicCall();
842 bFound
= SfxQueryMacro( pMgr
, rCode
) != 0;
843 SFX_APP()->LeaveBasicCall();
847 ErrCode
SfxMacroConfig::Call(
848 SbxObject
* /*pVCtrl*/,
854 SfxApplication
*pApp
= SFX_APP();
855 pApp
->EnterBasicCall();
856 SbMethod
* pMethod
= SfxQueryMacro( pMgr
, rCode
);
861 pMethod
->SetParameters( pArgs
);
862 nErr
= pMethod
->Call( pRet
);
865 nErr
= ERRCODE_BASIC_PROC_UNDEFINED
;
867 pApp
->LeaveBasicCall();
872 sal_Bool
SfxMacroConfig::IsMacroSlot( sal_uInt16 nId
)
874 return ( nId
>= SID_MACRO_START
&& nId
<= SID_MACRO_END
);