xref: /AOO41X/main/desktop/source/deployment/misc/dp_interact.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "dp_interact.h"
32*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
33*cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
34*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir using namespace ::com::sun::star;
38*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
40*cdf0e10cSrcweir using ::rtl::OUString;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace dp_misc {
43*cdf0e10cSrcweir namespace {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //==============================================================================
46*cdf0e10cSrcweir class InteractionContinuationImpl : public ::cppu::OWeakObject,
47*cdf0e10cSrcweir                                     public task::XInteractionContinuation
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     const Type m_type;
50*cdf0e10cSrcweir     bool * m_pselect;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir public:
53*cdf0e10cSrcweir     inline InteractionContinuationImpl( Type const & type, bool * pselect )
54*cdf0e10cSrcweir         : m_type( type ),
55*cdf0e10cSrcweir           m_pselect( pselect )
56*cdf0e10cSrcweir         { OSL_ASSERT(
57*cdf0e10cSrcweir             ::getCppuType(
58*cdf0e10cSrcweir                 static_cast< Reference<task::XInteractionContinuation>
59*cdf0e10cSrcweir                 const *>(0) ).isAssignableFrom(m_type) ); }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     // XInterface
62*cdf0e10cSrcweir     virtual void SAL_CALL acquire() throw ();
63*cdf0e10cSrcweir     virtual void SAL_CALL release() throw ();
64*cdf0e10cSrcweir     virtual Any SAL_CALL queryInterface( Type const & type )
65*cdf0e10cSrcweir         throw (RuntimeException);
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     // XInteractionContinuation
68*cdf0e10cSrcweir     virtual void SAL_CALL select() throw (RuntimeException);
69*cdf0e10cSrcweir };
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // XInterface
72*cdf0e10cSrcweir //______________________________________________________________________________
73*cdf0e10cSrcweir void InteractionContinuationImpl::acquire() throw ()
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     OWeakObject::acquire();
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //______________________________________________________________________________
79*cdf0e10cSrcweir void InteractionContinuationImpl::release() throw ()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     OWeakObject::release();
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //______________________________________________________________________________
85*cdf0e10cSrcweir Any InteractionContinuationImpl::queryInterface( Type const & type )
86*cdf0e10cSrcweir     throw (RuntimeException)
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     if (type.isAssignableFrom( m_type )) {
89*cdf0e10cSrcweir         Reference<task::XInteractionContinuation> xThis(this);
90*cdf0e10cSrcweir         return Any( &xThis, type );
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir     else
93*cdf0e10cSrcweir         return OWeakObject::queryInterface(type);
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir // XInteractionContinuation
97*cdf0e10cSrcweir //______________________________________________________________________________
98*cdf0e10cSrcweir void InteractionContinuationImpl::select() throw (RuntimeException)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     *m_pselect = true;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir //==============================================================================
104*cdf0e10cSrcweir class InteractionRequest :
105*cdf0e10cSrcweir     public ::cppu::WeakImplHelper1<task::XInteractionRequest>
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     Any m_request;
108*cdf0e10cSrcweir     Sequence< Reference<task::XInteractionContinuation> > m_conts;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir public:
111*cdf0e10cSrcweir     inline InteractionRequest(
112*cdf0e10cSrcweir         Any const & request,
113*cdf0e10cSrcweir         Sequence< Reference<task::XInteractionContinuation> > const & conts )
114*cdf0e10cSrcweir         : m_request( request ),
115*cdf0e10cSrcweir           m_conts( conts )
116*cdf0e10cSrcweir         {}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // XInteractionRequest
119*cdf0e10cSrcweir     virtual Any SAL_CALL getRequest()
120*cdf0e10cSrcweir         throw (RuntimeException);
121*cdf0e10cSrcweir     virtual Sequence< Reference<task::XInteractionContinuation> >
122*cdf0e10cSrcweir     SAL_CALL getContinuations() throw (RuntimeException);
123*cdf0e10cSrcweir };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // XInteractionRequest
126*cdf0e10cSrcweir //______________________________________________________________________________
127*cdf0e10cSrcweir Any InteractionRequest::getRequest() throw (RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     return m_request;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir //______________________________________________________________________________
133*cdf0e10cSrcweir Sequence< Reference< task::XInteractionContinuation > >
134*cdf0e10cSrcweir InteractionRequest::getContinuations() throw (RuntimeException)
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     return m_conts;
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir } // anon namespace
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir //==============================================================================
142*cdf0e10cSrcweir bool interactContinuation( Any const & request,
143*cdf0e10cSrcweir                            Type const & continuation,
144*cdf0e10cSrcweir                            Reference<XCommandEnvironment> const & xCmdEnv,
145*cdf0e10cSrcweir                            bool * pcont, bool * pabort )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     OSL_ASSERT(
148*cdf0e10cSrcweir         task::XInteractionContinuation::static_type().isAssignableFrom(
149*cdf0e10cSrcweir             continuation ) );
150*cdf0e10cSrcweir     if (xCmdEnv.is()) {
151*cdf0e10cSrcweir         Reference<task::XInteractionHandler> xInteractionHandler(
152*cdf0e10cSrcweir             xCmdEnv->getInteractionHandler() );
153*cdf0e10cSrcweir         if (xInteractionHandler.is()) {
154*cdf0e10cSrcweir             bool cont = false;
155*cdf0e10cSrcweir             bool abort = false;
156*cdf0e10cSrcweir             Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
157*cdf0e10cSrcweir             conts[ 0 ] = new InteractionContinuationImpl(
158*cdf0e10cSrcweir                 continuation, &cont );
159*cdf0e10cSrcweir             conts[ 1 ] = new InteractionContinuationImpl(
160*cdf0e10cSrcweir                 task::XInteractionAbort::static_type(), &abort );
161*cdf0e10cSrcweir             xInteractionHandler->handle(
162*cdf0e10cSrcweir                 new InteractionRequest( request, conts ) );
163*cdf0e10cSrcweir             if (cont || abort) {
164*cdf0e10cSrcweir                 if (pcont != 0)
165*cdf0e10cSrcweir                     *pcont = cont;
166*cdf0e10cSrcweir                 if (pabort != 0)
167*cdf0e10cSrcweir                     *pabort = abort;
168*cdf0e10cSrcweir                 return true;
169*cdf0e10cSrcweir             }
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir     return false;
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir // XAbortChannel
176*cdf0e10cSrcweir //______________________________________________________________________________
177*cdf0e10cSrcweir void AbortChannel::sendAbort() throw (RuntimeException)
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir     m_aborted = true;
180*cdf0e10cSrcweir     if (m_xNext.is())
181*cdf0e10cSrcweir         m_xNext->sendAbort();
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir } // dp_misc
185*cdf0e10cSrcweir 
186