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

Generated by: LCOV version 1.10