1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "docinteraction.hxx"
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/task/InteractionHandler.hpp>
24 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
26 #include <comphelper/namedvaluecollection.hxx>
27 #include <comphelper/interaction.hxx>
28 #include <rtl/ref.hxx>
29 #include <tools/diagnose_ex.h>
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::XInterface
;
36 using ::com::sun::star::uno::UNO_QUERY
;
37 using ::com::sun::star::uno::UNO_QUERY_THROW
;
38 using ::com::sun::star::uno::UNO_SET_THROW
;
39 using ::com::sun::star::uno::Exception
;
40 using ::com::sun::star::uno::RuntimeException
;
41 using ::com::sun::star::uno::Any
;
42 using ::com::sun::star::uno::makeAny
;
43 using ::com::sun::star::uno::XComponentContext
;
44 using ::com::sun::star::task::XInteractionHandler
;
45 using ::com::sun::star::frame::XModel
;
46 using ::com::sun::star::task::DocumentPasswordRequest
;
47 using ::com::sun::star::task::InteractionClassification_QUERY
;
48 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER
;
49 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER
;
51 // InteractionHandler_Data
52 struct InteractionHandler_Data
54 Reference
< XInteractionHandler
> xHandler
;
56 InteractionHandler_Data( const Reference
<XComponentContext
>& _rContext
)
57 :xHandler( ::com::sun::star::task::InteractionHandler::createWithParent(_rContext
, 0), UNO_QUERY
)
63 InteractionHandler::InteractionHandler( const Reference
<XComponentContext
>& _rContext
, const Reference
< XModel
>& _rxDocument
)
64 :m_pData( new InteractionHandler_Data( _rContext
) )
66 // check whether the doumentc has an own interaction handler set
67 ::comphelper::NamedValueCollection
aDocArgs( _rxDocument
->getArgs() );
68 m_pData
->xHandler
= aDocArgs
.getOrDefault( "InteractionHandler", m_pData
->xHandler
);
71 InteractionHandler::~InteractionHandler()
75 bool InteractionHandler::requestDocumentPassword( const OUString
& _rDocumentName
, OUString
& _io_rPassword
)
78 DocumentPasswordRequest
aRequest(
80 InteractionClassification_QUERY
,
81 _io_rPassword
.isEmpty() ? PasswordRequestMode_PASSWORD_ENTER
: PasswordRequestMode_PASSWORD_REENTER
,
85 ::rtl::Reference
< ::comphelper::OInteractionRequest
> pRequest( new ::comphelper::OInteractionRequest( makeAny( aRequest
) ) );
86 ::rtl::Reference
< ::comphelper::OInteractionPassword
> pPassword( new ::comphelper::OInteractionPassword( _io_rPassword
) );
87 ::rtl::Reference
< ::comphelper::OInteractionAbort
> pAbort( new ::comphelper::OInteractionAbort
);
88 pRequest
->addContinuation( pPassword
.get() );
89 pRequest
->addContinuation( pAbort
.get() );
92 m_pData
->xHandler
->handle( pRequest
.get() );
95 if ( pAbort
->wasSelected() )
98 _io_rPassword
= pPassword
->getPassword();
102 void InteractionHandler::reportError( const Any
& _rError
)
104 ::rtl::Reference
< ::comphelper::OInteractionRequest
> pRequest( new ::comphelper::OInteractionRequest( _rError
) );
105 ::rtl::Reference
< ::comphelper::OInteractionApprove
> pApprove( new ::comphelper::OInteractionApprove
);
106 pRequest
->addContinuation( pApprove
.get() );
108 m_pData
->xHandler
->handle( pRequest
.get() );
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */