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 {
147 // checks for filter or type name would be necessary in case we want to use the filter also for "602" files
148 // without the magic bytes at the beginning; I leave the code as comment in case of
149 // ::rtl::OUString aFilterName, aTypeName;
150 sal_Int32 nLength = Descriptor.getLength();
151 const PropertyValue * pValue = Descriptor.getConstArray();
152 for ( sal_Int32 i = 0 ; i < nLength; i++)
153 {
154 if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
155 pValue[i].Value >>= mxInputStream;
156 /* else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "FilterName" ) ) )
157 pValue[i].Value >>= aFilterName;
158 else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TypeName" ) ) )
159 pValue[i].Value >>= aTypeName; */
160 }
161
162 if (!mxInputStream.is())
163 return ::rtl::OUString();
164
165 /* if ( aFilterName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "T602Document" ) ) ||
166 aTypeName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "writer_T602_Document" ) ) )
167 // preselection by type (extension) or filter name: no reason to check type
168 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_T602_Document" ) ); */
169
170 ::com::sun::star::uno::Sequence< sal_Int8 > aData;
171 size_t numBytes = 4;
172 size_t numBytesRead = 0;
173
174 numBytesRead = mxInputStream->readSomeBytes (aData, numBytes);
175
176 if ((numBytesRead != numBytes) || (aData[0] != '@') ||
177 (aData[1] != 'C') || (aData[2] != 'T') || (aData[3] != ' '))
178 return ::rtl::OUString();
179
180 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_T602_Document" ) );
181 }
182
183 // XFilter
filter(const Sequence<::com::sun::star::beans::PropertyValue> & aDescriptor)184 sal_Bool SAL_CALL T602ImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
185 {
186 return importImpl ( aDescriptor );
187 }
188
189 // XImporter
setTargetDocument(const Reference<::com::sun::star::lang::XComponent> & xDoc)190 void SAL_CALL T602ImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
191 {
192 mxDoc = xDoc;
193 }
194
195 // XInitialization
initialize(const Sequence<Any> & aArguments)196 void SAL_CALL T602ImportFilter::initialize( const Sequence< Any >& aArguments )
197 {
198 Sequence < PropertyValue > aAnySeq;
199 sal_Int32 nLength = aArguments.getLength();
200 if ( nLength && ( aArguments[0] >>= aAnySeq ) )
201 {
202 const PropertyValue * pValue = aAnySeq.getConstArray();
203 nLength = aAnySeq.getLength();
204 for ( sal_Int32 i = 0 ; i < nLength; i++)
205 {
206 if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
207 {
208 pValue[i].Value >>= msFilterName;
209 break;
210 }
211 }
212 }
213 }
214
215 // Other functions
216
inschr(unsigned char ch)217 void T602ImportFilter::inschr(unsigned char ch)
218 {
219 Reference < XAttributeList > mAttrList ( mpAttrList );
220
221 if(!ini.showcomm&&pst.comment) return;
222
223 if(ch==' ') {
224 setfnt(chngul,true);
225 pst.wasspace++;
226 return;
227 }
228
229 if(pst.wasspace > 0) {
230 if(ini.reformatpars) {
231 if(!pst.wasfdash)
232 inschrdef(' ');
233 pst.wasfdash = false;
234 } else {
235 char s[20];
236 sprintf(s,"%i",pst.wasspace);
237 _AddAtt("text:c",s);
238 _Start("text:s");
239 _End("text:s");
240 }
241 }
242
243 pst.wasspace = 0;
244 setfnt(chngul,true);
245 inschrdef(ch);
246 }
247
importImpl(const Sequence<::com::sun::star::beans::PropertyValue> & aDescriptor)248 sal_Bool SAL_CALL T602ImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
249 {
250 Reset602();
251
252 sal_Int32 nLength = aDescriptor.getLength();
253 const PropertyValue * pValue = aDescriptor.getConstArray();
254 OUString sURL;
255 for ( sal_Int32 i = 0 ; i < nLength; i++)
256 {
257 if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
258 pValue[i].Value >>= mxInputStream;
259 }
260
261 if ( !mxInputStream.is() )
262 {
263 OSL_ASSERT( 0 );
264 return sal_False;
265 }
266
267 // An XML import service: what we push sax messages to..
268 OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XMLImporter" ) );
269
270 mxHandler = Reference< XDocumentHandler >( mxMSF->createInstance( sXMLImportService ), UNO_QUERY );
271
272 // The XImporter sets up an empty target document for XDocumentHandler to write to..
273 Reference < XImporter > xImporter(mxHandler, UNO_QUERY);
274 xImporter->setTargetDocument(mxDoc);
275
276 char fs[32], fs2[32];
277 sprintf(fs, "%ipt", ini.fontsize);
278 sprintf(fs2,"%ipt", 2*ini.fontsize);
279
280 mpAttrList = new SvXMLAttributeList;
281
282 Reference < XAttributeList > mAttrList ( mpAttrList );
283
284 mxHandler->startDocument();
285
286 _AddAtt("xmlns:office", "http://openoffice.org/2000/office");
287 _AddAtt("xmlns:style", "http://openoffice.org/2000/style");
288 _AddAtt("xmlns:text", "http://openoffice.org/2000/text");
289 _AddAtt("xmlns:table", "http://openoffice.org/2000/table");
290 _AddAtt("xmlns:draw", "http://openoffice.org/2000/draw");
291 _AddAtt("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
292 _AddAtt("xmlns:xlink", "http://www.w3.org/1999/xlink");
293 _AddAtt("xmlns:number", "http://openoffice.org/2000/datastyle");
294 _AddAtt("xmlns:svg", "http://www.w3.org/2000/svg");
295 _AddAtt("xmlns:chart", "http://openoffice.org/2000/chart");
296 _AddAtt("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
297 _AddAtt("xmlns:math", "http://www.w3.org/1998/Math/MathML");
298 _AddAtt("xmlns:form", "http://openoffice.org/2000/form");
299 _AddAtt("xmlns:script", "http://openoffice.org/2000/script");
300 _AddAtt("office:class", "text");
301 _AddAtt("office:version", "1.0");
302 _Start("office:document-content");
303
304 _Start("office:font-decls");
305 _AddAtt("style:name","Courier New");
306 _AddAtt("fo:font-family","Courier New");
307 _AddAtt("style:font-pitch","fixed");
308 _Start("style:font-decl");
309 _End("style:font-decl");
310 _End("office:font-decls");
311
312 _Start("office:automatic-styles");
313
314 // Standardni text
315 _AddAtt("style:name","P1");
316 _AddAtt("style:family","paragraph");
317 _AddAtt("style:parent-style-name","Standard");
318 _Start("style:style");
319 _AddAtt("style:font-name","Courier New");
320 _AddAtt("fo:font-size",fs);
321 _Start("style:properties");
322 _End("style:properties");
323 _End("style:style");
324
325 // Standardni text - konec stranky
326 _AddAtt("style:name","P2");
327 _AddAtt("style:family","paragraph");
328 _AddAtt("style:parent-style-name","Standard");
329 _Start("style:style");
330 _AddAtt("style:font-name","Courier New");
331 _AddAtt("fo:font-size",fs);
332 _AddAtt("fo:break-before","page");
333 _Start("style:properties");
334 _End("style:properties");
335 _End("style:style");
336
337 // T1 Normalni text
338 _AddAtt("style:name","T1");
339 _AddAtt("style:family","text");
340 _Start("style:style");
341 _Start("style:properties");
342 _End("style:properties");
343 _End("style:style");
344
345 // T2 Tucny text
346 _AddAtt("style:name","T2");
347 _AddAtt("style:family","text");
348 _Start("style:style");
349 _AddAtt("fo:font-weight","bold");
350 _Start("style:properties");
351 _End("style:properties");
352 _End("style:style");
353
354 // T3 Kurziva
355 _AddAtt("style:name","T3");
356 _AddAtt("style:family","text");
357 _Start("style:style");
358 _AddAtt("fo:font-style","italic");
359 _Start("style:properties");
360 _End("style:properties");
361 _End("style:style");
362
363 // T4 Siroky text
364 _AddAtt("style:name","T4");
365 _AddAtt("style:family","text");
366 _Start("style:style");
367 _AddAtt("fo:font-weight","bold");
368 _AddAtt("style:text-scale","200%");
369 _Start("style:properties");
370 _End("style:properties");
371 _End("style:style");
372
373 // T5 Vysoky text
374 _AddAtt("style:name","T5");
375 _AddAtt("style:family","text");
376 _Start("style:style");
377 _AddAtt("fo:font-size",fs2);
378 _AddAtt("fo:font-weight","bold");
379 _AddAtt("style:text-scale","50%");
380 _Start("style:properties");
381 _End("style:properties");
382 _End("style:style");
383
384 // T6 Velky text
385 _AddAtt("style:name","T6");
386 _AddAtt("style:family","text");
387 _Start("style:style");
388 _AddAtt("fo:font-size",fs2);
389 _AddAtt("fo:font-weight","bold");
390 _Start("style:properties");
391 _End("style:properties");
392 _End("style:style");
393
394 // T7 Podtrzeny text
395 _AddAtt("style:name","T7");
396 _AddAtt("style:family","text");
397 _Start("style:style");
398 _AddAtt("style:text-underline","single");
399 _Start("style:properties");
400 _End("style:properties");
401 _End("style:style");
402
403 // T8 Podtrzena tucny text
404 _AddAtt("style:name","T8");
405 _AddAtt("style:family","text");
406 _Start("style:style");
407 _AddAtt("fo:font-weight","bold");
408 _AddAtt("style:text-underline","single");
409 _Start("style:properties");
410 _End("style:properties");
411 _End("style:style");
412
413 // T9 Podtrzena kurziva
414 _AddAtt("style:name","T9");
415 _AddAtt("style:family","text");
416 _Start("style:style");
417 _AddAtt("fo:font-style","italic");
418 _AddAtt("style:text-underline","single");
419 _Start("style:properties");
420 _End("style:properties");
421 _End("style:style");
422
423 // T10 Horni index
424 _AddAtt("style:name","T10");
425 _AddAtt("style:family","text");
426 _Start("style:style");
427 _AddAtt("style:text-position","27% 100%");
428 _Start("style:properties");
429 _End("style:properties");
430 _End("style:style");
431
432 // T11 Dolni index
433 _AddAtt("style:name","T11");
434 _AddAtt("style:family","text");
435 _Start("style:style");
436 _AddAtt("style:text-position","-27% 100%");
437 _Start("style:properties");
438 _End("style:properties");
439 _End("style:style");
440
441 _End("office:automatic-styles");
442
443 _Start("office:styles");
444 _End("office:styles");
445
446 _Start("office:body");
447
448 Read602();
449
450 _End("office:body");
451 _End("office:document-content");
452
453 mxHandler->endDocument();
454
455 return sal_True;
456 }
457
Reset602()458 void T602ImportFilter::Reset602()
459 {
460 node = START;
461
462 format602.mt = 0;
463 format602.mb = 0;
464 format602.tb = 0;
465 format602.ct = 0;
466 format602.pn = 1;
467 format602.lh = 1;
468 format602.lm = 6;
469 format602.rm = 60;
470 format602.pl = 60;
471
472 ini.showcomm = false;
473 ini.forcecode = false;
474 ini.xcode = KAM;
475 ini.ruscode = false;
476 ini.reformatpars= false;
477 ini.fontsize = 10;
478
479 fst.nowfnt = fst.oldfnt = standard;
480 fst.uline = fst.olduline = false;
481
482 pst.pars = 0;
483 pst.comment = false;
484 pst.wasspace = 0;
485 pst.ccafterln = false;
486 pst.willbeeop = false;
487 pst.waspar = false;
488 pst.wasfdash = false;
489 }
490
inschrdef(unsigned char ch)491 void T602ImportFilter::inschrdef(unsigned char ch)
492 {
493 static sal_Unicode xch[2];
494
495 xch[1] = 0;
496
497 if(ch > 127) {
498
499 switch(ini.xcode) {
500 case L2 : break;
501 case KOI: ch = koi2lat[ch-128]; break;
502 case KAM: ch = kam2lat[ch-128]; break;
503 default : ch = kam2lat[ch-128];
504 }
505
506 if(ini.ruscode)
507 xch[0] = (rus2UNC[(ch-128)*2] << 8) + rus2UNC[(ch-128)*2+1];
508 else
509 xch[0] = (lat2UNC[(ch-128)*2] << 8) + lat2UNC[(ch-128)*2+1];
510 } else
511 xch[0] = ch;
512
513 pst.waspar = false;
514 mxHandler->characters(OUString(xch));
515 }
516
wrtfnt()517 void T602ImportFilter::wrtfnt()
518 {
519 Reference < XAttributeList > mAttrList ( mpAttrList );
520 const sal_Char *style = "P1";
521
522 switch(fst.nowfnt) {
523 case standard : style = (char*)(fst.uline ? "T7" : "T1"); break;
524 case fat : style = (char*)(fst.uline ? "T8" : "T2"); break;
525 case cursive : style = (char*)(fst.uline ? "T9" : "T3"); break;
526 case bold : style = "T4"; break;
527 case tall : style = "T5"; break;
528 case big : style = "T6"; break;
529 case lindex : style = "T11";break;
530 case hindex : style = "T10";break;
531 default : style = "T1"; break;
532 }
533
534 _End("text:span");
535 _AddAtt("text:style-name", style);
536 _Start("text:span");
537 }
538
setfnt(fonts fnt,bool mustwrite)539 void T602ImportFilter::setfnt(fonts fnt,bool mustwrite)
540 {
541 if( fnt == fst.oldfnt &&
542 fnt == fst.nowfnt &&
543 !mustwrite )
544 fst.nowfnt = standard;
545 else
546 if (fnt != chngul) fst.nowfnt = fnt;
547
548 if(mustwrite)
549 if(fst.oldfnt != fst.nowfnt || fst.olduline != fst.uline) {
550 wrtfnt();
551 fst.oldfnt = fst.nowfnt;
552 fst.olduline = fst.uline;
553 }
554 }
555
Readchar602()556 unsigned char T602ImportFilter::Readchar602()
557 {
558 static Sequence< sal_Int8 > aData;
559
560 return (mxInputStream->readBytes(aData, 1) > 0) ?
561 ((unsigned char *) aData.getConstArray())[0] : 0;
562 }
563
par602(bool endofpage)564 void T602ImportFilter::par602(bool endofpage)
565 {
566 sal_Int16 endp;
567 Reference < XAttributeList > mAttrList ( mpAttrList );
568
569 if(!endofpage || !pst.waspar) {
570 if(ini.showcomm||!pst.comment) {
571 if(pst.waspar||ini.reformatpars) {
572 _End("text:span");
573 _End("text:p");
574 _AddAtt("text:style-name", "P1");
575 _Start("text:p");
576 _Start("text:span");
577 wrtfnt();
578 } else {
579 _Start("text:line-break");
580 _End("text:line-break");
581 }
582 }
583
584 pst.waspar = true;
585 }
586
587 if(!pst.comment) {
588 switch(format602.lh) {
589 case 3: pst.pars += 4; break;
590 case 4: pst.pars += 3; break;
591 case 6: pst.pars += 2; break;
592 default: pst.pars +=2; break;
593 }
594 endp = format602.pl-format602.mt-format602.mb;
595 if(((pst.pars+1)/2) >= endp || endofpage) {
596 pst.pars = 0;
597 if(!ini.reformatpars) {
598 _End("text:span");
599 _End("text:p");
600 _AddAtt("text:style-name", "P2");
601 _Start("text:p");
602 _Start("text:span");
603 wrtfnt();
604 }
605 }
606 }
607 }
608
readnum(unsigned char * ch,bool show)609 sal_Int16 T602ImportFilter::readnum(unsigned char *ch, bool show)
610 {
611 unsigned char buff[21];
612 sal_Int16 i=0;
613
614 while((i<20) && *ch && (*ch!='\n') && (*ch!=','))
615 {
616 *ch = Readchar602();
617 if(show) inschr(*ch);
618 buff[i++] = *ch;
619 }
620 buff[i]='\0';
621
622 // mba: cast from unsigned char via int to sal_Int16 seems to be safe
623 return (sal_Int16) atoi((char *)buff);
624 }
625
Setformat602(char * cmd)626 unsigned char T602ImportFilter::Setformat602(char *cmd)
627 {
628 unsigned char ch;
629 sal_Int16 i;
630
631 ch = Readchar602();
632
633 if (cmd[0]=='M' && cmd[1]=='T') format602.mt = readnum(&ch,false);
634 else if (cmd[0]=='M' && cmd[1]=='B') format602.mb = readnum(&ch,false);
635 // else if (cmd[0]=='T' && cmd[1]=='B') {}
636 // else if (cmd[0]=='H' && cmd[1]=='E') {}
637 // else if (cmd[0]=='F' && cmd[1]=='O') {}
638 else if (cmd[0]=='C' && cmd[1]=='T') {
639 format602.ct = readnum(&ch,false);
640 if (!ini.forcecode)
641 switch(format602.ct) {
642 case 0: ini.xcode = KAM; break;
643 case 1: ini.xcode = L2; break;
644 case 2: ini.xcode = KOI; break;
645 default: ini.xcode = KAM; break;
646 }
647 }
648 else if (cmd[0]=='P' && cmd[1]=='N') format602.pn = readnum(&ch,false);
649 else if (cmd[0]=='L' && cmd[1]=='H') format602.lh = readnum(&ch,false);
650 // else if(cmd[0]=='S' && cmd[1]=='T') {} //styl
651 else if (cmd[0]=='L' && cmd[1]=='M') format602.lm = readnum(&ch,false);
652 else if (cmd[0]=='R' && cmd[1]=='M') format602.rm = readnum(&ch,false);
653 else if (cmd[0]=='P' && cmd[1]=='L') format602.pl = readnum(&ch,false);
654 else if (cmd[0]=='P' && cmd[1]=='A') { if(pst.pars) par602(true); }
655 else if (cmd[0]=='C' && cmd[1]=='P') {
656 i = readnum(&ch,false);
657 if ((i+pst.pars/2) > (format602.pl-format602.mt-format602.mb))
658 if(pst.pars) par602(true);
659 }
660 while (ch && (ch != '\n')) ch = Readchar602();
661 return ch;
662 }
663
PointCmd602(unsigned char * ch)664 tnode T602ImportFilter::PointCmd602(unsigned char *ch)
665 {
666 char pcmd[2];
667
668 // warning: uChar -> char
669 pcmd[0] = (char) toupper(*ch); inschr(*ch);
670 *ch = Readchar602();
671 if (!*ch) return EEND;
672 if (*ch=='\n') return EOL;
673 if (!isalpha(*ch)) return (*ch<32) ? SETCH : WRITE;
674
675 // warning: uChar -> char
676 pcmd[1] = (char) toupper(*ch); inschr(*ch);
677
678 if (pcmd[0]=='P' && pcmd[1]=='A') { if (pst.pars) pst.willbeeop = true; }
679 else if (pcmd[0]=='C' && pcmd[1]=='P') { if (pst.pars) pst.willbeeop = true; }
680 else if (pcmd[0]=='P' && pcmd[1]=='I') {
681 while (*ch && (*ch != '\n') && (*ch != ','))
682 { *ch = Readchar602(); inschr(*ch); }
683 if (!*ch) return EEND;
684 if (*ch=='\n') return EOL;
685 if (*ch==',') { *ch = Readchar602(); inschr(*ch); }
686 pst.pars += (readnum(ch,true)*2);
687 if (!*ch) return EEND;
688 if (*ch=='\n') return EOL;
689 }
690 // else if(pcmd[0]=='K'&&pcmd[1]=='P') {}
691 // else if(pcmd[0]=='H'&&pcmd[1]=='E') {}
692 // else if(pcmd[0]=='F'&&pcmd[1]=='O') {}
693
694 return READCH;
695 }
696
697
Read602()698 void T602ImportFilter::Read602()
699 {
700 unsigned char ch=0;
701 char cmd602[3];
702
703 Reference < XAttributeList > mAttrList ( mpAttrList );
704
705 if (node==QUIT) return;
706
707 _AddAtt("text:style-name", "P1");
708 _Start("text:p");
709 _AddAtt("text:style-name", "T1");
710 _Start("text:span");
711
712 if (node==START) { node = EOL; }
713
714 while (node != EEND) {
715 switch (node) {
716 case READCH:
717 ch = Readchar602();
718 if (ch == 0) node = EEND;
719 else if (ch == '\n') {
720 if(!pst.willbeeop) par602(false);
721 node = EOL;
722 } else if (ch < 32) node = SETCH;
723 else node = WRITE;
724 break;
725 case EOL:
726 ch = Readchar602();
727 pst.comment = false;
728 if (pst.willbeeop) par602(true);
729 pst.willbeeop = false;
730 if(ch == 0) node = EEND;
731 else if (ch == '@') node = EXPCMD;
732 else if (ch == '\n') { par602(false); node = EOL; }
733 else if (ch < 32) {pst.ccafterln = true; node = SETCH; break;}
734 else node = WRITE;
735 if (ch == '.') { pst.comment = true; node = POCMD; }
736 pst.ccafterln = false;
737 break;
738
739 case POCMD: inschr('.');
740 ch = Readchar602();
741 if(ch == 0) node = EEND;
742 else if(isalpha(ch)) node = PointCmd602(&ch);
743 else if(ch <32) node=SETCH;
744 else node = WRITE;
745 break;
746
747 case EXPCMD: ch = Readchar602();
748 if(ch == 0) {inschr('@'); node = EEND; }
749 else if(isupper(ch)) {
750 cmd602[0] = ch;
751 ch = Readchar602();
752 cmd602[1] = ch;
753 cmd602[2] = '\0';
754 if(isupper(ch)) node = SETCMD; //nedodelano
755 else { inschr('@'); _Chars(cmd602); node = READCH; }
756 } else {
757 inschr('@');
758 if(ch<32) node = SETCH;
759 else node = WRITE;}
760 break;
761
762 case SETCMD:
763 ch = Setformat602(cmd602);
764 if(ch == 0) node = EEND;
765 else if(ch == '\n') node = EOL;
766 else node = READCH;
767 break;
768
769 case SETCH :
770 // warning: potentially uninitialized
771 switch(ch) {
772 case '\t' : _Start("text:tab-stop");
773 _End("text:tab-stop");
774 break;
775 case 0x03 : break; //condensed
776 case 0x01 : break; //elite
777 case 0x11 : break; //uzv1
778 case 0x12 : break; //uzv2
779 case 0x15 : break; //uzv3
780 case 0x17 : break; //uzv4
781 case 0x18 : break; //uzv5
782 case 0x19 : break; //uzv6
783 case 0x13 : fst.uline = !fst.uline;break;
784 case 0x02 : setfnt(fat,false); break;
785 case 0x04 : setfnt(cursive,false); break;
786 case 0x0f : setfnt(bold,false); break;
787 case 0x10 : setfnt(tall,false); break;
788 case 0x1d : setfnt(big,false); break;
789 case 0x14 : setfnt(hindex,false); break;
790 case 0x16 : setfnt(lindex,false); break;
791 default : break;
792 }
793 if(pst.ccafterln) node = EOL;
794 else node = READCH;
795 break;
796
797 case WRITE :
798 switch(ch) {
799 case 0x8d:
800 ch = Readchar602();
801 if( ch == 0x0a) {
802 if(ini.reformatpars) inschr(' ');
803 else par602(false); //formatovaci radek
804 node = EOL;
805 } else {
806 inschr(0x8d);//inschr(' ');
807 if(ch == 0) node = EEND;
808 else if(ch == '\n') {
809 if(!pst.willbeeop) par602(false);
810 node = EOL; }
811 else if(ch < 32) node = SETCH;
812 else node = WRITE;
813 }
814 break;
815 case 0xfe:
816 if (ini.showcomm||!pst.comment) inschr(' ');
817 node = READCH;
818 break;
819 case 0xad:
820 ch = Readchar602();
821 if( ch==0x8d ) {
822 if(ini.showcomm||!pst.comment) { //formatovaci pomlcka
823 if(!ini.reformatpars)
824 inschr('-');
825 else {
826 pst.wasspace--;
827 pst.wasfdash = true;
828 }
829 }
830 node=WRITE;
831 } else {
832 inschr(0xad);
833 if(ch == 0) node = EEND;
834 else if(ch == '\n') {
835 if(!pst.willbeeop) par602(false);
836 node = EOL; }
837 else if(ch < 32) node = SETCH;
838 else node = WRITE;
839 }
840 break;
841 default:
842 inschr(ch);
843 node = READCH;
844 break;
845 }
846 break;
847 default: break;
848 }
849 }
850
851 _End("text:span");
852 _End("text:p");
853 node = QUIT;
854 }
855
856 // XServiceInfo
getImplementationName()857 OUString SAL_CALL T602ImportFilter::getImplementationName( )
858 {
859 return T602ImportFilter_getImplementationName();
860 }
861
supportsService(const OUString & rServiceName)862 sal_Bool SAL_CALL T602ImportFilter::supportsService( const OUString& rServiceName )
863 {
864 return T602ImportFilter_supportsService( rServiceName );
865 }
866
getSupportedServiceNames()867 Sequence< OUString > SAL_CALL T602ImportFilter::getSupportedServiceNames( )
868 {
869 return T602ImportFilter_getSupportedServiceNames();
870 }
871
872 #define IMPLEMENTATION_NAME "com.sun.star.comp.Writer.T602ImportFilter"
873
T602ImportFilter_getImplementationName()874 OUString T602ImportFilter_getImplementationName ()
875 {
876 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
877 }
878
879 #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
880 #define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
T602ImportFilter_supportsService(const OUString & ServiceName)881 sal_Bool SAL_CALL T602ImportFilter_supportsService( const OUString& ServiceName )
882 {
883 return (ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
884 ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ) );
885 }
886
T602ImportFilter_getSupportedServiceNames()887 Sequence< OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames( )
888 {
889 Sequence < OUString > aRet(2);
890 OUString* pArray = aRet.getArray();
891 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
892 pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
893 return aRet;
894 }
895 #undef SERVICE_NAME2
896 #undef SERVICE_NAME1
897 #undef IMPLEMENTATION_NAME
898
T602ImportFilter_createInstance(const Reference<XMultiServiceFactory> & rSMgr)899 Reference< XInterface > SAL_CALL T602ImportFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
900 {
901 return (cppu::OWeakObject*) new T602ImportFilter( rSMgr );
902 }
903
904 /* Reference < XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r)
905 throw ( Exception )
906 {
907 return Reference< XInterface > (( OWeakObject *) new T602ImportFilter(r));
908 }
909
910 Sequence < OUString > getSupportedServiceNames()
911 throw ( RuntimeException )
912 {
913 static Sequence < OUString > *pNames = 0;
914 if( ! pNames ) {
915 MutexGuard guard( Mutex::getGlobalMutex() );
916 if( !pNames ) {
917 static Sequence< OUString > seqNames(2);
918 seqNames.getArray()[0] = OUString::createFromAscii(IMPLEMENTATION_NAME);
919 pNames = &seqNames;
920 }
921 }
922 return *pNames;
923 }*/
924
T602ImportFilterDialog(const::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> & r)925 T602ImportFilterDialog::T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r ) :
926 mxMSF( r ), mpResMgr( NULL ) {}
927
~T602ImportFilterDialog()928 T602ImportFilterDialog::~T602ImportFilterDialog()
929 {
930 if (mpResMgr)
931 delete mpResMgr;
932 }
933
934 // XLocalizable
935
setLocale(const Locale & eLocale)936 void SAL_CALL T602ImportFilterDialog::setLocale( const Locale& eLocale )
937 {
938 meLocale = eLocale;
939 initLocale();
940 }
941
getLocale()942 Locale SAL_CALL T602ImportFilterDialog::getLocale()
943 {
944 return meLocale;
945 }
946
OptionsDlg()947 sal_Bool T602ImportFilterDialog::OptionsDlg()
948 {
949 sal_Bool ret = sal_False;
950
951 Any any;
952 #define _propInt(_prop,_nam,_val) \
953 any <<= (sal_Int32)_val;\
954 _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
955 #define _propShort(_prop,_nam,_val) \
956 any <<= (sal_Int16)_val;\
957 _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
958 #define _propBool(_prop,_nam,_val) \
959 any <<= (sal_Bool)_val;\
960 _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
961 #define _propString(_prop,_nam,_val) \
962 any <<= OUString::createFromAscii(_val);\
963 _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
964 #define _propStringFromResId(_prop,_nam,_val) \
965 any <<= getResStr(_val);\
966 _prop->setPropertyValue(OUString::createFromAscii(_nam), any);
967 #define _propGet(_prop,_nam) \
968 _prop->getPropertyValue(OUString::createFromAscii(_nam));
969 #define _InstCtx(_path,_ctx)\
970 rServiceManager->createInstanceWithContext(\
971 OUString::createFromAscii(_path),_ctx);
972 #define _Inst(_path)\
973 xMultiServiceFactory->createInstance(OUString::createFromAscii(_path) );
974 #define _Insert(_cont,_nam,_obj) \
975 any <<= _obj;\
976 _cont->insertByName( OUString::createFromAscii(_nam), any );
977
978 Reference < XComponentContext > rComponentContext = defaultBootstrap_InitialComponentContext();
979 Reference < XMultiComponentFactory > rServiceManager = rComponentContext->getServiceManager();
980 Reference < XInterface > rInstance = _InstCtx("com.sun.star.awt.UnoControlDialogModel", rComponentContext );
981
982 Reference <XMultiServiceFactory> xMultiServiceFactory (rInstance,UNO_QUERY);
983
984 Reference < XPropertySet > xPSetDialog( rInstance, UNO_QUERY );
985 _propInt(xPSetDialog,"PositionX",100);
986 _propInt(xPSetDialog,"PositionY",100);
987 _propInt(xPSetDialog,"Width",130);
988 _propInt(xPSetDialog,"Height",90);
989 _propStringFromResId(xPSetDialog,"Title", T602FILTER_STR_IMPORT_DIALOG_TITLE);
990
991 #define T602DLG_OK_BUTTON "ok_button"
992 #define T602DLG_CANCEL_BUTTON "cancel_button"
993 #define T602DLG_CODE_LB "code_lb"
994 #define T602DLG_AZBUKA_CB "azbuka_cb"
995 #define T602DLG_COMMENT_CB "comment_cb"
996 #define T602DLG_REFORMAT_CB "reformat_cb"
997 #define T602DLG_CODE_TXT "code_txt"
998
999 Reference < XInterface > TextModel = _Inst("com.sun.star.awt.UnoControlFixedTextModel");
1000 Reference < XPropertySet > xPSetText( TextModel, UNO_QUERY );
1001 _propInt(xPSetText,"PositionX",10);
1002 _propInt(xPSetText,"PositionY",8);
1003 _propInt(xPSetText,"Width",30);
1004 _propInt(xPSetText,"Height",14);
1005 _propString(xPSetText,"Name",T602DLG_CODE_TXT);
1006 _propStringFromResId(xPSetText,"Label",T602FILTER_STR_ENCODING_LABEL);
1007
1008 Reference < XInterface > ListBoxModel = _Inst("com.sun.star.awt.UnoControlListBoxModel");
1009 Reference < XPropertySet > xPSetCodeLB( ListBoxModel, UNO_QUERY );
1010 _propInt(xPSetCodeLB,"PositionX",40);
1011 _propInt(xPSetCodeLB,"PositionY",5);
1012 _propInt(xPSetCodeLB,"Width",85);
1013 _propInt(xPSetCodeLB,"Height",14);
1014 _propString(xPSetCodeLB,"Name",T602DLG_CODE_LB);
1015 _propShort(xPSetCodeLB,"TabIndex",1);
1016 _propBool(xPSetCodeLB,"Dropdown",true);
1017 _propBool(xPSetCodeLB,"MultiSelection",false);
1018
1019 Sequence< OUString > ous(4);
1020 ous[0] = getResStr(T602FILTER_STR_ENCODING_AUTO);
1021 ous[1] = getResStr(T602FILTER_STR_ENCODING_CP852);
1022 ous[2] = getResStr(T602FILTER_STR_ENCODING_CP895);
1023 ous[3] = getResStr(T602FILTER_STR_ENCODING_KOI8CS2);
1024 any <<= ous;
1025 xPSetCodeLB->setPropertyValue(OUString::createFromAscii("StringItemList"), any);
1026
1027 Sequence < sal_Int16 > shr(1);
1028 shr[0] = ini.forcecode ? ((sal_Int16) ini.xcode) + 1 : 0;
1029 any <<= shr;
1030 xPSetCodeLB->setPropertyValue(OUString::createFromAscii("SelectedItems"), any);
1031
1032 Reference < XInterface > AzbCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1033 Reference < XPropertySet > xPSetAzbukaCB( AzbCheckBoxModel, UNO_QUERY );
1034 _propInt(xPSetAzbukaCB,"PositionX",10);
1035 _propInt(xPSetAzbukaCB,"PositionY",25);
1036 _propInt(xPSetAzbukaCB,"Width",100);
1037 _propInt(xPSetAzbukaCB,"Height",14);
1038 _propString(xPSetAzbukaCB,"Name",T602DLG_AZBUKA_CB);
1039 _propShort(xPSetAzbukaCB,"TabIndex",2);
1040 _propStringFromResId(xPSetAzbukaCB,"Label",T602FILTER_STR_CYRILLIC_MODE);
1041 _propShort(xPSetAzbukaCB,"State",ini.ruscode);
1042
1043 Reference < XInterface > RefCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1044 Reference < XPropertySet > xPSetRefCB( RefCheckBoxModel, UNO_QUERY );
1045 _propInt(xPSetRefCB,"PositionX",10);
1046 _propInt(xPSetRefCB,"PositionY",40);
1047 _propInt(xPSetRefCB,"Width",100);
1048 _propInt(xPSetRefCB,"Height",14);
1049 _propString(xPSetRefCB,"Name",T602DLG_REFORMAT_CB);
1050 _propShort(xPSetRefCB,"TabIndex",3);
1051 _propStringFromResId(xPSetRefCB,"Label",T602FILTER_STR_REFORMAT_TEXT);
1052 _propShort(xPSetRefCB,"State",ini.reformatpars);
1053
1054 Reference < XInterface > CommCheckBoxModel = _Inst("com.sun.star.awt.UnoControlCheckBoxModel");
1055 Reference < XPropertySet > xPSetCommCB( CommCheckBoxModel, UNO_QUERY );
1056 _propInt(xPSetCommCB,"PositionX",10);
1057 _propInt(xPSetCommCB,"PositionY",55);
1058 _propInt(xPSetCommCB,"Width",100);
1059 _propInt(xPSetCommCB,"Height",14);
1060 _propString(xPSetCommCB,"Name",T602DLG_COMMENT_CB);
1061 _propShort(xPSetCommCB,"TabIndex",4);
1062 _propStringFromResId(xPSetCommCB,"Label",T602FILTER_STR_DOT_COMMANDS);
1063 _propShort(xPSetCommCB,"State",ini.showcomm);
1064
1065 Reference < XInterface > CancelButtonModel = _Inst("com.sun.star.awt.UnoControlButtonModel");
1066 Reference < XPropertySet > xPSetCancelButton( CancelButtonModel, UNO_QUERY );
1067 _propInt(xPSetCancelButton,"PositionX",10);
1068 _propInt(xPSetCancelButton,"PositionY",70);
1069 _propInt(xPSetCancelButton,"Width",50);
1070 _propInt(xPSetCancelButton,"Height",14);
1071 _propString(xPSetCancelButton,"Name",T602DLG_CANCEL_BUTTON);
1072 _propShort(xPSetCancelButton,"TabIndex",5);
1073 _propShort(xPSetCancelButton,"PushButtonType",2);
1074 _propStringFromResId(xPSetCancelButton,"Label",T602FILTER_STR_CANCEL_BUTTON);
1075
1076 Reference < XInterface > OkButtonModel = _Inst("com.sun.star.awt.UnoControlButtonModel");
1077 Reference < XPropertySet > xPSetOkButton( OkButtonModel, UNO_QUERY );
1078 _propInt(xPSetOkButton,"PositionX",70);
1079 _propInt(xPSetOkButton,"PositionY",70);
1080 _propInt(xPSetOkButton,"Width",50);
1081 _propInt(xPSetOkButton,"Height",14);
1082 _propString(xPSetOkButton,"Name",T602DLG_OK_BUTTON);
1083 _propShort(xPSetOkButton,"TabIndex",0);
1084 _propShort(xPSetOkButton,"PushButtonType",1);
1085 _propStringFromResId(xPSetOkButton,"Label",T602FILTER_STR_OK_BUTTON);
1086 _propBool(xPSetOkButton,"DefaultButton",true);
1087
1088 Reference < XNameContainer > xNameCont (rInstance,UNO_QUERY);
1089
1090 _Insert(xNameCont, T602DLG_OK_BUTTON, OkButtonModel);
1091 _Insert(xNameCont, T602DLG_CANCEL_BUTTON, CancelButtonModel);
1092 _Insert(xNameCont, T602DLG_AZBUKA_CB, AzbCheckBoxModel);
1093 _Insert(xNameCont, T602DLG_REFORMAT_CB, RefCheckBoxModel);
1094 _Insert(xNameCont, T602DLG_COMMENT_CB, CommCheckBoxModel);
1095 _Insert(xNameCont, T602DLG_CODE_LB, ListBoxModel);
1096 _Insert(xNameCont, T602DLG_CODE_TXT, TextModel);
1097
1098 Reference< XInterface > dialog = _InstCtx("com.sun.star.awt.UnoControlDialog",rComponentContext);
1099
1100 Reference < XControl > xControl (dialog,UNO_QUERY);
1101 Reference < XControlModel > xControlModel (rInstance,UNO_QUERY);
1102
1103 if(!xControl.is())
1104 return sal_False;
1105
1106 xControl->setModel( xControlModel );
1107
1108 Reference< XInterface > toolkit = _InstCtx("com.sun.star.awt.ExtToolkit", rComponentContext);
1109
1110 Reference < XToolkit > xToolkit (toolkit,UNO_QUERY);
1111 Reference < XWindow > xWindow (xControl,UNO_QUERY);
1112
1113 if(!xWindow.is())
1114 return sal_False;
1115
1116 xWindow->setVisible( false );
1117 xControl->createPeer( xToolkit, NULL );
1118
1119 Reference < XDialog > xDialog (dialog,UNO_QUERY);
1120
1121 if(!xDialog.is())
1122 return sal_False;
1123
1124 ret = ( xDialog->execute() != 0 );
1125 if ( ret ) {
1126
1127 sal_Int16 tt = 0;
1128
1129 any = _propGet(xPSetAzbukaCB, "State"); any >>= tt; ini.ruscode = tt;
1130 any = _propGet(xPSetRefCB, "State"); any >>= tt; ini.reformatpars = tt;
1131 any = _propGet(xPSetCommCB, "State"); any >>= tt; ini.showcomm = tt;
1132
1133 any = _propGet(xPSetCodeLB, "SelectedItems"); any >>= shr;
1134
1135 if( shr[0] > 0 ) {
1136 ini.xcode = (tcode)(shr[0]-1);
1137 ini.forcecode = true;
1138 } else {
1139 ini.forcecode = false;
1140 }
1141 }
1142
1143 Reference < XComponent > xComponent (dialog,UNO_QUERY);
1144
1145 xComponent->dispose();
1146
1147 return ret;
1148 }
1149
initLocale()1150 void T602ImportFilterDialog::initLocale()
1151 {
1152 rtl::OString aModName( "t602filter" );
1153 aModName += rtl::OString::valueOf( sal_Int32( SUPD ) );
1154
1155 mpResMgr = ResMgr::CreateResMgr( aModName.getStr(), meLocale );
1156 }
1157
getResMgr()1158 ResMgr* T602ImportFilterDialog::getResMgr()
1159 {
1160 if( !mpResMgr )
1161 initLocale();
1162 return mpResMgr;
1163 }
1164
setTitle(const::rtl::OUString &)1165 void SAL_CALL T602ImportFilterDialog::setTitle( const ::rtl::OUString& )
1166 {
1167 }
1168
execute()1169 sal_Int16 SAL_CALL T602ImportFilterDialog::execute()
1170 {
1171 if (OptionsDlg())
1172 return com::sun::star::ui::dialogs::ExecutableDialogResults::OK;
1173 else
1174 return com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
1175 }
1176
getResStr(sal_Int16 resid)1177 rtl::OUString T602ImportFilterDialog::getResStr( sal_Int16 resid )
1178 {
1179 rtl::OUString sStr = String( ResId( resid, *getResMgr() ) );
1180 return sStr;
1181 }
1182
getPropertyValues()1183 uno::Sequence<beans::PropertyValue> SAL_CALL T602ImportFilterDialog::getPropertyValues()
1184 {
1185 return uno::Sequence<beans::PropertyValue>();
1186 }
1187
setPropertyValues(const uno::Sequence<beans::PropertyValue> &)1188 void SAL_CALL T602ImportFilterDialog::setPropertyValues( const uno::Sequence<beans::PropertyValue>& )
1189 {
1190 }
1191
1192
1193 // XServiceInfo
getImplementationName()1194 OUString SAL_CALL T602ImportFilterDialog::getImplementationName( )
1195 {
1196 return T602ImportFilterDialog_getImplementationName();
1197 }
1198
supportsService(const OUString & rServiceName)1199 sal_Bool SAL_CALL T602ImportFilterDialog::supportsService( const OUString& rServiceName )
1200 {
1201 return T602ImportFilterDialog_supportsService( rServiceName );
1202 }
1203
getSupportedServiceNames()1204 Sequence< OUString > SAL_CALL T602ImportFilterDialog::getSupportedServiceNames( )
1205 {
1206 return T602ImportFilterDialog_getSupportedServiceNames();
1207 }
1208
1209 #define IMPLEMENTATION_NAME "com.sun.star.comp.Writer.T602ImportFilterDialog"
1210
T602ImportFilterDialog_getImplementationName()1211 OUString T602ImportFilterDialog_getImplementationName ()
1212 {
1213 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
1214 }
1215
1216 #define SERVICE_NAME "com.sun.star.ui.dialogs.FilterOptionsDialog"
T602ImportFilterDialog_supportsService(const OUString & ServiceName)1217 sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const OUString& ServiceName )
1218 {
1219 return ( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ) );
1220 }
1221
T602ImportFilterDialog_getSupportedServiceNames()1222 Sequence< OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames( )
1223 {
1224 Sequence < OUString > aRet(1);
1225 OUString* pArray = aRet.getArray();
1226 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
1227 return aRet;
1228 }
1229 #undef SERVICE_NAME
1230
T602ImportFilterDialog_createInstance(const Reference<XMultiServiceFactory> & rSMgr)1231 Reference< XInterface > SAL_CALL T602ImportFilterDialog_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
1232 {
1233 return (cppu::OWeakObject*) new T602ImportFilterDialog( rSMgr );
1234 }
1235
1236 }
1237