LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/filter/source/t602 - t602filter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 678 0.0 %
Date: 2013-07-09 Functions: 0 48 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10