xref: /trunk/main/filter/source/t602/t602filter.cxx (revision 9e0fc027)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_filter.hxx"
25 
26 #include "t602filter.hxx"
27 #include "t602filter.hrc"
28 
29 #include <ctype.h>
30 #include <stdio.h>
31 
32 #include <cppuhelper/factory.hxx>
33 #include <cppuhelper/bootstrap.hxx>
34 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
37 #include <com/sun/star/text/XTextDocument.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/awt/XControl.hpp>
40 #include <com/sun/star/awt/XDialog.hpp>
41 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 
43 using namespace ::rtl;
44 using namespace ::cppu;
45 using namespace ::osl;
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::registry;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::beans;
52 using namespace ::com::sun::star::awt;
53 using namespace ::com::sun::star::xml::sax;
54 using namespace ::com::sun::star::document;
55 using com::sun::star::io::XInputStream;
56 
57 namespace T602ImportFilter {
58 
59     unsigned char kam2lat[129] =
60         //    0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
61         "\xAC\x81\x82\xD4\x84\xD2\x9B\x9F\xD8\xB7\x91\xD6\x96\x92\x8E\xB5"  // 8
62         "\x90\xA7\xA6\x93\x94\xE0\x85\xE9\xEC\x99\x9A\xE6\x95\xED\xFC\x9C"  // 9
63         "\xA0\xA1\xA2\xA3\xE5\xD5\xDE\xE2\xE7\xFD\xEA\xE8\xCE\xF5\xAE\xAF"  // A
64         "\x80\x80\x83\xB3\xB4\xE1\x87\x88\x89\x8A\x8B\x8C\x8F\x97\x8D\xBF"  // B
65         "\xC0\xC1\xC2\xC3\xC4\xC5\xCF\x98\x9D\x9E\xA4\xA5\xA8\xA9\x86\xF3"  // C
66         "\xCD\xB1\xB2\xB6\xB8\xB9\xBA\xBB\xF7\xD9\xDA\xDB\xDC\xF8\xF9\xDF"  // D
67         "\xD0\xD1\xD3\xD7\xAA\xAB\xDD\xB0\xE3\xE4\xEB\xEE\xEF\xF0\xF2\xF4"  // E
68         "\xBC\xBD\xBE\xC6\xC7\xC8\xF6\xC9\xCA\xFA\xFB\xCB\xF1\xCC\xFE\xFF"; // F
69 
70     unsigned char koi2lat[129] =
71         //    0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
72         "\x80\x83\x86\xF5\xE1\x87\x88\x89\x8A\x8B\x8C\x8F\x97\xCF\xCF\x98"  // 8
73         "\x9D\x9E\xA4\xA5\xA8\xA9\xDB\xDC\xDF\xB1\xB2\xB6\xB8\xB9\xBA\xBB"  // 9
74         "\xBC\xBD\xBE\xC6\xC7\xC8\xF6\xC9\xCA\xCB\xCC\xCD\xCE\xAD\xAE\xAF"  // A
75         "\xD0\xD1\xD3\xD7\xAA\xAB\xDD\xB0\xE3\xE4\xEB\xEE\xEF\xF0\xF2\xF4"  // B
76         "\xDA\xA0\xC0\x9F\xD4\xD8\xEA\xC4\x81\xA1\x85\x92\x96\x94\xE5\xA2"  // C
77         "\x93\x84\xFD\xE7\x9C\xA3\xC3\x82\xF7\xEC\xA7\xC2\xF3\xF8\xF9\xC5"  // D
78         "\xBF\xB5\xD9\xAC\xD2\xB7\xE8\xB3\x9A\xD6\xDE\x91\x95\x99\xD5\xE0"  // E
79         "\xE2\x8E\xFC\xE6\x9B\xE9\xB4\x90\xFA\xED\xA6\xC1\xF1\xFB\xFE\xFF"; // F
80 
81     unsigned char lat2UNC[257] =
82         //    0       1       2       3       4       5       6       7
83         //    8       9       A       B       C       D       E       F
84         "\x00\xe7\x00\xfc\x00\xe9\x00\xf9\x00\xe4\x01\x6f\x00\xe8\x00\xa3"  // 8
85         "\x00\xc6\x00\xd8\x00\xc5\x00\xe6\x00\xf8\x00\xc4\x00\xc4\x00\xe5"
86         "\x00\xc9\x01\x39\x00\xf4\x00\xf4\x00\xf6\x01\x3d\x01\x3e\x00\x20"  // 9
87         "\x00\xf2\x00\xd6\x00\xdc\x01\x64\x01\x65\x00\xec\x20\xa7\x01\x0d"
88         "\x00\xe1\x00\xed\x00\xf3\x00\xfa\x00\xa1\x00\xd1\x01\x7d\x01\x7e"  // A
89         "\x00\xbf\x00\xf1\x22\x11\x03\xc3\x01\x0c\x00\xa7\x00\xbb\x00\xab"
90         "\x25\x91\x25\x92\x25\x93\x25\x02\x25\x24\x00\xc1\x00\xc2\x01\x1a"  // B
91         "\x00\x20\x00\x20\x00\x20\x00\x20\x22\x61\x00\xb1\x22\x65\x25\x10"
92         "\x25\x14\x25\x34\x25\x2c\x25\x1c\x25\x00\x25\x3c\x22\x64\x23\x20"  // C
93         "\x23\x21\x22\x48\x00\xba\x22\x1a\x00\xb2\x00\xbd\x00\xbc\x00\xa4"
94         "\x03\xb1\x03\xb2\x01\x0e\x03\x93\x01\x0f\x01\x47\x00\xcd\x03\xc0"  // D
95         "\x01\x1b\x25\x18\x25\x0c\x25\x88\x25\x84\x00\xb5\x01\x6e\x25\x80"
96         "\x00\xd3\x00\xdf\x00\xd4\x03\xa6\x03\x98\x01\x48\x01\x60\x01\x61"  // E
97         "\x01\x54\x00\xda\x01\x55\x03\xa9\x00\xfd\x00\xdd\x03\xb4\x22\x1e"
98         "\x00\xf8\x02\xdd\x03\xb5\x02\xc7\x22\x29\x00\xa7\x00\xf7\x00\xe0"  // F
99         "\x00\xb4\x00\xb0\x00\xc0\x02\xc6\x01\x58\x01\x59\x00\x20\x00\x20";
100 
101     unsigned char rus2UNC[257] =
102         //    0       1       2       3       4       5       6       7
103         //    8       9       A       B       C       D       E       F
104         "\x04\x11\x00\xfc\x00\xe9\x04\x12\x00\xe4\x01\x6f\x04\x13\x04\x14"  // 8
105         "\x04\x01\x04\x16\x04\x17\x04\x18\x04\x19\x00\xc4\x00\xc4\x04\x1a"
106         "\x00\xc9\x01\x39\x01\x3a\x00\xf4\x00\xf6\x01\x3d\x01\x3e\x00\x20"  // 9
107         "\x04\x1c\x00\xd6\x00\xdc\x01\x64\x01\x65\x04\x1d\x04\x1f\x01\x0a"
108         "\x00\xe1\x00\xed\x00\xf3\x00\xfa\x04\x20\x04\x22\x01\x7d\x01\x7e"  // A
109         "\x04\x23\x04\x24\x04\x43\x04\x44\x01\x0c\x00\xa7\x04\x3b\x04\x3c"
110         "\x04\x47\x04\x26\x04\x27\x25\x02\x25\x24\x00\xc1\x04\x28\x01\x1a"  // B
111         "\x04\x29\x04\x2a\x04\x2b\x04\x2c\x04\x2d\x04\x2e\x04\x2f\x25\x10"
112         "\x25\x14\x25\x34\x25\x2c\x25\x1c\x25\x00\x25\x3c\x04\x31\x04\x32"  // C
113         "\x04\x33\x04\x51\x04\x36\x04\x37\x04\x38\x04\x39\x04\x3a\x04\x1b"
114         "\x04\x3d\x04\x3f\x01\x0e\x04\x40\x01\x0f\x01\x47\x00\xcd\x04\x42"  // D
115         "\x01\x1b\x25\x18\x25\x0c\x25\x88\x25\x84\x04\x46\x01\x6e\x25\x80"
116         "\x00\xd3\x00\xdf\x00\xd4\x04\x48\x04\x49\x01\x48\x01\x60\x01\x61"  // E
117         "\x01\x54\x00\xda\x01\x55\x04\x4a\x00\xfd\x00\xdd\x04\x4b\x04\x4c"
118         "\x04\x4d\x02\xdd\x04\x4e\x02\xc7\x04\x4f\x00\xa7\x04\x34\x00\xe0"  // F
119         "\x00\xb4\x00\xb0\x00\xc0\x02\xc6\x01\x58\x01\x59\x00\x20\x00\x20";
120 
121 #define _AddAtt(_nam, _val) \
122     mpAttrList->AddAttribute(OUString::createFromAscii( _nam ),\
123     OUString::createFromAscii( _val ) );
124 
125 #define _Start(_nam) \
126     mxHandler->startElement(OUString::createFromAscii(_nam), mAttrList);\
127     mpAttrList->Clear();
128 
129 #define _End(_nam) \
130     mxHandler->endElement(OUString::createFromAscii(_nam));
131 
132 #define _Chars(_ch) \
133     mxHandler->characters(OUString::createFromAscii((sal_Char *) _ch) );
134 
135 inistruct ini;
136 
T602ImportFilter(const::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & r)137 T602ImportFilter::T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ) :
138     mxMSF( r ) {}
139 
~T602ImportFilter()140 T602ImportFilter::~T602ImportFilter()
141 {
142 }
143 
144 // XExtendedTypeDetection
detect(Sequence<PropertyValue> & Descriptor)145 ::rtl::OUString T602ImportFilter::detect( Sequence<PropertyValue>& Descriptor)
146     throw(RuntimeException)
147 {
148 	// checks for filter or type name would be necessary in case we want to use the filter also for "602" files
149 	// without the magic bytes at the beginning; I leave the code as comment in case of
150 	// ::rtl::OUString aFilterName, aTypeName;
151     sal_Int32 nLength = Descriptor.getLength();
152     const PropertyValue * pValue = Descriptor.getConstArray();
153     for ( sal_Int32 i = 0 ; i < nLength; i++)
154     {
155         if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
156             pValue[i].Value >>= mxInputStream;
157 /*        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "FilterName" ) ) )
158             pValue[i].Value >>= aFilterName;
159         else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TypeName" ) ) )
160             pValue[i].Value >>= aTypeName; */
161     }
162 
163     if (!mxInputStream.is())
164         return ::rtl::OUString();
165 
166 /*    if ( aFilterName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "T602Document" ) )  ||
167 		   aTypeName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "writer_T602_Document" ) ) )
168 		// preselection by type (extension) or filter name: no reason to check type
169         return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_T602_Document" ) ); */
170 
171     ::com::sun::star::uno::Sequence< sal_Int8 > aData;
172     size_t numBytes = 4;
173     size_t numBytesRead = 0;
174 
175     numBytesRead = mxInputStream->readSomeBytes (aData, numBytes);
176 
177     if ((numBytesRead != numBytes) || (aData[0] != '@') ||
178         (aData[1] != 'C') || (aData[2] != 'T') || (aData[3] != ' '))
179         return ::rtl::OUString();
180 
181     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_T602_Document" ) );;
182 }
183 
184 // XFilter
filter(const Sequence<::com::sun::star::beans::PropertyValue> & aDescriptor)185 sal_Bool SAL_CALL T602ImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
186 	throw (RuntimeException)
187 {
188 	return importImpl ( aDescriptor );
189 }
190 
191 // XImporter
setTargetDocument(const Reference<::com::sun::star::lang::XComponent> & xDoc)192 void SAL_CALL T602ImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
193 	throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
194 {
195 	mxDoc = xDoc;
196 }
197 
198 // XInitialization
initialize(const Sequence<Any> & aArguments)199 void SAL_CALL T602ImportFilter::initialize( const Sequence< Any >& aArguments )
200     throw (Exception, RuntimeException)
201 {
202     Sequence < PropertyValue > aAnySeq;
203     sal_Int32 nLength = aArguments.getLength();
204     if ( nLength && ( aArguments[0] >>= aAnySeq ) )
205     {
206         const PropertyValue * pValue = aAnySeq.getConstArray();
207         nLength = aAnySeq.getLength();
208         for ( sal_Int32 i = 0 ; i < nLength; i++)
209         {
210             if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
211             {
212                 pValue[i].Value >>= msFilterName;
213                 break;
214             }
215         }
216     }
217 }
218 
219 // Other functions
220 
inschr(unsigned char ch)221 void T602ImportFilter::inschr(unsigned char ch)
222 {
223     Reference < XAttributeList > mAttrList ( mpAttrList );
224 
225     if(!ini.showcomm&&pst.comment) return;
226 
227     if(ch==' ') {
228         setfnt(chngul,true);
229         pst.wasspace++;
230         return;
231     }
232 
233     if(pst.wasspace > 0) {
234         if(ini.reformatpars) {
235             if(!pst.wasfdash)
236                 inschrdef(' ');
237             pst.wasfdash = false;
238         } else {
239             char s[20];
240             sprintf(s,"%i",pst.wasspace);
241             _AddAtt("text:c",s);
242             _Start("text:s");
243             _End("text:s");
244         }
245     }
246 
247     pst.wasspace = 0;
248     setfnt(chngul,true);
249     inschrdef(ch);
250 }
251 
importImpl(const Sequence<::com::sun::star::beans::PropertyValue> & aDescriptor)252 sal_Bool SAL_CALL T602ImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
253     throw (RuntimeException)
254 {
255     Reset602();
256 
257     sal_Int32 nLength = aDescriptor.getLength();
258     const PropertyValue * pValue = aDescriptor.getConstArray();
259     OUString sURL;
260     for ( sal_Int32 i = 0 ; i < nLength; i++)
261     {
262         if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
263             pValue[i].Value >>= mxInputStream;
264     }
265 
266     if ( !mxInputStream.is() )
267     {
268         OSL_ASSERT( 0 );
269         return sal_False;
270     }
271 
272     // An XML import service: what we push sax messages to..
273     OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XMLImporter" ) );
274 
275     mxHandler = Reference< XDocumentHandler >( mxMSF->createInstance( sXMLImportService ), UNO_QUERY );
276 
277     // The XImporter sets up an empty target document for XDocumentHandler to write to..
278     Reference < XImporter > xImporter(mxHandler, UNO_QUERY);
279     xImporter->setTargetDocument(mxDoc);
280 
281     char fs[32], fs2[32];
282     sprintf(fs, "%ipt", ini.fontsize);
283     sprintf(fs2,"%ipt", 2*ini.fontsize);
284 
285     mpAttrList = new SvXMLAttributeList;
286 
287     Reference < XAttributeList > mAttrList ( mpAttrList );
288 
289     mxHandler->startDocument();
290 
291 	_AddAtt("xmlns:office", "http://openoffice.org/2000/office");
292 	_AddAtt("xmlns:style", "http://openoffice.org/2000/style");
293 	_AddAtt("xmlns:text", "http://openoffice.org/2000/text");
294 	_AddAtt("xmlns:table", "http://openoffice.org/2000/table");
295 	_AddAtt("xmlns:draw", "http://openoffice.org/2000/draw");
296 	_AddAtt("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
297 	_AddAtt("xmlns:xlink", "http://www.w3.org/1999/xlink");
298 	_AddAtt("xmlns:number", "http://openoffice.org/2000/datastyle");
299 	_AddAtt("xmlns:svg", "http://www.w3.org/2000/svg");
300 	_AddAtt("xmlns:chart", "http://openoffice.org/2000/chart");
301 	_AddAtt("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
302 	_AddAtt("xmlns:math", "http://www.w3.org/1998/Math/MathML");
303 	_AddAtt("xmlns:form", "http://openoffice.org/2000/form");
304 	_AddAtt("xmlns:script", "http://openoffice.org/2000/script");
305 	_AddAtt("office:class", "text");
306 	_AddAtt("office:version", "1.0");
307     _Start("office:document-content");
308 
309     _Start("office:font-decls");
310     _AddAtt("style:name","Courier New");
311     _AddAtt("fo:font-family","Courier New");
312     _AddAtt("style:font-pitch","fixed");
313     _Start("style:font-decl");
314     _End("style:font-decl");
315     _End("office:font-decls");
316 
317     _Start("office:automatic-styles");
318 
319     // Standardni text
320     _AddAtt("style:name","P1");
321     _AddAtt("style:family","paragraph");
322     _AddAtt("style:parent-style-name","Standard");
323     _Start("style:style");
324     _AddAtt("style:font-name","Courier New");
325     _AddAtt("fo:font-size",fs);
326     _Start("style:properties");
327     _End("style:properties");
328     _End("style:style");
329 
330     // Standardni text - konec stranky
331     _AddAtt("style:name","P2");
332     _AddAtt("style:family","paragraph");
333     _AddAtt("style:parent-style-name","Standard");
334     _Start("style:style");
335     _AddAtt("style:font-name","Courier New");
336     _AddAtt("fo:font-size",fs);
337     _AddAtt("fo:break-before","page");
338     _Start("style:properties");
339     _End("style:properties");
340     _End("style:style");
341 
342     // T1 Normalni text
343     _AddAtt("style:name","T1");
344     _AddAtt("style:family","text");
345     _Start("style:style");
346     _Start("style:properties");
347     _End("style:properties");
348     _End("style:style");
349 
350     // T2 Tucny text
351     _AddAtt("style:name","T2");
352     _AddAtt("style:family","text");
353     _Start("style:style");
354     _AddAtt("fo:font-weight","bold");
355     _Start("style:properties");
356     _End("style:properties");
357     _End("style:style");
358 
359     // T3 Kurziva
360     _AddAtt("style:name","T3");
361     _AddAtt("style:family","text");
362     _Start("style:style");
363     _AddAtt("fo:font-style","italic");
364     _Start("style:properties");
365     _End("style:properties");
366     _End("style:style");
367 
368     // T4 Siroky text
369     _AddAtt("style:name","T4");
370     _AddAtt("style:family","text");
371     _Start("style:style");
372     _AddAtt("fo:font-weight","bold");
373     _AddAtt("style:text-scale","200%");
374     _Start("style:properties");
375     _End("style:properties");
376     _End("style:style");
377 
378     // T5 Vysoky text
379     _AddAtt("style:name","T5");
380     _AddAtt("style:family","text");
381     _Start("style:style");
382     _AddAtt("fo:font-size",fs2);
383     _AddAtt("fo:font-weight","bold");
384     _AddAtt("style:text-scale","50%");
385     _Start("style:properties");
386     _End("style:properties");
387     _End("style:style");
388 
389     // T6 Velky text
390     _AddAtt("style:name","T6");
391     _AddAtt("style:family","text");
392     _Start("style:style");
393     _AddAtt("fo:font-size",fs2);
394     _AddAtt("fo:font-weight","bold");
395     _Start("style:properties");
396     _End("style:properties");
397     _End("style:style");
398 
399     // T7 Podtrzeny text
400     _AddAtt("style:name","T7");
401     _AddAtt("style:family","text");
402     _Start("style:style");
403     _AddAtt("style:text-underline","single");
404     _Start("style:properties");
405     _End("style:properties");
406     _End("style:style");
407 
408     // T8 Podtrzena tucny text
409     _AddAtt("style:name","T8");
410     _AddAtt("style:family","text");
411     _Start("style:style");
412     _AddAtt("fo:font-weight","bold");
413     _AddAtt("style:text-underline","single");
414     _Start("style:properties");
415     _End("style:properties");
416     _End("style:style");
417 
418     // T9 Podtrzena kurziva
419     _AddAtt("style:name","T9");
420     _AddAtt("style:family","text");
421     _Start("style:style");
422     _AddAtt("fo:font-style","italic");
423     _AddAtt("style:text-underline","single");
424     _Start("style:properties");
425     _End("style:properties");
426     _End("style:style");
427 
428     // T10 Horni index
429     _AddAtt("style:name","T10");
430     _AddAtt("style:family","text");
431     _Start("style:style");
432     _AddAtt("style:text-position","27% 100%");
433     _Start("style:properties");
434     _End("style:properties");
435     _End("style:style");
436 
437     // T11 Dolni index
438     _AddAtt("style:name","T11");
439     _AddAtt("style:family","text");
440     _Start("style:style");
441     _AddAtt("style:text-position","-27% 100%");
442     _Start("style:properties");
443     _End("style:properties");
444     _End("style:style");
445 
446     _End("office:automatic-styles");
447 
448     _Start("office:styles");
449     _End("office:styles");
450 
451     _Start("office:body");
452 
453     Read602();
454 
455     _End("office:body");
456     _End("office:document-content");
457 
458     mxHandler->endDocument();
459 
460     return sal_True;
461 }
462 
Reset602()463 void T602ImportFilter::Reset602()
464 {
465     node = START;
466 
467     format602.mt = 0;
468     format602.mb = 0;
469     format602.tb = 0;
470     format602.ct = 0;
471     format602.pn = 1;
472     format602.lh = 1;
473     format602.lm = 6;
474     format602.rm = 60;
475     format602.pl = 60;
476 
477     ini.showcomm    = false;
478     ini.forcecode   = false;
479     ini.xcode    = KAM;
480     ini.ruscode    = false;
481     ini.reformatpars= false;
482     ini.fontsize    = 10;
483 
484     fst.nowfnt    = fst.oldfnt    = standard;
485     fst.uline    = fst.olduline    = false;
486 
487     pst.pars    = 0;
488     pst.comment    = false;
489     pst.wasspace    = 0;
490     pst.ccafterln    = false;
491     pst.willbeeop    = false;
492     pst.waspar    = false;
493     pst.wasfdash    = false;
494 }
495 
inschrdef(unsigned char ch)496 void T602ImportFilter::inschrdef(unsigned char ch)
497 {
498     static sal_Unicode xch[2];
499 
500     xch[1] = 0;
501 
502     if(ch > 127) {
503 
504         switch(ini.xcode) {
505             case L2 : break;
506             case KOI: ch = koi2lat[ch-128]; break;
507             case KAM: ch = kam2lat[ch-128]; break;
508             default : ch = kam2lat[ch-128];
509         }
510 
511         if(ini.ruscode)
512             xch[0] = (rus2UNC[(ch-128)*2] << 8) + rus2UNC[(ch-128)*2+1];
513         else
514             xch[0] = (lat2UNC[(ch-128)*2] << 8) + lat2UNC[(ch-128)*2+1];
515     } else
516         xch[0] = ch;
517 
518     pst.waspar = false;
519     mxHandler->characters(OUString(xch));
520 }
521 
wrtfnt()522 void T602ImportFilter::wrtfnt()
523 {
524     Reference < XAttributeList > mAttrList ( mpAttrList );
525     const sal_Char *style = "P1";
526 
527     switch(fst.nowfnt) {
528         case standard : style = (char*)(fst.uline ? "T7" : "T1"); break;
529         case fat      : style = (char*)(fst.uline ? "T8" : "T2"); break;
530         case cursive  : style = (char*)(fst.uline ? "T9" : "T3"); break;
531         case bold     : style = "T4"; break;
532         case tall     : style = "T5"; break;
533         case big      : style = "T6"; break;
534         case lindex   : style = "T11";break;
535         case hindex   : style = "T10";break;
536         default       : style = "T1"; break;
537     }
538 
539     _End("text:span");
540     _AddAtt("text:style-name", style);
541     _Start("text:span");
542 }
543 
setfnt(fonts fnt,bool mustwrite)544 void T602ImportFilter::setfnt(fonts fnt,bool mustwrite)
545 {
546     if( fnt == fst.oldfnt &&
547         fnt == fst.nowfnt &&
548         !mustwrite )
549         fst.nowfnt = standard;
550     else
551         if (fnt != chngul) fst.nowfnt = fnt;
552 
553         if(mustwrite)
554             if(fst.oldfnt != fst.nowfnt || fst.olduline != fst.uline) {
555                 wrtfnt();
556                 fst.oldfnt = fst.nowfnt;
557                 fst.olduline = fst.uline;
558             }
559 }
560 
Readchar602()561 unsigned char T602ImportFilter::Readchar602()
562 {
563     static Sequence< sal_Int8 > aData;
564 
565     return (mxInputStream->readBytes(aData, 1) > 0) ?
566         ((unsigned char *) aData.getConstArray())[0] : 0;
567 }
568 
par602(bool endofpage)569 void T602ImportFilter::par602(bool endofpage)
570 {
571     sal_Int16 endp;
572     Reference < XAttributeList > mAttrList ( mpAttrList );
573 
574     if(!endofpage || !pst.waspar) {
575         if(ini.showcomm||!pst.comment) {
576             if(pst.waspar||ini.reformatpars) {
577                 _End("text:span");
578                 _End("text:p");
579                 _AddAtt("text:style-name", "P1");
580                 _Start("text:p");
581                 _Start("text:span");
582                 wrtfnt();
583             } else {
584                 _Start("text:line-break");
585                 _End("text:line-break");
586             }
587         }
588 
589         pst.waspar = true;
590     }
591 
592     if(!pst.comment) {
593         switch(format602.lh) {
594             case 3: pst.pars += 4; break;
595             case 4: pst.pars += 3; break;
596             case 6: pst.pars += 2; break;
597             default: pst.pars +=2; break;
598         }
599         endp = format602.pl-format602.mt-format602.mb;
600         if(((pst.pars+1)/2) >= endp || endofpage) {
601             pst.pars = 0;
602             if(!ini.reformatpars) {
603                 _End("text:span");
604                 _End("text:p");
605                 _AddAtt("text:style-name", "P2");
606                 _Start("text:p");
607                 _Start("text:span");
608                 wrtfnt();
609             }
610         }
611     }
612 }
613 
readnum(unsigned char * ch,bool show)614 sal_Int16 T602ImportFilter::readnum(unsigned char *ch, bool show)
615 {
616     unsigned char buff[21];
617     sal_Int16 i=0;
618 
619     while((i<20) && *ch && (*ch!='\n') && (*ch!=','))
620     {
621         *ch = Readchar602();
622         if(show) inschr(*ch);
623         buff[i++] = *ch;
624     }
625     buff[i]='\0';
626 
627     // mba: cast from unsigned char via int to sal_Int16 seems to be safe
628 	return (sal_Int16) atoi((char *)buff);
629 }
630 
Setformat602(char * cmd)631 unsigned char T602ImportFilter::Setformat602(char *cmd)
632 {
633     unsigned char ch;
634     sal_Int16 i;
635 
636     ch = Readchar602();
637 
638          if (cmd[0]=='M' && cmd[1]=='T') format602.mt = readnum(&ch,false);
639     else if (cmd[0]=='M' && cmd[1]=='B') format602.mb = readnum(&ch,false);
640     // else if (cmd[0]=='T' && cmd[1]=='B') {}
641     // else if (cmd[0]=='H' && cmd[1]=='E') {}
642     // else if (cmd[0]=='F' && cmd[1]=='O') {}
643     else if (cmd[0]=='C' && cmd[1]=='T') {
644         format602.ct = readnum(&ch,false);
645         if (!ini.forcecode)
646             switch(format602.ct) {
647                 case 0:  ini.xcode = KAM; break;
648                 case 1:  ini.xcode = L2;  break;
649                 case 2:  ini.xcode = KOI; break;
650                 default: ini.xcode = KAM; break;
651             }
652         }
653     else if (cmd[0]=='P' && cmd[1]=='N')  format602.pn = readnum(&ch,false);
654     else if (cmd[0]=='L' && cmd[1]=='H')  format602.lh = readnum(&ch,false);
655     // else if(cmd[0]=='S' && cmd[1]=='T') {} //styl
656     else if (cmd[0]=='L' && cmd[1]=='M')  format602.lm = readnum(&ch,false);
657     else if (cmd[0]=='R' && cmd[1]=='M')  format602.rm = readnum(&ch,false);
658     else if (cmd[0]=='P' && cmd[1]=='L')  format602.pl = readnum(&ch,false);
659     else if (cmd[0]=='P' && cmd[1]=='A') { if(pst.pars) par602(true); }
660     else if (cmd[0]=='C' && cmd[1]=='P') {
661         i = readnum(&ch,false);
662         if ((i+pst.pars/2) > (format602.pl-format602.mt-format602.mb))
663             if(pst.pars) par602(true);
664     }
665     while (ch && (ch != '\n')) ch = Readchar602();
666     return ch;
667 }
668 
PointCmd602(unsigned char * ch)669 tnode T602ImportFilter::PointCmd602(unsigned char *ch)
670 {
671     char pcmd[2];
672 
673     // warning: uChar -> char
674 	pcmd[0] = (char) toupper(*ch); inschr(*ch);
675     *ch = Readchar602();
676     if (!*ch) return EEND;
677     if (*ch=='\n') return EOL;
678     if (!isalpha(*ch)) return (*ch<32) ? SETCH : WRITE;
679 
680 	// warning: uChar -> char
681     pcmd[1] = (char) toupper(*ch); inschr(*ch);
682 
683          if (pcmd[0]=='P' && pcmd[1]=='A') { if (pst.pars) pst.willbeeop = true; }
684     else if (pcmd[0]=='C' && pcmd[1]=='P') { if (pst.pars) pst.willbeeop = true; }
685     else if (pcmd[0]=='P' && pcmd[1]=='I') {
686         while (*ch && (*ch != '\n') && (*ch != ','))
687             { *ch = Readchar602(); inschr(*ch); }
688         if (!*ch) return EEND;
689         if (*ch=='\n') return EOL;
690         if (*ch==',') { *ch = Readchar602(); inschr(*ch); }
691         pst.pars += (readnum(ch,true)*2);
692         if (!*ch) return EEND;
693         if (*ch=='\n') return EOL;
694     }
695     // else if(pcmd[0]=='K'&&pcmd[1]=='P') {}
696     // else if(pcmd[0]=='H'&&pcmd[1]=='E') {}
697     // else if(pcmd[0]=='F'&&pcmd[1]=='O') {}
698 
699     return READCH;
700 }
701 
702 
Read602()703 void T602ImportFilter::Read602()
704 {
705     unsigned char ch=0;
706     char cmd602[3];
707 
708     Reference < XAttributeList > mAttrList ( mpAttrList );
709 
710     if (node==QUIT) return;
711 
712     _AddAtt("text:style-name", "P1");
713     _Start("text:p");
714     _AddAtt("text:style-name", "T1");
715     _Start("text:span");
716 
717     if (node==START) { node = EOL; }
718 
719     while (node != EEND) {
720         switch (node) {
721         case READCH:
722             ch = Readchar602();
723             if (ch == 0) node = EEND;
724             else if (ch == '\n') {
725                 if(!pst.willbeeop) par602(false);
726                 node = EOL;
727             } else if (ch < 32) node = SETCH;
728             else node = WRITE;
729             break;
730         case EOL:
731             ch = Readchar602();
732             pst.comment = false;
733             if (pst.willbeeop) par602(true);
734             pst.willbeeop = false;
735             if(ch == 0) node = EEND;
736             else if (ch == '@') node = EXPCMD;
737             else if (ch == '\n') { par602(false); node = EOL; }
738             else if (ch < 32) {pst.ccafterln = true; node = SETCH; break;}
739             else node = WRITE;
740             if (ch == '.') { pst.comment = true; node = POCMD; }
741             pst.ccafterln = false;
742             break;
743 
744         case POCMD: inschr('.');
745             ch = Readchar602();
746             if(ch == 0) node = EEND;
747             else if(isalpha(ch)) node = PointCmd602(&ch);
748             else if(ch <32) node=SETCH;
749             else node = WRITE;
750             break;
751 
752         case EXPCMD: ch = Readchar602();
753             if(ch == 0) {inschr('@'); node = EEND; }
754             else if(isupper(ch)) {
755                 cmd602[0] = ch;
756                 ch = Readchar602();
757                 cmd602[1] = ch;
758                 cmd602[2] = '\0';
759                 if(isupper(ch)) node = SETCMD;   //nedodelano
760                 else { inschr('@'); _Chars(cmd602); node = READCH; }
761             } else {
762                 inschr('@');
763                 if(ch<32) node = SETCH;
764                 else node = WRITE;}
765             break;
766 
767         case SETCMD:
768             ch = Setformat602(cmd602);
769             if(ch == 0) node = EEND;
770             else if(ch == '\n') node = EOL;
771             else node = READCH;
772             break;
773 
774         case SETCH :
775 			// warning: potentially uninitialized
776             switch(ch) {
777             case '\t' : _Start("text:tab-stop");
778                     _End("text:tab-stop");
779                     break;
780             case 0x03 : break; //condensed
781             case 0x01 : break; //elite
782             case 0x11 : break; //uzv1
783             case 0x12 : break; //uzv2
784             case 0x15 : break; //uzv3
785             case 0x17 : break; //uzv4
786             case 0x18 : break; //uzv5
787             case 0x19 : break; //uzv6
788             case 0x13 : fst.uline = !fst.uline;break;
789             case 0x02 : setfnt(fat,false);     break;
790             case 0x04 : setfnt(cursive,false); break;
791             case 0x0f : setfnt(bold,false);    break;
792             case 0x10 : setfnt(tall,false);    break;
793             case 0x1d : setfnt(big,false);     break;
794             case 0x14 : setfnt(hindex,false);  break;
795             case 0x16 : setfnt(lindex,false);  break;
796             default   : break;
797             }
798             if(pst.ccafterln) node = EOL;
799             else node = READCH;
800             break;
801 
802         case WRITE :
803             switch(ch) {
804             case 0x8d:
805                 ch = Readchar602();
806                 if( ch == 0x0a) {
807                     if(ini.reformatpars) inschr(' ');
808                     else par602(false); //formatovaci radek
809                     node = EOL;
810                 } else {
811                     inschr(0x8d);//inschr(' ');
812                     if(ch == 0) node = EEND;
813                     else if(ch == '\n') {
814                         if(!pst.willbeeop) par602(false);
815                         node = EOL; }
816                     else if(ch < 32) node = SETCH;
817                     else node = WRITE;
818                 }
819                 break;
820             case 0xfe:
821                 if (ini.showcomm||!pst.comment) inschr(' ');
822                 node = READCH;
823                 break;
824             case 0xad:
825                 ch = Readchar602();
826                 if( ch==0x8d ) {
827                     if(ini.showcomm||!pst.comment) { //formatovaci pomlcka
828                         if(!ini.reformatpars)
829                             inschr('-');
830                         else {
831                             pst.wasspace--;
832                             pst.wasfdash = true;
833                         }
834                     }
835                     node=WRITE;
836                 } else {
837                     inschr(0xad);
838                     if(ch == 0) node = EEND;
839                     else if(ch == '\n') {
840                         if(!pst.willbeeop) par602(false);
841                         node = EOL; }
842                     else if(ch < 32) node = SETCH;
843                     else node = WRITE;
844                 }
845                 break;
846             default:
847                 inschr(ch);
848                 node = READCH;
849                 break;
850             }
851             break;
852         default: break;
853         }
854     }
855 
856     _End("text:span");
857     _End("text:p");
858     node = QUIT;
859 }
860 
861 // XServiceInfo
getImplementationName()862 OUString SAL_CALL T602ImportFilter::getImplementationName(  )
863     throw (RuntimeException)
864 {
865     return T602ImportFilter_getImplementationName();
866 }
867 
supportsService(const OUString & rServiceName)868 sal_Bool SAL_CALL T602ImportFilter::supportsService( const OUString& rServiceName )
869     throw (RuntimeException)
870 {
871     return T602ImportFilter_supportsService( rServiceName );
872 }
873 
getSupportedServiceNames()874 Sequence< OUString > SAL_CALL T602ImportFilter::getSupportedServiceNames(  )
875     throw (RuntimeException)
876 {
877     return T602ImportFilter_getSupportedServiceNames();
878 }
879 
880 #define IMPLEMENTATION_NAME "com.sun.star.comp.Writer.T602ImportFilter"
881 
T602ImportFilter_getImplementationName()882 OUString T602ImportFilter_getImplementationName ()
883     throw (RuntimeException)
884 {
885     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
886 }
887 
888 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
889 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
T602ImportFilter_supportsService(const OUString & ServiceName)890 sal_Bool SAL_CALL T602ImportFilter_supportsService( const OUString& ServiceName )
891     throw (RuntimeException)
892 {
893     return (ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
894         ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ) );
895 }
896 
T602ImportFilter_getSupportedServiceNames()897 Sequence< OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames(  )
898     throw (RuntimeException)
899 {
900     Sequence < OUString > aRet(2);
901     OUString* pArray = aRet.getArray();
902     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
903     pArray[1] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
904     return aRet;
905 }
906 #undef SERVICE_NAME2
907 #undef SERVICE_NAME1
908 #undef IMPLEMENTATION_NAME
909 
T602ImportFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)910 Reference< XInterface > SAL_CALL T602ImportFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
911     throw( Exception )
912 {
913     return (cppu::OWeakObject*) new T602ImportFilter( rSMgr );
914 }
915 
916 /* Reference < XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r)
917 throw ( Exception )
918 {
919     return Reference< XInterface > (( OWeakObject *) new T602ImportFilter(r));
920 }
921 
922 Sequence < OUString > getSupportedServiceNames()
923 throw ( RuntimeException )
924 {
925     static Sequence < OUString > *pNames = 0;
926     if( ! pNames ) {
927         MutexGuard guard( Mutex::getGlobalMutex() );
928         if( !pNames ) {
929             static Sequence< OUString > seqNames(2);
930             seqNames.getArray()[0] = OUString::createFromAscii(IMPLEMENTATION_NAME);
931             pNames = &seqNames;
932         }
933     }
934     return *pNames;
935 }*/
936 
T602ImportFilterDialog(const::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & r)937 T602ImportFilterDialog::T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ) :
938     mxMSF( r ), mpResMgr( NULL ) {}
939 
~T602ImportFilterDialog()940 T602ImportFilterDialog::~T602ImportFilterDialog()
941 {
942     if (mpResMgr)
943     	delete mpResMgr;
944 }
945 
946 // XLocalizable
947 
setLocale(const Locale & eLocale)948 void SAL_CALL T602ImportFilterDialog::setLocale( const Locale& eLocale )
949 	throw(::com::sun::star::uno::RuntimeException)
950 {
951 	meLocale = eLocale;
952 	initLocale();
953 }
954 
getLocale()955 Locale SAL_CALL T602ImportFilterDialog::getLocale()
956 	throw(::com::sun::star::uno::RuntimeException)
957 {
958 	return meLocale;
959 }
960 
OptionsDlg()961 sal_Bool T602ImportFilterDialog::OptionsDlg()
962 {
963     sal_Bool ret = sal_False;
964 
965     Any any;
966 #define _propInt(_prop,_nam,_val) \
967     any <<= (sal_Int32)_val;\
968     _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
969 #define _propShort(_prop,_nam,_val) \
970     any <<= (sal_Int16)_val;\
971     _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
972 #define _propBool(_prop,_nam,_val) \
973     any <<= (sal_Bool)_val;\
974     _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
975 #define _propString(_prop,_nam,_val) \
976     any <<= OUString::createFromAscii(_val);\
977     _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
978 #define _propStringFromResId(_prop,_nam,_val) \
979     any <<= getResStr(_val);\
980     _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
981 #define _propGet(_prop,_nam) \
982     _prop->getPropertyValue(OUString::createFromAscii(_nam));
983 #define _InstCtx(_path,_ctx)\
984     rServiceManager->createInstanceWithContext(\
985     OUString::createFromAscii(_path),_ctx);
986 #define _Inst(_path)\
987     xMultiServiceFactory->createInstance(OUString::createFromAscii(_path) );
988 #define _Insert(_cont,_nam,_obj) \
989     any <<= _obj;\
990     _cont->insertByName( OUString::createFromAscii(_nam), any );
991 
992     Reference < XComponentContext > rComponentContext = defaultBootstrap_InitialComponentContext();
993     Reference < XMultiComponentFactory > rServiceManager = rComponentContext->getServiceManager();
994     Reference < XInterface > rInstance = _InstCtx("com.sun.star.awt.UnoControlDialogModel", rComponentContext );
995 
996     Reference <XMultiServiceFactory> xMultiServiceFactory (rInstance,UNO_QUERY);
997 
998     Reference < XPropertySet > xPSetDialog( rInstance, UNO_QUERY );
999     _propInt(xPSetDialog,"PositionX",100);
1000     _propInt(xPSetDialog,"PositionY",100);
1001     _propInt(xPSetDialog,"Width",130);
1002     _propInt(xPSetDialog,"Height",90);
1003     _propStringFromResId(xPSetDialog,"Title", T602FILTER_STR_IMPORT_DIALOG_TITLE);
1004 
1005 #define T602DLG_OK_BUTTON    "ok_button"
1006 #define T602DLG_CANCEL_BUTTON    "cancel_button"
1007 #define T602DLG_CODE_LB        "code_lb"
1008 #define T602DLG_AZBUKA_CB    "azbuka_cb"
1009 #define T602DLG_COMMENT_CB    "comment_cb"
1010 #define T602DLG_REFORMAT_CB    "reformat_cb"
1011 #define T602DLG_CODE_TXT    "code_txt"
1012 
1013     Reference < XInterface > TextModel = _Inst("com.sun.star.awt.UnoControlFixedTextModel");
1014     Reference < XPropertySet > xPSetText( TextModel, UNO_QUERY );
1015     _propInt(xPSetText,"PositionX",10);
1016     _propInt(xPSetText,"PositionY",8);
1017     _propInt(xPSetText,"Width",30);
1018     _propInt(xPSetText,"Height",14);
1019     _propString(xPSetText,"Name",T602DLG_CODE_TXT);
1020     _propStringFromResId(xPSetText,"Label",T602FILTER_STR_ENCODING_LABEL);
1021 
1022     Reference < XInterface > ListBoxModel = _Inst("com.sun.star.awt.UnoControlListBoxModel");
1023     Reference < XPropertySet > xPSetCodeLB( ListBoxModel, UNO_QUERY );
1024     _propInt(xPSetCodeLB,"PositionX",40);
1025     _propInt(xPSetCodeLB,"PositionY",5);
1026     _propInt(xPSetCodeLB,"Width",85);
1027     _propInt(xPSetCodeLB,"Height",14);
1028     _propString(xPSetCodeLB,"Name",T602DLG_CODE_LB);
1029     _propShort(xPSetCodeLB,"TabIndex",1);
1030     _propBool(xPSetCodeLB,"Dropdown",true);
1031     _propBool(xPSetCodeLB,"MultiSelection",false);
1032 
1033     Sequence< OUString > ous(4);
1034     ous[0] = getResStr(T602FILTER_STR_ENCODING_AUTO);
1035     ous[1] = getResStr(T602FILTER_STR_ENCODING_CP852);
1036     ous[2] = getResStr(T602FILTER_STR_ENCODING_CP895);
1037     ous[3] = getResStr(T602FILTER_STR_ENCODING_KOI8CS2);
1038     any <<= ous;
1039     xPSetCodeLB->setPropertyValue(OUString::createFromAscii("StringItemList"), any);
1040 
1041     Sequence < sal_Int16 > shr(1);
1042     shr[0] = ini.forcecode ? ((sal_Int16) ini.xcode) + 1 : 0;
1043     any <<= shr;
1044     xPSetCodeLB->setPropertyValue(OUString::createFromAscii("SelectedItems"), any);
1045 
1046     Reference < XInterface > AzbCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1047     Reference < XPropertySet > xPSetAzbukaCB( AzbCheckBoxModel, UNO_QUERY );
1048     _propInt(xPSetAzbukaCB,"PositionX",10);
1049     _propInt(xPSetAzbukaCB,"PositionY",25);
1050     _propInt(xPSetAzbukaCB,"Width",100);
1051     _propInt(xPSetAzbukaCB,"Height",14);
1052     _propString(xPSetAzbukaCB,"Name",T602DLG_AZBUKA_CB);
1053     _propShort(xPSetAzbukaCB,"TabIndex",2);
1054     _propStringFromResId(xPSetAzbukaCB,"Label",T602FILTER_STR_CYRILLIC_MODE);
1055     _propShort(xPSetAzbukaCB,"State",ini.ruscode);
1056 
1057     Reference < XInterface > RefCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1058     Reference < XPropertySet > xPSetRefCB( RefCheckBoxModel, UNO_QUERY );
1059     _propInt(xPSetRefCB,"PositionX",10);
1060     _propInt(xPSetRefCB,"PositionY",40);
1061     _propInt(xPSetRefCB,"Width",100);
1062     _propInt(xPSetRefCB,"Height",14);
1063     _propString(xPSetRefCB,"Name",T602DLG_REFORMAT_CB);
1064     _propShort(xPSetRefCB,"TabIndex",3);
1065     _propStringFromResId(xPSetRefCB,"Label",T602FILTER_STR_REFORMAT_TEXT);
1066     _propShort(xPSetRefCB,"State",ini.reformatpars);
1067 
1068     Reference < XInterface > CommCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1069     Reference < XPropertySet > xPSetCommCB( CommCheckBoxModel, UNO_QUERY );
1070     _propInt(xPSetCommCB,"PositionX",10);
1071     _propInt(xPSetCommCB,"PositionY",55);
1072     _propInt(xPSetCommCB,"Width",100);
1073     _propInt(xPSetCommCB,"Height",14);
1074     _propString(xPSetCommCB,"Name",T602DLG_COMMENT_CB);
1075     _propShort(xPSetCommCB,"TabIndex",4);
1076     _propStringFromResId(xPSetCommCB,"Label",T602FILTER_STR_DOT_COMMANDS);
1077     _propShort(xPSetCommCB,"State",ini.showcomm);
1078 
1079     Reference < XInterface > CancelButtonModel = _Inst("com.sun.star.awt.UnoControlButtonModel");
1080     Reference < XPropertySet > xPSetCancelButton( CancelButtonModel, UNO_QUERY );
1081     _propInt(xPSetCancelButton,"PositionX",10);
1082     _propInt(xPSetCancelButton,"PositionY",70);
1083     _propInt(xPSetCancelButton,"Width",50);
1084     _propInt(xPSetCancelButton,"Height",14);
1085     _propString(xPSetCancelButton,"Name",T602DLG_CANCEL_BUTTON);
1086     _propShort(xPSetCancelButton,"TabIndex",5);
1087     _propShort(xPSetCancelButton,"PushButtonType",2);
1088     _propStringFromResId(xPSetCancelButton,"Label",T602FILTER_STR_CANCEL_BUTTON);
1089 
1090     Reference < XInterface > OkButtonModel = _Inst("com.sun.star.awt.UnoControlButtonModel");
1091     Reference < XPropertySet > xPSetOkButton( OkButtonModel, UNO_QUERY );
1092     _propInt(xPSetOkButton,"PositionX",70);
1093     _propInt(xPSetOkButton,"PositionY",70);
1094     _propInt(xPSetOkButton,"Width",50);
1095     _propInt(xPSetOkButton,"Height",14);
1096     _propString(xPSetOkButton,"Name",T602DLG_OK_BUTTON);
1097     _propShort(xPSetOkButton,"TabIndex",0);
1098     _propShort(xPSetOkButton,"PushButtonType",1);
1099     _propStringFromResId(xPSetOkButton,"Label",T602FILTER_STR_OK_BUTTON);
1100     _propBool(xPSetOkButton,"DefaultButton",true);
1101 
1102     Reference < XNameContainer > xNameCont (rInstance,UNO_QUERY);
1103 
1104     _Insert(xNameCont, T602DLG_OK_BUTTON, OkButtonModel);
1105     _Insert(xNameCont, T602DLG_CANCEL_BUTTON, CancelButtonModel);
1106     _Insert(xNameCont, T602DLG_AZBUKA_CB, AzbCheckBoxModel);
1107     _Insert(xNameCont, T602DLG_REFORMAT_CB, RefCheckBoxModel);
1108     _Insert(xNameCont, T602DLG_COMMENT_CB, CommCheckBoxModel);
1109     _Insert(xNameCont, T602DLG_CODE_LB, ListBoxModel);
1110     _Insert(xNameCont, T602DLG_CODE_TXT, TextModel);
1111 
1112     Reference< XInterface > dialog = _InstCtx("com.sun.star.awt.UnoControlDialog",rComponentContext);
1113 
1114     Reference < XControl > xControl (dialog,UNO_QUERY);
1115     Reference < XControlModel > xControlModel (rInstance,UNO_QUERY);
1116 
1117     if(!xControl.is())
1118         return sal_False;
1119 
1120     xControl->setModel( xControlModel );
1121 
1122     Reference< XInterface > toolkit = _InstCtx("com.sun.star.awt.ExtToolkit", rComponentContext);
1123 
1124     Reference < XToolkit > xToolkit (toolkit,UNO_QUERY);
1125     Reference < XWindow > xWindow (xControl,UNO_QUERY);
1126 
1127     if(!xWindow.is())
1128         return sal_False;
1129 
1130     xWindow->setVisible( false );
1131     xControl->createPeer( xToolkit, NULL );
1132 
1133     Reference < XDialog > xDialog (dialog,UNO_QUERY);
1134 
1135     if(!xDialog.is())
1136         return sal_False;
1137 
1138     ret = ( xDialog->execute() != 0 );
1139     if ( ret ) {
1140 
1141         sal_Int16 tt = 0;
1142 
1143         any = _propGet(xPSetAzbukaCB, "State"); any >>= tt; ini.ruscode      = tt;
1144         any = _propGet(xPSetRefCB,    "State"); any >>= tt; ini.reformatpars = tt;
1145         any = _propGet(xPSetCommCB,   "State"); any >>= tt; ini.showcomm     = tt;
1146 
1147         any = _propGet(xPSetCodeLB,   "SelectedItems"); any >>= shr;
1148 
1149         if( shr[0] > 0 ) {
1150             ini.xcode = (tcode)(shr[0]-1);
1151             ini.forcecode = true;
1152         } else {
1153             ini.forcecode = false;
1154         }
1155     }
1156 
1157     Reference < XComponent > xComponent (dialog,UNO_QUERY);
1158 
1159     xComponent->dispose();
1160 
1161     return ret;
1162 }
1163 
initLocale()1164 void T602ImportFilterDialog::initLocale()
1165 {
1166 	rtl::OString aModName( "t602filter" );
1167 	aModName += rtl::OString::valueOf( sal_Int32( SUPD ) );
1168 
1169 	mpResMgr = ResMgr::CreateResMgr( aModName.getStr(), meLocale );
1170 }
1171 
getResMgr()1172 ResMgr* T602ImportFilterDialog::getResMgr()
1173 {
1174 	if( !mpResMgr )
1175 		initLocale();
1176 	return mpResMgr;
1177 }
1178 
setTitle(const::rtl::OUString &)1179 void SAL_CALL T602ImportFilterDialog::setTitle( const ::rtl::OUString& )
1180             throw (::com::sun::star::uno::RuntimeException)
1181 {
1182 }
1183 
execute()1184 sal_Int16 SAL_CALL T602ImportFilterDialog::execute()
1185             throw (::com::sun::star::uno::RuntimeException)
1186 {
1187     if (OptionsDlg())
1188 		return com::sun::star::ui::dialogs::ExecutableDialogResults::OK;
1189 	else
1190 		return com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
1191 }
1192 
getResStr(sal_Int16 resid)1193 rtl::OUString T602ImportFilterDialog::getResStr( sal_Int16 resid )
1194 {
1195 	rtl::OUString sStr = String( ResId( resid, *getResMgr() ) );
1196 	return sStr;
1197 }
1198 
getPropertyValues()1199 uno::Sequence<beans::PropertyValue> SAL_CALL T602ImportFilterDialog::getPropertyValues() throw(uno::RuntimeException)
1200 {
1201 	return uno::Sequence<beans::PropertyValue>();
1202 }
1203 
setPropertyValues(const uno::Sequence<beans::PropertyValue> &)1204 void SAL_CALL T602ImportFilterDialog::setPropertyValues( const uno::Sequence<beans::PropertyValue>& )
1205 					throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1206 							lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
1207 {
1208 }
1209 
1210 
1211 // XServiceInfo
getImplementationName()1212 OUString SAL_CALL T602ImportFilterDialog::getImplementationName(  )
1213     throw (RuntimeException)
1214 {
1215     return T602ImportFilterDialog_getImplementationName();
1216 }
1217 
supportsService(const OUString & rServiceName)1218 sal_Bool SAL_CALL T602ImportFilterDialog::supportsService( const OUString& rServiceName )
1219     throw (RuntimeException)
1220 {
1221     return T602ImportFilterDialog_supportsService( rServiceName );
1222 }
1223 
getSupportedServiceNames()1224 Sequence< OUString > SAL_CALL T602ImportFilterDialog::getSupportedServiceNames(  )
1225     throw (RuntimeException)
1226 {
1227     return T602ImportFilterDialog_getSupportedServiceNames();
1228 }
1229 
1230 #define IMPLEMENTATION_NAME "com.sun.star.comp.Writer.T602ImportFilterDialog"
1231 
T602ImportFilterDialog_getImplementationName()1232 OUString T602ImportFilterDialog_getImplementationName ()
1233     throw (RuntimeException)
1234 {
1235     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
1236 }
1237 
1238 #define SERVICE_NAME "com.sun.star.ui.dialogs.FilterOptionsDialog"
T602ImportFilterDialog_supportsService(const OUString & ServiceName)1239 sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const OUString& ServiceName )
1240     throw (RuntimeException)
1241 {
1242     return ( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ) );
1243 }
1244 
T602ImportFilterDialog_getSupportedServiceNames()1245 Sequence< OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames(  )
1246     throw (RuntimeException)
1247 {
1248     Sequence < OUString > aRet(1);
1249     OUString* pArray = aRet.getArray();
1250     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
1251     return aRet;
1252 }
1253 #undef SERVICE_NAME
1254 
T602ImportFilterDialog_createInstance(const Reference<XMultiServiceFactory> & rSMgr)1255 Reference< XInterface > SAL_CALL T602ImportFilterDialog_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
1256     throw( Exception )
1257 {
1258     return (cppu::OWeakObject*) new T602ImportFilterDialog( rSMgr );
1259 }
1260 
1261 }
1262 
1263