merge the formfield patch from ooo-build
[ooovba.git] / framework / source / interaction / quietinteraction.cxx
blob83c7675b26dc193c086dc950a96e7782a8068a7a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: QuietInteraction.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include "interaction/quietinteraction.hxx"
36 //_________________________________________________________________________________________________________________
37 // my own includes
38 //_________________________________________________________________________________________________________________
39 #include <threadhelp/readguard.hxx>
40 #include <threadhelp/writeguard.hxx>
41 #include <macros/generic.hxx>
42 #include <macros/debug.hxx>
44 //_________________________________________________________________________________________________________________
45 // interface includes
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/task/XInteractionAbort.hpp>
48 #include <com/sun/star/task/XInteractionApprove.hpp>
49 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
50 #include <com/sun/star/document/AmbigousFilterRequest.hpp>
51 #include <com/sun/star/task/ErrorCodeRequest.hpp>
53 #ifndef _COM_SUN_STAR_DOCUMENT_LOCKEDDOCUMENTREQUEST_HPP_
54 #include <com/sun/star/document/LockedDocumentRequest.hpp>
55 #endif
57 //_________________________________________________________________________________________________________________
58 // other includes
59 //_________________________________________________________________________________________________________________
60 #include <vcl/svapp.hxx>
62 #ifndef __RSC
63 #include <tools/errinf.hxx>
64 #endif
66 //_________________________________________________________________________________________________________________
67 // namespace
68 //_________________________________________________________________________________________________________________
70 namespace framework{
72 //_________________________________________________________________________________________________________________
73 // exported const
74 //_________________________________________________________________________________________________________________
76 //_________________________________________________________________________________________________________________
77 // exported definitions
78 //_________________________________________________________________________________________________________________
80 DEFINE_XINTERFACE_2( QuietInteraction ,
81 OWeakObject ,
82 DIRECT_INTERFACE(css::lang::XTypeProvider ) ,
83 DIRECT_INTERFACE(css::task::XInteractionHandler) )
85 DEFINE_XTYPEPROVIDER_2( QuietInteraction ,
86 css::lang::XTypeProvider ,
87 css::task::XInteractionHandler )
89 //_________________________________________________________________________________________________________________
91 QuietInteraction::QuietInteraction()
92 : ThreadHelpBase ( &Application::GetSolarMutex() )
93 , ::cppu::OWeakObject( )
94 , m_aRequest ( )
98 //_________________________________________________________________________________________________________________
100 void SAL_CALL QuietInteraction::handle( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) throw( css::uno::RuntimeException )
102 // safe the request for outside analyzing everytime!
103 css::uno::Any aRequest = xRequest->getRequest();
104 /* SAFE { */
105 WriteGuard aWriteLock(m_aLock);
106 m_aRequest = aRequest;
107 aWriteLock.unlock();
108 /* } SAFE */
110 // analyze the request
111 // We need XAbort as possible continuation as minimum!
112 // An optional filter selection we can handle too.
113 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
114 css::uno::Reference< css::task::XInteractionAbort > xAbort ;
115 css::uno::Reference< css::task::XInteractionApprove > xApprove ;
116 css::uno::Reference< css::document::XInteractionFilterSelect > xFilter ;
118 sal_Int32 nCount=lContinuations.getLength();
119 for (sal_Int32 i=0; i<nCount; ++i)
121 if ( ! xAbort.is() )
122 xAbort = css::uno::Reference< css::task::XInteractionAbort >( lContinuations[i], css::uno::UNO_QUERY );
124 if( ! xApprove.is() )
125 xApprove = css::uno::Reference< css::task::XInteractionApprove >( lContinuations[i], css::uno::UNO_QUERY );
127 if ( ! xFilter.is() )
128 xFilter = css::uno::Reference< css::document::XInteractionFilterSelect >( lContinuations[i], css::uno::UNO_QUERY );
131 // differ between abortable interactions (error, unknown filter ...)
132 // and other ones (ambigous but not unknown filter ...)
133 css::task::ErrorCodeRequest aErrorCodeRequest ;
134 css::document::AmbigousFilterRequest aAmbigousFilterRequest;
135 css::document::LockedDocumentRequest aLockedDocumentRequest;
137 if (aRequest>>=aAmbigousFilterRequest)
139 if (xFilter.is())
141 // user selected filter wins everytime!
142 xFilter->setFilter( aAmbigousFilterRequest.SelectedFilter );
143 xFilter->select();
146 else
147 if( aRequest >>= aErrorCodeRequest )
149 // warnings can be ignored => approve
150 // errors must break loading => abort
151 sal_Bool bWarning = (aErrorCodeRequest.ErrCode & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK;
152 if (xApprove.is() && bWarning)
153 xApprove->select();
154 else
155 if (xAbort.is())
156 xAbort->select();
158 else
159 if( aRequest >>= aLockedDocumentRequest )
161 // the locked document should be opened readonly by default
162 if (xApprove.is())
163 xApprove->select();
164 else
165 if (xAbort.is())
166 xAbort->select();
168 else
169 if (xAbort.is())
170 xAbort->select();
173 //_________________________________________________________________________________________________________________
175 css::uno::Any QuietInteraction::getRequest() const
177 /* SAFE { */
178 ReadGuard aReadLock(m_aLock);
179 return m_aRequest;
180 /* } SAFE */
183 //_________________________________________________________________________________________________________________
185 sal_Bool QuietInteraction::wasUsed() const
187 /* SAFE { */
188 ReadGuard aReadLock(m_aLock);
189 return m_aRequest.hasValue();
190 /* } SAFE */
193 } // namespace framework