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