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