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