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