Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "dp_interact.h"
22 : #include <cppuhelper/exc_hlp.hxx>
23 : #include <cppuhelper/implbase1.hxx>
24 : #include <com/sun/star/task/XInteractionAbort.hpp>
25 :
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::ucb;
30 :
31 : namespace dp_misc {
32 : namespace {
33 :
34 :
35 0 : class InteractionContinuationImpl : public ::cppu::OWeakObject,
36 : public task::XInteractionContinuation
37 : {
38 : const Type m_type;
39 : bool * m_pselect;
40 :
41 : public:
42 4 : inline InteractionContinuationImpl( Type const & type, bool * pselect )
43 : : m_type( type ),
44 4 : m_pselect( pselect )
45 : { OSL_ASSERT(
46 4 : cppu::UnoType<task::XInteractionContinuation>::get().isAssignableFrom(m_type) ); }
47 :
48 : // XInterface
49 : virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
50 : virtual void SAL_CALL release() throw () SAL_OVERRIDE;
51 : virtual Any SAL_CALL queryInterface( Type const & type )
52 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
53 :
54 : // XInteractionContinuation
55 : virtual void SAL_CALL select() throw (RuntimeException, std::exception) SAL_OVERRIDE;
56 : };
57 :
58 : // XInterface
59 :
60 28 : void InteractionContinuationImpl::acquire() throw ()
61 : {
62 28 : OWeakObject::acquire();
63 28 : }
64 :
65 :
66 12 : void InteractionContinuationImpl::release() throw ()
67 : {
68 12 : OWeakObject::release();
69 12 : }
70 :
71 :
72 6 : Any InteractionContinuationImpl::queryInterface( Type const & type )
73 : throw (RuntimeException, std::exception)
74 : {
75 6 : if (type.isAssignableFrom( m_type )) {
76 6 : Reference<task::XInteractionContinuation> xThis(this);
77 6 : return Any( &xThis, type );
78 : }
79 : else
80 0 : return OWeakObject::queryInterface(type);
81 : }
82 :
83 : // XInteractionContinuation
84 :
85 2 : void InteractionContinuationImpl::select() throw (RuntimeException, std::exception)
86 : {
87 2 : *m_pselect = true;
88 2 : }
89 :
90 :
91 0 : class InteractionRequest :
92 : public ::cppu::WeakImplHelper1<task::XInteractionRequest>
93 : {
94 : Any m_request;
95 : Sequence< Reference<task::XInteractionContinuation> > m_conts;
96 :
97 : public:
98 2 : inline InteractionRequest(
99 : Any const & request,
100 : Sequence< Reference<task::XInteractionContinuation> > const & conts )
101 : : m_request( request ),
102 2 : m_conts( conts )
103 2 : {}
104 :
105 : // XInteractionRequest
106 : virtual Any SAL_CALL getRequest()
107 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
108 : virtual Sequence< Reference<task::XInteractionContinuation> >
109 : SAL_CALL getContinuations() throw (RuntimeException, std::exception) SAL_OVERRIDE;
110 : };
111 :
112 : // XInteractionRequest
113 :
114 2 : Any InteractionRequest::getRequest() throw (RuntimeException, std::exception)
115 : {
116 2 : return m_request;
117 : }
118 :
119 :
120 : Sequence< Reference< task::XInteractionContinuation > >
121 2 : InteractionRequest::getContinuations() throw (RuntimeException, std::exception)
122 : {
123 2 : return m_conts;
124 : }
125 :
126 : } // anon namespace
127 :
128 :
129 2 : bool interactContinuation( Any const & request,
130 : Type const & continuation,
131 : Reference<XCommandEnvironment> const & xCmdEnv,
132 : bool * pcont, bool * pabort )
133 : {
134 : OSL_ASSERT(
135 : cppu::UnoType<task::XInteractionContinuation>::get().isAssignableFrom(
136 : continuation ) );
137 2 : if (xCmdEnv.is()) {
138 : Reference<task::XInteractionHandler> xInteractionHandler(
139 2 : xCmdEnv->getInteractionHandler() );
140 2 : if (xInteractionHandler.is()) {
141 2 : bool cont = false;
142 2 : bool abort = false;
143 2 : Sequence< Reference<task::XInteractionContinuation> > conts( 2 );
144 4 : conts[ 0 ] = new InteractionContinuationImpl(
145 4 : continuation, &cont );
146 4 : conts[ 1 ] = new InteractionContinuationImpl(
147 4 : cppu::UnoType<task::XInteractionAbort>::get(), &abort );
148 2 : xInteractionHandler->handle(
149 2 : new InteractionRequest( request, conts ) );
150 2 : if (cont || abort) {
151 2 : if (pcont != 0)
152 2 : *pcont = cont;
153 2 : if (pabort != 0)
154 2 : *pabort = abort;
155 2 : return true;
156 0 : }
157 0 : }
158 : }
159 0 : return false;
160 : }
161 :
162 : // XAbortChannel
163 :
164 0 : void AbortChannel::sendAbort() throw (RuntimeException, std::exception)
165 : {
166 0 : m_aborted = true;
167 0 : if (m_xNext.is())
168 0 : m_xNext->sendAbort();
169 0 : }
170 :
171 : } // dp_misc
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|