1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 //========================================================================
34 //========================================================================
36 class ScDelimiterTable
39 ScDelimiterTable( const String
& rDelTab
)
40 : theDelTab ( rDelTab
),
42 nCount ( comphelper::string::getTokenCount(rDelTab
, '\t') ),
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
); }
53 const String theDelTab
;
54 const sal_Unicode cSep
;
55 const xub_StrLen nCount
;
59 //------------------------------------------------------------------------
61 sal_uInt16
ScDelimiterTable::GetCode( const String
& rDel
) const
63 sal_Unicode nCode
= 0;
70 if ( rDel
== theDelTab
.GetToken( i
, cSep
) )
72 nCode
= (sal_Unicode
) theDelTab
.GetToken( i
+1, cSep
).ToInt32();
83 //------------------------------------------------------------------------
85 String
ScDelimiterTable::GetDelimiter( sal_Unicode nCode
) const
94 if ( nCode
== (sal_Unicode
) theDelTab
.GetToken( i
+1, cSep
).ToInt32() )
96 aStrDel
= theDelTab
.GetToken( i
, cSep
);
107 //========================================================================
108 // ScImportOptionsDlg
109 //========================================================================
111 ScImportOptionsDlg::ScImportOptionsDlg(
114 const ScImportOptions
* pOptions
,
115 const String
* pStrTitle
,
117 sal_Bool bOnlyDbtoolsEncodings
,
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();
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
168 aLbFont
.FillFromDbTextEncodingMap( bImport
);
170 aLbFont
.FillFromDbTextEncodingMap( bImport
, RTL_TEXTENCODING_INFO_MULTIBYTE
);
173 { //!TODO: Unicode would need work in each filter
175 aLbFont
.FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
);
177 aLbFont
.FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
|
178 RTL_TEXTENCODING_INFO_MULTIBYTE
);
184 nCode
= pOptions
->nFieldSepCode
;
185 aStr
= pFieldSepTab
->GetDelimiter( nCode
);
188 aEdFieldSep
.SetText( OUString((sal_Unicode
)nCode
) );
190 aEdFieldSep
.SetText( aStr
);
192 nCode
= pOptions
->nTextSepCode
;
193 aStr
= pTextSepTab
->GetDelimiter( nCode
);
196 aEdTextSep
.SetText( OUString((sal_Unicode
)nCode
) );
198 aEdTextSep
.SetText( aStr
);
200 // all encodings allowed, even Unicode
201 aLbFont
.FillFromTextEncodingTable( bImport
);
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
);
212 aCbFixed
.SetClickHdl( LINK( this, ScImportOptionsDlg
, FixedWidthHdl
) );
213 aCbFixed
.Check( false );
215 aCbShown
.Check( sal_True
);
217 aCbQuoteAll
.Check( false );
219 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, SfxViewShell::Current());
220 bool bFormulas
= (pViewSh
?
221 pViewSh
->GetViewData()->GetOptions().GetOption( VOPT_FORMULAS
) :
223 aCbFormulas
.Check( bFormulas
);
227 aFlFieldOpt
.SetText( aFtFont
.GetText() );
238 aLbFont
.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg
, DoubleClickHdl
) );
241 aLbFont
.SelectTextEncoding( pOptions
? pOptions
->eCharSet
:
242 osl_getThreadTextEncoding() );
246 SetText( *pStrTitle
);
251 //------------------------------------------------------------------------
253 ScImportOptionsDlg::~ScImportOptionsDlg()
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() );
284 if ( &rEd
== &aEdTextSep
)
291 nCode
= 0; // kein Trennzeichen
295 nCode
= pTab
->GetCode( aStr
);
298 nCode
= (sal_uInt16
)aStr
.GetChar(0);
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
);
321 IMPL_LINK( ScImportOptionsDlg
, DoubleClickHdl
, ListBox
*, pLb
)
323 if ( pLb
== &aLbFont
)
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */