fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / source / ui / dbgui / scuiasciiopt.cxx
blobfd44245b9a308875ec3574b5a0a8e2cd43e33934
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 .
21 #undef SC_DLLIMPLEMENTATION
23 #include "global.hxx"
24 #include "scresid.hxx"
25 #include "impex.hxx"
26 #include "scuiasciiopt.hxx"
27 #include "asciiopt.hrc"
28 #include <comphelper/string.hxx>
29 #include <rtl/tencinfo.h>
30 #include <unotools/transliterationwrapper.hxx>
31 #include "editutil.hxx"
33 #include <optutil.hxx>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include "miscuno.hxx"
37 #include <tools/urlobj.hxx>
39 //! TODO make dynamic
40 const SCSIZE ASCIIDLG_MAXROWS = MAXROWCOUNT;
43 using namespace com::sun::star::uno;
46 // Defines - CSV Import Preserve Options
47 #define FIXED_WIDTH "FixedWidth"
48 #define FROM_ROW "FromRow"
49 #define CHAR_SET "CharSet"
50 #define SEPARATORS "Separators"
51 #define TEXT_SEPARATORS "TextSeparators"
52 #define MERGE_DELIMITERS "MergeDelimiters"
53 #define QUOTED_AS_TEXT "QuotedFieldAsText"
54 #define DETECT_SPECIAL_NUM "DetectSpecialNumbers"
55 #define LANGUAGE "Language"
56 #define SEP_PATH "Office.Calc/Dialogs/CSVImport"
57 #define SEP_PATH_CLPBRD "Office.Calc/Dialogs/ClipboardTextImport"
58 #define SEP_PATH_TEXT2COL "Office.Calc/Dialogs/TextToColumnsImport"
60 // ============================================================================
62 static void lcl_FillCombo( ComboBox& rCombo, const String& rList, sal_Unicode cSelect )
64 xub_StrLen i;
65 xub_StrLen nCount = comphelper::string::getTokenCount(rList, '\t');
66 for ( i=0; i<nCount; i+=2 )
67 rCombo.InsertEntry( rList.GetToken(i,'\t') );
69 if ( cSelect )
71 String aStr;
72 for ( i=0; i<nCount; i+=2 )
73 if ( (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32() == cSelect )
74 aStr = rList.GetToken(i,'\t');
75 if (!aStr.Len())
76 aStr = cSelect; // Ascii
78 rCombo.SetText(aStr);
82 static sal_Unicode lcl_CharFromCombo( ComboBox& rCombo, const String& rList )
84 sal_Unicode c = 0;
85 String aStr = rCombo.GetText();
86 if ( aStr.Len() )
88 xub_StrLen nCount = comphelper::string::getTokenCount(rList, '\t');
89 for ( xub_StrLen i=0; i<nCount; i+=2 )
91 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rList.GetToken(i,'\t') ) )
92 c = (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32();
94 if (!c && aStr.Len())
96 sal_Unicode cFirst = aStr.GetChar( 0 );
97 // #i24235# first try the first character of the string directly
98 if( (aStr.Len() == 1) || (cFirst < '0') || (cFirst > '9') )
99 c = cFirst;
100 else // keep old behaviour for compatibility (i.e. "39" -> "'")
101 c = (sal_Unicode) aStr.ToInt32(); // Ascii
104 return c;
107 static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparators,
108 bool &bMergeDelimiters, bool& bQuotedAsText, bool& bDetectSpecialNum,
109 bool &bFixedWidth, sal_Int32 &nFromRow, sal_Int32 &nCharSet,
110 sal_Int32& nLanguage, ScImportAsciiCall eCall )
112 Sequence<Any>aValues;
113 const Any *pProperties;
114 Sequence<OUString> aNames( eCall == SC_TEXTTOCOLUMNS ? 4 : 9 );
115 OUString* pNames = aNames.getArray();
116 OUString aSepPath;
117 switch(eCall)
119 case SC_IMPORTFILE:
120 aSepPath = SEP_PATH;
121 break;
122 case SC_PASTETEXT:
123 aSepPath = SEP_PATH_CLPBRD;
124 break;
125 case SC_TEXTTOCOLUMNS:
126 default:
127 aSepPath = SEP_PATH_TEXT2COL;
128 break;
130 ScLinkConfigItem aItem( aSepPath );
132 pNames[0] = OUString( MERGE_DELIMITERS );
133 pNames[1] = OUString( SEPARATORS );
134 pNames[2] = OUString( TEXT_SEPARATORS );
135 pNames[3] = OUString( FIXED_WIDTH );
136 if (eCall != SC_TEXTTOCOLUMNS)
138 pNames[4] = OUString( FROM_ROW );
139 pNames[5] = OUString( CHAR_SET );
140 pNames[6] = OUString( QUOTED_AS_TEXT );
141 pNames[7] = OUString( DETECT_SPECIAL_NUM );
142 pNames[8] = OUString( LANGUAGE );
144 aValues = aItem.GetProperties( aNames );
145 pProperties = aValues.getConstArray();
147 if( pProperties[0].hasValue() )
148 bMergeDelimiters = ScUnoHelpFunctions::GetBoolFromAny( pProperties[0] );
150 if( pProperties[1].hasValue() )
151 pProperties[1] >>= sFieldSeparators;
153 if( pProperties[2].hasValue() )
154 pProperties[2] >>= sTextSeparators;
156 if( pProperties[3].hasValue() )
157 bFixedWidth = ScUnoHelpFunctions::GetBoolFromAny( pProperties[3] );
159 if (eCall != SC_TEXTTOCOLUMNS)
161 if( pProperties[4].hasValue() )
162 pProperties[4] >>= nFromRow;
164 if( pProperties[5].hasValue() )
165 pProperties[5] >>= nCharSet;
167 if ( pProperties[6].hasValue() )
168 pProperties[6] >>= bQuotedAsText;
170 if ( pProperties[7].hasValue() )
171 pProperties[7] >>= bDetectSpecialNum;
173 if ( pProperties[8].hasValue() )
174 pProperties[8] >>= nLanguage;
178 static void save_Separators(
179 String maSeparators, String maTxtSep, bool bMergeDelimiters, bool bQuotedAsText,
180 bool bDetectSpecialNum, bool bFixedWidth, sal_Int32 nFromRow,
181 sal_Int32 nCharSet, sal_Int32 nLanguage, ScImportAsciiCall eCall )
183 OUString sFieldSeparators = OUString( maSeparators );
184 OUString sTextSeparators = OUString( maTxtSep );
185 Sequence<Any> aValues;
186 Any *pProperties;
187 Sequence<OUString> aNames( eCall == SC_TEXTTOCOLUMNS ? 4 : 9 );
188 OUString* pNames = aNames.getArray();
189 OUString aSepPath;
190 switch(eCall)
192 case SC_IMPORTFILE:
193 aSepPath = SEP_PATH;
194 break;
195 case SC_PASTETEXT:
196 aSepPath = SEP_PATH_CLPBRD;
197 break;
198 case SC_TEXTTOCOLUMNS:
199 default:
200 aSepPath = SEP_PATH_TEXT2COL;
201 break;
203 ScLinkConfigItem aItem( aSepPath );
205 pNames[0] = OUString( MERGE_DELIMITERS );
206 pNames[1] = OUString( SEPARATORS );
207 pNames[2] = OUString( TEXT_SEPARATORS );
208 pNames[3] = OUString( FIXED_WIDTH );
209 if (eCall != SC_TEXTTOCOLUMNS)
211 pNames[4] = OUString( FROM_ROW );
212 pNames[5] = OUString( CHAR_SET );
213 pNames[6] = OUString( QUOTED_AS_TEXT );
214 pNames[7] = OUString( DETECT_SPECIAL_NUM );
215 pNames[8] = OUString( LANGUAGE );
217 aValues = aItem.GetProperties( aNames );
218 pProperties = aValues.getArray();
219 ScUnoHelpFunctions::SetBoolInAny( pProperties[0], bMergeDelimiters );
220 pProperties[1] <<= sFieldSeparators;
221 pProperties[2] <<= sTextSeparators;
222 ScUnoHelpFunctions::SetBoolInAny( pProperties[3], bFixedWidth );
223 if (eCall != SC_TEXTTOCOLUMNS)
225 pProperties[4] <<= nFromRow;
226 pProperties[5] <<= nCharSet;
227 pProperties[6] <<= static_cast<sal_Bool>(bQuotedAsText);
228 pProperties[7] <<= static_cast<sal_Bool>(bDetectSpecialNum);
229 pProperties[8] <<= nLanguage;
232 aItem.PutProperties(aNames, aValues);
235 // ----------------------------------------------------------------------------
237 ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
238 SvStream* pInStream, ScImportAsciiCall eCall ) :
239 ModalDialog (pParent, "TextImportCsvDialog",
240 "modules/scalc/ui/textimportcsv.ui"),
241 mpDatStream ( pInStream ),
242 mnStreamPos( pInStream ? pInStream->Tell() : 0 ),
244 mpRowPosArray( NULL ),
245 mnRowPosCount(0),
247 aCharSetUser( ScResId( SCSTR_CHARSET_USER ) ),
248 aColumnUser ( ScResId( SCSTR_COLUMN_USER ) ),
249 aTextSepList( ScResId( SCSTR_TEXTSEP ) ),
250 mcTextSep ( ScAsciiOptions::cDefaultTextSep ),
251 meCall(eCall)
253 get(pFtCharSet, "textcharset");
254 get(pLbCharSet, "charset");
255 pLbCharSet->SetStyle(pLbCharSet->GetStyle() | WB_SORT);
256 get(pFtCustomLang, "textlanguage");
257 get(pLbCustomLang, "language");
258 pLbCustomLang->SetStyle(pLbCustomLang->GetStyle() | WB_SORT);
259 get(pFtRow, "textfromrow");
260 get(pNfRow, "fromrow");
261 get(pRbFixed, "tofixedwidth");
262 get(pRbSeparated, "toseparatedby");
263 get(pCkbTab, "tab");
264 get(pCkbSemicolon, "semicolon");
265 get(pCkbComma, "comma");
266 get(pCkbSpace, "space");
267 get(pCkbOther, "other");
268 get(pEdOther, "inputother");
269 get(pCkbAsOnce, "mergedelimiters");
270 get(pFtTextSep, "texttextdelimiter");
271 get(pCbTextSep, "textdelimiter");
272 get(pCkbQuotedAsText, "quotedfieldastext");
273 get(pCkbDetectNumber, "detectspecialnumbers");
274 get(pFtType, "textcolumntype");
275 get(pLbType, "columntype");
276 get(mpTableBox, "scrolledwindowcolumntype");
278 String aName = GetText();
279 switch (meCall)
281 case SC_TEXTTOCOLUMNS:
282 SetText( get<FixedText>("textalttitle")->GetText() );
283 break;
284 case SC_IMPORTFILE:
285 aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - ["));
286 aName += aDatName;
287 aName += ']';
288 default:
289 SetText( aName );
292 // Default options are set in officecfg/registry/schema/org/openoffice/Office/Calc.xcs
293 OUString sFieldSeparators(",;\t");
294 OUString sTextSeparators(mcTextSep);
295 bool bMergeDelimiters = false;
296 bool bFixedWidth = false;
297 bool bQuotedFieldAsText = false;
298 bool bDetectSpecialNum = true;
299 sal_Int32 nFromRow = 1;
300 sal_Int32 nCharSet = -1;
301 sal_Int32 nLanguage = 0;
302 load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
303 bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage, meCall);
304 // load from saved settings
305 maFieldSeparators = String(sFieldSeparators);
307 if( bMergeDelimiters )
308 pCkbAsOnce->Check();
309 if (bQuotedFieldAsText)
310 pCkbQuotedAsText->Check();
311 if (bDetectSpecialNum)
312 pCkbDetectNumber->Check();
313 if( bFixedWidth )
314 pRbFixed->Check();
315 if( nFromRow != 1 )
316 pNfRow->SetValue( nFromRow );
318 // Set Separators in the dialog from maFieldSeparators (empty are not set)
319 SetSeparators();
321 // Get Separators from the dialog (empty are set from default)
322 maFieldSeparators = GetSeparators();
324 // Clipboard is always Unicode, else detect.
325 rtl_TextEncoding ePreselectUnicode = (meCall == SC_IMPORTFILE ?
326 RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE);
327 // Sniff for Unicode / not
328 if( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW && mpDatStream )
330 Seek( 0 );
331 mpDatStream->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW );
332 sal_uLong nUniPos = mpDatStream->Tell();
333 switch (nUniPos)
335 case 2:
336 ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16
337 break;
338 case 3:
339 ePreselectUnicode = RTL_TEXTENCODING_UTF8; // UTF-8
340 break;
341 case 0:
343 sal_uInt16 n;
344 *mpDatStream >> n;
345 // Assume that normal ASCII/ANSI/ISO/etc. text doesn't start with
346 // control characters except CR,LF,TAB
347 if ( (n & 0xff00) < 0x2000 )
349 switch ( n & 0xff00 )
351 case 0x0900 :
352 case 0x0a00 :
353 case 0x0d00 :
354 break;
355 default:
356 ePreselectUnicode = RTL_TEXTENCODING_UNICODE; // UTF-16
359 mpDatStream->Seek(0);
361 break;
362 default:
363 ; // nothing
365 mnStreamPos = mpDatStream->Tell();
368 pNfRow->SetModifyHdl( LINK( this, ScImportAsciiDlg, FirstRowHdl ) );
370 // *** Separator characters ***
371 lcl_FillCombo( *pCbTextSep, aTextSepList, mcTextSep );
372 pCbTextSep->SetText( sTextSeparators );
374 Link aSeparatorHdl =LINK( this, ScImportAsciiDlg, SeparatorHdl );
375 pCbTextSep->SetSelectHdl( aSeparatorHdl );
376 pCbTextSep->SetModifyHdl( aSeparatorHdl );
377 pCkbTab->SetClickHdl( aSeparatorHdl );
378 pCkbSemicolon->SetClickHdl( aSeparatorHdl );
379 pCkbComma->SetClickHdl( aSeparatorHdl );
380 pCkbAsOnce->SetClickHdl( aSeparatorHdl );
381 pCkbQuotedAsText->SetClickHdl( aSeparatorHdl );
382 pCkbDetectNumber->SetClickHdl( aSeparatorHdl );
383 pCkbSpace->SetClickHdl( aSeparatorHdl );
384 pCkbOther->SetClickHdl( aSeparatorHdl );
385 pEdOther->SetModifyHdl( aSeparatorHdl );
387 // *** text encoding ListBox ***
388 // all encodings allowed, including Unicode, but subsets are excluded
389 pLbCharSet->FillFromTextEncodingTable( sal_True );
390 // Insert one "SYSTEM" entry for compatibility in AsciiOptions and system
391 // independent document linkage.
392 pLbCharSet->InsertTextEncoding( RTL_TEXTENCODING_DONTKNOW, aCharSetUser );
393 pLbCharSet->SelectTextEncoding( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW ?
394 osl_getThreadTextEncoding() : ePreselectUnicode );
396 if( nCharSet >= 0 && ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW )
397 pLbCharSet->SelectEntryPos( static_cast<sal_uInt16>(nCharSet) );
399 SetSelectedCharSet();
400 pLbCharSet->SetSelectHdl( LINK( this, ScImportAsciiDlg, CharSetHdl ) );
402 pLbCustomLang->SetLanguageList(
403 LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, false, false);
404 pLbCustomLang->InsertLanguage(LANGUAGE_SYSTEM);
405 pLbCustomLang->SelectLanguage(static_cast<LanguageType>(nLanguage), true);
407 // *** column type ListBox ***
408 xub_StrLen nCount = comphelper::string::getTokenCount(aColumnUser, ';');
409 for (xub_StrLen i=0; i<nCount; i++)
410 pLbType->InsertEntry( aColumnUser.GetToken( i ) );
412 pLbType->SetSelectHdl( LINK( this, ScImportAsciiDlg, LbColTypeHdl ) );
413 pFtType->Disable();
414 pLbType->Disable();
416 // *** table box preview ***
417 mpTableBox->Init();
418 mpTableBox->SetUpdateTextHdl( LINK( this, ScImportAsciiDlg, UpdateTextHdl ) );
419 mpTableBox->InitTypes( *pLbType );
420 mpTableBox->SetColTypeHdl( LINK( this, ScImportAsciiDlg, ColTypeHdl ) );
422 pRbSeparated->SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
423 pRbFixed->SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
425 SetupSeparatorCtrls();
426 RbSepFixHdl( pRbFixed );
428 UpdateVertical();
430 mpTableBox->Execute( CSVCMD_NEWCELLTEXTS );
432 pEdOther->SetAccessibleName(pCkbOther->GetText());
433 pEdOther->SetAccessibleRelationLabeledBy(pCkbOther);
435 if (meCall == SC_TEXTTOCOLUMNS)
437 pFtCharSet->Disable();
438 pLbCharSet->Disable();
439 pFtCustomLang->Disable();
440 pLbCustomLang->SelectLanguage(LANGUAGE_SYSTEM);
441 pLbCustomLang->Disable();
442 pFtRow->Disable();
443 pNfRow->Disable();
445 // Quoted field as text option is not used for text-to-columns mode.
446 pCkbQuotedAsText->Check(false);
447 pCkbQuotedAsText->Disable();
449 // Always detect special numbers for text-to-columns mode.
450 pCkbDetectNumber->Check();
451 pCkbDetectNumber->Disable();
456 ScImportAsciiDlg::~ScImportAsciiDlg()
458 delete[] mpRowPosArray;
462 // ----------------------------------------------------------------------------
464 bool ScImportAsciiDlg::GetLine( sal_uLong nLine, OUString &rText )
466 if (nLine >= ASCIIDLG_MAXROWS || !mpDatStream)
467 return false;
469 bool bRet = true;
470 bool bFixed = pRbFixed->IsChecked();
472 if (!mpRowPosArray)
473 mpRowPosArray = new sal_uLong[ASCIIDLG_MAXROWS + 2];
475 if (!mnRowPosCount) // complete re-fresh
477 memset( mpRowPosArray, 0, sizeof(mpRowPosArray[0]) * (ASCIIDLG_MAXROWS+2));
479 Seek(0);
480 mpDatStream->StartReadingUnicodeText( mpDatStream->GetStreamCharSet() );
482 mnStreamPos = mpDatStream->Tell();
483 mpRowPosArray[mnRowPosCount] = mnStreamPos;
486 if (nLine >= mnRowPosCount)
488 // need to work out some more line information
491 if (!Seek( mpRowPosArray[mnRowPosCount]) ||
492 mpDatStream->GetError() != ERRCODE_NONE ||
493 mpDatStream->IsEof())
495 bRet = false;
496 break;
498 rText = ReadCsvLine(*mpDatStream, !bFixed, maFieldSeparators,
499 mcTextSep);
500 mnStreamPos = mpDatStream->Tell();
501 mpRowPosArray[++mnRowPosCount] = mnStreamPos;
502 } while (nLine >= mnRowPosCount &&
503 mpDatStream->GetError() == ERRCODE_NONE &&
504 !mpDatStream->IsEof());
505 if (mpDatStream->IsEof() &&
506 mnStreamPos == mpRowPosArray[mnRowPosCount-1])
508 // the very end, not even an empty line read
509 bRet = false;
510 --mnRowPosCount;
513 else
515 Seek( mpRowPosArray[nLine]);
516 rText = ReadCsvLine(*mpDatStream, !bFixed, maFieldSeparators, mcTextSep);
517 mnStreamPos = mpDatStream->Tell();
520 // If the file content isn't unicode, ReadUniStringLine
521 // may try to seek beyond the file's end and cause a CANTSEEK error
522 // (depending on the stream type). The error code has to be cleared,
523 // or further read operations (including non-unicode) will fail.
524 if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK )
525 mpDatStream->ResetError();
527 ScImportExport::EmbeddedNullTreatment( rText);
529 return bRet;
533 void ScImportAsciiDlg::GetOptions( ScAsciiOptions& rOpt )
535 rOpt.SetCharSet( meCharSet );
536 rOpt.SetCharSetSystem( mbCharSetSystem );
537 rOpt.SetLanguage(pLbCustomLang->GetSelectLanguage());
538 rOpt.SetFixedLen( pRbFixed->IsChecked() );
539 rOpt.SetStartRow( (long)pNfRow->GetValue() );
540 mpTableBox->FillColumnData( rOpt );
541 if( pRbSeparated->IsChecked() )
543 rOpt.SetFieldSeps( GetSeparators() );
544 rOpt.SetMergeSeps( pCkbAsOnce->IsChecked() );
545 rOpt.SetTextSep( lcl_CharFromCombo( *pCbTextSep, aTextSepList ) );
548 rOpt.SetQuotedAsText(pCkbQuotedAsText->IsChecked());
549 rOpt.SetDetectSpecialNumber(pCkbDetectNumber->IsChecked());
552 void ScImportAsciiDlg::SaveParameters()
554 save_Separators( maFieldSeparators, pCbTextSep->GetText(), pCkbAsOnce->IsChecked(),
555 pCkbQuotedAsText->IsChecked(), pCkbDetectNumber->IsChecked(),
556 pRbFixed->IsChecked(),
557 static_cast<sal_Int32>(pNfRow->GetValue()),
558 static_cast<sal_Int32>(pLbCharSet->GetSelectEntryPos()),
559 static_cast<sal_Int32>(pLbCustomLang->GetSelectLanguage()), meCall );
562 void ScImportAsciiDlg::SetSeparators()
564 OString sString(OUStringToOString(maFieldSeparators,
565 RTL_TEXTENCODING_MS_1252));
566 const sal_Char *aSep = sString.getStr();
567 int len = maFieldSeparators.Len();
568 for (int i = 0; i < len; ++i)
570 switch( aSep[i] )
572 case '\t': pCkbTab->Check(); break;
573 case ';': pCkbSemicolon->Check(); break;
574 case ',': pCkbComma->Check(); break;
575 case ' ': pCkbSpace->Check(); break;
576 default:
577 pCkbOther->Check();
578 pEdOther->SetText( pEdOther->GetText() + OUString( aSep[i] ) );
583 void ScImportAsciiDlg::SetSelectedCharSet()
585 meCharSet = pLbCharSet->GetSelectTextEncoding();
586 mbCharSetSystem = (meCharSet == RTL_TEXTENCODING_DONTKNOW);
587 if( mbCharSetSystem )
588 meCharSet = osl_getThreadTextEncoding();
591 String ScImportAsciiDlg::GetSeparators() const
593 String aSepChars;
594 if( pCkbTab->IsChecked() )
595 aSepChars += '\t';
596 if( pCkbSemicolon->IsChecked() )
597 aSepChars += ';';
598 if( pCkbComma->IsChecked() )
599 aSepChars += ',';
600 if( pCkbSpace->IsChecked() )
601 aSepChars += ' ';
602 if( pCkbOther->IsChecked() )
603 aSepChars += pEdOther->GetText();
604 return aSepChars;
607 void ScImportAsciiDlg::SetupSeparatorCtrls()
609 sal_Bool bEnable = pRbSeparated->IsChecked();
610 pCkbTab->Enable( bEnable );
611 pCkbSemicolon->Enable( bEnable );
612 pCkbComma->Enable( bEnable );
613 pCkbSpace->Enable( bEnable );
614 pCkbOther->Enable( bEnable );
615 pEdOther->Enable( bEnable );
616 pCkbAsOnce->Enable( bEnable );
617 pFtTextSep->Enable( bEnable );
618 pCbTextSep->Enable( bEnable );
621 void ScImportAsciiDlg::UpdateVertical()
623 mnRowPosCount = 0;
624 if (mpDatStream)
625 mpDatStream->SetStreamCharSet(meCharSet);
629 // ----------------------------------------------------------------------------
631 IMPL_LINK( ScImportAsciiDlg, RbSepFixHdl, RadioButton*, pButton )
633 OSL_ENSURE( pButton, "ScImportAsciiDlg::RbSepFixHdl - missing sender" );
635 if( (pButton == pRbFixed) || (pButton == pRbSeparated) )
637 SetPointer( Pointer( POINTER_WAIT ) );
638 if( pRbFixed->IsChecked() )
639 mpTableBox->SetFixedWidthMode();
640 else
641 mpTableBox->SetSeparatorsMode();
642 SetPointer( Pointer( POINTER_ARROW ) );
644 SetupSeparatorCtrls();
646 return 0;
649 IMPL_LINK( ScImportAsciiDlg, SeparatorHdl, Control*, pCtrl )
651 OSL_ENSURE( pCtrl, "ScImportAsciiDlg::SeparatorHdl - missing sender" );
652 OSL_ENSURE( !pRbFixed->IsChecked(), "ScImportAsciiDlg::SeparatorHdl - not allowed in fixed width" );
654 /* #i41550# First update state of the controls. The GetSeparators()
655 function needs final state of the check boxes. */
656 if( (pCtrl == pCkbOther) && pCkbOther->IsChecked() )
657 pEdOther->GrabFocus();
658 else if( pCtrl == pEdOther )
659 pCkbOther->Check( !pEdOther->GetText().isEmpty() );
661 String aOldFldSeps( maFieldSeparators);
662 maFieldSeparators = GetSeparators();
663 sal_Unicode cOldSep = mcTextSep;
664 mcTextSep = lcl_CharFromCombo( *pCbTextSep, aTextSepList );
665 // Any separator changed may result in completely different lines due to
666 // embedded line breaks.
667 if (cOldSep != mcTextSep || aOldFldSeps != maFieldSeparators)
668 UpdateVertical();
670 mpTableBox->Execute( CSVCMD_NEWCELLTEXTS );
671 return 0;
674 IMPL_LINK( ScImportAsciiDlg, CharSetHdl, SvxTextEncodingBox*, pCharSetBox )
676 OSL_ENSURE( pCharSetBox, "ScImportAsciiDlg::CharSetHdl - missing sender" );
678 if( (pCharSetBox == pLbCharSet) && (pCharSetBox->GetSelectEntryCount() == 1) )
680 SetPointer( Pointer( POINTER_WAIT ) );
681 CharSet eOldCharSet = meCharSet;
682 SetSelectedCharSet();
683 // switching char-set invalidates 8bit -> String conversions
684 if (eOldCharSet != meCharSet)
685 UpdateVertical();
687 mpTableBox->Execute( CSVCMD_NEWCELLTEXTS );
688 SetPointer( Pointer( POINTER_ARROW ) );
690 return 0;
693 IMPL_LINK( ScImportAsciiDlg, FirstRowHdl, NumericField*, pNumField )
695 OSL_ENSURE( pNumField, "ScImportAsciiDlg::FirstRowHdl - missing sender" );
696 mpTableBox->Execute( CSVCMD_SETFIRSTIMPORTLINE, sal::static_int_cast<sal_Int32>( pNumField->GetValue() - 1 ) );
697 return 0;
700 IMPL_LINK( ScImportAsciiDlg, LbColTypeHdl, ListBox*, pListBox )
702 OSL_ENSURE( pListBox, "ScImportAsciiDlg::LbColTypeHdl - missing sender" );
703 if( pListBox == pLbType )
704 mpTableBox->Execute( CSVCMD_SETCOLUMNTYPE, pListBox->GetSelectEntryPos() );
705 return 0;
708 IMPL_LINK_NOARG(ScImportAsciiDlg, UpdateTextHdl)
710 sal_Int32 nBaseLine = mpTableBox->GetFirstVisLine();
711 sal_Int32 nRead = mpTableBox->GetVisLineCount();
712 // If mnRowPosCount==0, this is an initializing call, read ahead for row
713 // count and resulting scroll bar size and position to be able to scroll at
714 // all. When adding lines, read only the amount of next lines to be
715 // displayed.
716 if (!mnRowPosCount || nRead > CSV_PREVIEW_LINES)
717 nRead = CSV_PREVIEW_LINES;
719 sal_Int32 i;
720 for (i = 0; i < nRead; i++)
722 if (!GetLine( nBaseLine + i, maPreviewLine[i]))
723 break;
725 for (; i < CSV_PREVIEW_LINES; i++)
726 maPreviewLine[i] = OUString();
728 mpTableBox->Execute( CSVCMD_SETLINECOUNT, mnRowPosCount);
729 bool bMergeSep = (pCkbAsOnce->IsChecked() == sal_True);
730 mpTableBox->SetUniStrings( maPreviewLine, maFieldSeparators, mcTextSep, bMergeSep);
732 return 0;
735 IMPL_LINK( ScImportAsciiDlg, ColTypeHdl, ScCsvTableBox*, pTableBox )
737 OSL_ENSURE( pTableBox, "ScImportAsciiDlg::ColTypeHdl - missing sender" );
739 sal_Int32 nType = pTableBox->GetSelColumnType();
740 sal_Int32 nTypeCount = pLbType->GetEntryCount();
741 bool bEmpty = (nType == CSV_TYPE_MULTI);
742 bool bEnable = ((0 <= nType) && (nType < nTypeCount)) || bEmpty;
744 pFtType->Enable( bEnable );
745 pLbType->Enable( bEnable );
747 Link aSelHdl = pLbType->GetSelectHdl();
748 pLbType->SetSelectHdl( Link() );
749 if( bEmpty )
750 pLbType->SetNoSelection();
751 else if( bEnable )
752 pLbType->SelectEntryPos( static_cast< sal_uInt16 >( nType ) );
753 pLbType->SetSelectHdl( aSelHdl );
755 return 0;
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */