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