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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "scuiimoptdlg.hxx"
23 #include "tabvwsh.hxx"
24 #include "scresid.hxx"
26 #include <comphelper/string.hxx>
27 #include <osl/thread.h>
28 #include <rtl/tencinfo.h>
32 class ScDelimiterTable
35 ScDelimiterTable( const OUString
& rDelTab
)
36 : theDelTab ( rDelTab
),
38 nCount ( comphelper::string::getTokenCount(rDelTab
, '\t') ),
42 sal_uInt16
GetCode( const OUString
& rDelimiter
) const;
43 OUString
GetDelimiter( sal_Unicode nCode
) const;
45 OUString
FirstDel() { nIter
= 0; return theDelTab
.getToken( nIter
, cSep
); }
46 OUString
NextDel() { nIter
+=2; return theDelTab
.getToken( nIter
, cSep
); }
49 const OUString theDelTab
;
50 const sal_Unicode cSep
;
51 const sal_Int32 nCount
;
55 sal_uInt16
ScDelimiterTable::GetCode( const OUString
& rDel
) const
57 sal_Unicode nCode
= 0;
64 if ( rDel
== theDelTab
.getToken( i
, cSep
) )
66 nCode
= (sal_Unicode
) theDelTab
.getToken( i
+1, cSep
).toInt32();
77 OUString
ScDelimiterTable::GetDelimiter( sal_Unicode nCode
) const
86 if ( nCode
== (sal_Unicode
) theDelTab
.getToken( i
+1, cSep
).toInt32() )
88 aStrDel
= theDelTab
.getToken( i
, cSep
);
101 ScImportOptionsDlg::ScImportOptionsDlg(
102 vcl::Window
* pParent
,
104 const ScImportOptions
* pOptions
,
105 const OUString
* pStrTitle
,
107 bool bOnlyDbtoolsEncodings
,
109 : ModalDialog ( pParent
, "ImOptDialog",
110 "modules/scalc/ui/imoptdialog.ui" )
112 get(m_pFieldFrame
, "fieldframe");
113 get(m_pFtCharset
, "charsetft");
115 get(m_pLbCharset
, "charsetdropdown");
118 get(m_pLbCharset
, "charsetlist");
119 m_pLbCharset
->set_height_request(6 * m_pLbCharset
->GetTextHeight());
121 m_pLbCharset
->SetStyle(m_pLbCharset
->GetStyle() | WB_SORT
);
122 m_pLbCharset
->Show();
123 get(m_pFtFieldSep
, "fieldft");
124 get(m_pEdFieldSep
, "field");
125 get(m_pFtTextSep
, "textft");
126 get(m_pEdTextSep
, "text");
127 get(m_pCbShown
, "asshown");
128 get(m_pCbFormulas
, "formulas");
129 get(m_pCbQuoteAll
, "quoteall");
130 get(m_pCbFixed
, "fixedwidth");
133 OUString
sFieldSep(SC_RESSTR(SCSTR_FIELDSEP
));
134 sFieldSep
= sFieldSep
.replaceFirst( "%TAB", SC_RESSTR(SCSTR_FIELDSEP_TAB
) );
135 sFieldSep
= sFieldSep
.replaceFirst( "%SPACE", SC_RESSTR(SCSTR_FIELDSEP_SPACE
) );
137 // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
138 pFieldSepTab
= new ScDelimiterTable( sFieldSep
);
139 pTextSepTab
= new ScDelimiterTable( OUString(ScResId(SCSTR_TEXTSEP
)) );
141 OUString aStr
= pFieldSepTab
->FirstDel();
144 while ( !aStr
.isEmpty() )
146 m_pEdFieldSep
->InsertEntry( aStr
);
147 aStr
= pFieldSepTab
->NextDel();
150 aStr
= pTextSepTab
->FirstDel();
152 while ( !aStr
.isEmpty() )
154 m_pEdTextSep
->InsertEntry( aStr
);
155 aStr
= pTextSepTab
->NextDel();
158 m_pEdFieldSep
->SetText( m_pEdFieldSep
->GetEntry(0) );
159 m_pEdTextSep
->SetText( m_pEdTextSep
->GetEntry(0) );
161 if ( bOnlyDbtoolsEncodings
)
163 // Even dBase export allows multibyte now
165 m_pLbCharset
->FillFromDbTextEncodingMap( bImport
);
167 m_pLbCharset
->FillFromDbTextEncodingMap( bImport
, RTL_TEXTENCODING_INFO_MULTIBYTE
);
170 { //!TODO: Unicode would need work in each filter
172 m_pLbCharset
->FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
);
174 m_pLbCharset
->FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
|
175 RTL_TEXTENCODING_INFO_MULTIBYTE
);
181 nCode
= pOptions
->nFieldSepCode
;
182 aStr
= pFieldSepTab
->GetDelimiter( nCode
);
184 if ( aStr
.isEmpty() )
185 m_pEdFieldSep
->SetText( OUString((sal_Unicode
)nCode
) );
187 m_pEdFieldSep
->SetText( aStr
);
189 nCode
= pOptions
->nTextSepCode
;
190 aStr
= pTextSepTab
->GetDelimiter( nCode
);
192 if ( aStr
.isEmpty() )
193 m_pEdTextSep
->SetText( OUString((sal_Unicode
)nCode
) );
195 m_pEdTextSep
->SetText( aStr
);
197 // all encodings allowed, even Unicode
198 m_pLbCharset
->FillFromTextEncodingTable( bImport
);
204 m_pCbFixed
->SetClickHdl( LINK( this, ScImportOptionsDlg
, FixedWidthHdl
) );
205 m_pCbFixed
->Check( false );
207 m_pCbShown
->Check( true );
208 m_pCbQuoteAll
->Show();
209 m_pCbQuoteAll
->Check( false );
210 m_pCbFormulas
->Show();
211 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, SfxViewShell::Current());
212 bool bFormulas
= pViewSh
&&
213 pViewSh
->GetViewData().GetOptions().GetOption( VOPT_FORMULAS
);
214 m_pCbFormulas
->Check( bFormulas
);
218 m_pFieldFrame
->set_label(m_pFtCharset
->GetText());
219 m_pFtFieldSep
->Hide();
220 m_pFtTextSep
->Hide();
221 m_pFtCharset
->Hide();
222 m_pEdFieldSep
->Hide();
223 m_pEdTextSep
->Hide();
226 m_pCbQuoteAll
->Hide();
227 m_pCbFormulas
->Hide();
228 m_pLbCharset
->GrabFocus();
229 m_pLbCharset
->SetDoubleClickHdl( LINK( this, ScImportOptionsDlg
, DoubleClickHdl
) );
232 m_pLbCharset
->SelectTextEncoding( pOptions
? pOptions
->eCharSet
:
233 osl_getThreadTextEncoding() );
237 SetText( *pStrTitle
);
240 ScImportOptionsDlg::~ScImportOptionsDlg()
245 void ScImportOptionsDlg::dispose()
249 m_pFieldFrame
.clear();
250 m_pFtCharset
.clear();
251 m_pLbCharset
.clear();
252 m_pFtFieldSep
.clear();
253 m_pEdFieldSep
.clear();
254 m_pFtTextSep
.clear();
255 m_pEdTextSep
.clear();
257 m_pCbFormulas
.clear();
258 m_pCbQuoteAll
.clear();
261 ModalDialog::dispose();
264 void ScImportOptionsDlg::GetImportOptions( ScImportOptions
& rOptions
) const
266 rOptions
.SetTextEncoding( m_pLbCharset
->GetSelectTextEncoding() );
268 if ( m_pCbFixed
->IsVisible() )
270 rOptions
.nFieldSepCode
= GetCodeFromCombo( *m_pEdFieldSep
);
271 rOptions
.nTextSepCode
= GetCodeFromCombo( *m_pEdTextSep
);
272 rOptions
.bFixedWidth
= m_pCbFixed
->IsChecked();
273 rOptions
.bSaveAsShown
= m_pCbShown
->IsChecked();
274 rOptions
.bQuoteAllText
= m_pCbQuoteAll
->IsChecked();
275 rOptions
.bSaveFormulas
= m_pCbFormulas
->IsChecked();
279 sal_uInt16
ScImportOptionsDlg::GetCodeFromCombo( const ComboBox
& rEd
) const
281 ScDelimiterTable
* pTab
;
282 OUString
aStr( rEd
.GetText() );
285 if ( &rEd
== m_pEdTextSep
)
290 if ( aStr
.isEmpty() )
292 nCode
= 0; // kein Trennzeichen
296 nCode
= pTab
->GetCode( aStr
);
299 nCode
= (sal_uInt16
)aStr
[0];
305 IMPL_LINK( ScImportOptionsDlg
, FixedWidthHdl
, CheckBox
*, pCheckBox
)
307 if (pCheckBox
== m_pCbFixed
)
309 bool bEnable
= !m_pCbFixed
->IsChecked();
310 m_pFtFieldSep
->Enable( bEnable
);
311 m_pEdFieldSep
->Enable( bEnable
);
312 m_pFtTextSep
->Enable( bEnable
);
313 m_pEdTextSep
->Enable( bEnable
);
314 m_pCbShown
->Enable( bEnable
);
315 m_pCbQuoteAll
->Enable( bEnable
);
320 IMPL_LINK( ScImportOptionsDlg
, DoubleClickHdl
, ListBox
*, pLb
)
322 if (pLb
== m_pLbCharset
)
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */