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  const beans::PropertyValue* pPropArray = aProps.getConstArray();
61  long nPropCount = aProps.getLength();
62  for (long i = 0; i < nPropCount; i++)
63  {
64  const beans::PropertyValue& rProp = pPropArray[i];
65  OUString aPropName = rProp.Name;
66 
67  if ( aPropName == FILTER_OPTIONS_NAME )
68  rProp.Value >>= sFilterOptions;
69  else if ( aPropName == "InputStream" )
70  rProp.Value >>= xInputStream;
71  }
72 }
73 
74 void SwXFilterOptions::setTitle( const OUString& /*rTitle*/ )
75 {
76 }
77 
79 {
80  sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
81 
82  std::unique_ptr<SvStream> pInStream;
83  if ( xInputStream.is() )
85 
86  uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
87  SwDocShell* pDocShell = nullptr;
88  if(xTunnel.is())
89  {
90  SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >(
91  sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
92  pDocShell = pXDoc ? pXDoc->GetDocShell() : nullptr;
93  }
94  if(pDocShell)
95  {
98  pInStream.get()));
99  if(RET_OK == pAsciiDlg->Execute())
100  {
101  SwAsciiOptions aOptions;
102  pAsciiDlg->FillOptions( aOptions );
103  aOptions.WriteUserData(sFilterOptions);
104  nRet = ui::dialogs::ExecutableDialogResults::OK;
105  }
106  }
107 
108  return nRet;
109 }
110 
111 void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
112 {
113  xModel = xDoc;
114 }
115 
116 void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
117 {
118  xModel = xDoc;
119 }
120 
121 void SAL_CALL SwXFilterOptions::initialize(const uno::Sequence<uno::Any>& rArguments)
122 {
123  ::comphelper::NamedValueCollection aProperties(rArguments);
124  if (aProperties.has("ParentWindow"))
125  aProperties.get("ParentWindow") >>= xDialogParent;
126 }
127 
129 {
130  return OUString("com.sun.star.comp.Writer.FilterOptionsDialog");
131 }
132 
133 sal_Bool SwXFilterOptions::supportsService( const OUString& rServiceName )
134 {
135  return cppu::supportsService(this, rServiceName);
136 }
137 
139 {
140  OUString sService("com.sun.star.ui.dialogs.FilterOptionsDialog");
141  return uno::Sequence< OUString> (&sService, 1);
142 }
143 
144 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
146  css::uno::Sequence<css::uno::Any> const &)
147 {
148  SolarMutexGuard aGuard;
149 
150  //the module may not be loaded
152  return cppu::acquire(new SwXFilterOptions());
153 
154 }
155 
156 /* 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
int i
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