bump product version to 4.1.6.2
[LibreOffice.git] / desktop / source / deployment / misc / dp_interact.cxx
blob4d9f40df91b030fbfcea2c6ccd737479037f6375
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "dp_interact.h"
22 #include "cppuhelper/exc_hlp.hxx"
23 #include "cppuhelper/implbase1.hxx"
24 #include "com/sun/star/task/XInteractionAbort.hpp"
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::ucb;
31 namespace dp_misc {
32 namespace {
34 //==============================================================================
35 class InteractionContinuationImpl : public ::cppu::OWeakObject,
36 public task::XInteractionContinuation
38 const Type m_type;
39 bool * m_pselect;
41 public:
42 inline InteractionContinuationImpl( Type const & type, bool * pselect )
43 : m_type( type ),
44 m_pselect( pselect )
45 { OSL_ASSERT(
46 ::getCppuType(
47 static_cast< Reference<task::XInteractionContinuation>
48 const *>(0) ).isAssignableFrom(m_type) ); }
50 // XInterface
51 virtual void SAL_CALL acquire() throw ();
52 virtual void SAL_CALL release() throw ();
53 virtual Any SAL_CALL queryInterface( Type const & type )
54 throw (RuntimeException);
56 // XInteractionContinuation
57 virtual void SAL_CALL select() throw (RuntimeException);
60 // XInterface
61 //______________________________________________________________________________
62 void InteractionContinuationImpl::acquire() throw ()
64 OWeakObject::acquire();
67 //______________________________________________________________________________
68 void InteractionContinuationImpl::release() throw ()
70 OWeakObject::release();
73 //______________________________________________________________________________
74 Any InteractionContinuationImpl::queryInterface( Type const & type )
75 throw (RuntimeException)
77 if (type.isAssignableFrom( m_type )) {
78 Reference<task::XInteractionContinuation> xThis(this);
79 return Any( &xThis, type );
81 else
82 return OWeakObject::queryInterface(type);
85 // XInteractionContinuation
86 //______________________________________________________________________________
87 void InteractionContinuationImpl::select() throw (RuntimeException)
89 *m_pselect = true;
92 //==============================================================================
93 class InteractionRequest :
94 public ::cppu::WeakImplHelper1<task::XInteractionRequest>
96 Any m_request;
97 Sequence< Reference<task::XInteractionContinuation> > m_conts;
99 public:
100 inline InteractionRequest(
101 Any const & request,
102 Sequence< Reference<task::XInteractionContinuation> > const & conts )
103 : m_request( request ),
104 m_conts( conts )
107 // XInteractionRequest
108 virtual Any SAL_CALL getRequest()
109 throw (RuntimeException);
110 virtual Sequence< Reference<task::XInteractionContinuation> >
111 SAL_CALL getContinuations() throw (RuntimeException);
114 // XInteractionRequest
115 //______________________________________________________________________________
116 Any InteractionRequest::getRequest() throw (RuntimeException)
118 return m_request;
121 //______________________________________________________________________________
122 Sequence< Reference< task::XInteractionContinuation > >
123 InteractionRequest::getContinuations() throw (RuntimeException)
125 return m_conts;
128 } // anon namespace
130 //==============================================================================
131 bool interactContinuation( Any const & request,
132 Type const & continuation,
133 Reference<XCommandEnvironment> const & xCmdEnv,
134 bool * pcont, bool * pabort )
136 OSL_ASSERT(
137 task::XInteractionContinuation::static_type().isAssignableFrom(
138 continuation ) );
139 if (xCmdEnv.is()) {
140 Reference<task::XInteractionHandler> xInteractionHandler(
141 xCmdEnv->getInteractionHandler() );
142 if (xInteractionHandler.is()) {
143 bool cont = false;
144 bool abort = false;
145 Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
146 conts[ 0 ] = new InteractionContinuationImpl(
147 continuation, &cont );
148 conts[ 1 ] = new InteractionContinuationImpl(
149 task::XInteractionAbort::static_type(), &abort );
150 xInteractionHandler->handle(
151 new InteractionRequest( request, conts ) );
152 if (cont || abort) {
153 if (pcont != 0)
154 *pcont = cont;
155 if (pabort != 0)
156 *pabort = abort;
157 return true;
161 return false;
164 // XAbortChannel
165 //______________________________________________________________________________
166 void AbortChannel::sendAbort() throw (RuntimeException)
168 m_aborted = true;
169 if (m_xNext.is())
170 m_xNext->sendAbort();
173 } // dp_misc
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */