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