LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/dbgui - scuiimoptdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2013-07-09 Functions: 0 17 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             : 
      21             : #undef SC_DLLIMPLEMENTATION
      22             : 
      23             : 
      24             : 
      25             : #include "scuiimoptdlg.hxx"
      26             : #include "tabvwsh.hxx"
      27             : #include "scresid.hxx"
      28             : #include "imoptdlg.hrc"
      29             : #include <comphelper/string.hxx>
      30             : #include <rtl/tencinfo.h>
      31             : 
      32             : //========================================================================
      33             : // ScDelimiterTable
      34             : //========================================================================
      35             : 
      36           0 : class ScDelimiterTable
      37             : {
      38             : public:
      39           0 :         ScDelimiterTable( const String& rDelTab )
      40             :             :   theDelTab ( rDelTab ),
      41             :                 cSep      ( '\t' ),
      42           0 :                 nCount    ( comphelper::string::getTokenCount(rDelTab, '\t') ),
      43           0 :                 nIter     ( 0 )
      44           0 :             {}
      45             : 
      46             :     sal_uInt16  GetCode( const String& rDelimiter ) const;
      47             :     String  GetDelimiter( sal_Unicode nCode ) const;
      48             : 
      49           0 :     String  FirstDel()  { nIter = 0; return theDelTab.GetToken( nIter, cSep ); }
      50           0 :     String  NextDel()   { nIter +=2; return theDelTab.GetToken( nIter, cSep ); }
      51             : 
      52             : private:
      53             :     const String        theDelTab;
      54             :     const sal_Unicode   cSep;
      55             :     const xub_StrLen    nCount;
      56             :     xub_StrLen          nIter;
      57             : };
      58             : 
      59             : //------------------------------------------------------------------------
      60             : 
      61           0 : sal_uInt16 ScDelimiterTable::GetCode( const String& rDel ) const
      62             : {
      63           0 :     sal_Unicode nCode = 0;
      64             : 
      65           0 :     if ( nCount >= 2 )
      66             :     {
      67           0 :         xub_StrLen i = 0;
      68           0 :         while ( i<nCount )
      69             :         {
      70           0 :             if ( rDel == theDelTab.GetToken( i, cSep ) )
      71             :             {
      72           0 :                 nCode = (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32();
      73           0 :                 i     = nCount;
      74             :             }
      75             :             else
      76           0 :                 i += 2;
      77             :         }
      78             :     }
      79             : 
      80           0 :     return nCode;
      81             : }
      82             : 
      83             : //------------------------------------------------------------------------
      84             : 
      85           0 : String ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
      86             : {
      87           0 :     String aStrDel;
      88             : 
      89           0 :     if ( nCount >= 2 )
      90             :     {
      91           0 :         xub_StrLen i = 0;
      92           0 :         while ( i<nCount )
      93             :         {
      94           0 :             if ( nCode == (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32() )
      95             :             {
      96           0 :                 aStrDel = theDelTab.GetToken( i, cSep );
      97           0 :                 i       = nCount;
      98             :             }
      99             :             else
     100           0 :                 i += 2;
     101             :         }
     102             :     }
     103             : 
     104           0 :     return aStrDel;
     105             : }
     106             : 
     107             : //========================================================================
     108             : // ScImportOptionsDlg
     109             : //========================================================================
     110             : 
     111           0 : ScImportOptionsDlg::ScImportOptionsDlg(
     112             :         Window*                 pParent,
     113             :         sal_Bool                    bAscii,
     114             :         const ScImportOptions*  pOptions,
     115             :         const String*           pStrTitle,
     116             :         sal_Bool                    bMultiByte,
     117             :         sal_Bool                    bOnlyDbtoolsEncodings,
     118             :         sal_Bool                    bImport )
     119             : 
     120             :     :   ModalDialog ( pParent, ScResId( RID_SCDLG_IMPORTOPT ) ),
     121             :         aFlFieldOpt ( this, ScResId( FL_FIELDOPT ) ),
     122             :         aFtFont     ( this, ScResId( FT_FONT ) ),
     123             :         aLbFont     ( this, ScResId( bAscii ? DDLB_FONT : LB_FONT ) ),
     124             :         aFtFieldSep ( this, ScResId( FT_FIELDSEP ) ),
     125             :         aEdFieldSep ( this, ScResId( ED_FIELDSEP ) ),
     126             :         aFtTextSep  ( this, ScResId( FT_TEXTSEP ) ),
     127             :         aEdTextSep  ( this, ScResId( ED_TEXTSEP ) ),
     128             :         aCbShown    ( this, ScResId( CB_SAVESHOWN ) ),
     129             :         aCbFormulas ( this, ScResId( CB_FORMULAS ) ),
     130             :         aCbQuoteAll ( this, ScResId( CB_QUOTEALL ) ),
     131             :         aCbFixed    ( this, ScResId( CB_FIXEDWIDTH ) ),
     132             :         aBtnOk      ( this, ScResId( BTN_OK ) ),
     133             :         aBtnCancel  ( this, ScResId( BTN_CANCEL ) ),
     134           0 :         aBtnHelp    ( this, ScResId( BTN_HELP ) )
     135             : {
     136           0 :     String sFieldSep( ScResId( SCSTR_FIELDSEP ) );
     137           0 :     sFieldSep.SearchAndReplaceAscii( "%TAB",   String(ScResId(SCSTR_FIELDSEP_TAB)) );
     138           0 :     sFieldSep.SearchAndReplaceAscii( "%SPACE", String(ScResId(SCSTR_FIELDSEP_SPACE)) );
     139             : 
     140             :     // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
     141           0 :     pFieldSepTab = new ScDelimiterTable( sFieldSep );
     142           0 :     pTextSepTab  = new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP)) );
     143             : 
     144           0 :     String aStr = pFieldSepTab->FirstDel();
     145             :     sal_Unicode nCode;
     146             : 
     147           0 :     while ( aStr.Len() > 0 )
     148             :     {
     149           0 :         aEdFieldSep.InsertEntry( aStr );
     150           0 :         aStr = pFieldSepTab->NextDel();
     151             :     }
     152             : 
     153           0 :     aStr = pTextSepTab->FirstDel();
     154             : 
     155           0 :     while ( aStr.Len() > 0 )
     156             :     {
     157           0 :         aEdTextSep.InsertEntry( aStr );
     158           0 :         aStr = pTextSepTab->NextDel();
     159             :     }
     160             : 
     161           0 :     aEdFieldSep.SetText( aEdFieldSep.GetEntry(0) );
     162           0 :     aEdTextSep.SetText( aEdTextSep.GetEntry(0) );
     163             : 
     164           0 :     if ( bOnlyDbtoolsEncodings )
     165             :     {
     166             :         // Even dBase export allows multibyte now
     167           0 :         if ( bMultiByte )
     168           0 :             aLbFont.FillFromDbTextEncodingMap( bImport );
     169             :         else
     170           0 :             aLbFont.FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
     171             :     }
     172           0 :     else if ( !bAscii )
     173             :     {   //!TODO: Unicode would need work in each filter
     174           0 :         if ( bMultiByte )
     175           0 :             aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
     176             :         else
     177             :             aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
     178           0 :                 RTL_TEXTENCODING_INFO_MULTIBYTE );
     179             :     }
     180             :     else
     181             :     {
     182           0 :         if ( pOptions )
     183             :         {
     184           0 :             nCode = pOptions->nFieldSepCode;
     185           0 :             aStr  = pFieldSepTab->GetDelimiter( nCode );
     186             : 
     187           0 :             if ( !aStr.Len() )
     188           0 :                 aEdFieldSep.SetText( OUString((sal_Unicode)nCode) );
     189             :             else
     190           0 :                 aEdFieldSep.SetText( aStr );
     191             : 
     192           0 :             nCode = pOptions->nTextSepCode;
     193           0 :             aStr  = pTextSepTab->GetDelimiter( nCode );
     194             : 
     195           0 :             if ( !aStr.Len() )
     196           0 :                 aEdTextSep.SetText( OUString((sal_Unicode)nCode) );
     197             :             else
     198           0 :                 aEdTextSep.SetText( aStr );
     199             :         }
     200             :         // all encodings allowed, even Unicode
     201           0 :         aLbFont.FillFromTextEncodingTable( bImport );
     202             :     }
     203             : 
     204           0 :     if( bAscii )
     205             :     {
     206           0 :         Size aWinSize( GetSizePixel() );
     207           0 :         aWinSize.Height() = aCbFixed.GetPosPixel().Y() + aCbFixed.GetSizePixel().Height();
     208           0 :         Size aDiffSize( LogicToPixel( Size( 0, 6 ), MapMode( MAP_APPFONT ) ) );
     209           0 :         aWinSize.Height() += aDiffSize.Height();
     210           0 :         SetSizePixel( aWinSize );
     211           0 :         aCbFixed.Show();
     212           0 :         aCbFixed.SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) );
     213           0 :         aCbFixed.Check( false );
     214           0 :         aCbShown.Show();
     215           0 :         aCbShown.Check( sal_True );
     216           0 :         aCbQuoteAll.Show();
     217           0 :         aCbQuoteAll.Check( false );
     218           0 :         aCbFormulas.Show();
     219           0 :         ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current());
     220             :         bool bFormulas = (pViewSh ?
     221           0 :                 pViewSh->GetViewData()->GetOptions().GetOption( VOPT_FORMULAS) :
     222           0 :                 false);
     223           0 :         aCbFormulas.Check( bFormulas );
     224             :     }
     225             :     else
     226             :     {
     227           0 :         aFlFieldOpt.SetText( aFtFont.GetText() );
     228           0 :         aFtFieldSep.Hide();
     229           0 :         aFtTextSep.Hide();
     230           0 :         aFtFont.Hide();
     231           0 :         aEdFieldSep.Hide();
     232           0 :         aEdTextSep.Hide();
     233           0 :         aCbFixed.Hide();
     234           0 :         aCbShown.Hide();
     235           0 :         aCbQuoteAll.Hide();
     236           0 :         aCbFormulas.Hide();
     237           0 :         aLbFont.GrabFocus();
     238           0 :         aLbFont.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) );
     239             :     }
     240             : 
     241             :     aLbFont.SelectTextEncoding( pOptions ? pOptions->eCharSet :
     242           0 :         osl_getThreadTextEncoding() );
     243             : 
     244             :     // optionaler Titel:
     245           0 :     if ( pStrTitle )
     246           0 :         SetText( *pStrTitle );
     247             : 
     248           0 :     FreeResource();
     249           0 : }
     250             : 
     251             : //------------------------------------------------------------------------
     252             : 
     253           0 : ScImportOptionsDlg::~ScImportOptionsDlg()
     254             : {
     255           0 :     delete pFieldSepTab;
     256           0 :     delete pTextSepTab;
     257           0 : }
     258             : 
     259             : //------------------------------------------------------------------------
     260             : 
     261           0 : void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
     262             : {
     263           0 :     rOptions.SetTextEncoding( aLbFont.GetSelectTextEncoding() );
     264             : 
     265           0 :     if ( aCbFixed.IsVisible() )
     266             :     {
     267           0 :         rOptions.nFieldSepCode = GetCodeFromCombo( aEdFieldSep );
     268           0 :         rOptions.nTextSepCode  = GetCodeFromCombo( aEdTextSep );
     269           0 :         rOptions.bFixedWidth = aCbFixed.IsChecked();
     270           0 :         rOptions.bSaveAsShown = aCbShown.IsChecked();
     271           0 :         rOptions.bQuoteAllText = aCbQuoteAll.IsChecked();
     272           0 :         rOptions.bSaveFormulas = aCbFormulas.IsChecked();
     273             :     }
     274           0 : }
     275             : 
     276             : //------------------------------------------------------------------------
     277             : 
     278           0 : sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
     279             : {
     280             :     ScDelimiterTable* pTab;
     281           0 :     String  aStr( rEd.GetText() );
     282             :     sal_uInt16  nCode;
     283             : 
     284           0 :     if ( &rEd == &aEdTextSep )
     285           0 :         pTab = pTextSepTab;
     286             :     else
     287           0 :         pTab = pFieldSepTab;
     288             : 
     289           0 :     if ( !aStr.Len() )
     290             :     {
     291           0 :         nCode = 0;          // kein Trennzeichen
     292             :     }
     293             :     else
     294             :     {
     295           0 :         nCode = pTab->GetCode( aStr );
     296             : 
     297           0 :         if ( nCode == 0 )
     298           0 :             nCode = (sal_uInt16)aStr.GetChar(0);
     299             :     }
     300             : 
     301           0 :     return nCode;
     302             : }
     303             : 
     304             : //------------------------------------------------------------------------
     305             : 
     306           0 : IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, CheckBox*, pCheckBox )
     307             : {
     308           0 :     if( pCheckBox == &aCbFixed )
     309             :     {
     310           0 :         sal_Bool bEnable = !aCbFixed.IsChecked();
     311           0 :         aFtFieldSep.Enable( bEnable );
     312           0 :         aEdFieldSep.Enable( bEnable );
     313           0 :         aFtTextSep.Enable( bEnable );
     314           0 :         aEdTextSep.Enable( bEnable );
     315           0 :         aCbShown.Enable( bEnable );
     316           0 :         aCbQuoteAll.Enable( bEnable );
     317             :     }
     318           0 :     return 0;
     319             : }
     320             : 
     321           0 : IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox*, pLb )
     322             : {
     323           0 :     if ( pLb == &aLbFont )
     324             :     {
     325           0 :         aBtnOk.Click();
     326             :     }
     327           0 :     return 0;
     328           0 : }
     329             : 
     330             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10