Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / fwe / dispatch / interaction.cxx
blobfbcf9df3dc868e3891d6a2199f69d7f864ac1c89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/interaction.hxx>
21 #include <framework/interaction.hxx>
22 #include <general.h>
23 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
24 #include <com/sun/star/document/NoSuchFilterRequest.hpp>
26 using namespace ::com::sun::star;
28 namespace framework{
30 /*-************************************************************************************************************
31 @short declaration of special continuation for filter selection
32 @descr Sometimes filter detection during loading document failed. Then we need a possibility
33 to ask user for his decision. These continuation transport selected filter by user to
34 code user of interaction.
36 @attention This implementation could be used one times only. We don't support a resettable continuation yet!
37 Why? Normally interaction should show a filter selection dialog and ask user for his decision.
38 He can select any filter - then instances of these class will be called by handler... or user
39 close dialog without any selection. Then another continuation should be selected by handler to
40 abort continuations... Retrying isn't very useful here... I think.
42 @implements XInteractionFilterSelect
44 @base ImplInheritanceHelper
45 ContinuationBase
47 @devstatus ready to use
48 @threadsafe no (used on once position only!)
49 *//*-*************************************************************************************************************/
50 class ContinuationFilterSelect : public comphelper::OInteraction< css::document::XInteractionFilterSelect >
52 // c++ interface
53 public:
54 ContinuationFilterSelect();
56 // uno interface
57 public:
58 virtual void SAL_CALL setFilter( const OUString& sFilter ) override;
59 virtual OUString SAL_CALL getFilter( ) override;
61 // member
62 private:
63 OUString m_sFilter;
65 }; // class ContinuationFilterSelect
67 // initialize continuation with right start values
69 ContinuationFilterSelect::ContinuationFilterSelect()
70 : m_sFilter( OUString() )
74 // handler should use it after selection to set user specified filter for transport
76 void SAL_CALL ContinuationFilterSelect::setFilter( const OUString& sFilter )
78 m_sFilter = sFilter;
81 // read access to transported filter
83 OUString SAL_CALL ContinuationFilterSelect::getFilter()
85 return m_sFilter;
88 class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
90 public:
91 explicit RequestFilterSelect_Impl(const OUString& rURL);
92 bool isAbort () const;
93 OUString getFilter() const;
95 public:
96 virtual css::uno::Any SAL_CALL getRequest() override;
97 virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override;
99 private:
100 css::uno::Any m_aRequest;
101 rtl::Reference<comphelper::OInteractionAbort> m_xAbort;
102 rtl::Reference<ContinuationFilterSelect> m_xFilter;
105 // initialize instance with all necessary information
106 // We use it without any further checks on our member then ...!
108 RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString& sURL )
110 css::uno::Reference< css::uno::XInterface > temp2;
111 css::document::NoSuchFilterRequest aFilterRequest( OUString(),
112 temp2 ,
113 sURL );
114 m_aRequest <<= aFilterRequest;
116 m_xAbort = new comphelper::OInteractionAbort;
117 m_xFilter = new ContinuationFilterSelect;
120 // return abort state of interaction
121 // If it is true, return value of method "getFilter()" will be unspecified then!
123 bool RequestFilterSelect_Impl::isAbort() const
125 return m_xAbort->wasSelected();
128 // return user selected filter
129 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
131 OUString RequestFilterSelect_Impl::getFilter() const
133 return m_xFilter->getFilter();
136 // handler call it to get type of request
137 // Is hard coded to "please select filter" here. see ctor for further information.
139 css::uno::Any SAL_CALL RequestFilterSelect_Impl::getRequest()
141 return m_aRequest;
144 // handler call it to get possible continuations
145 // We support "abort/select_filter" only here.
146 // After interaction we support read access on these continuations on our c++ interface to
147 // return user decision.
149 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations()
151 return { m_xAbort.get(), m_xFilter.get() };
154 RequestFilterSelect::RequestFilterSelect( const OUString& sURL )
155 : mxImpl(new RequestFilterSelect_Impl( sURL ))
159 RequestFilterSelect::~RequestFilterSelect()
163 // return abort state of interaction
164 // If it is true, return value of method "getFilter()" will be unspecified then!
166 bool RequestFilterSelect::isAbort() const
168 return mxImpl->isAbort();
171 // return user selected filter
172 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
174 OUString RequestFilterSelect::getFilter() const
176 return mxImpl->getFilter();
179 uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest()
181 return mxImpl.get();
184 class InteractionRequest_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
186 uno::Any m_aRequest;
187 uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations;
189 public:
190 InteractionRequest_Impl( const css::uno::Any& aRequest,
191 const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations )
193 m_aRequest = aRequest;
194 m_lContinuations = lContinuations;
197 virtual uno::Any SAL_CALL getRequest() override;
198 virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() override;
201 uno::Any SAL_CALL InteractionRequest_Impl::getRequest()
203 return m_aRequest;
206 uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
208 return m_lContinuations;
211 uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
212 const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > >& lContinuations )
214 return new InteractionRequest_Impl( aRequest, lContinuations );
217 } // namespace framework
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */