LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/dbgui - scuiimoptdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 136 0.0 %
Date: 2012-12-17 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             :     // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
     137           0 :     pFieldSepTab = new ScDelimiterTable( String(ScResId(SCSTR_FIELDSEP)) );
     138           0 :     pTextSepTab  = new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP)) );
     139             : 
     140           0 :     String aStr = pFieldSepTab->FirstDel();
     141             :     sal_Unicode nCode;
     142             : 
     143           0 :     while ( aStr.Len() > 0 )
     144             :     {
     145           0 :         aEdFieldSep.InsertEntry( aStr );
     146           0 :         aStr = pFieldSepTab->NextDel();
     147             :     }
     148             : 
     149           0 :     aStr = pTextSepTab->FirstDel();
     150             : 
     151           0 :     while ( aStr.Len() > 0 )
     152             :     {
     153           0 :         aEdTextSep.InsertEntry( aStr );
     154           0 :         aStr = pTextSepTab->NextDel();
     155             :     }
     156             : 
     157           0 :     aEdFieldSep.SetText( aEdFieldSep.GetEntry(0) );
     158           0 :     aEdTextSep.SetText( aEdTextSep.GetEntry(0) );
     159             : 
     160           0 :     if ( bOnlyDbtoolsEncodings )
     161             :     {
     162             :         // Even dBase export allows multibyte now
     163           0 :         if ( bMultiByte )
     164           0 :             aLbFont.FillFromDbTextEncodingMap( bImport );
     165             :         else
     166           0 :             aLbFont.FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
     167             :     }
     168           0 :     else if ( !bAscii )
     169             :     {   //!TODO: Unicode would need work in each filter
     170           0 :         if ( bMultiByte )
     171           0 :             aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
     172             :         else
     173             :             aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
     174           0 :                 RTL_TEXTENCODING_INFO_MULTIBYTE );
     175             :     }
     176             :     else
     177             :     {
     178           0 :         if ( pOptions )
     179             :         {
     180           0 :             nCode = pOptions->nFieldSepCode;
     181           0 :             aStr  = pFieldSepTab->GetDelimiter( nCode );
     182             : 
     183           0 :             if ( !aStr.Len() )
     184           0 :                 aEdFieldSep.SetText( rtl::OUString((sal_Unicode)nCode) );
     185             :             else
     186           0 :                 aEdFieldSep.SetText( aStr );
     187             : 
     188           0 :             nCode = pOptions->nTextSepCode;
     189           0 :             aStr  = pTextSepTab->GetDelimiter( nCode );
     190             : 
     191           0 :             if ( !aStr.Len() )
     192           0 :                 aEdTextSep.SetText( rtl::OUString((sal_Unicode)nCode) );
     193             :             else
     194           0 :                 aEdTextSep.SetText( aStr );
     195             :         }
     196             :         // all encodings allowed, even Unicode
     197           0 :         aLbFont.FillFromTextEncodingTable( bImport );
     198             :     }
     199             : 
     200           0 :     if( bAscii )
     201             :     {
     202           0 :         Size aWinSize( GetSizePixel() );
     203           0 :         aWinSize.Height() = aCbFixed.GetPosPixel().Y() + aCbFixed.GetSizePixel().Height();
     204           0 :         Size aDiffSize( LogicToPixel( Size( 0, 6 ), MapMode( MAP_APPFONT ) ) );
     205           0 :         aWinSize.Height() += aDiffSize.Height();
     206           0 :         SetSizePixel( aWinSize );
     207           0 :         aCbFixed.Show();
     208           0 :         aCbFixed.SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) );
     209           0 :         aCbFixed.Check( false );
     210           0 :         aCbShown.Show();
     211           0 :         aCbShown.Check( sal_True );
     212           0 :         aCbQuoteAll.Show();
     213           0 :         aCbQuoteAll.Check( false );
     214           0 :         aCbFormulas.Show();
     215           0 :         ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current());
     216             :         bool bFormulas = (pViewSh ?
     217           0 :                 pViewSh->GetViewData()->GetOptions().GetOption( VOPT_FORMULAS) :
     218           0 :                 false);
     219           0 :         aCbFormulas.Check( bFormulas );
     220             :     }
     221             :     else
     222             :     {
     223           0 :         aFlFieldOpt.SetText( aFtFont.GetText() );
     224           0 :         aFtFieldSep.Hide();
     225           0 :         aFtTextSep.Hide();
     226           0 :         aFtFont.Hide();
     227           0 :         aEdFieldSep.Hide();
     228           0 :         aEdTextSep.Hide();
     229           0 :         aCbFixed.Hide();
     230           0 :         aCbShown.Hide();
     231           0 :         aCbQuoteAll.Hide();
     232           0 :         aCbFormulas.Hide();
     233           0 :         aLbFont.GrabFocus();
     234           0 :         aLbFont.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) );
     235             :     }
     236             : 
     237             :     aLbFont.SelectTextEncoding( pOptions ? pOptions->eCharSet :
     238           0 :         osl_getThreadTextEncoding() );
     239             : 
     240             :     // optionaler Titel:
     241           0 :     if ( pStrTitle )
     242           0 :         SetText( *pStrTitle );
     243             : 
     244           0 :     FreeResource();
     245           0 : }
     246             : 
     247             : //------------------------------------------------------------------------
     248             : 
     249           0 : ScImportOptionsDlg::~ScImportOptionsDlg()
     250             : {
     251           0 :     delete pFieldSepTab;
     252           0 :     delete pTextSepTab;
     253           0 : }
     254             : 
     255             : //------------------------------------------------------------------------
     256             : 
     257           0 : void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
     258             : {
     259           0 :     rOptions.SetTextEncoding( aLbFont.GetSelectTextEncoding() );
     260             : 
     261           0 :     if ( aCbFixed.IsVisible() )
     262             :     {
     263           0 :         rOptions.nFieldSepCode = GetCodeFromCombo( aEdFieldSep );
     264           0 :         rOptions.nTextSepCode  = GetCodeFromCombo( aEdTextSep );
     265           0 :         rOptions.bFixedWidth = aCbFixed.IsChecked();
     266           0 :         rOptions.bSaveAsShown = aCbShown.IsChecked();
     267           0 :         rOptions.bQuoteAllText = aCbQuoteAll.IsChecked();
     268           0 :         rOptions.bSaveFormulas = aCbFormulas.IsChecked();
     269             :     }
     270           0 : }
     271             : 
     272             : //------------------------------------------------------------------------
     273             : 
     274           0 : sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
     275             : {
     276             :     ScDelimiterTable* pTab;
     277           0 :     String  aStr( rEd.GetText() );
     278             :     sal_uInt16  nCode;
     279             : 
     280           0 :     if ( &rEd == &aEdTextSep )
     281           0 :         pTab = pTextSepTab;
     282             :     else
     283           0 :         pTab = pFieldSepTab;
     284             : 
     285           0 :     if ( !aStr.Len() )
     286             :     {
     287           0 :         nCode = 0;          // kein Trennzeichen
     288             :     }
     289             :     else
     290             :     {
     291           0 :         nCode = pTab->GetCode( aStr );
     292             : 
     293           0 :         if ( nCode == 0 )
     294           0 :             nCode = (sal_uInt16)aStr.GetChar(0);
     295             :     }
     296             : 
     297           0 :     return nCode;
     298             : }
     299             : 
     300             : //------------------------------------------------------------------------
     301             : 
     302           0 : IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, CheckBox*, pCheckBox )
     303             : {
     304           0 :     if( pCheckBox == &aCbFixed )
     305             :     {
     306           0 :         sal_Bool bEnable = !aCbFixed.IsChecked();
     307           0 :         aFtFieldSep.Enable( bEnable );
     308           0 :         aEdFieldSep.Enable( bEnable );
     309           0 :         aFtTextSep.Enable( bEnable );
     310           0 :         aEdTextSep.Enable( bEnable );
     311           0 :         aCbShown.Enable( bEnable );
     312           0 :         aCbQuoteAll.Enable( bEnable );
     313             :     }
     314           0 :     return 0;
     315             : }
     316             : 
     317           0 : IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox*, pLb )
     318             : {
     319           0 :     if ( pLb == &aLbFont )
     320             :     {
     321           0 :         aBtnOk.Click();
     322             :     }
     323           0 :     return 0;
     324           0 : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10