1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _COMPHELPER_INTERACTION_HXX_
25 #define _COMPHELPER_INTERACTION_HXX_
26 
27 #include <comphelper/uno3.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <com/sun/star/task/XInteractionApprove.hpp>
30 #include <com/sun/star/task/XInteractionDisapprove.hpp>
31 #include <com/sun/star/task/XInteractionAbort.hpp>
32 #include <com/sun/star/task/XInteractionRetry.hpp>
33 #include <com/sun/star/task/XInteractionPassword.hpp>
34 #include <com/sun/star/task/XInteractionRequest.hpp>
35 #include "comphelper/comphelperdllapi.h"
36 
37 //.........................................................................
38 namespace comphelper
39 {
40 //.........................................................................
41 
42 	//=========================================================================
43 	//= OInteractionSelect
44 	//=========================================================================
45 	/** base class for concrete XInteractionContinuation implementations.<p/>
46 		Instances of the classes maintain a flag indicating if the handler was called.
47 	*/
48 	class OInteractionSelect
49 	{
50 		sal_Bool	m_bSelected : 1;	/// indicates if the select event occured
51 
52 	protected:
OInteractionSelect()53 		OInteractionSelect() : m_bSelected(sal_False) { }
54 
55 	public:
56 		/// determines whether or not this handler was selected
wasSelected() const57 		sal_Bool	wasSelected() const { return m_bSelected; }
58 		/// resets the state to "not selected", so you may reuse the handler
reset()59 		void		reset() { m_bSelected = sal_False; }
60 
61 	protected:
implSelected()62 		void	implSelected() { m_bSelected = sal_True; }
63 	};
64 
65 	//=========================================================================
66 	//= OInteraction
67 	//=========================================================================
68 	/** template for instantiating concret interaction handlers<p/>
69 		the template argument must eb an interface derived from XInteractionContinuation
70 	*/
71 	template <class INTERACTION>
72 	class OInteraction
73 			:public ::cppu::WeakImplHelper1< INTERACTION >
74 			,public OInteractionSelect
75 	{
76 	public:
OInteraction()77 		OInteraction() { }
78 
79 	// XInteractionContinuation
80 	    virtual void SAL_CALL select(  ) throw(::com::sun::star::uno::RuntimeException);
81 	};
82 
83 	//.........................................................................
84 	template <class INTERACTION>
select()85 	void SAL_CALL OInteraction< INTERACTION >::select(  ) throw(::com::sun::star::uno::RuntimeException)
86 	{
87 		implSelected();
88 	}
89 
90 	//=========================================================================
91 	//= OInteractionApprove
92 	//=========================================================================
93 	typedef OInteraction< ::com::sun::star::task::XInteractionApprove >	OInteractionApprove;
94 
95 	//=========================================================================
96 	//= OInteractionDispprove
97 	//=========================================================================
98 	typedef OInteraction< ::com::sun::star::task::XInteractionDisapprove >	OInteractionDisapprove;
99 
100 	//=========================================================================
101 	//= OInteractionAbort
102 	//=========================================================================
103 	typedef OInteraction< ::com::sun::star::task::XInteractionAbort >	OInteractionAbort;
104 
105 	//=========================================================================
106 	//= OInteractionRetry
107 	//=========================================================================
108 	typedef OInteraction< ::com::sun::star::task::XInteractionRetry >	OInteractionRetry;
109 
110     //=========================================================================
111 	//= OInteractionPassword
112 	//=========================================================================
113     class COMPHELPER_DLLPUBLIC OInteractionPassword : public OInteraction< ::com::sun::star::task::XInteractionPassword >
114 	{
115 	public:
OInteractionPassword()116 		OInteractionPassword()
117         {
118         }
119 
OInteractionPassword(const::rtl::OUString & _rInitialPassword)120         OInteractionPassword( const ::rtl::OUString& _rInitialPassword )
121             :m_sPassword( _rInitialPassword )
122         {
123         }
124 
125         // XInteractionPassword
126         virtual void SAL_CALL setPassword( const ::rtl::OUString& _Password ) throw (::com::sun::star::uno::RuntimeException);
127         virtual ::rtl::OUString SAL_CALL getPassword(  ) throw (::com::sun::star::uno::RuntimeException);
128 
129     private:
130         ::rtl::OUString m_sPassword;
131 	};
132 
133 	//=========================================================================
134 	//= OInteractionRequest
135 	//=========================================================================
136 	typedef ::cppu::WeakImplHelper1	<	::com::sun::star::task::XInteractionRequest
137 									>	OInteractionRequest_Base;
138 	/** implements an interaction request (<type scope="com.sun.star.task">XInteractionRequest</type>)<p/>
139 		at run time, you can freely add any interaction continuation objects
140 	*/
141 	class COMPHELPER_DLLPUBLIC OInteractionRequest : public OInteractionRequest_Base
142 	{
143 		::com::sun::star::uno::Any
144 					m_aRequest;			/// the request we represent
145 		::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >
146 					m_aContinuations;	/// all registered continuations
147 
148 	public:
149 		OInteractionRequest(const ::com::sun::star::uno::Any& _rRequestDescription);
150 
151 		/// add a new continuation
152 		void addContinuation(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >& _rxContinuation);
153 		/// clear all continuations
154 		void clearContinuations();
155 
156 	// XInteractionRequest
157 		virtual ::com::sun::star::uno::Any SAL_CALL getRequest(  ) throw(::com::sun::star::uno::RuntimeException);
158 		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);
159 	};
160 //.........................................................................
161 }	// namespace comphelper
162 //.........................................................................
163 
164 #endif // _COMPHELPER_INTERACTION_HXX_
165 
166 
167