xref: /trunk/main/desktop/source/deployment/misc/dp_interact.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956) !
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 
62     // XInteractionContinuation
63     virtual void SAL_CALL select();
64 };
65 
66 // XInterface
67 //______________________________________________________________________________
acquire()68 void InteractionContinuationImpl::acquire() throw ()
69 {
70     OWeakObject::acquire();
71 }
72 
73 //______________________________________________________________________________
release()74 void InteractionContinuationImpl::release() throw ()
75 {
76     OWeakObject::release();
77 }
78 
79 //______________________________________________________________________________
queryInterface(Type const & type)80 Any InteractionContinuationImpl::queryInterface( Type const & type )
81 {
82     if (type.isAssignableFrom( m_type )) {
83         Reference<task::XInteractionContinuation> xThis(this);
84         return Any( &xThis, type );
85     }
86     else
87         return OWeakObject::queryInterface(type);
88 }
89 
90 // XInteractionContinuation
91 //______________________________________________________________________________
select()92 void InteractionContinuationImpl::select()
93 {
94     *m_pselect = true;
95 }
96 
97 //==============================================================================
98 class InteractionRequest :
99     public ::cppu::WeakImplHelper1<task::XInteractionRequest>
100 {
101     Any m_request;
102     Sequence< Reference<task::XInteractionContinuation> > m_conts;
103 
104 public:
InteractionRequest(Any const & request,Sequence<Reference<task::XInteractionContinuation>> const & conts)105     inline InteractionRequest(
106         Any const & request,
107         Sequence< Reference<task::XInteractionContinuation> > const & conts )
108         : m_request( request ),
109           m_conts( conts )
110         {}
111 
112     // XInteractionRequest
113     virtual Any SAL_CALL getRequest();
114     virtual Sequence< Reference<task::XInteractionContinuation> >
115     SAL_CALL getContinuations();
116 };
117 
118 // XInteractionRequest
119 //______________________________________________________________________________
getRequest()120 Any InteractionRequest::getRequest()
121 {
122     return m_request;
123 }
124 
125 //______________________________________________________________________________
126 Sequence< Reference< task::XInteractionContinuation > >
getContinuations()127 InteractionRequest::getContinuations()
128 {
129     return m_conts;
130 }
131 
132 } // anon namespace
133 
134 //==============================================================================
interactContinuation(Any const & request,Type const & continuation,Reference<XCommandEnvironment> const & xCmdEnv,bool * pcont,bool * pabort)135 bool interactContinuation( Any const & request,
136                            Type const & continuation,
137                            Reference<XCommandEnvironment> const & xCmdEnv,
138                            bool * pcont, bool * pabort )
139 {
140     OSL_ASSERT(
141         task::XInteractionContinuation::static_type().isAssignableFrom(
142             continuation ) );
143     if (xCmdEnv.is()) {
144         Reference<task::XInteractionHandler> xInteractionHandler(
145             xCmdEnv->getInteractionHandler() );
146         if (xInteractionHandler.is()) {
147             bool cont = false;
148             bool abort = false;
149             Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
150             conts[ 0 ] = new InteractionContinuationImpl(
151                 continuation, &cont );
152             conts[ 1 ] = new InteractionContinuationImpl(
153                 task::XInteractionAbort::static_type(), &abort );
154             xInteractionHandler->handle(
155                 new InteractionRequest( request, conts ) );
156             if (cont || abort) {
157                 if (pcont != 0)
158                     *pcont = cont;
159                 if (pabort != 0)
160                     *pabort = abort;
161                 return true;
162             }
163         }
164     }
165     return false;
166 }
167 
168 // XAbortChannel
169 //______________________________________________________________________________
sendAbort()170 void AbortChannel::sendAbort()
171 {
172     m_aborted = true;
173     if (m_xNext.is())
174         m_xNext->sendAbort();
175 }
176 
177 } // dp_misc
178