1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "scuiimoptdlg.hxx" 36*cdf0e10cSrcweir #include "scresid.hxx" 37*cdf0e10cSrcweir #include "imoptdlg.hrc" 38*cdf0e10cSrcweir #include <rtl/tencinfo.h> 39*cdf0e10cSrcweir //======================================================================== 40*cdf0e10cSrcweir // ScDelimiterTable 41*cdf0e10cSrcweir //======================================================================== 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir class ScDelimiterTable 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir public: 46*cdf0e10cSrcweir ScDelimiterTable( const String& rDelTab ) 47*cdf0e10cSrcweir : theDelTab ( rDelTab ), 48*cdf0e10cSrcweir cSep ( '\t' ), 49*cdf0e10cSrcweir nCount ( rDelTab.GetTokenCount('\t') ), 50*cdf0e10cSrcweir nIter ( 0 ) 51*cdf0e10cSrcweir {} 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir sal_uInt16 GetCode( const String& rDelimiter ) const; 54*cdf0e10cSrcweir String GetDelimiter( sal_Unicode nCode ) const; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir String FirstDel() { nIter = 0; return theDelTab.GetToken( nIter, cSep ); } 57*cdf0e10cSrcweir String NextDel() { nIter +=2; return theDelTab.GetToken( nIter, cSep ); } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir private: 60*cdf0e10cSrcweir const String theDelTab; 61*cdf0e10cSrcweir const sal_Unicode cSep; 62*cdf0e10cSrcweir const xub_StrLen nCount; 63*cdf0e10cSrcweir xub_StrLen nIter; 64*cdf0e10cSrcweir }; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //------------------------------------------------------------------------ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir sal_uInt16 ScDelimiterTable::GetCode( const String& rDel ) const 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir sal_Unicode nCode = 0; 71*cdf0e10cSrcweir xub_StrLen i = 0; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir if ( nCount >= 2 ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir while ( i<nCount ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir if ( rDel == theDelTab.GetToken( i, cSep ) ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir nCode = (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32(); 80*cdf0e10cSrcweir i = nCount; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir else 83*cdf0e10cSrcweir i += 2; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir return nCode; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //------------------------------------------------------------------------ 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir String ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir String aStrDel; 95*cdf0e10cSrcweir xub_StrLen i = 0; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if ( nCount >= 2 ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir while ( i<nCount ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if ( nCode == (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32() ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir aStrDel = theDelTab.GetToken( i, cSep ); 104*cdf0e10cSrcweir i = nCount; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir else 107*cdf0e10cSrcweir i += 2; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir return aStrDel; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //======================================================================== 115*cdf0e10cSrcweir // ScImportOptionsDlg 116*cdf0e10cSrcweir //======================================================================== 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir ScImportOptionsDlg::ScImportOptionsDlg( 119*cdf0e10cSrcweir Window* pParent, 120*cdf0e10cSrcweir sal_Bool bAscii, 121*cdf0e10cSrcweir const ScImportOptions* pOptions, 122*cdf0e10cSrcweir const String* pStrTitle, 123*cdf0e10cSrcweir sal_Bool bMultiByte, 124*cdf0e10cSrcweir sal_Bool bOnlyDbtoolsEncodings, 125*cdf0e10cSrcweir sal_Bool bImport ) 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir : ModalDialog ( pParent, ScResId( RID_SCDLG_IMPORTOPT ) ), 128*cdf0e10cSrcweir aFlFieldOpt ( this, ScResId( FL_FIELDOPT ) ), 129*cdf0e10cSrcweir aFtFont ( this, ScResId( FT_FONT ) ), 130*cdf0e10cSrcweir aLbFont ( this, ScResId( bAscii ? DDLB_FONT : LB_FONT ) ), 131*cdf0e10cSrcweir aFtFieldSep ( this, ScResId( FT_FIELDSEP ) ), 132*cdf0e10cSrcweir aEdFieldSep ( this, ScResId( ED_FIELDSEP ) ), 133*cdf0e10cSrcweir aFtTextSep ( this, ScResId( FT_TEXTSEP ) ), 134*cdf0e10cSrcweir aEdTextSep ( this, ScResId( ED_TEXTSEP ) ), 135*cdf0e10cSrcweir aCbQuoteAll ( this, ScResId( CB_QUOTEALL ) ), 136*cdf0e10cSrcweir aCbShown ( this, ScResId( CB_SAVESHOWN ) ), 137*cdf0e10cSrcweir aCbFixed ( this, ScResId( CB_FIXEDWIDTH ) ), 138*cdf0e10cSrcweir aBtnOk ( this, ScResId( BTN_OK ) ), 139*cdf0e10cSrcweir aBtnCancel ( this, ScResId( BTN_CANCEL ) ), 140*cdf0e10cSrcweir aBtnHelp ( this, ScResId( BTN_HELP ) ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir // im Ctor-Initializer nicht moeglich (MSC kann das nicht): 143*cdf0e10cSrcweir pFieldSepTab = new ScDelimiterTable( String(ScResId(SCSTR_FIELDSEP)) ); 144*cdf0e10cSrcweir pTextSepTab = new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP)) ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir String aStr = pFieldSepTab->FirstDel(); 147*cdf0e10cSrcweir sal_Unicode nCode; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir while ( aStr.Len() > 0 ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir aEdFieldSep.InsertEntry( aStr ); 152*cdf0e10cSrcweir aStr = pFieldSepTab->NextDel(); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir aStr = pTextSepTab->FirstDel(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir while ( aStr.Len() > 0 ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir aEdTextSep.InsertEntry( aStr ); 160*cdf0e10cSrcweir aStr = pTextSepTab->NextDel(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir aEdFieldSep.SetText( aEdFieldSep.GetEntry(0) ); 164*cdf0e10cSrcweir aEdTextSep.SetText( aEdTextSep.GetEntry(0) ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( bOnlyDbtoolsEncodings ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir // Even dBase export allows multibyte now 169*cdf0e10cSrcweir if ( bMultiByte ) 170*cdf0e10cSrcweir aLbFont.FillFromDbTextEncodingMap( bImport ); 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir aLbFont.FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir else if ( !bAscii ) 175*cdf0e10cSrcweir { //!TODO: Unicode would need work in each filter 176*cdf0e10cSrcweir if ( bMultiByte ) 177*cdf0e10cSrcweir aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE ); 178*cdf0e10cSrcweir else 179*cdf0e10cSrcweir aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE | 180*cdf0e10cSrcweir RTL_TEXTENCODING_INFO_MULTIBYTE ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir else 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir if ( pOptions ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir nCode = pOptions->nFieldSepCode; 187*cdf0e10cSrcweir aStr = pFieldSepTab->GetDelimiter( nCode ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir if ( !aStr.Len() ) 190*cdf0e10cSrcweir aEdFieldSep.SetText( String((sal_Unicode)nCode) ); 191*cdf0e10cSrcweir else 192*cdf0e10cSrcweir aEdFieldSep.SetText( aStr ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir nCode = pOptions->nTextSepCode; 195*cdf0e10cSrcweir aStr = pTextSepTab->GetDelimiter( nCode ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir if ( !aStr.Len() ) 198*cdf0e10cSrcweir aEdTextSep.SetText( String((sal_Unicode)nCode) ); 199*cdf0e10cSrcweir else 200*cdf0e10cSrcweir aEdTextSep.SetText( aStr ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir // all encodings allowed, even Unicode 203*cdf0e10cSrcweir aLbFont.FillFromTextEncodingTable( bImport ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir if( bAscii ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir Size aWinSize( GetSizePixel() ); 209*cdf0e10cSrcweir aWinSize.Height() = aCbFixed.GetPosPixel().Y() + aCbFixed.GetSizePixel().Height(); 210*cdf0e10cSrcweir Size aDiffSize( LogicToPixel( Size( 0, 6 ), MapMode( MAP_APPFONT ) ) ); 211*cdf0e10cSrcweir aWinSize.Height() += aDiffSize.Height(); 212*cdf0e10cSrcweir SetSizePixel( aWinSize ); 213*cdf0e10cSrcweir aCbFixed.Show(); 214*cdf0e10cSrcweir aCbFixed.SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) ); 215*cdf0e10cSrcweir aCbFixed.Check( sal_False ); 216*cdf0e10cSrcweir aCbShown.Show(); 217*cdf0e10cSrcweir aCbShown.Check( sal_True ); 218*cdf0e10cSrcweir aCbQuoteAll.Show(); 219*cdf0e10cSrcweir aCbQuoteAll.Check( sal_False ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir else 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir aFlFieldOpt.SetText( aFtFont.GetText() ); 224*cdf0e10cSrcweir aFtFieldSep.Hide(); 225*cdf0e10cSrcweir aFtTextSep.Hide(); 226*cdf0e10cSrcweir aFtFont.Hide(); 227*cdf0e10cSrcweir aEdFieldSep.Hide(); 228*cdf0e10cSrcweir aEdTextSep.Hide(); 229*cdf0e10cSrcweir aCbFixed.Hide(); 230*cdf0e10cSrcweir aCbShown.Hide(); 231*cdf0e10cSrcweir aCbQuoteAll.Hide(); 232*cdf0e10cSrcweir aLbFont.GrabFocus(); 233*cdf0e10cSrcweir aLbFont.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir aLbFont.SelectTextEncoding( pOptions ? pOptions->eCharSet : 237*cdf0e10cSrcweir gsl_getSystemTextEncoding() ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // optionaler Titel: 240*cdf0e10cSrcweir if ( pStrTitle ) 241*cdf0e10cSrcweir SetText( *pStrTitle ); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir FreeResource(); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir //------------------------------------------------------------------------ 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir __EXPORT ScImportOptionsDlg::~ScImportOptionsDlg() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir delete pFieldSepTab; 251*cdf0e10cSrcweir delete pTextSepTab; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir //------------------------------------------------------------------------ 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir rOptions.SetTextEncoding( aLbFont.GetSelectTextEncoding() ); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir if ( aCbFixed.IsVisible() ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir rOptions.nFieldSepCode = GetCodeFromCombo( aEdFieldSep ); 263*cdf0e10cSrcweir rOptions.nTextSepCode = GetCodeFromCombo( aEdTextSep ); 264*cdf0e10cSrcweir rOptions.bFixedWidth = aCbFixed.IsChecked(); 265*cdf0e10cSrcweir rOptions.bSaveAsShown = aCbShown.IsChecked(); 266*cdf0e10cSrcweir rOptions.bQuoteAllText = aCbQuoteAll.IsChecked(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir //------------------------------------------------------------------------ 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir ScDelimiterTable* pTab; 275*cdf0e10cSrcweir String aStr( rEd.GetText() ); 276*cdf0e10cSrcweir sal_uInt16 nCode; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if ( &rEd == &aEdTextSep ) 279*cdf0e10cSrcweir pTab = pTextSepTab; 280*cdf0e10cSrcweir else 281*cdf0e10cSrcweir pTab = pFieldSepTab; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if ( !aStr.Len() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir nCode = 0; // kein Trennzeichen 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir else 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir nCode = pTab->GetCode( aStr ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir if ( nCode == 0 ) 292*cdf0e10cSrcweir nCode = (sal_uInt16)aStr.GetChar(0); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir return nCode; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir //------------------------------------------------------------------------ 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, CheckBox*, pCheckBox ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir if( pCheckBox == &aCbFixed ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir sal_Bool bEnable = !aCbFixed.IsChecked(); 305*cdf0e10cSrcweir aFtFieldSep.Enable( bEnable ); 306*cdf0e10cSrcweir aEdFieldSep.Enable( bEnable ); 307*cdf0e10cSrcweir aFtTextSep.Enable( bEnable ); 308*cdf0e10cSrcweir aEdTextSep.Enable( bEnable ); 309*cdf0e10cSrcweir aCbShown.Enable( bEnable ); 310*cdf0e10cSrcweir aCbQuoteAll.Enable( bEnable ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir return 0; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox*, pLb ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir if ( pLb == &aLbFont ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir aBtnOk.Click(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir return 0; 322*cdf0e10cSrcweir } 323