LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/dialog - ascfldlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 179 0.0 %
Date: 2013-07-09 Functions: 0 12 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 <hintids.hxx>
      21             : #include <rtl/textenc.h>
      22             : #include <i18nlangtag/mslangid.hxx>
      23             : #include <com/sun/star/i18n/ScriptType.hpp>
      24             : #include <unotools/lingucfg.hxx>
      25             : #include <fontcfg.hxx>
      26             : #include <swmodule.hxx>
      27             : #include <editeng/unolingu.hxx>
      28             : #include <sfx2/printer.hxx>
      29             : #include <editeng/flstitem.hxx>
      30             : #include <svx/dlgutil.hxx>
      31             : #include <editeng/fontitem.hxx>
      32             : #include <editeng/langitem.hxx>
      33             : #include <editeng/scripttypeitem.hxx>
      34             : #include <swtypes.hxx>
      35             : #include <ascfldlg.hxx>
      36             : #include <shellio.hxx>
      37             : #include <docsh.hxx>
      38             : #include <doc.hxx>
      39             : 
      40             : #include <dialog.hrc>
      41             : 
      42             : #include "vcl/metric.hxx"
      43             : 
      44             : 
      45             : using namespace ::com::sun::star;
      46             : 
      47             : const sal_Unicode cDialogExtraDataClose = '}';
      48             : const char sDialogImpExtraData[] = "EncImpDlg:{";
      49             : const char sDialogExpExtraData[] = "EncExpDlg:{";
      50             : const sal_uInt16 nDialogExtraDataLen = 11;      // 12345678901
      51             : 
      52           0 : SwAsciiFilterDlg::SwAsciiFilterDlg( Window* pParent, SwDocShell& rDocSh,
      53             :                                     SvStream* pStream )
      54             :     : SfxModalDialog(pParent, "AsciiFilterDialog", "modules/swriter/ui/asciifilterdialog.ui")
      55           0 :     , m_bSaveLineStatus(true)
      56             : {
      57           0 :     get(m_pCharSetLB, "charset");
      58           0 :     m_pCharSetLB->SetStyle(m_pCharSetLB->GetStyle() | WB_SORT);
      59           0 :     get(m_pFontFT, "fontft");
      60           0 :     get(m_pFontLB, "font");
      61           0 :     m_pFontLB->SetStyle(m_pFontLB->GetStyle() | WB_SORT);
      62           0 :     get(m_pLanguageFT, "languageft");
      63           0 :     get(m_pLanguageLB, "language");
      64           0 :     m_pLanguageLB->SetStyle(m_pLanguageLB->GetStyle() | WB_SORT);
      65           0 :     get(m_pCRLF_RB, "crlf");
      66           0 :     get(m_pCR_RB, "cr");
      67           0 :     get(m_pLF_RB, "lf");
      68             : 
      69           0 :     SwAsciiOptions aOpt;
      70             :     {
      71             :         const OUString sFindNm = OUString::createFromAscii(
      72             :                                     pStream ? sDialogImpExtraData
      73           0 :                                               : sDialogExpExtraData);
      74           0 :         sal_uInt16 nEnd, nStt = GetExtraData().Search( sFindNm );
      75           0 :         if( STRING_NOTFOUND != nStt )
      76             :         {
      77           0 :             nStt += nDialogExtraDataLen;
      78           0 :             nEnd = GetExtraData().Search( cDialogExtraDataClose, nStt );
      79           0 :             if( STRING_NOTFOUND != nEnd )
      80             :             {
      81           0 :                 aOpt.ReadUserData( GetExtraData().Copy( nStt, nEnd - nStt ));
      82           0 :                 nStt -= nDialogExtraDataLen;
      83           0 :                 GetExtraData().Erase( nStt, nEnd - nStt + 1 );
      84             :             }
      85           0 :         }
      86             :     }
      87             : 
      88             :     // read the first chars and check the charset, (language - with L&H)
      89           0 :     if( pStream )
      90             :     {
      91             :         char aBuffer[ 4098 ];
      92           0 :         sal_uLong nOldPos = pStream->Tell();
      93           0 :         sal_uLong nBytesRead = pStream->Read( aBuffer, 4096 );
      94           0 :         pStream->Seek( nOldPos );
      95             : 
      96           0 :         if( nBytesRead <= 4096 )
      97             :         {
      98           0 :             aBuffer[ nBytesRead ] = '0';
      99           0 :             aBuffer[ nBytesRead+1 ] = '0';
     100             :         }
     101             : 
     102           0 :         bool bCR = false, bLF = false, bNullChar = false;
     103           0 :         for( sal_uInt16 nCnt = 0; nCnt < nBytesRead; ++nCnt )
     104           0 :             switch( aBuffer[ nCnt ] )
     105             :             {
     106           0 :                 case 0x0:   bNullChar = true; break;
     107           0 :                 case 0xA:   bLF = true; break;
     108           0 :                 case 0xD:   bCR = true; break;
     109             :                 case 0xC:
     110             :                 case 0x1A:
     111           0 :                 case 0x9:   break;
     112           0 :                 default:    break;
     113             :             }
     114             : 
     115           0 :         if( !bNullChar )
     116             :         {
     117           0 :             if( bCR )
     118             :             {
     119           0 :                 if( bLF )
     120             :                 {
     121           0 :                     aOpt.SetParaFlags( LINEEND_CRLF );
     122             :                 }
     123             :                 else
     124             :                 {
     125           0 :                     aOpt.SetParaFlags( LINEEND_CR );
     126             :                 }
     127             :             }
     128           0 :             else if( bLF )
     129             :             {
     130           0 :                 aOpt.SetParaFlags( LINEEND_LF );
     131             :             }
     132             :         }
     133             : 
     134           0 :         sal_uInt16 nAppScriptType = GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
     135           0 :         SwDoc* pDoc = rDocSh.GetDoc();
     136             : 
     137             :         // initialise language
     138             :         {
     139           0 :             if( !aOpt.GetLanguage() )
     140             :             {
     141           0 :                 if(pDoc)
     142             :                 {
     143           0 :                     sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
     144             :                     aOpt.SetLanguage( ((SvxLanguageItem&)pDoc->
     145           0 :                                 GetDefault( nWhich )).GetLanguage());
     146             :                 }
     147             :                 else
     148             :                 {
     149           0 :                     SvtLinguOptions aLinguOpt;
     150           0 :                     SvtLinguConfig().GetOptions( aLinguOpt );
     151           0 :                     switch(nAppScriptType)
     152             :                     {
     153             :                         case SCRIPTTYPE_ASIAN:
     154           0 :                             aOpt.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, SCRIPTTYPE_ASIAN));
     155           0 :                         break;
     156             :                         case SCRIPTTYPE_COMPLEX:
     157           0 :                             aOpt.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, SCRIPTTYPE_COMPLEX));
     158           0 :                         break;
     159             :                         //SCRIPTTYPE_LATIN:
     160             :                         default:
     161           0 :                             aOpt.SetLanguage(MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, SCRIPTTYPE_LATIN));
     162           0 :                     }
     163             :                 }
     164             :             }
     165             : 
     166           0 :             m_pLanguageLB->SetLanguageList( LANG_LIST_ALL, sal_True, sal_False );
     167           0 :             m_pLanguageLB->SelectLanguage( aOpt.GetLanguage() );
     168             :         }
     169             : 
     170             :         {
     171           0 :             bool bDelPrinter = false;
     172           0 :             SfxPrinter* pPrt = pDoc ? pDoc->getPrinter(false) : 0;
     173           0 :             if( !pPrt )
     174             :             {
     175           0 :                 SfxItemSet* pSet = new SfxItemSet( rDocSh.GetPool(),
     176             :                             SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
     177             :                             SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
     178           0 :                             0 );
     179           0 :                 pPrt = new SfxPrinter( pSet );
     180           0 :                 bDelPrinter = true;
     181             :             }
     182             : 
     183             :             // get the set of disctinct available family names
     184           0 :             std::set< String > aFontNames;
     185           0 :             int nFontNames = pPrt->GetDevFontCount();
     186           0 :             for( int i = 0; i < nFontNames; i++ )
     187             :             {
     188           0 :                 FontInfo aInf( pPrt->GetDevFont( i ) );
     189           0 :                 aFontNames.insert( aInf.GetName() );
     190           0 :             }
     191             : 
     192             :             // insert to listbox
     193           0 :             for( std::set< String >::const_iterator it = aFontNames.begin();
     194           0 :                  it != aFontNames.end(); ++it )
     195             :             {
     196           0 :                 m_pFontLB->InsertEntry( *it );
     197             :             }
     198             : 
     199           0 :             if( !aOpt.GetFontName().Len() )
     200             :             {
     201           0 :                 LanguageType eLang = aOpt.GetLanguage();
     202           0 :                 Font aTmpFont(OutputDevice::GetDefaultFont(DEFAULTFONT_FIXED, eLang, DEFAULTFONT_FLAGS_ONLYONE, pPrt));
     203           0 :                 aOpt.SetFontName(aTmpFont.GetName());
     204             :             }
     205             : 
     206           0 :             m_pFontLB->SelectEntry( aOpt.GetFontName() );
     207             : 
     208           0 :             if( bDelPrinter )
     209           0 :                 delete pPrt;
     210             :         }
     211             : 
     212             : 
     213             :     }
     214             :     else
     215             :     {
     216             :         // hide the unused Controls for Export
     217           0 :         m_pFontFT->Hide();
     218           0 :         m_pFontLB->Hide();
     219           0 :         m_pLanguageFT->Hide();
     220           0 :         m_pLanguageLB->Hide();
     221             :     }
     222             : 
     223             :     // initialise character set
     224           0 :     m_pCharSetLB->FillFromTextEncodingTable( pStream != NULL );
     225           0 :     m_pCharSetLB->SelectTextEncoding( aOpt.GetCharSet()  );
     226             : 
     227           0 :     m_pCharSetLB->SetSelectHdl( LINK( this, SwAsciiFilterDlg, CharSetSelHdl ));
     228           0 :     m_pCRLF_RB->SetToggleHdl( LINK( this, SwAsciiFilterDlg, LineEndHdl ));
     229           0 :     m_pLF_RB->SetToggleHdl( LINK( this, SwAsciiFilterDlg, LineEndHdl ));
     230           0 :     m_pCR_RB->SetToggleHdl( LINK( this, SwAsciiFilterDlg, LineEndHdl ));
     231             : 
     232           0 :     SetCRLF( aOpt.GetParaFlags() );
     233             : 
     234           0 :     m_pCRLF_RB->SaveValue();
     235           0 :     m_pLF_RB->SaveValue();
     236           0 :     m_pCR_RB->SaveValue();
     237           0 : }
     238             : 
     239             : 
     240           0 : SwAsciiFilterDlg::~SwAsciiFilterDlg()
     241             : {
     242           0 : }
     243             : 
     244             : 
     245           0 : void SwAsciiFilterDlg::FillOptions( SwAsciiOptions& rOptions )
     246             : {
     247           0 :     sal_uLong nCCode = m_pCharSetLB->GetSelectTextEncoding();
     248           0 :     String sFont;
     249           0 :     sal_uLong nLng = 0;
     250           0 :     if( m_pFontLB->IsVisible() )
     251             :     {
     252           0 :         sFont = m_pFontLB->GetSelectEntry();
     253           0 :         nLng = (sal_uLong)m_pLanguageLB->GetSelectLanguage();
     254             :     }
     255             : 
     256           0 :     rOptions.SetFontName( sFont );
     257           0 :     rOptions.SetCharSet( rtl_TextEncoding( nCCode ) );
     258           0 :     rOptions.SetLanguage( sal_uInt16( nLng ) );
     259           0 :     rOptions.SetParaFlags( GetCRLF() );
     260             : 
     261             :     // save the user settings
     262           0 :     String sData;
     263           0 :     rOptions.WriteUserData( sData );
     264           0 :     if( sData.Len() )
     265             :     {
     266             :         const OUString sFindNm = OUString::createFromAscii(
     267           0 :                                     m_pFontLB->IsVisible() ? sDialogImpExtraData
     268           0 :                                               : sDialogExpExtraData);
     269           0 :         sal_uInt16 nEnd, nStt = GetExtraData().Search( sFindNm );
     270           0 :         if( STRING_NOTFOUND != nStt )
     271             :         {
     272             :             // called twice, so remove "old" settings
     273           0 :             nEnd = GetExtraData().Search( cDialogExtraDataClose,
     274           0 :                                             nStt + nDialogExtraDataLen );
     275           0 :             if( STRING_NOTFOUND != nEnd )
     276           0 :                 GetExtraData().Erase( nStt, nEnd - nStt + 1 );
     277             :         }
     278           0 :         String sTmp(GetExtraData());
     279           0 :         sTmp += sFindNm;
     280           0 :         sTmp += sData;
     281           0 :         sTmp += cDialogExtraDataClose;
     282           0 :         GetExtraData() = sTmp;
     283           0 :     }
     284           0 : }
     285             : 
     286           0 : void SwAsciiFilterDlg::SetCRLF( LineEnd eEnd )
     287             : {
     288           0 :     switch( eEnd )
     289             :     {
     290           0 :     case LINEEND_CR:    m_pCR_RB->Check();     break;
     291           0 :     case LINEEND_CRLF:  m_pCRLF_RB->Check();   break;
     292           0 :     case LINEEND_LF:    m_pLF_RB->Check();     break;
     293             :     }
     294           0 : }
     295             : 
     296           0 : LineEnd SwAsciiFilterDlg::GetCRLF() const
     297             : {
     298             :     LineEnd eEnd;
     299           0 :     if( m_pCR_RB->IsChecked() )
     300           0 :         eEnd = LINEEND_CR;
     301           0 :     else if( m_pLF_RB->IsChecked() )
     302           0 :         eEnd = LINEEND_LF;
     303             :     else
     304           0 :         eEnd = LINEEND_CRLF;
     305           0 :     return eEnd;
     306             : }
     307             : 
     308           0 : IMPL_LINK( SwAsciiFilterDlg, CharSetSelHdl, SvxTextEncodingBox*, pBox )
     309             : {
     310           0 :     LineEnd eOldEnd = GetCRLF(), eEnd = (LineEnd)-1;
     311           0 :     LanguageType nLng = m_pFontLB->IsVisible()
     312           0 :                     ? m_pLanguageLB->GetSelectLanguage()
     313           0 :                     : LANGUAGE_SYSTEM,
     314           0 :                 nOldLng = nLng;
     315             : 
     316           0 :     rtl_TextEncoding nChrSet = pBox->GetSelectTextEncoding();
     317           0 :     if( nChrSet == osl_getThreadTextEncoding() )
     318           0 :         eEnd = GetSystemLineEnd();
     319             :     else
     320             :     {
     321           0 :         switch( nChrSet )
     322             :         {
     323             :         case RTL_TEXTENCODING_MS_1252:
     324             : #ifdef UNX
     325           0 :             eEnd = LINEEND_LF;
     326             : #else
     327             :             eEnd = LINEEND_CRLF;                // ANSI
     328             : #endif
     329           0 :             break;
     330             : 
     331             :         case RTL_TEXTENCODING_APPLE_ROMAN:      // MAC
     332           0 :             eEnd = LINEEND_CR;
     333           0 :             break;
     334             : 
     335             :         case RTL_TEXTENCODING_IBM_850:          // DOS
     336           0 :             eEnd = LINEEND_CRLF;
     337           0 :             break;
     338             : 
     339             :         case RTL_TEXTENCODING_APPLE_ARABIC:
     340             :         case RTL_TEXTENCODING_APPLE_CENTEURO:
     341             :         case RTL_TEXTENCODING_APPLE_CROATIAN:
     342             :         case RTL_TEXTENCODING_APPLE_CYRILLIC:
     343             :         case RTL_TEXTENCODING_APPLE_DEVANAGARI:
     344             :         case RTL_TEXTENCODING_APPLE_FARSI:
     345             :         case RTL_TEXTENCODING_APPLE_GREEK:
     346             :         case RTL_TEXTENCODING_APPLE_GUJARATI:
     347             :         case RTL_TEXTENCODING_APPLE_GURMUKHI:
     348             :         case RTL_TEXTENCODING_APPLE_HEBREW:
     349             :         case RTL_TEXTENCODING_APPLE_ICELAND:
     350             :         case RTL_TEXTENCODING_APPLE_ROMANIAN:
     351             :         case RTL_TEXTENCODING_APPLE_THAI:
     352             :         case RTL_TEXTENCODING_APPLE_TURKISH:
     353             :         case RTL_TEXTENCODING_APPLE_UKRAINIAN:
     354             :         case RTL_TEXTENCODING_APPLE_CHINSIMP:
     355             :         case RTL_TEXTENCODING_APPLE_CHINTRAD:
     356             :         case RTL_TEXTENCODING_APPLE_JAPANESE:
     357             :         case RTL_TEXTENCODING_APPLE_KOREAN:
     358           0 :             eEnd = LINEEND_CR;
     359           0 :             break;
     360             :         }
     361             :     }
     362             : 
     363           0 :     m_bSaveLineStatus = false;
     364           0 :     if( eEnd != (LineEnd)-1 )       // changed?
     365             :     {
     366           0 :         if( eOldEnd != eEnd )
     367           0 :             SetCRLF( eEnd );
     368             :     }
     369             :     else
     370             :     {
     371             :         // restore old user choise (not the automatic!)
     372           0 :         m_pCRLF_RB->Check( m_pCRLF_RB->GetSavedValue() );
     373           0 :         m_pCR_RB->Check( m_pCR_RB->GetSavedValue() );
     374           0 :         m_pLF_RB->Check( m_pLF_RB->GetSavedValue() );
     375             :     }
     376           0 :     m_bSaveLineStatus = true;
     377             : 
     378           0 :     if( nOldLng != nLng && m_pFontLB->IsVisible() )
     379           0 :         m_pLanguageLB->SelectLanguage( nLng );
     380             : 
     381           0 :     return 0;
     382             : }
     383             : 
     384           0 : IMPL_LINK( SwAsciiFilterDlg, LineEndHdl, RadioButton*, pBtn )
     385             : {
     386           0 :     if( m_bSaveLineStatus )
     387           0 :         pBtn->SaveValue();
     388           0 :     return 0;
     389           0 : }
     390             : 
     391             : 
     392             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10