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 explicit 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());
120 get(m_pEncGrid
, "grid2");
121 m_pEncGrid
->set_vexpand(true);
123 m_pLbCharset
->SetStyle(m_pLbCharset
->GetStyle() | WB_SORT
);
124 m_pLbCharset
->Show();
125 get(m_pFtFieldSep
, "fieldft");
126 get(m_pEdFieldSep
, "field");
127 get(m_pFtTextSep
, "textft");
128 get(m_pEdTextSep
, "text");
129 get(m_pCbShown
, "asshown");
130 get(m_pCbFormulas
, "formulas");
131 get(m_pCbQuoteAll
, "quoteall");
132 get(m_pCbFixed
, "fixedwidth");
135 OUString
sFieldSep(SC_RESSTR(SCSTR_FIELDSEP
));
136 sFieldSep
= sFieldSep
.replaceFirst( "%TAB", SC_RESSTR(SCSTR_FIELDSEP_TAB
) );
137 sFieldSep
= sFieldSep
.replaceFirst( "%SPACE", SC_RESSTR(SCSTR_FIELDSEP_SPACE
) );
139 // im Ctor-Initializer nicht moeglich (MSC kann das nicht):
140 pFieldSepTab
= new ScDelimiterTable( sFieldSep
);
141 pTextSepTab
= new ScDelimiterTable( OUString(ScResId(SCSTR_TEXTSEP
)) );
143 OUString aStr
= pFieldSepTab
->FirstDel();
146 while ( !aStr
.isEmpty() )
148 m_pEdFieldSep
->InsertEntry( aStr
);
149 aStr
= pFieldSepTab
->NextDel();
152 aStr
= pTextSepTab
->FirstDel();
154 while ( !aStr
.isEmpty() )
156 m_pEdTextSep
->InsertEntry( aStr
);
157 aStr
= pTextSepTab
->NextDel();
160 m_pEdFieldSep
->SetText( m_pEdFieldSep
->GetEntry(0) );
161 m_pEdTextSep
->SetText( m_pEdTextSep
->GetEntry(0) );
163 if ( bOnlyDbtoolsEncodings
)
165 // Even dBase export allows multibyte now
167 m_pLbCharset
->FillFromDbTextEncodingMap( bImport
);
169 m_pLbCharset
->FillFromDbTextEncodingMap( bImport
, RTL_TEXTENCODING_INFO_MULTIBYTE
);
172 { //!TODO: Unicode would need work in each filter
174 m_pLbCharset
->FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
);
176 m_pLbCharset
->FillFromTextEncodingTable( bImport
, RTL_TEXTENCODING_INFO_UNICODE
|
177 RTL_TEXTENCODING_INFO_MULTIBYTE
);
183 nCode
= pOptions
->nFieldSepCode
;
184 aStr
= pFieldSepTab
->GetDelimiter( nCode
);
186 if ( aStr
.isEmpty() )
187 m_pEdFieldSep
->SetText( OUString((sal_Unicode
)nCode
) );
189 m_pEdFieldSep
->SetText( aStr
);
191 nCode
= pOptions
->nTextSepCode
;
192 aStr
= pTextSepTab
->GetDelimiter( nCode
);
194 if ( aStr
.isEmpty() )
195 m_pEdTextSep
->SetText( OUString((sal_Unicode
)nCode
) );
197 m_pEdTextSep
->SetText( aStr
);
199 // all encodings allowed, even Unicode
200 m_pLbCharset
->FillFromTextEncodingTable( bImport
);
206 m_pCbFixed
->SetClickHdl( LINK( this, ScImportOptionsDlg
, FixedWidthHdl
) );
207 m_pCbFixed
->Check( false );
210 m_pCbQuoteAll
->Show();
211 m_pCbQuoteAll
->Check( false );
212 m_pCbFormulas
->Show();
213 ScTabViewShell
* pViewSh
= dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
214 bool bFormulas
= pViewSh
&&
215 pViewSh
->GetViewData().GetOptions().GetOption( VOPT_FORMULAS
);
216 m_pCbFormulas
->Check( bFormulas
);
220 m_pFieldFrame
->set_label(m_pFtCharset
->GetText());
221 m_pFtFieldSep
->Hide();
222 m_pFtTextSep
->Hide();
223 m_pFtCharset
->Hide();
224 m_pEdFieldSep
->Hide();
225 m_pEdTextSep
->Hide();
228 m_pCbQuoteAll
->Hide();
229 m_pCbFormulas
->Hide();
230 m_pLbCharset
->GrabFocus();
231 m_pLbCharset
->SetDoubleClickHdl( LINK( this, ScImportOptionsDlg
, DoubleClickHdl
) );
234 m_pLbCharset
->SelectTextEncoding( pOptions
? pOptions
->eCharSet
:
235 osl_getThreadTextEncoding() );
239 SetText( *pStrTitle
);
242 ScImportOptionsDlg::~ScImportOptionsDlg()
247 void ScImportOptionsDlg::dispose()
251 m_pFieldFrame
.clear();
252 m_pFtCharset
.clear();
253 m_pLbCharset
.clear();
254 m_pFtFieldSep
.clear();
255 m_pEdFieldSep
.clear();
256 m_pFtTextSep
.clear();
257 m_pEdTextSep
.clear();
259 m_pCbFormulas
.clear();
260 m_pCbQuoteAll
.clear();
263 ModalDialog::dispose();
266 void ScImportOptionsDlg::GetImportOptions( ScImportOptions
& rOptions
) const
268 rOptions
.SetTextEncoding( m_pLbCharset
->GetSelectTextEncoding() );
270 if ( m_pCbFixed
->IsVisible() )
272 rOptions
.nFieldSepCode
= GetCodeFromCombo( *m_pEdFieldSep
);
273 rOptions
.nTextSepCode
= GetCodeFromCombo( *m_pEdTextSep
);
274 rOptions
.bFixedWidth
= m_pCbFixed
->IsChecked();
275 rOptions
.bSaveAsShown
= m_pCbShown
->IsChecked();
276 rOptions
.bQuoteAllText
= m_pCbQuoteAll
->IsChecked();
277 rOptions
.bSaveFormulas
= m_pCbFormulas
->IsChecked();
281 sal_uInt16
ScImportOptionsDlg::GetCodeFromCombo( const ComboBox
& rEd
) const
283 ScDelimiterTable
* pTab
;
284 OUString
aStr( rEd
.GetText() );
287 if ( &rEd
== m_pEdTextSep
)
292 if ( aStr
.isEmpty() )
294 nCode
= 0; // kein Trennzeichen
298 nCode
= pTab
->GetCode( aStr
);
301 nCode
= (sal_uInt16
)aStr
[0];
307 IMPL_LINK_TYPED( ScImportOptionsDlg
, FixedWidthHdl
, Button
*, pCheckBox
, void )
309 if (pCheckBox
== m_pCbFixed
)
311 bool bEnable
= !m_pCbFixed
->IsChecked();
312 m_pFtFieldSep
->Enable( bEnable
);
313 m_pEdFieldSep
->Enable( bEnable
);
314 m_pFtTextSep
->Enable( bEnable
);
315 m_pEdTextSep
->Enable( bEnable
);
316 m_pCbShown
->Enable( bEnable
);
317 m_pCbQuoteAll
->Enable( bEnable
);
321 IMPL_LINK_TYPED( ScImportOptionsDlg
, DoubleClickHdl
, ListBox
&, rLb
, void )
323 if (&rLb
== m_pLbCharset
)
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */