update dev300-m58
[ooovba.git] / comphelper / source / misc / docpasswordrequest.cxx
blob187642e10fe9c526f6ce72ab078446191572f9c8
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: docpasswordrequest.cxx,v $
10 * $Revision: 1.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_comphelper.hxx"
34 #include "comphelper/docpasswordrequest.hxx"
35 #include <com/sun/star/task/DocumentMSPasswordRequest.hpp>
36 #include <com/sun/star/task/DocumentPasswordRequest.hpp>
37 #include <com/sun/star/task/XInteractionAbort.hpp>
38 #include <com/sun/star/task/XInteractionPassword.hpp>
40 using ::rtl::OUString;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::RuntimeException;
44 using ::com::sun::star::uno::Sequence;
45 using ::com::sun::star::uno::XInterface;
46 using ::com::sun::star::task::InteractionClassification_QUERY;
47 using ::com::sun::star::task::DocumentMSPasswordRequest;
48 using ::com::sun::star::task::DocumentPasswordRequest;
49 using ::com::sun::star::task::PasswordRequestMode;
50 using ::com::sun::star::task::XInteractionAbort;
51 using ::com::sun::star::task::XInteractionContinuation;
52 using ::com::sun::star::task::XInteractionPassword;
54 namespace comphelper {
56 // ============================================================================
58 class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
60 public:
61 inline explicit AbortContinuation() : mbSelected( false ) {}
63 inline bool isSelected() const { return mbSelected; }
64 inline void reset() { mbSelected = false; }
66 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
68 private:
69 bool mbSelected;
72 // ============================================================================
74 class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword >
76 public:
77 inline explicit PasswordContinuation() : mbSelected( false ) {}
79 inline bool isSelected() const { return mbSelected; }
80 inline void reset() { mbSelected = false; }
82 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
83 virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
84 virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
86 private:
87 OUString maPassword;
88 bool mbSelected;
91 // ============================================================================
93 DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
94 PasswordRequestMode eMode, const OUString& rDocumentName )
96 switch( eType )
98 case DocPasswordRequestType_STANDARD:
100 DocumentPasswordRequest aRequest( OUString(), Reference< XInterface >(),
101 InteractionClassification_QUERY, eMode, rDocumentName );
102 maRequest <<= aRequest;
104 break;
105 case DocPasswordRequestType_MS:
107 DocumentMSPasswordRequest aRequest( OUString(), Reference< XInterface >(),
108 InteractionClassification_QUERY, eMode, rDocumentName );
109 maRequest <<= aRequest;
111 break;
112 /* no 'default', so compilers will complain about missing
113 implementation of a new enum value. */
116 maContinuations.realloc( 2 );
117 maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
118 maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
121 DocPasswordRequest::~DocPasswordRequest()
125 bool DocPasswordRequest::isAbort() const
127 return mpAbort->isSelected();
130 bool DocPasswordRequest::isPassword() const
132 return mpPassword->isSelected();
135 OUString DocPasswordRequest::getPassword() const
137 return mpPassword->getPassword();
140 Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
142 return maRequest;
145 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
147 return maContinuations;
150 // ============================================================================
152 } // namespace comphelper