1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2722ceddSAndrew Rist  * distributed with this work for additional information
6*2722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2722ceddSAndrew Rist  *
11*2722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist  *
13*2722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist  * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2722ceddSAndrew Rist  * specific language governing permissions and limitations
18*2722ceddSAndrew Rist  * under the License.
19*2722ceddSAndrew Rist  *
20*2722ceddSAndrew Rist  *************************************************************/
21*2722ceddSAndrew Rist 
22*2722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dp_interact.h"
28cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
29cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
30cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace dp_misc {
39cdf0e10cSrcweir namespace {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //==============================================================================
42cdf0e10cSrcweir class InteractionContinuationImpl : public ::cppu::OWeakObject,
43cdf0e10cSrcweir                                     public task::XInteractionContinuation
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     const Type m_type;
46cdf0e10cSrcweir     bool * m_pselect;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir public:
InteractionContinuationImpl(Type const & type,bool * pselect)49cdf0e10cSrcweir     inline InteractionContinuationImpl( Type const & type, bool * pselect )
50cdf0e10cSrcweir         : m_type( type ),
51cdf0e10cSrcweir           m_pselect( pselect )
52cdf0e10cSrcweir         { OSL_ASSERT(
53cdf0e10cSrcweir             ::getCppuType(
54cdf0e10cSrcweir                 static_cast< Reference<task::XInteractionContinuation>
55cdf0e10cSrcweir                 const *>(0) ).isAssignableFrom(m_type) ); }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     // XInterface
58cdf0e10cSrcweir     virtual void SAL_CALL acquire() throw ();
59cdf0e10cSrcweir     virtual void SAL_CALL release() throw ();
60cdf0e10cSrcweir     virtual Any SAL_CALL queryInterface( Type const & type )
61cdf0e10cSrcweir         throw (RuntimeException);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     // XInteractionContinuation
64cdf0e10cSrcweir     virtual void SAL_CALL select() throw (RuntimeException);
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // XInterface
68cdf0e10cSrcweir //______________________________________________________________________________
acquire()69cdf0e10cSrcweir void InteractionContinuationImpl::acquire() throw ()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     OWeakObject::acquire();
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //______________________________________________________________________________
release()75cdf0e10cSrcweir void InteractionContinuationImpl::release() throw ()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     OWeakObject::release();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //______________________________________________________________________________
queryInterface(Type const & type)81cdf0e10cSrcweir Any InteractionContinuationImpl::queryInterface( Type const & type )
82cdf0e10cSrcweir     throw (RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     if (type.isAssignableFrom( m_type )) {
85cdf0e10cSrcweir         Reference<task::XInteractionContinuation> xThis(this);
86cdf0e10cSrcweir         return Any( &xThis, type );
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir     else
89cdf0e10cSrcweir         return OWeakObject::queryInterface(type);
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // XInteractionContinuation
93cdf0e10cSrcweir //______________________________________________________________________________
select()94cdf0e10cSrcweir void InteractionContinuationImpl::select() throw (RuntimeException)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     *m_pselect = true;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //==============================================================================
100cdf0e10cSrcweir class InteractionRequest :
101cdf0e10cSrcweir     public ::cppu::WeakImplHelper1<task::XInteractionRequest>
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     Any m_request;
104cdf0e10cSrcweir     Sequence< Reference<task::XInteractionContinuation> > m_conts;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir public:
InteractionRequest(Any const & request,Sequence<Reference<task::XInteractionContinuation>> const & conts)107cdf0e10cSrcweir     inline InteractionRequest(
108cdf0e10cSrcweir         Any const & request,
109cdf0e10cSrcweir         Sequence< Reference<task::XInteractionContinuation> > const & conts )
110cdf0e10cSrcweir         : m_request( request ),
111cdf0e10cSrcweir           m_conts( conts )
112cdf0e10cSrcweir         {}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     // XInteractionRequest
115cdf0e10cSrcweir     virtual Any SAL_CALL getRequest()
116cdf0e10cSrcweir         throw (RuntimeException);
117cdf0e10cSrcweir     virtual Sequence< Reference<task::XInteractionContinuation> >
118cdf0e10cSrcweir     SAL_CALL getContinuations() throw (RuntimeException);
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // XInteractionRequest
122cdf0e10cSrcweir //______________________________________________________________________________
getRequest()123cdf0e10cSrcweir Any InteractionRequest::getRequest() throw (RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     return m_request;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //______________________________________________________________________________
129cdf0e10cSrcweir Sequence< Reference< task::XInteractionContinuation > >
getContinuations()130cdf0e10cSrcweir InteractionRequest::getContinuations() throw (RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     return m_conts;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir } // anon namespace
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //==============================================================================
interactContinuation(Any const & request,Type const & continuation,Reference<XCommandEnvironment> const & xCmdEnv,bool * pcont,bool * pabort)138cdf0e10cSrcweir bool interactContinuation( Any const & request,
139cdf0e10cSrcweir                            Type const & continuation,
140cdf0e10cSrcweir                            Reference<XCommandEnvironment> const & xCmdEnv,
141cdf0e10cSrcweir                            bool * pcont, bool * pabort )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     OSL_ASSERT(
144cdf0e10cSrcweir         task::XInteractionContinuation::static_type().isAssignableFrom(
145cdf0e10cSrcweir             continuation ) );
146cdf0e10cSrcweir     if (xCmdEnv.is()) {
147cdf0e10cSrcweir         Reference<task::XInteractionHandler> xInteractionHandler(
148cdf0e10cSrcweir             xCmdEnv->getInteractionHandler() );
149cdf0e10cSrcweir         if (xInteractionHandler.is()) {
150cdf0e10cSrcweir             bool cont = false;
151cdf0e10cSrcweir             bool abort = false;
152cdf0e10cSrcweir             Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
153cdf0e10cSrcweir             conts[ 0 ] = new InteractionContinuationImpl(
154cdf0e10cSrcweir                 continuation, &cont );
155cdf0e10cSrcweir             conts[ 1 ] = new InteractionContinuationImpl(
156cdf0e10cSrcweir                 task::XInteractionAbort::static_type(), &abort );
157cdf0e10cSrcweir             xInteractionHandler->handle(
158cdf0e10cSrcweir                 new InteractionRequest( request, conts ) );
159cdf0e10cSrcweir             if (cont || abort) {
160cdf0e10cSrcweir                 if (pcont != 0)
161cdf0e10cSrcweir                     *pcont = cont;
162cdf0e10cSrcweir                 if (pabort != 0)
163cdf0e10cSrcweir                     *pabort = abort;
164cdf0e10cSrcweir                 return true;
165cdf0e10cSrcweir             }
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir     return false;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // XAbortChannel
172cdf0e10cSrcweir //______________________________________________________________________________
sendAbort()173cdf0e10cSrcweir void AbortChannel::sendAbort() throw (RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     m_aborted = true;
176cdf0e10cSrcweir     if (m_xNext.is())
177cdf0e10cSrcweir         m_xNext->sendAbort();
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir } // dp_misc
181cdf0e10cSrcweir 
182