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