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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "dp_interact.h"
28 #include "cppuhelper/exc_hlp.hxx"
29 #include "cppuhelper/implbase1.hxx"
30 #include "com/sun/star/task/XInteractionAbort.hpp"
31 
32 
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::ucb;
36 using ::rtl::OUString;
37 
38 namespace dp_misc {
39 namespace {
40 
41 //==============================================================================
42 class InteractionContinuationImpl : public ::cppu::OWeakObject,
43                                     public task::XInteractionContinuation
44 {
45     const Type m_type;
46     bool * m_pselect;
47 
48 public:
InteractionContinuationImpl(Type const & type,bool * pselect)49     inline InteractionContinuationImpl( Type const & type, bool * pselect )
50         : m_type( type ),
51           m_pselect( pselect )
52         { OSL_ASSERT(
53             ::getCppuType(
54                 static_cast< Reference<task::XInteractionContinuation>
55                 const *>(0) ).isAssignableFrom(m_type) ); }
56 
57     // XInterface
58     virtual void SAL_CALL acquire() throw ();
59     virtual void SAL_CALL release() throw ();
60     virtual Any SAL_CALL queryInterface( Type const & type )
61         throw (RuntimeException);
62 
63     // XInteractionContinuation
64     virtual void SAL_CALL select() throw (RuntimeException);
65 };
66 
67 // XInterface
68 //______________________________________________________________________________
acquire()69 void InteractionContinuationImpl::acquire() throw ()
70 {
71     OWeakObject::acquire();
72 }
73 
74 //______________________________________________________________________________
release()75 void InteractionContinuationImpl::release() throw ()
76 {
77     OWeakObject::release();
78 }
79 
80 //______________________________________________________________________________
queryInterface(Type const & type)81 Any InteractionContinuationImpl::queryInterface( Type const & type )
82     throw (RuntimeException)
83 {
84     if (type.isAssignableFrom( m_type )) {
85         Reference<task::XInteractionContinuation> xThis(this);
86         return Any( &xThis, type );
87     }
88     else
89         return OWeakObject::queryInterface(type);
90 }
91 
92 // XInteractionContinuation
93 //______________________________________________________________________________
select()94 void InteractionContinuationImpl::select() throw (RuntimeException)
95 {
96     *m_pselect = true;
97 }
98 
99 //==============================================================================
100 class InteractionRequest :
101     public ::cppu::WeakImplHelper1<task::XInteractionRequest>
102 {
103     Any m_request;
104     Sequence< Reference<task::XInteractionContinuation> > m_conts;
105 
106 public:
InteractionRequest(Any const & request,Sequence<Reference<task::XInteractionContinuation>> const & conts)107     inline InteractionRequest(
108         Any const & request,
109         Sequence< Reference<task::XInteractionContinuation> > const & conts )
110         : m_request( request ),
111           m_conts( conts )
112         {}
113 
114     // XInteractionRequest
115     virtual Any SAL_CALL getRequest()
116         throw (RuntimeException);
117     virtual Sequence< Reference<task::XInteractionContinuation> >
118     SAL_CALL getContinuations() throw (RuntimeException);
119 };
120 
121 // XInteractionRequest
122 //______________________________________________________________________________
getRequest()123 Any InteractionRequest::getRequest() throw (RuntimeException)
124 {
125     return m_request;
126 }
127 
128 //______________________________________________________________________________
129 Sequence< Reference< task::XInteractionContinuation > >
getContinuations()130 InteractionRequest::getContinuations() throw (RuntimeException)
131 {
132     return m_conts;
133 }
134 
135 } // anon namespace
136 
137 //==============================================================================
interactContinuation(Any const & request,Type const & continuation,Reference<XCommandEnvironment> const & xCmdEnv,bool * pcont,bool * pabort)138 bool interactContinuation( Any const & request,
139                            Type const & continuation,
140                            Reference<XCommandEnvironment> const & xCmdEnv,
141                            bool * pcont, bool * pabort )
142 {
143     OSL_ASSERT(
144         task::XInteractionContinuation::static_type().isAssignableFrom(
145             continuation ) );
146     if (xCmdEnv.is()) {
147         Reference<task::XInteractionHandler> xInteractionHandler(
148             xCmdEnv->getInteractionHandler() );
149         if (xInteractionHandler.is()) {
150             bool cont = false;
151             bool abort = false;
152             Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
153             conts[ 0 ] = new InteractionContinuationImpl(
154                 continuation, &cont );
155             conts[ 1 ] = new InteractionContinuationImpl(
156                 task::XInteractionAbort::static_type(), &abort );
157             xInteractionHandler->handle(
158                 new InteractionRequest( request, conts ) );
159             if (cont || abort) {
160                 if (pcont != 0)
161                     *pcont = cont;
162                 if (pabort != 0)
163                     *pabort = abort;
164                 return true;
165             }
166         }
167     }
168     return false;
169 }
170 
171 // XAbortChannel
172 //______________________________________________________________________________
sendAbort()173 void AbortChannel::sendAbort() throw (RuntimeException)
174 {
175     m_aborted = true;
176     if (m_xNext.is())
177         m_xNext->sendAbort();
178 }
179 
180 } // dp_misc
181 
182