LibreOffice Module sw (master)  1
SwXFilterOptions.cxx
Go to the documentation of this file.
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 #include <SwXFilterOptions.hxx>
21 #include <shellio.hxx>
22 #include <swdll.hxx>
23 #include <unoprnms.hxx>
24 #include <vcl/svapp.hxx>
25 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31 #include <unotxdoc.hxx>
32 
33 #include <swabstdlg.hxx>
34 #include <memory>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::ui::dialogs;
38 using namespace ::com::sun::star::document;
39 using namespace ::com::sun::star::lang;
40 
41 #define FILTER_OPTIONS_NAME "FilterOptions"
42 
44 {
45 }
46 
48 {
49 }
50 
51 uno::Sequence< beans::PropertyValue > SwXFilterOptions::getPropertyValues()
52 {
55  });
56 }
57 
58 void SwXFilterOptions::setPropertyValues( const uno::Sequence<beans::PropertyValue >& aProps )
59 {
60  for (const beans::PropertyValue& rProp : aProps)
61  {
62  OUString aPropName = rProp.Name;
63 
64  if ( aPropName == FILTER_OPTIONS_NAME )
65  rProp.Value >>= sFilterOptions;
66  else if ( aPropName == "InputStream" )
67  rProp.Value >>= xInputStream;
68  }
69 }
70 
71 void SwXFilterOptions::setTitle( const OUString& /*rTitle*/ )
72 {
73 }
74 
76 {
77  sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
78 
79  std::unique_ptr<SvStream> pInStream;
80  if ( xInputStream.is() )
82 
83  uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
84  SwDocShell* pDocShell = nullptr;
85  if(xTunnel.is())
86  {
87  SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >(
88  sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
89  pDocShell = pXDoc ? pXDoc->GetDocShell() : nullptr;
90  }
91  if(pDocShell)
92  {
95  pInStream.get()));
96  if(RET_OK == pAsciiDlg->Execute())
97  {
98  SwAsciiOptions aOptions;
99  pAsciiDlg->FillOptions( aOptions );
100  aOptions.WriteUserData(sFilterOptions);
101  nRet = ui::dialogs::ExecutableDialogResults::OK;
102  }
103  }
104 
105  return nRet;
106 }
107 
108 void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
109 {
110  xModel = xDoc;
111 }
112 
113 void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
114 {
115  xModel = xDoc;
116 }
117 
118 void SAL_CALL SwXFilterOptions::initialize(const uno::Sequence<uno::Any>& rArguments)
119 {
120  ::comphelper::NamedValueCollection aProperties(rArguments);
121  if (aProperties.has("ParentWindow"))
122  aProperties.get("ParentWindow") >>= xDialogParent;
123 }
124 
126 {
127  return "com.sun.star.comp.Writer.FilterOptionsDialog";
128 }
129 
130 sal_Bool SwXFilterOptions::supportsService( const OUString& rServiceName )
131 {
132  return cppu::supportsService(this, rServiceName);
133 }
134 
136 {
137  OUString sService("com.sun.star.ui.dialogs.FilterOptionsDialog");
138  return uno::Sequence< OUString> (&sService, 1);
139 }
140 
141 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
143  css::uno::Sequence<css::uno::Any> const &)
144 {
145  SolarMutexGuard aGuard;
146 
147  //the module may not be loaded
149  return cppu::acquire(new SwXFilterOptions());
150 
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::io::XInputStream > xInputStream
virtual short Execute()=0
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getPropertyValues() override
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
virtual sal_Int16 SAL_CALL execute() override
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void FillOptions(SwAsciiOptions &rOptions)=0
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_FilterOptionsDialog_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
css::uno::Reference< css::awt::XWindow > xDialogParent
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
virtual ~SwXFilterOptions() override
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unotxdoc.cxx:294
virtual VclPtr< AbstractSwAsciiFilterDlg > CreateSwAsciiFilterDlg(weld::Window *pParent, SwDocShell &rDocSh, SvStream *pStream)=0
void ensure()
Definition: swdll.cxx:69
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
bool has(const sal_Char *_pAsciiValueName) const
unsigned char sal_Bool
SwDocShell * GetDocShell()
Definition: unotxdoc.hxx:464
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void WriteUserData(OUString &)
Definition: fltini.cxx:603
#define FILTER_OPTIONS_NAME
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
RET_OK
virtual void SAL_CALL setTitle(const OUString &aTitle) override
css::uno::Reference< css::lang::XComponent > xModel
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &aProps) override
const css::uno::Any & get(const sal_Char *_pAsciiValueName) const