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