23#include <com/sun/star/beans/PropertyVetoException.hpp>
24#include <com/sun/star/lang/DisposedException.hpp>
25#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
26#include <com/sun/star/util/XModifiable.hpp>
27#include <com/sun/star/util/XProtectable.hpp>
28#include <com/sun/star/util/XCloseable.hpp>
29#include <com/sun/star/util/URLTransformer.hpp>
30#include <com/sun/star/util/XURLTransformer.hpp>
31#include <com/sun/star/frame/XDispatchProvider.hpp>
32#include <com/sun/star/frame/XStorable.hpp>
33#include <com/sun/star/frame/XFrame.hpp>
34#include <com/sun/star/frame/XTitle.hpp>
35#include <ooo/vba/XApplicationBase.hpp>
40#include <osl/file.hxx>
59 SAL_INFO(
"vbahelper",
"VbaDocumentBase::getName: '" <<
sName <<
"'");
67 if ( !
sName.isEmpty() )
71 ::osl::File::getSystemPathFromFileURL(
aURL.GetLastName(),
sName );
75 uno::Reference< frame::XTitle > xTitle(
xModel, uno::UNO_QUERY_THROW );
76 sName = xTitle->getTitle();
89 sURL = sURL.copy( 0, sURL.getLength() -
aURL.GetLastName().getLength() - 1 );
90 ::osl::File::getSystemPathFromFileURL( sURL, sPath );
92 SAL_INFO(
"vbahelper",
"VbaDocumentBase::getPath: '" << sPath <<
"'");
105 SAL_INFO(
"vbahelper",
"VbaDocumentBase::getFullName: '" << sPath <<
"'");
111 SAL_INFO(
"vbahelper",
"VbaDocumentBase::getFullName: '" << sPath <<
"'");
119 bool bSaveChanges =
false;
121 bool bRouteWorkbook =
true;
123 rSaveArg >>= bSaveChanges;
124 bool bFileName = ( rFileArg >>= aFileName );
125 rRouteArg >>= bRouteWorkbook;
126 uno::Reference< frame::XStorable > xStorable(
getModel(), uno::UNO_QUERY_THROW );
127 uno::Reference< util::XModifiable > xModifiable(
getModel(), uno::UNO_QUERY_THROW );
131 if( xStorable->isReadonly() )
133 throw uno::RuntimeException(
"Unable to save to a read only file " );
136 xStorable->storeAsURL( aFileName, uno::Sequence< beans::PropertyValue >(0) );
141 xModifiable->setModified(
false );
144 bool bUIClose =
false;
147 uno::Reference< frame::XController >
xController(
getModel()->getCurrentController(), uno::UNO_SET_THROW );
148 uno::Reference< frame::XDispatchProvider > xDispatchProvider(
xController->getFrame(), uno::UNO_QUERY_THROW );
150 uno::Reference< lang::XMultiComponentFactory > xServiceManager(
mxContext->getServiceManager(), uno::UNO_SET_THROW );
151 uno::Reference< util::XURLTransformer > xURLTransformer( util::URLTransformer::create(
mxContext) );
154 aURL.Complete =
".uno:CloseDoc";
155 xURLTransformer->parseStrict(
aURL );
157 uno::Reference< css::frame::XDispatch >
xDispatch(
158 xDispatchProvider->queryDispatch(
aURL,
"_self" , 0 ),
159 uno::UNO_SET_THROW );
160 xDispatch->dispatch(
aURL, uno::Sequence< beans::PropertyValue >() );
163 catch(
const uno::Exception&)
171 bool bCloseable =
false;
175 uno::Reference< util::XCloseable > xCloseable(
xModel, uno::UNO_QUERY );
182 if ( xCloseable.is() )
185 xCloseable->close(
true);
188 catch (
const uno::Exception &)
199 uno::Reference< lang::XComponent > xDisposable (
xModel, uno::UNO_QUERY_THROW );
200 xDisposable->dispose();
202 catch(
const uno::Exception&)
211 uno::Reference< util::XProtectable > xProt(
getModel(), uno::UNO_QUERY_THROW );
212 SAL_INFO(
"vbahelper",
"Workbook::Protect stub");
213 if( aPassword >>= rPassword )
214 xProt->protect( rPassword );
216 xProt->protect( OUString() );
223 uno::Reference< util::XProtectable > xProt(
getModel(), uno::UNO_QUERY_THROW );
224 if( !xProt->isProtected() )
225 throw uno::RuntimeException(
"File is already unprotected" );
226 if( aPassword >>= rPassword )
227 xProt->unprotect( rPassword );
229 xProt->unprotect( OUString() );
235 uno::Reference< util::XModifiable > xModifiable(
getModel(), uno::UNO_QUERY_THROW );
238 xModifiable->setModified( !bSave );
240 catch (
const lang::DisposedException&)
244 catch (
const beans::PropertyVetoException&)
246 uno::Any aCaught( ::cppu::getCaughtException() );
247 throw lang::WrappedTargetRuntimeException(
248 "Can't change modified state of model!",
249 uno::Reference< uno::XInterface >(),
257 uno::Reference< util::XModifiable > xModifiable(
getModel(), uno::UNO_QUERY_THROW );
258 return !xModifiable->isModified();
271 uno::Reference< frame::XFrame >
xFrame(
getModel()->getCurrentController()->getFrame(), uno::UNO_SET_THROW );
280 uno::Reference< XApplicationBase > xApp(
Application(), uno::UNO_QUERY_THROW );
281 uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW );
282 uno::Sequence< uno::Any > aArgs{
uno::Any(xVBE),
284 uno::Reference< lang::XMultiComponentFactory > xServiceManager(
mxContext->getServiceManager(), uno::UNO_SET_THROW );
285 mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext(
286 "ooo.vba.vbide.VBProject", aArgs,
mxContext );
288 catch(
const uno::Exception&)
297 return "VbaDocumentBase";
300uno::Sequence< OUString >
305 "ooo.vba.VbaDocumentBase"
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Application() override
virtual void SAL_CALL Unprotect(const css::uno::Any &aPassword) override
virtual OUString SAL_CALL getPath() override
virtual OUString SAL_CALL getFullName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL Activate() override
virtual void SAL_CALL Save() override
css::uno::Reference< css::uno::XInterface > mxVBProject
virtual OUString getServiceImplName() override
virtual sal_Bool SAL_CALL getSaved() override
static OUString getNameFromModel(const css::uno::Reference< css::frame::XModel > &xModel)
virtual void SAL_CALL setSaved(sal_Bool bSave) override
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL Close(const css::uno::Any &bSaveChanges, const css::uno::Any &aFileName, const css::uno::Any &bRouteWorkbook) override
virtual css::uno::Any SAL_CALL getVBProject() override
virtual void SAL_CALL Protect(const css::uno::Any &aPassword)
const css::uno::Reference< css::frame::XModel > & getModel() const
VbaDocumentBase(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::frame::XModel > xModel)
Reference< XDispatch > xDispatch
Sequence< OUString > aServiceNames
#define SAL_INFO(area, stream)
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
void dispatchRequests(const uno::Reference< frame::XModel > &xModel, const OUString &aUrl, const uno::Sequence< beans::PropertyValue > &sProps)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel