merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / dbgui / scuiasciiopt.cxx
blobe18b420348e842b85f8039a35578519f9d9065bb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scuiasciiopt.cxx,v $
10 * $Revision: 1.14 $
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
36 #include "global.hxx"
37 #include "scresid.hxx"
38 #include "impex.hxx"
39 #include "scuiasciiopt.hxx"
40 #include "asciiopt.hrc"
41 #include <tools/debug.hxx>
42 #include <rtl/tencinfo.h>
43 #include <unotools/transliterationwrapper.hxx>
44 // ause
45 #include "editutil.hxx"
47 #include <optutil.hxx>
48 #include <com/sun/star/uno/Any.hxx>
49 #include <com/sun/star/uno/Sequence.hxx>
50 #include "miscuno.hxx"
53 //! TODO make dynamic
54 #ifdef WIN
55 const SCSIZE ASCIIDLG_MAXROWS = 10000;
56 #else
57 const SCSIZE ASCIIDLG_MAXROWS = MAXROWCOUNT;
58 #endif
61 using namespace rtl;
62 using namespace com::sun::star::uno;
64 // Defines - CSV Import Preserve Options
65 #define FIXED_WIDTH "FixedWidth"
66 #define FROM_ROW "FromRow"
67 #define CHAR_SET "CharSet"
68 #define SEPARATORS "Separators"
69 #define TEXT_SEPARATORS "TextSeparators"
70 #define MERGE_DELIMITERS "MergeDelimiters"
71 #define QUOTED_AS_TEXT "QuotedFieldAsText"
72 #define DETECT_SPECIAL_NUM "DetectSpecialNumbers"
73 #define LANGUAGE "Language"
74 #define SEP_PATH "Office.Calc/Dialogs/CSVImport"
76 // ============================================================================
78 void lcl_FillCombo( ComboBox& rCombo, const String& rList, sal_Unicode cSelect )
80 xub_StrLen i;
81 xub_StrLen nCount = rList.GetTokenCount('\t');
82 for ( i=0; i<nCount; i+=2 )
83 rCombo.InsertEntry( rList.GetToken(i,'\t') );
85 if ( cSelect )
87 String aStr;
88 for ( i=0; i<nCount; i+=2 )
89 if ( (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32() == cSelect )
90 aStr = rList.GetToken(i,'\t');
91 if (!aStr.Len())
92 aStr = cSelect; // Ascii
94 rCombo.SetText(aStr);
98 sal_Unicode lcl_CharFromCombo( ComboBox& rCombo, const String& rList )
100 sal_Unicode c = 0;
101 String aStr = rCombo.GetText();
102 if ( aStr.Len() )
104 xub_StrLen nCount = rList.GetTokenCount('\t');
105 for ( xub_StrLen i=0; i<nCount; i+=2 )
107 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rList.GetToken(i,'\t') ) )//CHINA001 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rList.GetToken(i,'\t') ) )
108 c = (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32();
110 if (!c && aStr.Len())
112 sal_Unicode cFirst = aStr.GetChar( 0 );
113 // #i24235# first try the first character of the string directly
114 if( (aStr.Len() == 1) || (cFirst < '0') || (cFirst > '9') )
115 c = cFirst;
116 else // keep old behaviour for compatibility (i.e. "39" -> "'")
117 c = (sal_Unicode) aStr.ToInt32(); // Ascii
120 return c;
123 static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparators,
124 bool &bMergeDelimiters, bool& bQuotedAsText, bool& bDetectSpecialNum,
125 bool &bFixedWidth, sal_Int32 &nFromRow, sal_Int32 &nCharSet,
126 sal_Int32& nLanguage )
128 Sequence<Any>aValues;
129 const Any *pProperties;
130 Sequence<OUString> aNames(9);
131 OUString* pNames = aNames.getArray();
132 ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) );
134 pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS );
135 pNames[1] = OUString::createFromAscii( SEPARATORS );
136 pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS );
137 pNames[3] = OUString::createFromAscii( FIXED_WIDTH );
138 pNames[4] = OUString::createFromAscii( FROM_ROW );
139 pNames[5] = OUString::createFromAscii( CHAR_SET );
140 pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT );
141 pNames[7] = OUString::createFromAscii( DETECT_SPECIAL_NUM );
142 pNames[8] = OUString::createFromAscii( LANGUAGE );
143 aValues = aItem.GetProperties( aNames );
144 pProperties = aValues.getConstArray();
145 if( pProperties[1].hasValue() )
146 pProperties[1] >>= sFieldSeparators;
148 if( pProperties[2].hasValue() )
149 pProperties[2] >>= sTextSeparators;
151 if( pProperties[0].hasValue() )
152 bMergeDelimiters = ScUnoHelpFunctions::GetBoolFromAny( pProperties[0] );
154 if( pProperties[3].hasValue() )
155 bFixedWidth = ScUnoHelpFunctions::GetBoolFromAny( pProperties[3] );
157 if( pProperties[4].hasValue() )
158 pProperties[4] >>= nFromRow;
160 if( pProperties[5].hasValue() )
161 pProperties[5] >>= nCharSet;
163 if ( pProperties[6].hasValue() )
164 pProperties[6] >>= bQuotedAsText;
166 if ( pProperties[7].hasValue() )
167 pProperties[7] >>= bDetectSpecialNum;
169 if ( pProperties[8].hasValue() )
170 pProperties[8] >>= nLanguage;
173 static void save_Separators(
174 String maSeparators, String maTxtSep, bool bMergeDelimiters, bool bQuotedAsText,
175 bool bDetectSpecialNum, bool bFixedWidth, sal_Int32 nFromRow, sal_Int32 nCharSet, sal_Int32 nLanguage )
177 OUString sFieldSeparators = OUString( maSeparators );
178 OUString sTextSeparators = OUString( maTxtSep );
179 Sequence<Any> aValues;
180 Any *pProperties;
181 Sequence<OUString> aNames(9);
182 OUString* pNames = aNames.getArray();
183 ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) );
185 pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS );
186 pNames[1] = OUString::createFromAscii( SEPARATORS );
187 pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS );
188 pNames[3] = OUString::createFromAscii( FIXED_WIDTH );
189 pNames[4] = OUString::createFromAscii( FROM_ROW );
190 pNames[5] = OUString::createFromAscii( CHAR_SET );
191 pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT );
192 pNames[7] = OUString::createFromAscii( DETECT_SPECIAL_NUM );
193 pNames[8] = OUString::createFromAscii( LANGUAGE );
194 aValues = aItem.GetProperties( aNames );
195 pProperties = aValues.getArray();
196 pProperties[1] <<= sFieldSeparators;
197 pProperties[2] <<= sTextSeparators;
198 ScUnoHelpFunctions::SetBoolInAny( pProperties[0], bMergeDelimiters );
199 ScUnoHelpFunctions::SetBoolInAny( pProperties[3], bFixedWidth );
200 pProperties[4] <<= nFromRow;
201 pProperties[5] <<= nCharSet;
202 pProperties[6] <<= static_cast<sal_Bool>(bQuotedAsText);
203 pProperties[7] <<= static_cast<sal_Bool>(bDetectSpecialNum);
204 pProperties[8] <<= nLanguage;
206 aItem.PutProperties(aNames, aValues);
209 // ----------------------------------------------------------------------------
211 ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
212 SvStream* pInStream, sal_Unicode /*cSep*/ ) :
213 ModalDialog ( pParent, ScResId( RID_SCDLG_ASCII ) ),
214 mpDatStream ( pInStream ),
215 mnStreamPos( pInStream ? pInStream->Tell() : 0 ),
217 mpRowPosArray( NULL ),
218 mnRowPosCount(0),
220 aFlFieldOpt ( this, ScResId( FL_FIELDOPT ) ),
221 aFtCharSet ( this, ScResId( FT_CHARSET ) ),
222 aLbCharSet ( this, ScResId( LB_CHARSET ) ),
223 aFtCustomLang( this, ScResId( FT_CUSTOMLANG ) ),
224 aLbCustomLang( this, ScResId( LB_CUSTOMLANG ) ),
226 aFtRow ( this, ScResId( FT_AT_ROW ) ),
227 aNfRow ( this, ScResId( NF_AT_ROW ) ),
229 aFlSepOpt ( this, ScResId( FL_SEPOPT ) ),
230 aRbFixed ( this, ScResId( RB_FIXED ) ),
231 aRbSeparated( this, ScResId( RB_SEPARATED ) ),
233 aCkbTab ( this, ScResId( CKB_TAB ) ),
234 aCkbSemicolon(this, ScResId( CKB_SEMICOLON ) ),
235 aCkbComma ( this, ScResId( CKB_COMMA ) ),
236 aCkbSpace ( this, ScResId( CKB_SPACE ) ),
237 aCkbOther ( this, ScResId( CKB_OTHER ) ),
238 aEdOther ( this, ScResId( ED_OTHER ) ),
239 aCkbAsOnce ( this, ScResId( CB_ASONCE) ),
240 aFlOtherOpt ( this, ScResId( FL_OTHER_OPTIONS ) ),
242 aCkbQuotedAsText( this, ScResId(CB_QUOTED_AS_TEXT) ),
243 aCkbDetectNumber( this, ScResId(CB_DETECT_SPECIAL_NUMBER) ),
244 aFtTextSep ( this, ScResId( FT_TEXTSEP ) ),
245 aCbTextSep ( this, ScResId( CB_TEXTSEP ) ),
247 aFlWidth ( this, ScResId( FL_WIDTH ) ),
248 aFtType ( this, ScResId( FT_TYPE ) ),
249 aLbType ( this, ScResId( LB_TYPE1 ) ),
251 maTableBox ( this, ScResId( CTR_TABLEBOX ) ),
253 aBtnOk ( this, ScResId( BTN_OK ) ),
254 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
255 aBtnHelp ( this, ScResId( BTN_HELP ) ),
257 aCharSetUser( ScResId( SCSTR_CHARSET_USER ) ),
258 aColumnUser ( ScResId( SCSTR_COLUMN_USER ) ),
259 aFldSepList ( ScResId( SCSTR_FIELDSEP ) ),
260 aTextSepList( ScResId( SCSTR_TEXTSEP ) ),
261 mcTextSep ( ScAsciiOptions::cDefaultTextSep ),
262 maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ),
263 mbFileImport(true)
265 FreeResource();
266 mbFileImport = aDatName.Len() > 0;
268 String aName = GetText();
269 // aDatName is empty if invoked during paste from clipboard.
270 if (mbFileImport)
272 aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - ["));
273 aName += aDatName;
274 aName += ']';
276 SetText( aName );
279 OUString sFieldSeparators;
280 OUString sTextSeparators;
281 bool bMergeDelimiters = false;
282 bool bFixedWidth = false;
283 bool bQuotedFieldAsText = true;
284 bool bDetectSpecialNum = false;
285 sal_Int32 nFromRow = 1;
286 sal_Int32 nCharSet = -1;
287 sal_Int32 nLanguage = 0;
288 if (mbFileImport)
289 // load separators only when importing csv files.
290 load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
291 bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage);
292 maFieldSeparators = String(sFieldSeparators);
294 if( bMergeDelimiters )
295 aCkbAsOnce.Check();
296 if (bQuotedFieldAsText)
297 aCkbQuotedAsText.Check();
298 if (bDetectSpecialNum)
299 aCkbDetectNumber.Check();
300 if( bFixedWidth )
301 aRbFixed.Check();
302 if( nFromRow != 1 )
303 aNfRow.SetValue( nFromRow );
305 ByteString bString(maFieldSeparators,RTL_TEXTENCODING_MS_1252);
306 const sal_Char *aSep = bString.GetBuffer();
307 int len = maFieldSeparators.Len();
308 for (int i = 0; i < len; ++i)
310 switch( aSep[i] )
312 case '\t': aCkbTab.Check(); break;
313 case ';': aCkbSemicolon.Check(); break;
314 case ',': aCkbComma.Check(); break;
315 case ' ': aCkbSpace.Check(); break;
316 default:
317 aCkbOther.Check();
318 aEdOther.SetText( aEdOther.GetText() + OUString( aSep[i] ) );
322 // Get Separators from the dialog
323 maFieldSeparators = GetSeparators();
325 // Clipboard is always Unicode, else detect.
326 bool bPreselectUnicode = !mbFileImport;
327 // Sniff for Unicode / not
328 if( !bPreselectUnicode && mpDatStream )
330 Seek( 0 );
331 mpDatStream->StartReadingUnicodeText();
332 ULONG nUniPos = mpDatStream->Tell();
333 if ( nUniPos > 0 )
334 bPreselectUnicode = TRUE; // read 0xfeff/0xfffe
335 else
337 UINT16 n;
338 *mpDatStream >> n;
339 // Assume that normal ASCII/ANSI/ISO/etc. text doesn't start with
340 // control characters except CR,LF,TAB
341 if ( (n & 0xff00) < 0x2000 )
343 switch ( n & 0xff00 )
345 case 0x0900 :
346 case 0x0a00 :
347 case 0x0d00 :
348 break;
349 default:
350 bPreselectUnicode = TRUE;
353 mpDatStream->Seek(0);
355 mnStreamPos = mpDatStream->Tell();
358 aNfRow.SetModifyHdl( LINK( this, ScImportAsciiDlg, FirstRowHdl ) );
360 // *** Separator characters ***
361 lcl_FillCombo( aCbTextSep, aTextSepList, mcTextSep );
362 aCbTextSep.SetText( sTextSeparators );
364 Link aSeparatorHdl =LINK( this, ScImportAsciiDlg, SeparatorHdl );
365 aCbTextSep.SetSelectHdl( aSeparatorHdl );
366 aCbTextSep.SetModifyHdl( aSeparatorHdl );
367 aCkbTab.SetClickHdl( aSeparatorHdl );
368 aCkbSemicolon.SetClickHdl( aSeparatorHdl );
369 aCkbComma.SetClickHdl( aSeparatorHdl );
370 aCkbAsOnce.SetClickHdl( aSeparatorHdl );
371 aCkbQuotedAsText.SetClickHdl( aSeparatorHdl );
372 aCkbDetectNumber.SetClickHdl( aSeparatorHdl );
373 aCkbSpace.SetClickHdl( aSeparatorHdl );
374 aCkbOther.SetClickHdl( aSeparatorHdl );
375 aEdOther.SetModifyHdl( aSeparatorHdl );
377 // *** text encoding ListBox ***
378 // all encodings allowed, including Unicode, but subsets are excluded
379 aLbCharSet.FillFromTextEncodingTable( TRUE );
380 // Insert one "SYSTEM" entry for compatibility in AsciiOptions and system
381 // independent document linkage.
382 aLbCharSet.InsertTextEncoding( RTL_TEXTENCODING_DONTKNOW, aCharSetUser );
383 aLbCharSet.SelectTextEncoding( bPreselectUnicode ?
384 RTL_TEXTENCODING_UNICODE : gsl_getSystemTextEncoding() );
386 if( nCharSet >= 0 )
387 aLbCharSet.SelectEntryPos( nCharSet );
389 SetSelectedCharSet();
390 aLbCharSet.SetSelectHdl( LINK( this, ScImportAsciiDlg, CharSetHdl ) );
392 aLbCustomLang.SetLanguageList(
393 LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, false, false);
394 aLbCustomLang.InsertLanguage(LANGUAGE_SYSTEM);
395 aLbCustomLang.SelectLanguage(static_cast<LanguageType>(nLanguage), true);
397 // *** column type ListBox ***
398 xub_StrLen nCount = aColumnUser.GetTokenCount();
399 for (xub_StrLen i=0; i<nCount; i++)
400 aLbType.InsertEntry( aColumnUser.GetToken( i ) );
402 aLbType.SetSelectHdl( LINK( this, ScImportAsciiDlg, LbColTypeHdl ) );
403 aFtType.Disable();
404 aLbType.Disable();
406 // *** table box preview ***
407 maTableBox.SetUpdateTextHdl( LINK( this, ScImportAsciiDlg, UpdateTextHdl ) );
408 maTableBox.InitTypes( aLbType );
409 maTableBox.SetColTypeHdl( LINK( this, ScImportAsciiDlg, ColTypeHdl ) );
411 aRbSeparated.SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
412 aRbFixed.SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
414 SetupSeparatorCtrls();
415 RbSepFixHdl( &aRbFixed );
417 UpdateVertical();
419 maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
423 ScImportAsciiDlg::~ScImportAsciiDlg()
425 if (mbFileImport)
426 save_Separators( maFieldSeparators, aCbTextSep.GetText(), aCkbAsOnce.IsChecked(),
427 aCkbQuotedAsText.IsChecked(), aCkbDetectNumber.IsChecked(),
428 aRbFixed.IsChecked(), aNfRow.GetValue(), aLbCharSet.GetSelectEntryPos(),
429 static_cast<sal_Int32>(aLbCustomLang.GetSelectLanguage()) );
430 delete[] mpRowPosArray;
434 // ----------------------------------------------------------------------------
436 bool ScImportAsciiDlg::GetLine( ULONG nLine, String &rText )
438 if (nLine >= ASCIIDLG_MAXROWS || !mpDatStream)
439 return false;
441 bool bRet = true;
442 bool bFixed = aRbFixed.IsChecked();
444 if (!mpRowPosArray)
445 mpRowPosArray = new ULONG[ASCIIDLG_MAXROWS + 2];
447 if (!mnRowPosCount) // complete re-fresh
449 memset( mpRowPosArray, 0, sizeof(mpRowPosArray[0]) * (ASCIIDLG_MAXROWS+2));
451 Seek(0);
452 if ( mpDatStream->GetStreamCharSet() == RTL_TEXTENCODING_UNICODE )
453 mpDatStream->StartReadingUnicodeText();
455 mnStreamPos = mpDatStream->Tell();
456 mpRowPosArray[mnRowPosCount] = mnStreamPos;
459 if (nLine >= mnRowPosCount)
461 // need to work out some more line information
464 if (!Seek( mpRowPosArray[mnRowPosCount]) ||
465 mpDatStream->GetError() != ERRCODE_NONE ||
466 mpDatStream->IsEof())
468 bRet = false;
469 break;
471 mpDatStream->ReadCsvLine( rText, !bFixed, maFieldSeparators,
472 mcTextSep);
473 mnStreamPos = mpDatStream->Tell();
474 mpRowPosArray[++mnRowPosCount] = mnStreamPos;
475 } while (nLine >= mnRowPosCount &&
476 mpDatStream->GetError() == ERRCODE_NONE &&
477 !mpDatStream->IsEof());
478 if (mpDatStream->IsEof() &&
479 mnStreamPos == mpRowPosArray[mnRowPosCount-1])
481 // the very end, not even an empty line read
482 bRet = false;
483 --mnRowPosCount;
486 else
488 Seek( mpRowPosArray[nLine]);
489 mpDatStream->ReadCsvLine( rText, !bFixed, maFieldSeparators, mcTextSep);
490 mnStreamPos = mpDatStream->Tell();
493 // #107455# If the file content isn't unicode, ReadUniStringLine
494 // may try to seek beyond the file's end and cause a CANTSEEK error
495 // (depending on the stream type). The error code has to be cleared,
496 // or further read operations (including non-unicode) will fail.
497 if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK )
498 mpDatStream->ResetError();
500 return bRet;
504 void ScImportAsciiDlg::GetOptions( ScAsciiOptions& rOpt )
506 rOpt.SetCharSet( meCharSet );
507 rOpt.SetCharSetSystem( mbCharSetSystem );
508 rOpt.SetLanguage(aLbCustomLang.GetSelectLanguage());
509 rOpt.SetFixedLen( aRbFixed.IsChecked() );
510 rOpt.SetStartRow( (long)aNfRow.GetValue() );
511 maTableBox.FillColumnData( rOpt );
512 if( aRbSeparated.IsChecked() )
514 rOpt.SetFieldSeps( GetSeparators() );
515 rOpt.SetMergeSeps( aCkbAsOnce.IsChecked() );
516 rOpt.SetTextSep( lcl_CharFromCombo( aCbTextSep, aTextSepList ) );
519 rOpt.SetQuotedAsText(aCkbQuotedAsText.IsChecked());
520 rOpt.SetDetectSpecialNumber(aCkbDetectNumber.IsChecked());
523 void ScImportAsciiDlg::SetTextToColumnsMode()
525 SetText( maStrTextToColumns );
526 aFtCharSet.Disable();
527 aLbCharSet.Disable();
528 aFtCustomLang.Disable();
529 aLbCustomLang.SelectLanguage(LANGUAGE_SYSTEM);
530 aLbCustomLang.Disable();
531 aFtRow.Disable();
532 aNfRow.Disable();
534 // Quoted field as text option is not used for text-to-columns mode.
535 aCkbQuotedAsText.Check(false);
536 aCkbQuotedAsText.Disable();
538 // Always detect special numbers for text-to-columns mode.
539 aCkbDetectNumber.Check();
540 aCkbDetectNumber.Disable();
543 void ScImportAsciiDlg::SetSelectedCharSet()
545 meCharSet = aLbCharSet.GetSelectTextEncoding();
546 mbCharSetSystem = (meCharSet == RTL_TEXTENCODING_DONTKNOW);
547 if( mbCharSetSystem )
548 meCharSet = gsl_getSystemTextEncoding();
551 String ScImportAsciiDlg::GetSeparators() const
553 String aSepChars;
554 if( aCkbTab.IsChecked() )
555 aSepChars += '\t';
556 if( aCkbSemicolon.IsChecked() )
557 aSepChars += ';';
558 if( aCkbComma.IsChecked() )
559 aSepChars += ',';
560 if( aCkbSpace.IsChecked() )
561 aSepChars += ' ';
562 if( aCkbOther.IsChecked() )
563 aSepChars += aEdOther.GetText();
564 return aSepChars;
567 void ScImportAsciiDlg::SetupSeparatorCtrls()
569 BOOL bEnable = aRbSeparated.IsChecked();
570 aCkbTab.Enable( bEnable );
571 aCkbSemicolon.Enable( bEnable );
572 aCkbComma.Enable( bEnable );
573 aCkbSpace.Enable( bEnable );
574 aCkbOther.Enable( bEnable );
575 aEdOther.Enable( bEnable );
576 aCkbAsOnce.Enable( bEnable );
577 aFtTextSep.Enable( bEnable );
578 aCbTextSep.Enable( bEnable );
581 void ScImportAsciiDlg::UpdateVertical()
583 mnRowPosCount = 0;
584 if (mpDatStream)
585 mpDatStream->SetStreamCharSet(meCharSet);
589 // ----------------------------------------------------------------------------
591 IMPL_LINK( ScImportAsciiDlg, RbSepFixHdl, RadioButton*, pButton )
593 DBG_ASSERT( pButton, "ScImportAsciiDlg::RbSepFixHdl - missing sender" );
595 if( (pButton == &aRbFixed) || (pButton == &aRbSeparated) )
597 SetPointer( Pointer( POINTER_WAIT ) );
598 if( aRbFixed.IsChecked() )
599 maTableBox.SetFixedWidthMode();
600 else
601 maTableBox.SetSeparatorsMode();
602 SetPointer( Pointer( POINTER_ARROW ) );
604 SetupSeparatorCtrls();
606 return 0;
609 IMPL_LINK( ScImportAsciiDlg, SeparatorHdl, Control*, pCtrl )
611 DBG_ASSERT( pCtrl, "ScImportAsciiDlg::SeparatorHdl - missing sender" );
612 DBG_ASSERT( !aRbFixed.IsChecked(), "ScImportAsciiDlg::SeparatorHdl - not allowed in fixed width" );
614 /* #i41550# First update state of the controls. The GetSeparators()
615 function needs final state of the check boxes. */
616 if( (pCtrl == &aCkbOther) && aCkbOther.IsChecked() )
617 aEdOther.GrabFocus();
618 else if( pCtrl == &aEdOther )
619 aCkbOther.Check( aEdOther.GetText().Len() > 0 );
621 String aOldFldSeps( maFieldSeparators);
622 maFieldSeparators = GetSeparators();
623 sal_Unicode cOldSep = mcTextSep;
624 mcTextSep = lcl_CharFromCombo( aCbTextSep, aTextSepList );
625 // Any separator changed may result in completely different lines due to
626 // embedded line breaks.
627 if (cOldSep != mcTextSep || aOldFldSeps != maFieldSeparators)
628 UpdateVertical();
630 maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
631 return 0;
634 IMPL_LINK( ScImportAsciiDlg, CharSetHdl, SvxTextEncodingBox*, pCharSetBox )
636 DBG_ASSERT( pCharSetBox, "ScImportAsciiDlg::CharSetHdl - missing sender" );
638 if( (pCharSetBox == &aLbCharSet) && (pCharSetBox->GetSelectEntryCount() == 1) )
640 SetPointer( Pointer( POINTER_WAIT ) );
641 CharSet eOldCharSet = meCharSet;
642 SetSelectedCharSet();
643 // switching char-set invalidates 8bit -> String conversions
644 if (eOldCharSet != meCharSet)
645 UpdateVertical();
647 maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
648 SetPointer( Pointer( POINTER_ARROW ) );
650 return 0;
653 IMPL_LINK( ScImportAsciiDlg, FirstRowHdl, NumericField*, pNumField )
655 DBG_ASSERT( pNumField, "ScImportAsciiDlg::FirstRowHdl - missing sender" );
656 maTableBox.Execute( CSVCMD_SETFIRSTIMPORTLINE, sal::static_int_cast<sal_Int32>( pNumField->GetValue() - 1 ) );
657 return 0;
660 IMPL_LINK( ScImportAsciiDlg, LbColTypeHdl, ListBox*, pListBox )
662 DBG_ASSERT( pListBox, "ScImportAsciiDlg::LbColTypeHdl - missing sender" );
663 if( pListBox == &aLbType )
664 maTableBox.Execute( CSVCMD_SETCOLUMNTYPE, pListBox->GetSelectEntryPos() );
665 return 0;
668 IMPL_LINK( ScImportAsciiDlg, UpdateTextHdl, ScCsvTableBox*, EMPTYARG )
670 sal_Int32 nBaseLine = maTableBox.GetFirstVisLine();
671 sal_Int32 nRead = maTableBox.GetVisLineCount();
672 // If mnRowPosCount==0, this is an initializing call, read ahead for row
673 // count and resulting scroll bar size and position to be able to scroll at
674 // all. When adding lines, read only the amount of next lines to be
675 // displayed.
676 if (!mnRowPosCount || nRead > CSV_PREVIEW_LINES)
677 nRead = CSV_PREVIEW_LINES;
679 sal_Int32 i;
680 for (i = 0; i < nRead; i++)
682 if (!GetLine( nBaseLine + i, maPreviewLine[i]))
683 break;
685 for (; i < CSV_PREVIEW_LINES; i++)
686 maPreviewLine[i].Erase();
688 maTableBox.Execute( CSVCMD_SETLINECOUNT, mnRowPosCount);
689 bool bMergeSep = (aCkbAsOnce.IsChecked() == TRUE);
690 maTableBox.SetUniStrings( maPreviewLine, maFieldSeparators, mcTextSep, bMergeSep);
692 return 0;
695 IMPL_LINK( ScImportAsciiDlg, ColTypeHdl, ScCsvTableBox*, pTableBox )
697 DBG_ASSERT( pTableBox, "ScImportAsciiDlg::ColTypeHdl - missing sender" );
699 sal_Int32 nType = pTableBox->GetSelColumnType();
700 sal_Int32 nTypeCount = aLbType.GetEntryCount();
701 bool bEmpty = (nType == CSV_TYPE_MULTI);
702 bool bEnable = ((0 <= nType) && (nType < nTypeCount)) || bEmpty;
704 aFtType.Enable( bEnable );
705 aLbType.Enable( bEnable );
707 Link aSelHdl = aLbType.GetSelectHdl();
708 aLbType.SetSelectHdl( Link() );
709 if( bEmpty )
710 aLbType.SetNoSelection();
711 else if( bEnable )
712 aLbType.SelectEntryPos( static_cast< sal_uInt16 >( nType ) );
713 aLbType.SetSelectHdl( aSelHdl );
715 return 0;