bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / dbgui / scuiimoptdlg.cxx
bloba28b7264d150c63db61db34f56c9e3a8ad748d08
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #undef SC_DLLIMPLEMENTATION
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>
32 //========================================================================
33 // ScDelimiterTable
34 //========================================================================
36 class ScDelimiterTable
38 public:
39 ScDelimiterTable( const String& rDelTab )
40 : theDelTab ( rDelTab ),
41 cSep ( '\t' ),
42 nCount ( comphelper::string::getTokenCount(rDelTab, '\t') ),
43 nIter ( 0 )
46 sal_uInt16 GetCode( const String& rDelimiter ) const;
47 String GetDelimiter( sal_Unicode nCode ) const;
49 String FirstDel() { nIter = 0; return theDelTab.GetToken( nIter, cSep ); }
50 String NextDel() { nIter +=2; return theDelTab.GetToken( nIter, cSep ); }
52 private:
53 const String theDelTab;
54 const sal_Unicode cSep;
55 const xub_StrLen nCount;
56 xub_StrLen nIter;
59 //------------------------------------------------------------------------
61 sal_uInt16 ScDelimiterTable::GetCode( const String& rDel ) const
63 sal_Unicode nCode = 0;
65 if ( nCount >= 2 )
67 xub_StrLen i = 0;
68 while ( i<nCount )
70 if ( rDel == theDelTab.GetToken( i, cSep ) )
72 nCode = (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32();
73 i = nCount;
75 else
76 i += 2;
80 return nCode;
83 //------------------------------------------------------------------------
85 String ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
87 String aStrDel;
89 if ( nCount >= 2 )
91 xub_StrLen i = 0;
92 while ( i<nCount )
94 if ( nCode == (sal_Unicode) theDelTab.GetToken( i+1, cSep ).ToInt32() )
96 aStrDel = theDelTab.GetToken( i, cSep );
97 i = nCount;
99 else
100 i += 2;
104 return aStrDel;
107 //========================================================================
108 // ScImportOptionsDlg
109 //========================================================================
111 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 )
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 aBtnHelp ( this, ScResId( BTN_HELP ) )
136 String sFieldSep( ScResId( SCSTR_FIELDSEP ) );
137 sFieldSep.SearchAndReplaceAscii( "%TAB", String(ScResId(SCSTR_FIELDSEP_TAB)) );
138 sFieldSep.SearchAndReplaceAscii( "%SPACE", String(ScResId(SCSTR_FIELDSEP_SPACE)) );
140 // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
141 pFieldSepTab = new ScDelimiterTable( sFieldSep );
142 pTextSepTab = new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP)) );
144 String aStr = pFieldSepTab->FirstDel();
145 sal_Unicode nCode;
147 while ( aStr.Len() > 0 )
149 aEdFieldSep.InsertEntry( aStr );
150 aStr = pFieldSepTab->NextDel();
153 aStr = pTextSepTab->FirstDel();
155 while ( aStr.Len() > 0 )
157 aEdTextSep.InsertEntry( aStr );
158 aStr = pTextSepTab->NextDel();
161 aEdFieldSep.SetText( aEdFieldSep.GetEntry(0) );
162 aEdTextSep.SetText( aEdTextSep.GetEntry(0) );
164 if ( bOnlyDbtoolsEncodings )
166 // Even dBase export allows multibyte now
167 if ( bMultiByte )
168 aLbFont.FillFromDbTextEncodingMap( bImport );
169 else
170 aLbFont.FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
172 else if ( !bAscii )
173 { //!TODO: Unicode would need work in each filter
174 if ( bMultiByte )
175 aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
176 else
177 aLbFont.FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
178 RTL_TEXTENCODING_INFO_MULTIBYTE );
180 else
182 if ( pOptions )
184 nCode = pOptions->nFieldSepCode;
185 aStr = pFieldSepTab->GetDelimiter( nCode );
187 if ( !aStr.Len() )
188 aEdFieldSep.SetText( OUString((sal_Unicode)nCode) );
189 else
190 aEdFieldSep.SetText( aStr );
192 nCode = pOptions->nTextSepCode;
193 aStr = pTextSepTab->GetDelimiter( nCode );
195 if ( !aStr.Len() )
196 aEdTextSep.SetText( OUString((sal_Unicode)nCode) );
197 else
198 aEdTextSep.SetText( aStr );
200 // all encodings allowed, even Unicode
201 aLbFont.FillFromTextEncodingTable( bImport );
204 if( bAscii )
206 Size aWinSize( GetSizePixel() );
207 aWinSize.Height() = aCbFixed.GetPosPixel().Y() + aCbFixed.GetSizePixel().Height();
208 Size aDiffSize( LogicToPixel( Size( 0, 6 ), MapMode( MAP_APPFONT ) ) );
209 aWinSize.Height() += aDiffSize.Height();
210 SetSizePixel( aWinSize );
211 aCbFixed.Show();
212 aCbFixed.SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) );
213 aCbFixed.Check( false );
214 aCbShown.Show();
215 aCbShown.Check( sal_True );
216 aCbQuoteAll.Show();
217 aCbQuoteAll.Check( false );
218 aCbFormulas.Show();
219 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current());
220 bool bFormulas = (pViewSh ?
221 pViewSh->GetViewData()->GetOptions().GetOption( VOPT_FORMULAS) :
222 false);
223 aCbFormulas.Check( bFormulas );
225 else
227 aFlFieldOpt.SetText( aFtFont.GetText() );
228 aFtFieldSep.Hide();
229 aFtTextSep.Hide();
230 aFtFont.Hide();
231 aEdFieldSep.Hide();
232 aEdTextSep.Hide();
233 aCbFixed.Hide();
234 aCbShown.Hide();
235 aCbQuoteAll.Hide();
236 aCbFormulas.Hide();
237 aLbFont.GrabFocus();
238 aLbFont.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) );
241 aLbFont.SelectTextEncoding( pOptions ? pOptions->eCharSet :
242 osl_getThreadTextEncoding() );
244 // optionaler Titel:
245 if ( pStrTitle )
246 SetText( *pStrTitle );
248 FreeResource();
251 //------------------------------------------------------------------------
253 ScImportOptionsDlg::~ScImportOptionsDlg()
255 delete pFieldSepTab;
256 delete pTextSepTab;
259 //------------------------------------------------------------------------
261 void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
263 rOptions.SetTextEncoding( aLbFont.GetSelectTextEncoding() );
265 if ( aCbFixed.IsVisible() )
267 rOptions.nFieldSepCode = GetCodeFromCombo( aEdFieldSep );
268 rOptions.nTextSepCode = GetCodeFromCombo( aEdTextSep );
269 rOptions.bFixedWidth = aCbFixed.IsChecked();
270 rOptions.bSaveAsShown = aCbShown.IsChecked();
271 rOptions.bQuoteAllText = aCbQuoteAll.IsChecked();
272 rOptions.bSaveFormulas = aCbFormulas.IsChecked();
276 //------------------------------------------------------------------------
278 sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
280 ScDelimiterTable* pTab;
281 String aStr( rEd.GetText() );
282 sal_uInt16 nCode;
284 if ( &rEd == &aEdTextSep )
285 pTab = pTextSepTab;
286 else
287 pTab = pFieldSepTab;
289 if ( !aStr.Len() )
291 nCode = 0; // kein Trennzeichen
293 else
295 nCode = pTab->GetCode( aStr );
297 if ( nCode == 0 )
298 nCode = (sal_uInt16)aStr.GetChar(0);
301 return nCode;
304 //------------------------------------------------------------------------
306 IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, CheckBox*, pCheckBox )
308 if( pCheckBox == &aCbFixed )
310 sal_Bool bEnable = !aCbFixed.IsChecked();
311 aFtFieldSep.Enable( bEnable );
312 aEdFieldSep.Enable( bEnable );
313 aFtTextSep.Enable( bEnable );
314 aEdTextSep.Enable( bEnable );
315 aCbShown.Enable( bEnable );
316 aCbQuoteAll.Enable( bEnable );
318 return 0;
321 IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox*, pLb )
323 if ( pLb == &aLbFont )
325 aBtnOk.Click();
327 return 0;
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */