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