update dev300-m58
[ooovba.git] / dbaccess / source / ext / macromigration / docinteraction.cxx
blob19d1f682f37ebfcab475c4c8727042560addbc07
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docinteraction.cxx,v $
10 * $Revision: 1.1.2.2 $
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_dbaccess.hxx"
34 #include "docinteraction.hxx"
36 /** === begin UNO includes === **/
37 #include <com/sun/star/frame/XModel.hpp>
38 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
39 /** === end UNO includes === **/
41 #include <comphelper/componentcontext.hxx>
42 #include <comphelper/namedvaluecollection.hxx>
43 #include <comphelper/interaction.hxx>
44 #include <rtl/ref.hxx>
45 #include <tools/diagnose_ex.h>
47 //........................................................................
48 namespace dbmm
50 //........................................................................
52 /** === begin UNO using === **/
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::XInterface;
55 using ::com::sun::star::uno::UNO_QUERY;
56 using ::com::sun::star::uno::UNO_QUERY_THROW;
57 using ::com::sun::star::uno::UNO_SET_THROW;
58 using ::com::sun::star::uno::Exception;
59 using ::com::sun::star::uno::RuntimeException;
60 using ::com::sun::star::uno::Any;
61 using ::com::sun::star::uno::makeAny;
62 using ::com::sun::star::task::XInteractionHandler;
63 using ::com::sun::star::frame::XModel;
64 using ::com::sun::star::task::DocumentPasswordRequest;
65 using ::com::sun::star::task::InteractionClassification_QUERY;
66 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER;
67 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
68 /** === end UNO using === **/
70 //====================================================================
71 //= InteractionHandler_Data
72 //====================================================================
73 struct InteractionHandler_Data
75 Reference< XInteractionHandler > xHandler;
77 InteractionHandler_Data( const Reference< XInteractionHandler >& _rxHandler )
78 :xHandler( _rxHandler )
82 InteractionHandler_Data( const ::comphelper::ComponentContext& _rContext )
83 :xHandler( _rContext.createComponent( "com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW )
88 //====================================================================
89 //= InteractionHandler
90 //====================================================================
91 //--------------------------------------------------------------------
92 InteractionHandler::InteractionHandler( const ::comphelper::ComponentContext& _rContext )
93 :m_pData( new InteractionHandler_Data( _rContext ) )
97 //--------------------------------------------------------------------
98 InteractionHandler::InteractionHandler( const Reference< XInteractionHandler >& _rxHandler )
99 :m_pData( new InteractionHandler_Data( _rxHandler ) )
103 //--------------------------------------------------------------------
104 InteractionHandler::InteractionHandler( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
105 :m_pData( new InteractionHandler_Data( _rContext ) )
107 // check whether the doumentc has an own interaction handler set
108 ::comphelper::NamedValueCollection aDocArgs( _rxDocument->getArgs() );
109 m_pData->xHandler = aDocArgs.getOrDefault( "InteractionHandler", m_pData->xHandler );
112 //--------------------------------------------------------------------
113 InteractionHandler::~InteractionHandler()
117 //--------------------------------------------------------------------
118 bool InteractionHandler::requestDocumentPassword( const ::rtl::OUString& _rDocumentName, ::rtl::OUString& _io_rPassword )
120 // create request
121 DocumentPasswordRequest aRequest(
122 ::rtl::OUString(), NULL,
123 InteractionClassification_QUERY,
124 _io_rPassword.getLength() ? PasswordRequestMode_PASSWORD_REENTER : PasswordRequestMode_PASSWORD_ENTER,
125 _rDocumentName
128 ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( makeAny( aRequest ) ) );
129 ::rtl::Reference< ::comphelper::OInteractionPassword > pPassword( new ::comphelper::OInteractionPassword( _io_rPassword ) );
130 ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
131 pRequest->addContinuation( pPassword.get() );
132 pRequest->addContinuation( pAbort.get() );
134 // handle
135 m_pData->xHandler->handle( pRequest.get() );
137 // finish up
138 if ( pAbort->wasSelected() )
139 return false;
141 _io_rPassword = pPassword->getPassword();
142 return true;
145 //--------------------------------------------------------------------
146 void InteractionHandler::reportError( const Any& _rError )
148 ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
149 ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
150 pRequest->addContinuation( pApprove.get() );
152 m_pData->xHandler->handle( pRequest.get() );
155 //........................................................................
156 } // namespace dbmm
157 //........................................................................