1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _COMPHELPER_INTERACTION_HXX_
29 #define _COMPHELPER_INTERACTION_HXX_
30 
31 #include <comphelper/uno3.hxx>
32 #include <cppuhelper/implbase1.hxx>
33 #include <com/sun/star/task/XInteractionApprove.hpp>
34 #include <com/sun/star/task/XInteractionDisapprove.hpp>
35 #include <com/sun/star/task/XInteractionAbort.hpp>
36 #include <com/sun/star/task/XInteractionRetry.hpp>
37 #include <com/sun/star/task/XInteractionPassword.hpp>
38 #include <com/sun/star/task/XInteractionRequest.hpp>
39 #include "comphelper/comphelperdllapi.h"
40 
41 //.........................................................................
42 namespace comphelper
43 {
44 //.........................................................................
45 
46 	//=========================================================================
47 	//= OInteractionSelect
48 	//=========================================================================
49 	/** base class for concrete XInteractionContinuation implementations.<p/>
50 		Instances of the classes maintain a flag indicating if the handler was called.
51 	*/
52 	class OInteractionSelect
53 	{
54 		sal_Bool	m_bSelected : 1;	/// indicates if the select event occured
55 
56 	protected:
57 		OInteractionSelect() : m_bSelected(sal_False) { }
58 
59 	public:
60 		/// determines whether or not this handler was selected
61 		sal_Bool	wasSelected() const { return m_bSelected; }
62 		/// resets the state to "not selected", so you may reuse the handler
63 		void		reset() { m_bSelected = sal_False; }
64 
65 	protected:
66 		void	implSelected() { m_bSelected = sal_True; }
67 	};
68 
69 	//=========================================================================
70 	//= OInteraction
71 	//=========================================================================
72 	/** template for instantiating concret interaction handlers<p/>
73 		the template argument must eb an interface derived from XInteractionContinuation
74 	*/
75 	template <class INTERACTION>
76 	class OInteraction
77 			:public ::cppu::WeakImplHelper1< INTERACTION >
78 			,public OInteractionSelect
79 	{
80 	public:
81 		OInteraction() { }
82 
83 	// XInteractionContinuation
84 	    virtual void SAL_CALL select(  ) throw(::com::sun::star::uno::RuntimeException);
85 	};
86 
87 	//.........................................................................
88 	template <class INTERACTION>
89 	void SAL_CALL OInteraction< INTERACTION >::select(  ) throw(::com::sun::star::uno::RuntimeException)
90 	{
91 		implSelected();
92 	}
93 
94 	//=========================================================================
95 	//= OInteractionApprove
96 	//=========================================================================
97 	typedef OInteraction< ::com::sun::star::task::XInteractionApprove >	OInteractionApprove;
98 
99 	//=========================================================================
100 	//= OInteractionDispprove
101 	//=========================================================================
102 	typedef OInteraction< ::com::sun::star::task::XInteractionDisapprove >	OInteractionDisapprove;
103 
104 	//=========================================================================
105 	//= OInteractionAbort
106 	//=========================================================================
107 	typedef OInteraction< ::com::sun::star::task::XInteractionAbort >	OInteractionAbort;
108 
109 	//=========================================================================
110 	//= OInteractionRetry
111 	//=========================================================================
112 	typedef OInteraction< ::com::sun::star::task::XInteractionRetry >	OInteractionRetry;
113 
114     //=========================================================================
115 	//= OInteractionPassword
116 	//=========================================================================
117     class COMPHELPER_DLLPUBLIC OInteractionPassword : public OInteraction< ::com::sun::star::task::XInteractionPassword >
118 	{
119 	public:
120 		OInteractionPassword()
121         {
122         }
123 
124         OInteractionPassword( const ::rtl::OUString& _rInitialPassword )
125             :m_sPassword( _rInitialPassword )
126         {
127         }
128 
129         // XInteractionPassword
130         virtual void SAL_CALL setPassword( const ::rtl::OUString& _Password ) throw (::com::sun::star::uno::RuntimeException);
131         virtual ::rtl::OUString SAL_CALL getPassword(  ) throw (::com::sun::star::uno::RuntimeException);
132 
133     private:
134         ::rtl::OUString m_sPassword;
135 	};
136 
137 	//=========================================================================
138 	//= OInteractionRequest
139 	//=========================================================================
140 	typedef ::cppu::WeakImplHelper1	<	::com::sun::star::task::XInteractionRequest
141 									>	OInteractionRequest_Base;
142 	/** implements an interaction request (<type scope="com.sun.star.task">XInteractionRequest</type>)<p/>
143 		at run time, you can freely add any interaction continuation objects
144 	*/
145 	class COMPHELPER_DLLPUBLIC OInteractionRequest : public OInteractionRequest_Base
146 	{
147 		::com::sun::star::uno::Any
148 					m_aRequest;			/// the request we represent
149 		::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >
150 					m_aContinuations;	/// all registered continuations
151 
152 	public:
153 		OInteractionRequest(const ::com::sun::star::uno::Any& _rRequestDescription);
154 
155 		/// add a new continuation
156 		void addContinuation(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >& _rxContinuation);
157 		/// clear all continuations
158 		void clearContinuations();
159 
160 	// XInteractionRequest
161 		virtual ::com::sun::star::uno::Any SAL_CALL getRequest(  ) throw(::com::sun::star::uno::RuntimeException);
162 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations(  ) throw(::com::sun::star::uno::RuntimeException);
163 	};
164 //.........................................................................
165 }	// namespace comphelper
166 //.........................................................................
167 
168 #endif // _COMPHELPER_INTERACTION_HXX_
169 
170 
171