1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scuiimoptdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 #include "scuiimoptdlg.hxx"
39 #include "scresid.hxx"
40 #include "imoptdlg.hrc"
41 #include <rtl/tencinfo.h>
42 //========================================================================
44 //========================================================================
46 class ScDelimiterTable
49 ScDelimiterTable( const String
& rDelTab
)
50 : theDelTab ( rDelTab
),
52 nCount ( rDelTab
.GetTokenCount('\t') ),
56 USHORT
GetCode( const String
& rDelimiter
) const;
57 String
GetDelimiter( sal_Unicode nCode
) const;
59 String
FirstDel() { nIter
= 0; return theDelTab
.GetToken( nIter
, cSep
); }
60 String
NextDel() { nIter
+=2; return theDelTab
.GetToken( nIter
, cSep
); }
63 const String theDelTab
;
64 const sal_Unicode cSep
;
65 const xub_StrLen nCount
;
69 //------------------------------------------------------------------------
71 USHORT
ScDelimiterTable::GetCode( const String
& rDel
) const
73 sal_Unicode nCode
= 0;
80 if ( rDel
== theDelTab
.GetToken( i
, cSep
) )
82 nCode
= (sal_Unicode
) theDelTab
.GetToken( i
+1, cSep
).ToInt32();
93 //------------------------------------------------------------------------
95 String
ScDelimiterTable::GetDelimiter( sal_Unicode nCode
) const
104 if ( nCode
== (sal_Unicode
) theDelTab
.GetToken( i
+1, cSep
).ToInt32() )
106 aStrDel
= theDelTab
.GetToken( i
, cSep
);
117 //========================================================================
118 // ScImportOptionsDlg
119 //========================================================================
121 ScImportOptionsDlg::ScImportOptionsDlg(
124 const ScImportOptions
* pOptions
,
125 const String
* pStrTitle
,
127 BOOL bOnlyDbtoolsEncodings
,
130 : ModalDialog ( pParent
, ScResId( RID_SCDLG_IMPORTOPT
) ),
131 aFlFieldOpt ( this, ScResId( FL_FIELDOPT
) ),
132 aFtFont ( this, ScResId( FT_FONT
) ),
133 aLbFont ( this, ScResId( bAscii
? DDLB_FONT
: LB_FONT
) ),
134 aFtFieldSep ( this, ScResId( FT_FIELDSEP
) ),
135 aEdFieldSep ( this, ScResId( ED_FIELDSEP
) ),
136 aFtTextSep ( this, ScResId( FT_TEXTSEP
) ),
137 aEdTextSep ( this, ScResId( ED_TEXTSEP
) ),
138 aCbFixed ( this, ScResId( CB_FIXEDWIDTH
) ),
139 aBtnOk ( this, ScResId( BTN_OK
) ),
140 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
141 aBtnHelp ( this, ScResId( BTN_HELP
) ),
142 aCbShown ( this, ScResId( CB_SAVESHOWN
) )
144 // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
145 pFieldSepTab
= new ScDelimiterTable( String(ScResId(SCSTR_FIELDSEP
)) );
146 pTextSepTab
= new ScDelimiterTable( String(ScResId(SCSTR_TEXTSEP
)) );
148 String aStr
= pFieldSepTab
->FirstDel();
151 while ( aStr
.Len() > 0 )
153 aEdFieldSep
.InsertEntry( aStr
);
154 aStr
= pFieldSepTab
->NextDel();
157 aStr
= pTextSepTab
->FirstDel();
159 while ( aStr
.Len() > 0 )
161 aEdTextSep
.InsertEntry( aStr
);
162 aStr
= pTextSepTab
->NextDel();
165 aEdFieldSep
.SetText( aEdFieldSep
.GetEntry(0) );
166 aEdTextSep
.SetText( aEdTextSep
.GetEntry(0) );
168 if ( bOnlyDbtoolsEncodings
)
170 // Even dBase export allows multibyte now
172 aLbFont
.FillFromDbTextEncodingMap( bImport
);
174 aLbFont
.FillFromDbTextEncodingMap( bImport
, RTL_TEXTENCODING_INFO_MULTIBYTE
);
177 { //!TODO: Unicode would need work in each filter
179 aLbFont
.FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
);
181 aLbFont
.FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
|
182 RTL_TEXTENCODING_INFO_MULTIBYTE
);
188 nCode
= pOptions
->nFieldSepCode
;
189 aStr
= pFieldSepTab
->GetDelimiter( nCode
);
192 aEdFieldSep
.SetText( String((sal_Unicode
)nCode
) );
194 aEdFieldSep
.SetText( aStr
);
196 nCode
= pOptions
->nTextSepCode
;
197 aStr
= pTextSepTab
->GetDelimiter( nCode
);
200 aEdTextSep
.SetText( String((sal_Unicode
)nCode
) );
202 aEdTextSep
.SetText( aStr
);
204 // all encodings allowed, even Unicode
205 aLbFont
.FillFromTextEncodingTable( bImport
);
210 Size
aWinSize( GetSizePixel() );
211 aWinSize
.Height() = aCbFixed
.GetPosPixel().Y() + aCbFixed
.GetSizePixel().Height();
212 Size
aDiffSize( LogicToPixel( Size( 0, 6 ), MapMode( MAP_APPFONT
) ) );
213 aWinSize
.Height() += aDiffSize
.Height();
214 SetSizePixel( aWinSize
);
216 aCbFixed
.SetClickHdl( LINK( this, ScImportOptionsDlg
, FixedWidthHdl
) );
217 aCbFixed
.Check( FALSE
);
219 aCbShown
.Check( TRUE
);
223 aFlFieldOpt
.SetText( aFtFont
.GetText() );
232 aLbFont
.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg
, DoubleClickHdl
) );
235 aLbFont
.SelectTextEncoding( pOptions
? pOptions
->eCharSet
:
236 gsl_getSystemTextEncoding() );
240 SetText( *pStrTitle
);
245 //------------------------------------------------------------------------
247 __EXPORT
ScImportOptionsDlg::~ScImportOptionsDlg()
253 //------------------------------------------------------------------------
255 void ScImportOptionsDlg::GetImportOptions( ScImportOptions
& rOptions
) const
257 rOptions
.SetTextEncoding( aLbFont
.GetSelectTextEncoding() );
259 if ( aCbFixed
.IsVisible() )
261 rOptions
.nFieldSepCode
= GetCodeFromCombo( aEdFieldSep
);
262 rOptions
.nTextSepCode
= GetCodeFromCombo( aEdTextSep
);
263 rOptions
.bFixedWidth
= aCbFixed
.IsChecked();
264 rOptions
.bSaveAsShown
= aCbShown
.IsChecked();
268 //------------------------------------------------------------------------
270 USHORT
ScImportOptionsDlg::GetCodeFromCombo( const ComboBox
& rEd
) const
272 ScDelimiterTable
* pTab
;
273 String
aStr( rEd
.GetText() );
276 if ( &rEd
== &aEdTextSep
)
283 nCode
= 0; // kein Trennzeichen
287 nCode
= pTab
->GetCode( aStr
);
290 nCode
= (USHORT
)aStr
.GetChar(0);
296 //------------------------------------------------------------------------
298 IMPL_LINK( ScImportOptionsDlg
, FixedWidthHdl
, CheckBox
*, pCheckBox
)
300 if( pCheckBox
== &aCbFixed
)
302 BOOL bEnable
= !aCbFixed
.IsChecked();
303 aFtFieldSep
.Enable( bEnable
);
304 aEdFieldSep
.Enable( bEnable
);
305 aFtTextSep
.Enable( bEnable
);
306 aEdTextSep
.Enable( bEnable
);
307 aCbShown
.Enable( bEnable
);
312 IMPL_LINK( ScImportOptionsDlg
, DoubleClickHdl
, ListBox
*, pLb
)
314 if ( pLb
== &aLbFont
)