fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / dbgui / scuiimoptdlg.cxx
bloba1c1e487b53001fb285fa340929a78a8d6816fe4
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "scuiimoptdlg.hxx"
23 #include "tabvwsh.hxx"
24 #include "scresid.hxx"
25 #include "sc.hrc"
26 #include <comphelper/string.hxx>
27 #include <osl/thread.h>
28 #include <rtl/tencinfo.h>
30 // ScDelimiterTable
32 class ScDelimiterTable
34 public:
35 ScDelimiterTable( const OUString& rDelTab )
36 : theDelTab ( rDelTab ),
37 cSep ( '\t' ),
38 nCount ( comphelper::string::getTokenCount(rDelTab, '\t') ),
39 nIter ( 0 )
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 ); }
48 private:
49 const OUString theDelTab;
50 const sal_Unicode cSep;
51 const sal_Int32 nCount;
52 sal_Int32 nIter;
55 sal_uInt16 ScDelimiterTable::GetCode( const OUString& rDel ) const
57 sal_Unicode nCode = 0;
59 if ( nCount >= 2 )
61 sal_Int32 i = 0;
62 while ( i<nCount )
64 if ( rDel == theDelTab.getToken( i, cSep ) )
66 nCode = (sal_Unicode) theDelTab.getToken( i+1, cSep ).toInt32();
67 i = nCount;
69 else
70 i += 2;
74 return nCode;
77 OUString ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
79 OUString aStrDel;
81 if ( nCount >= 2 )
83 sal_Int32 i = 0;
84 while ( i<nCount )
86 if ( nCode == (sal_Unicode) theDelTab.getToken( i+1, cSep ).toInt32() )
88 aStrDel = theDelTab.getToken( i, cSep );
89 i = nCount;
91 else
92 i += 2;
96 return aStrDel;
99 // ScImportOptionsDlg
101 ScImportOptionsDlg::ScImportOptionsDlg(
102 vcl::Window* pParent,
103 bool bAscii,
104 const ScImportOptions* pOptions,
105 const OUString* pStrTitle,
106 bool bMultiByte,
107 bool bOnlyDbtoolsEncodings,
108 bool bImport )
109 : ModalDialog ( pParent, "ImOptDialog",
110 "modules/scalc/ui/imoptdialog.ui" )
112 get(m_pFieldFrame, "fieldframe");
113 get(m_pFtCharset, "charsetft");
114 if (bAscii)
115 get(m_pLbCharset, "charsetdropdown");
116 else
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");
131 get(m_pBtnOk, "ok");
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();
142 sal_Unicode nCode;
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
164 if ( bMultiByte )
165 m_pLbCharset->FillFromDbTextEncodingMap( bImport );
166 else
167 m_pLbCharset->FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
169 else if ( !bAscii )
170 { //!TODO: Unicode would need work in each filter
171 if ( bMultiByte )
172 m_pLbCharset->FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
173 else
174 m_pLbCharset->FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
175 RTL_TEXTENCODING_INFO_MULTIBYTE );
177 else
179 if ( pOptions )
181 nCode = pOptions->nFieldSepCode;
182 aStr = pFieldSepTab->GetDelimiter( nCode );
184 if ( aStr.isEmpty() )
185 m_pEdFieldSep->SetText( OUString((sal_Unicode)nCode) );
186 else
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) );
194 else
195 m_pEdTextSep->SetText( aStr );
197 // all encodings allowed, even Unicode
198 m_pLbCharset->FillFromTextEncodingTable( bImport );
201 if( bAscii )
203 m_pCbFixed->Show();
204 m_pCbFixed->SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) );
205 m_pCbFixed->Check( false );
206 m_pCbShown->Show();
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 );
216 else
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();
224 m_pCbFixed->Hide();
225 m_pCbShown->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() );
235 // optionaler Titel:
236 if ( pStrTitle )
237 SetText( *pStrTitle );
240 ScImportOptionsDlg::~ScImportOptionsDlg()
242 disposeOnce();
245 void ScImportOptionsDlg::dispose()
247 delete pFieldSepTab;
248 delete pTextSepTab;
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();
256 m_pCbShown.clear();
257 m_pCbFormulas.clear();
258 m_pCbQuoteAll.clear();
259 m_pCbFixed.clear();
260 m_pBtnOk.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() );
283 sal_uInt16 nCode;
285 if ( &rEd == m_pEdTextSep )
286 pTab = pTextSepTab;
287 else
288 pTab = pFieldSepTab;
290 if ( aStr.isEmpty() )
292 nCode = 0; // kein Trennzeichen
294 else
296 nCode = pTab->GetCode( aStr );
298 if ( nCode == 0 )
299 nCode = (sal_uInt16)aStr[0];
302 return nCode;
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 );
317 return 0;
320 IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox*, pLb )
322 if (pLb == m_pLbCharset)
324 m_pBtnOk->Click();
326 return 0;
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */