1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #include <SwXFilterOptions.hxx>
27cdf0e10cSrcweir #include <shellio.hxx>
28cdf0e10cSrcweir #include <swdll.hxx>
29cdf0e10cSrcweir #include <unoprnms.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <vcl/msgbox.hxx>
33cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
35cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
36cdf0e10cSrcweir #include <unotxdoc.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "swabstdlg.hxx"
39cdf0e10cSrcweir #include "dialog.hrc"
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
43cdf0e10cSrcweir using namespace ::com::sun::star::document;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir
46cdf0e10cSrcweir #define SWFILTEROPTIONSOBJ_SERVICE RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.dialogs.FilterOptionsDialog")
47cdf0e10cSrcweir #define SWFILTEROPTIONSOBJ_IMPLNAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.FilterOptionsDialog")
48cdf0e10cSrcweir #define FILTER_OPTIONS_NAME RTL_CONSTASCII_USTRINGPARAM("FilterOptions")
49cdf0e10cSrcweir /*-- 2002/06/21 11:01:23---------------------------------------------------
50cdf0e10cSrcweir
51cdf0e10cSrcweir -----------------------------------------------------------------------*/
SwXFilterOptions()52cdf0e10cSrcweir SwXFilterOptions::SwXFilterOptions() :
53cdf0e10cSrcweir bExport( sal_False )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir /*-- 2002/06/21 11:01:24---------------------------------------------------
57cdf0e10cSrcweir
58cdf0e10cSrcweir -----------------------------------------------------------------------*/
~SwXFilterOptions()59cdf0e10cSrcweir SwXFilterOptions::~SwXFilterOptions()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir /*-- 2002/06/21 11:01:24---------------------------------------------------
63cdf0e10cSrcweir
64cdf0e10cSrcweir -----------------------------------------------------------------------*/
getImplementationName_Static()65cdf0e10cSrcweir ::rtl::OUString SwXFilterOptions::getImplementationName_Static()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
68cdf0e10cSrcweir }
69cdf0e10cSrcweir /*-- 2002/06/21 11:01:24---------------------------------------------------
70cdf0e10cSrcweir
71cdf0e10cSrcweir -----------------------------------------------------------------------*/
getSupportedServiceNames_Static()72cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SwXFilterOptions::getSupportedServiceNames_Static()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir ::rtl::OUString sService(SWFILTEROPTIONSOBJ_SERVICE);
75cdf0e10cSrcweir return uno::Sequence< ::rtl::OUString> (&sService, 1);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir /*-- 2002/06/21 11:01:25---------------------------------------------------
78cdf0e10cSrcweir
79cdf0e10cSrcweir -----------------------------------------------------------------------*/
getPropertyValues()80cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SwXFilterOptions::getPropertyValues() throw (uno::RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aRet(1);
83cdf0e10cSrcweir beans::PropertyValue* pArray = aRet.getArray();
84cdf0e10cSrcweir
85cdf0e10cSrcweir pArray[0].Name = rtl::OUString( FILTER_OPTIONS_NAME );
86cdf0e10cSrcweir pArray[0].Value <<= sFilterOptions;
87cdf0e10cSrcweir
88cdf0e10cSrcweir return aRet;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir /*-- 2002/06/21 11:01:25---------------------------------------------------
91cdf0e10cSrcweir
92cdf0e10cSrcweir -----------------------------------------------------------------------*/
setPropertyValues(const uno::Sequence<beans::PropertyValue> & aProps)93cdf0e10cSrcweir void SwXFilterOptions::setPropertyValues( const uno::Sequence<beans::PropertyValue >& aProps )
94cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException,
95cdf0e10cSrcweir IllegalArgumentException, WrappedTargetException, uno::RuntimeException)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir const beans::PropertyValue* pPropArray = aProps.getConstArray();
98cdf0e10cSrcweir long nPropCount = aProps.getLength();
99cdf0e10cSrcweir for (long i = 0; i < nPropCount; i++)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir const beans::PropertyValue& rProp = pPropArray[i];
102cdf0e10cSrcweir ::rtl::OUString aPropName = rProp.Name;
103cdf0e10cSrcweir
104cdf0e10cSrcweir if ( aPropName.equalsAscii( SW_PROP_NAME_STR(UNO_NAME_FILTER_NAME) ) )
105cdf0e10cSrcweir rProp.Value >>= sFilterName;
106cdf0e10cSrcweir else if ( aPropName == ::rtl::OUString(FILTER_OPTIONS_NAME) )
107cdf0e10cSrcweir rProp.Value >>= sFilterOptions;
108cdf0e10cSrcweir else if ( aPropName.equalsAscii( "InputStream" ) )
109cdf0e10cSrcweir rProp.Value >>= xInputStream;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir /*-- 2002/06/21 11:01:25---------------------------------------------------
113cdf0e10cSrcweir
114cdf0e10cSrcweir -----------------------------------------------------------------------*/
setTitle(const::rtl::OUString &)115cdf0e10cSrcweir void SwXFilterOptions::setTitle( const ::rtl::OUString& /*rTitle*/ )
116cdf0e10cSrcweir throw (uno::RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir }
119cdf0e10cSrcweir /*-- 2002.06.21 11:01:25---------------------------------------------------
120cdf0e10cSrcweir
121cdf0e10cSrcweir -----------------------------------------------------------------------*/
execute()122cdf0e10cSrcweir sal_Int16 SwXFilterOptions::execute() throw (uno::RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
125cdf0e10cSrcweir
126cdf0e10cSrcweir SvStream* pInStream = NULL;
127cdf0e10cSrcweir if ( xInputStream.is() )
128cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
129cdf0e10cSrcweir
130cdf0e10cSrcweir uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
131cdf0e10cSrcweir SwDocShell* pDocShell = 0;
132cdf0e10cSrcweir if(xTunnel.is())
133cdf0e10cSrcweir {
134cdf0e10cSrcweir SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >(
135cdf0e10cSrcweir sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
136cdf0e10cSrcweir pDocShell = pXDoc ? pXDoc->GetDocShell() : 0;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir if(pDocShell)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir
141cdf0e10cSrcweir SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
142cdf0e10cSrcweir DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
143cdf0e10cSrcweir
144cdf0e10cSrcweir AbstractSwAsciiFilterDlg* pAsciiDlg = pFact->CreateSwAsciiFilterDlg( NULL, *pDocShell,pInStream, DLG_ASCII_FILTER );
145cdf0e10cSrcweir DBG_ASSERT(pAsciiDlg, "Dialogdiet fail!");
146cdf0e10cSrcweir if(RET_OK == pAsciiDlg->Execute())
147cdf0e10cSrcweir {
148cdf0e10cSrcweir SwAsciiOptions aOptions;
149cdf0e10cSrcweir pAsciiDlg->FillOptions( aOptions );
150cdf0e10cSrcweir String sTmp;
151cdf0e10cSrcweir aOptions.WriteUserData(sTmp);
152cdf0e10cSrcweir sFilterOptions = sTmp;
153cdf0e10cSrcweir nRet = ui::dialogs::ExecutableDialogResults::OK;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir delete pAsciiDlg;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir if( pInStream )
159cdf0e10cSrcweir delete pInStream;
160cdf0e10cSrcweir
161cdf0e10cSrcweir return nRet;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir /*-- 2002/06/21 11:01:26---------------------------------------------------
164cdf0e10cSrcweir
165cdf0e10cSrcweir -----------------------------------------------------------------------*/
setTargetDocument(const uno::Reference<XComponent> & xDoc)166cdf0e10cSrcweir void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
167cdf0e10cSrcweir throw (IllegalArgumentException, uno::RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir bExport = sal_False;
170cdf0e10cSrcweir xModel = xDoc;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir /*-- 2002/06/21 11:01:26---------------------------------------------------
173cdf0e10cSrcweir
174cdf0e10cSrcweir -----------------------------------------------------------------------*/
setSourceDocument(const uno::Reference<XComponent> & xDoc)175cdf0e10cSrcweir void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
176cdf0e10cSrcweir throw (IllegalArgumentException,uno::RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir bExport = sal_True;
179cdf0e10cSrcweir xModel = xDoc;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir /*-- 2002/06/21 11:01:26---------------------------------------------------
182cdf0e10cSrcweir
183cdf0e10cSrcweir -----------------------------------------------------------------------*/
getImplementationName()184cdf0e10cSrcweir ::rtl::OUString SwXFilterOptions::getImplementationName() throw(uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir /*-- 2002/06/21 11:01:27---------------------------------------------------
189cdf0e10cSrcweir
190cdf0e10cSrcweir -----------------------------------------------------------------------*/
supportsService(const::rtl::OUString & rServiceName)191cdf0e10cSrcweir sal_Bool SwXFilterOptions::supportsService( const ::rtl::OUString& rServiceName )
192cdf0e10cSrcweir throw(uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir return rServiceName == ::rtl::OUString(SWFILTEROPTIONSOBJ_SERVICE);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir /*-- 2002/06/21 11:01:28---------------------------------------------------
197cdf0e10cSrcweir
198cdf0e10cSrcweir -----------------------------------------------------------------------*/
getSupportedServiceNames()199cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SwXFilterOptions::getSupportedServiceNames()
200cdf0e10cSrcweir throw(uno::RuntimeException)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir return SwXFilterOptions::getSupportedServiceNames_Static();
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir
SwXFilterOptions_createInstance(const uno::Reference<lang::XMultiServiceFactory> &)206cdf0e10cSrcweir uno::Reference<uno::XInterface> SAL_CALL SwXFilterOptions_createInstance(
207cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir ::vos::OGuard aGuard(Application::GetSolarMutex());
210cdf0e10cSrcweir SwDLL::Init();
211cdf0e10cSrcweir return (::cppu::OWeakObject*) new SwXFilterOptions;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214