xref: /aoo42x/main/sc/source/ui/dbgui/scuiasciiopt.cxx (revision a479921a)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "global.hxx"
29cdf0e10cSrcweir #include "scresid.hxx"
30cdf0e10cSrcweir #include "impex.hxx"
31cdf0e10cSrcweir #include "scuiasciiopt.hxx"
32cdf0e10cSrcweir #include "asciiopt.hrc"
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir #include <rtl/tencinfo.h>
35cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx>
36cdf0e10cSrcweir // ause
37cdf0e10cSrcweir #include "editutil.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <optutil.hxx>
40cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
41cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
42cdf0e10cSrcweir #include "miscuno.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //! TODO make dynamic
45cdf0e10cSrcweir const SCSIZE ASCIIDLG_MAXROWS                = MAXROWCOUNT;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir using namespace com::sun::star::uno;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // Defines - CSV Import Preserve Options
52cdf0e10cSrcweir #define FIXED_WIDTH         "FixedWidth"
53cdf0e10cSrcweir #define FROM_ROW            "FromRow"
54cdf0e10cSrcweir #define CHAR_SET            "CharSet"
55cdf0e10cSrcweir #define SEPARATORS          "Separators"
56cdf0e10cSrcweir #define TEXT_SEPARATORS     "TextSeparators"
57cdf0e10cSrcweir #define MERGE_DELIMITERS    "MergeDelimiters"
58cdf0e10cSrcweir #define QUOTED_AS_TEXT      "QuotedFieldAsText"
59cdf0e10cSrcweir #define DETECT_SPECIAL_NUM  "DetectSpecialNumbers"
60cdf0e10cSrcweir #define LANGUAGE            "Language"
61cdf0e10cSrcweir #define SEP_PATH            "Office.Calc/Dialogs/CSVImport"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // ============================================================================
64cdf0e10cSrcweir 
lcl_FillCombo(ComboBox & rCombo,const String & rList,sal_Unicode cSelect)65cdf0e10cSrcweir void lcl_FillCombo( ComboBox& rCombo, const String& rList, sal_Unicode cSelect )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	xub_StrLen i;
68cdf0e10cSrcweir 	xub_StrLen nCount = rList.GetTokenCount('\t');
69cdf0e10cSrcweir 	for ( i=0; i<nCount; i+=2 )
70cdf0e10cSrcweir 		rCombo.InsertEntry( rList.GetToken(i,'\t') );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	if ( cSelect )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		String aStr;
75cdf0e10cSrcweir 		for ( i=0; i<nCount; i+=2 )
76cdf0e10cSrcweir 			if ( (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32() == cSelect )
77cdf0e10cSrcweir 				aStr = rList.GetToken(i,'\t');
78cdf0e10cSrcweir 		if (!aStr.Len())
79cdf0e10cSrcweir 			aStr = cSelect;			// Ascii
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		rCombo.SetText(aStr);
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
lcl_CharFromCombo(ComboBox & rCombo,const String & rList)85cdf0e10cSrcweir sal_Unicode lcl_CharFromCombo( ComboBox& rCombo, const String& rList )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	sal_Unicode c = 0;
88cdf0e10cSrcweir 	String aStr = rCombo.GetText();
89cdf0e10cSrcweir 	if ( aStr.Len() )
90cdf0e10cSrcweir 	{
91cdf0e10cSrcweir 		xub_StrLen nCount = rList.GetTokenCount('\t');
92cdf0e10cSrcweir 		for ( xub_StrLen i=0; i<nCount; i+=2 )
93cdf0e10cSrcweir         {
94cdf0e10cSrcweir             if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rList.GetToken(i,'\t') ) )//CHINA001 if ( ScGlobal::GetpTransliteration()->isEqual( aStr, rList.GetToken(i,'\t') ) )
95cdf0e10cSrcweir 				c = (sal_Unicode)rList.GetToken(i+1,'\t').ToInt32();
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir         if (!c && aStr.Len())
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             sal_Unicode cFirst = aStr.GetChar( 0 );
100cdf0e10cSrcweir             // #i24235# first try the first character of the string directly
101cdf0e10cSrcweir             if( (aStr.Len() == 1) || (cFirst < '0') || (cFirst > '9') )
102cdf0e10cSrcweir                 c = cFirst;
103cdf0e10cSrcweir             else    // keep old behaviour for compatibility (i.e. "39" -> "'")
104cdf0e10cSrcweir                 c = (sal_Unicode) aStr.ToInt32();       // Ascii
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 	return c;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
load_Separators(OUString & sFieldSeparators,OUString & sTextSeparators,bool & bMergeDelimiters,bool & bQuotedAsText,bool & bDetectSpecialNum,bool & bFixedWidth,sal_Int32 & nFromRow,sal_Int32 & nCharSet,sal_Int32 & nLanguage)110cdf0e10cSrcweir static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparators,
111cdf0e10cSrcweir                              bool &bMergeDelimiters, bool& bQuotedAsText, bool& bDetectSpecialNum,
112cdf0e10cSrcweir                              bool &bFixedWidth, sal_Int32 &nFromRow, sal_Int32 &nCharSet,
113cdf0e10cSrcweir                              sal_Int32& nLanguage )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     Sequence<Any>aValues;
116cdf0e10cSrcweir     const Any *pProperties;
117cdf0e10cSrcweir     Sequence<OUString> aNames(9);
118cdf0e10cSrcweir     OUString* pNames = aNames.getArray();
119cdf0e10cSrcweir     ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS );
122cdf0e10cSrcweir     pNames[1] = OUString::createFromAscii( SEPARATORS );
123cdf0e10cSrcweir     pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS );
124cdf0e10cSrcweir     pNames[3] = OUString::createFromAscii( FIXED_WIDTH );
125cdf0e10cSrcweir     pNames[4] = OUString::createFromAscii( FROM_ROW );
126cdf0e10cSrcweir     pNames[5] = OUString::createFromAscii( CHAR_SET );
127cdf0e10cSrcweir     pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT );
128cdf0e10cSrcweir     pNames[7] = OUString::createFromAscii( DETECT_SPECIAL_NUM );
129cdf0e10cSrcweir     pNames[8] = OUString::createFromAscii( LANGUAGE );
130cdf0e10cSrcweir     aValues = aItem.GetProperties( aNames );
131cdf0e10cSrcweir     pProperties = aValues.getConstArray();
132cdf0e10cSrcweir     if( pProperties[1].hasValue() )
133cdf0e10cSrcweir         pProperties[1] >>= sFieldSeparators;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     if( pProperties[2].hasValue() )
136cdf0e10cSrcweir         pProperties[2] >>= sTextSeparators;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     if( pProperties[0].hasValue() )
139cdf0e10cSrcweir         bMergeDelimiters = ScUnoHelpFunctions::GetBoolFromAny( pProperties[0] );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     if( pProperties[3].hasValue() )
142cdf0e10cSrcweir         bFixedWidth = ScUnoHelpFunctions::GetBoolFromAny( pProperties[3] );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     if( pProperties[4].hasValue() )
145cdf0e10cSrcweir         pProperties[4] >>= nFromRow;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     if( pProperties[5].hasValue() )
148cdf0e10cSrcweir         pProperties[5] >>= nCharSet;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     if ( pProperties[6].hasValue() )
151cdf0e10cSrcweir         pProperties[6] >>= bQuotedAsText;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     if ( pProperties[7].hasValue() )
154cdf0e10cSrcweir         pProperties[7] >>= bDetectSpecialNum;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     if ( pProperties[8].hasValue() )
157cdf0e10cSrcweir         pProperties[8] >>= nLanguage;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
save_Separators(String maSeparators,String maTxtSep,bool bMergeDelimiters,bool bQuotedAsText,bool bDetectSpecialNum,bool bFixedWidth,sal_Int32 nFromRow,sal_Int32 nCharSet,sal_Int32 nLanguage)160cdf0e10cSrcweir static void save_Separators(
161cdf0e10cSrcweir     String maSeparators, String maTxtSep, bool bMergeDelimiters, bool bQuotedAsText,
162cdf0e10cSrcweir     bool bDetectSpecialNum, bool bFixedWidth, sal_Int32 nFromRow, sal_Int32 nCharSet, sal_Int32 nLanguage )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     OUString sFieldSeparators = OUString( maSeparators );
165cdf0e10cSrcweir     OUString sTextSeparators = OUString( maTxtSep );
166cdf0e10cSrcweir     Sequence<Any> aValues;
167cdf0e10cSrcweir     Any *pProperties;
168cdf0e10cSrcweir     Sequence<OUString> aNames(9);
169cdf0e10cSrcweir     OUString* pNames = aNames.getArray();
170cdf0e10cSrcweir     ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS );
173cdf0e10cSrcweir     pNames[1] = OUString::createFromAscii( SEPARATORS );
174cdf0e10cSrcweir     pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS );
175cdf0e10cSrcweir     pNames[3] = OUString::createFromAscii( FIXED_WIDTH );
176cdf0e10cSrcweir     pNames[4] = OUString::createFromAscii( FROM_ROW );
177cdf0e10cSrcweir     pNames[5] = OUString::createFromAscii( CHAR_SET );
178cdf0e10cSrcweir     pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT );
179cdf0e10cSrcweir     pNames[7] = OUString::createFromAscii( DETECT_SPECIAL_NUM );
180cdf0e10cSrcweir     pNames[8] = OUString::createFromAscii( LANGUAGE );
181cdf0e10cSrcweir     aValues = aItem.GetProperties( aNames );
182cdf0e10cSrcweir     pProperties = aValues.getArray();
183cdf0e10cSrcweir     pProperties[1] <<= sFieldSeparators;
184cdf0e10cSrcweir     pProperties[2] <<= sTextSeparators;
185cdf0e10cSrcweir     ScUnoHelpFunctions::SetBoolInAny( pProperties[0], bMergeDelimiters );
186cdf0e10cSrcweir     ScUnoHelpFunctions::SetBoolInAny( pProperties[3], bFixedWidth );
187cdf0e10cSrcweir     pProperties[4] <<= nFromRow;
188cdf0e10cSrcweir     pProperties[5] <<= nCharSet;
189cdf0e10cSrcweir     pProperties[6] <<= static_cast<sal_Bool>(bQuotedAsText);
190cdf0e10cSrcweir     pProperties[7] <<= static_cast<sal_Bool>(bDetectSpecialNum);
191cdf0e10cSrcweir     pProperties[8] <<= nLanguage;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     aItem.PutProperties(aNames, aValues);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir // ----------------------------------------------------------------------------
197cdf0e10cSrcweir 
ScImportAsciiDlg(Window * pParent,String aDatName,SvStream * pInStream,sal_Unicode cSep)198cdf0e10cSrcweir ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
199cdf0e10cSrcweir                                     SvStream* pInStream, sal_Unicode cSep ) :
200cdf0e10cSrcweir 		ModalDialog	( pParent, ScResId( RID_SCDLG_ASCII ) ),
201cdf0e10cSrcweir         mpDatStream  ( pInStream ),
202cdf0e10cSrcweir         mnStreamPos( pInStream ? pInStream->Tell() : 0 ),
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 		mpRowPosArray( NULL ),
205cdf0e10cSrcweir 		mnRowPosCount(0),
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         aFlFieldOpt ( this, ScResId( FL_FIELDOPT ) ),
208cdf0e10cSrcweir 		aFtCharSet	( this, ScResId( FT_CHARSET ) ),
209cdf0e10cSrcweir 		aLbCharSet	( this, ScResId( LB_CHARSET ) ),
210cdf0e10cSrcweir         aFtCustomLang( this, ScResId( FT_CUSTOMLANG ) ),
211cdf0e10cSrcweir         aLbCustomLang( this, ScResId( LB_CUSTOMLANG ) ),
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		aFtRow		( this, ScResId( FT_AT_ROW	) ),
214cdf0e10cSrcweir 		aNfRow		( this,	ScResId( NF_AT_ROW	) ),
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         aFlSepOpt   ( this, ScResId( FL_SEPOPT ) ),
217cdf0e10cSrcweir 		aRbFixed	( this, ScResId( RB_FIXED ) ),
218cdf0e10cSrcweir 		aRbSeparated( this, ScResId( RB_SEPARATED ) ),
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 		aCkbTab		( this, ScResId( CKB_TAB ) ),
221cdf0e10cSrcweir 		aCkbSemicolon(this, ScResId( CKB_SEMICOLON ) ),
222cdf0e10cSrcweir 		aCkbComma	( this, ScResId( CKB_COMMA	) ),
223cdf0e10cSrcweir 		aCkbSpace	( this,	ScResId( CKB_SPACE	 ) ),
224cdf0e10cSrcweir 		aCkbOther	( this, ScResId( CKB_OTHER ) ),
225cdf0e10cSrcweir 		aEdOther	( this, ScResId( ED_OTHER ) ),
226cdf0e10cSrcweir 		aCkbAsOnce	( this, ScResId( CB_ASONCE) ),
227cdf0e10cSrcweir         aFlOtherOpt ( this, ScResId( FL_OTHER_OPTIONS ) ),
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		aFtTextSep	( this, ScResId( FT_TEXTSEP ) ),
230cdf0e10cSrcweir 		aCbTextSep	( this, ScResId( CB_TEXTSEP ) ),
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         aCkbQuotedAsText( this, ScResId(CB_QUOTED_AS_TEXT) ),
233cdf0e10cSrcweir         aCkbDetectNumber( this, ScResId(CB_DETECT_SPECIAL_NUMBER) ),
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         aFlWidth    ( this, ScResId( FL_WIDTH ) ),
236cdf0e10cSrcweir 		aFtType		( this, ScResId( FT_TYPE ) ),
237cdf0e10cSrcweir 		aLbType		( this, ScResId( LB_TYPE1 ) ),
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         maTableBox  ( this, ScResId( CTR_TABLEBOX ) ),
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		aBtnOk		( this, ScResId( BTN_OK ) ),
242cdf0e10cSrcweir 		aBtnCancel	( this, ScResId( BTN_CANCEL ) ),
243cdf0e10cSrcweir 		aBtnHelp	( this, ScResId( BTN_HELP ) ),
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 		aCharSetUser( ScResId( SCSTR_CHARSET_USER ) ),
246cdf0e10cSrcweir 		aColumnUser	( ScResId( SCSTR_COLUMN_USER ) ),
247cdf0e10cSrcweir 		aTextSepList( ScResId( SCSTR_TEXTSEP ) ),
248cdf0e10cSrcweir         mcTextSep   ( ScAsciiOptions::cDefaultTextSep ),
249cdf0e10cSrcweir         maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ),
250cdf0e10cSrcweir         mbFileImport(true)
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	FreeResource();
253cdf0e10cSrcweir     mbFileImport = aDatName.Len() > 0;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	String aName = GetText();
256cdf0e10cSrcweir     // aDatName is empty if invoked during paste from clipboard.
257cdf0e10cSrcweir     if (mbFileImport)
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - ["));
260cdf0e10cSrcweir         aName += aDatName;
261cdf0e10cSrcweir         aName += ']';
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir 	SetText( aName );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     OUString sFieldSeparators;
266cdf0e10cSrcweir     OUString sTextSeparators;
267cdf0e10cSrcweir     bool bMergeDelimiters = false;
268cdf0e10cSrcweir     bool bFixedWidth = false;
269cdf0e10cSrcweir     bool bQuotedFieldAsText = false;
270cdf0e10cSrcweir     bool bDetectSpecialNum = false;
271cdf0e10cSrcweir     sal_Int32 nFromRow = 1;
272cdf0e10cSrcweir     sal_Int32 nCharSet = -1;
273cdf0e10cSrcweir     sal_Int32 nLanguage = 0;
274cdf0e10cSrcweir     if (mbFileImport)
275cdf0e10cSrcweir         // load separators only when importing csv files.
276cdf0e10cSrcweir         load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
277cdf0e10cSrcweir                          bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage);
278cdf0e10cSrcweir     else
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         // #i115474# otherwise use sensible defaults
281cdf0e10cSrcweir         sFieldSeparators = OUString( cSep );
282cdf0e10cSrcweir         sTextSeparators = OUString( ScAsciiOptions::cDefaultTextSep );
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir     maFieldSeparators = String(sFieldSeparators);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     if( bMergeDelimiters )
287cdf0e10cSrcweir         aCkbAsOnce.Check();
288cdf0e10cSrcweir     if (bQuotedFieldAsText)
289cdf0e10cSrcweir         aCkbQuotedAsText.Check();
290cdf0e10cSrcweir     if (bDetectSpecialNum)
291cdf0e10cSrcweir         aCkbDetectNumber.Check();
292cdf0e10cSrcweir     if( bFixedWidth )
293cdf0e10cSrcweir         aRbFixed.Check();
294cdf0e10cSrcweir     if( nFromRow != 1 )
295cdf0e10cSrcweir         aNfRow.SetValue( nFromRow );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     ByteString bString(maFieldSeparators,RTL_TEXTENCODING_MS_1252);
298cdf0e10cSrcweir     const sal_Char *aSep = bString.GetBuffer();
299cdf0e10cSrcweir     int len = maFieldSeparators.Len();
300cdf0e10cSrcweir     for (int i = 0; i < len; ++i)
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         switch( aSep[i] )
303cdf0e10cSrcweir         {
304cdf0e10cSrcweir             case '\t':  aCkbTab.Check();        break;
305cdf0e10cSrcweir             case ';':   aCkbSemicolon.Check();  break;
306cdf0e10cSrcweir             case ',':   aCkbComma.Check();      break;
307cdf0e10cSrcweir             case ' ':   aCkbSpace.Check();      break;
308cdf0e10cSrcweir             default:
309cdf0e10cSrcweir                 aCkbOther.Check();
310cdf0e10cSrcweir                 aEdOther.SetText( aEdOther.GetText() + OUString( aSep[i] ) );
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     // Get Separators from the dialog
315cdf0e10cSrcweir     maFieldSeparators = GetSeparators();
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     // Clipboard is always Unicode, else detect.
318cdf0e10cSrcweir     rtl_TextEncoding ePreselectUnicode = (mbFileImport ?
319cdf0e10cSrcweir             RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE);
320cdf0e10cSrcweir 	// Sniff for Unicode / not
321cdf0e10cSrcweir     if( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW && mpDatStream )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		Seek( 0 );
324cdf0e10cSrcweir 		mpDatStream->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW );
325cdf0e10cSrcweir 		sal_uLong nUniPos = mpDatStream->Tell();
326cdf0e10cSrcweir         switch (nUniPos)
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             case 2:
329cdf0e10cSrcweir                 ePreselectUnicode = RTL_TEXTENCODING_UNICODE;   // UTF-16
330cdf0e10cSrcweir                 break;
331cdf0e10cSrcweir             case 3:
332cdf0e10cSrcweir                 ePreselectUnicode = RTL_TEXTENCODING_UTF8;      // UTF-8
333cdf0e10cSrcweir                 break;
334cdf0e10cSrcweir             case 0:
335cdf0e10cSrcweir                 {
336cdf0e10cSrcweir                     sal_uInt16 n;
337cdf0e10cSrcweir                     *mpDatStream >> n;
338cdf0e10cSrcweir                     // Assume that normal ASCII/ANSI/ISO/etc. text doesn't start with
339cdf0e10cSrcweir                     // control characters except CR,LF,TAB
340cdf0e10cSrcweir                     if ( (n & 0xff00) < 0x2000 )
341cdf0e10cSrcweir                     {
342cdf0e10cSrcweir                         switch ( n & 0xff00 )
343cdf0e10cSrcweir                         {
344cdf0e10cSrcweir                             case 0x0900 :
345cdf0e10cSrcweir                             case 0x0a00 :
346cdf0e10cSrcweir                             case 0x0d00 :
347cdf0e10cSrcweir                                 break;
348cdf0e10cSrcweir                             default:
349cdf0e10cSrcweir                                 ePreselectUnicode = RTL_TEXTENCODING_UNICODE;   // UTF-16
350cdf0e10cSrcweir                         }
351cdf0e10cSrcweir                     }
352cdf0e10cSrcweir                     mpDatStream->Seek(0);
353cdf0e10cSrcweir                 }
354cdf0e10cSrcweir                 break;
355cdf0e10cSrcweir             default:
356cdf0e10cSrcweir                 ;   // nothing
357cdf0e10cSrcweir         }
358cdf0e10cSrcweir 		mnStreamPos = mpDatStream->Tell();
359cdf0e10cSrcweir 	}
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     aNfRow.SetModifyHdl( LINK( this, ScImportAsciiDlg, FirstRowHdl ) );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     // *** Separator characters ***
364cdf0e10cSrcweir     lcl_FillCombo( aCbTextSep, aTextSepList, mcTextSep );
365cdf0e10cSrcweir     aCbTextSep.SetText( sTextSeparators );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     Link aSeparatorHdl =LINK( this, ScImportAsciiDlg, SeparatorHdl );
368cdf0e10cSrcweir     aCbTextSep.SetSelectHdl( aSeparatorHdl );
369cdf0e10cSrcweir     aCbTextSep.SetModifyHdl( aSeparatorHdl );
370cdf0e10cSrcweir     aCkbTab.SetClickHdl( aSeparatorHdl );
371cdf0e10cSrcweir     aCkbSemicolon.SetClickHdl( aSeparatorHdl );
372cdf0e10cSrcweir     aCkbComma.SetClickHdl( aSeparatorHdl );
373cdf0e10cSrcweir     aCkbAsOnce.SetClickHdl( aSeparatorHdl );
374cdf0e10cSrcweir     aCkbQuotedAsText.SetClickHdl( aSeparatorHdl );
375cdf0e10cSrcweir     aCkbDetectNumber.SetClickHdl( aSeparatorHdl );
376cdf0e10cSrcweir     aCkbSpace.SetClickHdl( aSeparatorHdl );
377cdf0e10cSrcweir     aCkbOther.SetClickHdl( aSeparatorHdl );
378cdf0e10cSrcweir     aEdOther.SetModifyHdl( aSeparatorHdl );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     // *** text encoding ListBox ***
381cdf0e10cSrcweir 	// all encodings allowed, including Unicode, but subsets are excluded
382cdf0e10cSrcweir 	aLbCharSet.FillFromTextEncodingTable( sal_True );
383cdf0e10cSrcweir 	// Insert one "SYSTEM" entry for compatibility in AsciiOptions and system
384cdf0e10cSrcweir 	// independent document linkage.
385cdf0e10cSrcweir 	aLbCharSet.InsertTextEncoding( RTL_TEXTENCODING_DONTKNOW, aCharSetUser );
386cdf0e10cSrcweir 	aLbCharSet.SelectTextEncoding( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW ?
387cdf0e10cSrcweir             gsl_getSystemTextEncoding() : ePreselectUnicode );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     if( nCharSet >= 0 && ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW )
390cdf0e10cSrcweir         aLbCharSet.SelectEntryPos( static_cast<sal_uInt16>(nCharSet) );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     SetSelectedCharSet();
393cdf0e10cSrcweir 	aLbCharSet.SetSelectHdl( LINK( this, ScImportAsciiDlg, CharSetHdl ) );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir     aLbCustomLang.SetLanguageList(
396cdf0e10cSrcweir         LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, false, false);
397cdf0e10cSrcweir     aLbCustomLang.InsertLanguage(LANGUAGE_SYSTEM);
398cdf0e10cSrcweir     aLbCustomLang.SelectLanguage(static_cast<LanguageType>(nLanguage), true);
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     // *** column type ListBox ***
401cdf0e10cSrcweir 	xub_StrLen nCount = aColumnUser.GetTokenCount();
402cdf0e10cSrcweir 	for (xub_StrLen i=0; i<nCount; i++)
403cdf0e10cSrcweir         aLbType.InsertEntry( aColumnUser.GetToken( i ) );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     aLbType.SetSelectHdl( LINK( this, ScImportAsciiDlg, LbColTypeHdl ) );
406cdf0e10cSrcweir     aFtType.Disable();
407cdf0e10cSrcweir     aLbType.Disable();
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     // *** table box preview ***
410cdf0e10cSrcweir     maTableBox.SetUpdateTextHdl( LINK( this, ScImportAsciiDlg, UpdateTextHdl ) );
411cdf0e10cSrcweir     maTableBox.InitTypes( aLbType );
412cdf0e10cSrcweir     maTableBox.SetColTypeHdl( LINK( this, ScImportAsciiDlg, ColTypeHdl ) );
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     aRbSeparated.SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
415cdf0e10cSrcweir     aRbFixed.SetClickHdl( LINK( this, ScImportAsciiDlg, RbSepFixHdl ) );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     SetupSeparatorCtrls();
418cdf0e10cSrcweir     RbSepFixHdl( &aRbFixed );
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	UpdateVertical();
421cdf0e10cSrcweir 
422cdf0e10cSrcweir     maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	aEdOther.SetAccessibleName(aCkbOther.GetText());
425cdf0e10cSrcweir 	aEdOther.SetAccessibleRelationLabeledBy(&aCkbOther);
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
~ScImportAsciiDlg()429cdf0e10cSrcweir ScImportAsciiDlg::~ScImportAsciiDlg()
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	delete[] mpRowPosArray;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 
435cdf0e10cSrcweir // ----------------------------------------------------------------------------
436cdf0e10cSrcweir 
GetLine(sal_uLong nLine,String & rText)437cdf0e10cSrcweir bool ScImportAsciiDlg::GetLine( sal_uLong nLine, String &rText )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     if (nLine >= ASCIIDLG_MAXROWS || !mpDatStream)
440cdf0e10cSrcweir         return false;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     bool bRet = true;
443cdf0e10cSrcweir     bool bFixed = aRbFixed.IsChecked();
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     if (!mpRowPosArray)
446cdf0e10cSrcweir         mpRowPosArray = new sal_uLong[ASCIIDLG_MAXROWS + 2];
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     if (!mnRowPosCount) // complete re-fresh
449cdf0e10cSrcweir     {
450cdf0e10cSrcweir         memset( mpRowPosArray, 0, sizeof(mpRowPosArray[0]) * (ASCIIDLG_MAXROWS+2));
451cdf0e10cSrcweir 
452cdf0e10cSrcweir         Seek(0);
453cdf0e10cSrcweir         mpDatStream->StartReadingUnicodeText( mpDatStream->GetStreamCharSet() );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir         mnStreamPos = mpDatStream->Tell();
456cdf0e10cSrcweir         mpRowPosArray[mnRowPosCount] = mnStreamPos;
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     if (nLine >= mnRowPosCount)
460cdf0e10cSrcweir     {
461cdf0e10cSrcweir         // need to work out some more line information
462cdf0e10cSrcweir         do
463cdf0e10cSrcweir         {
464cdf0e10cSrcweir             if (!Seek( mpRowPosArray[mnRowPosCount]) ||
465cdf0e10cSrcweir                     mpDatStream->GetError() != ERRCODE_NONE ||
466cdf0e10cSrcweir                     mpDatStream->IsEof())
467cdf0e10cSrcweir             {
468cdf0e10cSrcweir                 bRet = false;
469cdf0e10cSrcweir                 break;
470cdf0e10cSrcweir             }
471cdf0e10cSrcweir             mpDatStream->ReadCsvLine( rText, !bFixed, maFieldSeparators,
472cdf0e10cSrcweir                     mcTextSep);
473cdf0e10cSrcweir             mnStreamPos = mpDatStream->Tell();
474cdf0e10cSrcweir             mpRowPosArray[++mnRowPosCount] = mnStreamPos;
475cdf0e10cSrcweir         } while (nLine >= mnRowPosCount &&
476cdf0e10cSrcweir                 mpDatStream->GetError() == ERRCODE_NONE &&
477cdf0e10cSrcweir                 !mpDatStream->IsEof());
478cdf0e10cSrcweir         if (mpDatStream->IsEof() &&
479cdf0e10cSrcweir                 mnStreamPos == mpRowPosArray[mnRowPosCount-1])
480cdf0e10cSrcweir         {
481cdf0e10cSrcweir             // the very end, not even an empty line read
482cdf0e10cSrcweir             bRet = false;
483cdf0e10cSrcweir             --mnRowPosCount;
484cdf0e10cSrcweir         }
485cdf0e10cSrcweir     }
486cdf0e10cSrcweir     else
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         Seek( mpRowPosArray[nLine]);
489cdf0e10cSrcweir         mpDatStream->ReadCsvLine( rText, !bFixed, maFieldSeparators, mcTextSep);
490cdf0e10cSrcweir         mnStreamPos = mpDatStream->Tell();
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     //	#107455# If the file content isn't unicode, ReadUniStringLine
494cdf0e10cSrcweir     //	may try to seek beyond the file's end and cause a CANTSEEK error
495cdf0e10cSrcweir     //	(depending on the stream type). The error code has to be cleared,
496cdf0e10cSrcweir     //	or further read operations (including non-unicode) will fail.
497cdf0e10cSrcweir     if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK )
498cdf0e10cSrcweir         mpDatStream->ResetError();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     return bRet;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 
GetOptions(ScAsciiOptions & rOpt)504cdf0e10cSrcweir void ScImportAsciiDlg::GetOptions( ScAsciiOptions& rOpt )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir     rOpt.SetCharSet( meCharSet );
507cdf0e10cSrcweir     rOpt.SetCharSetSystem( mbCharSetSystem );
508cdf0e10cSrcweir     rOpt.SetLanguage(aLbCustomLang.GetSelectLanguage());
509cdf0e10cSrcweir     rOpt.SetFixedLen( aRbFixed.IsChecked() );
510cdf0e10cSrcweir     rOpt.SetStartRow( (long)aNfRow.GetValue() );
511cdf0e10cSrcweir     maTableBox.FillColumnData( rOpt );
512cdf0e10cSrcweir     if( aRbSeparated.IsChecked() )
513cdf0e10cSrcweir     {
514cdf0e10cSrcweir         rOpt.SetFieldSeps( GetSeparators() );
515cdf0e10cSrcweir         rOpt.SetMergeSeps( aCkbAsOnce.IsChecked() );
516cdf0e10cSrcweir         rOpt.SetTextSep( lcl_CharFromCombo( aCbTextSep, aTextSepList ) );
517cdf0e10cSrcweir     }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     rOpt.SetQuotedAsText(aCkbQuotedAsText.IsChecked());
520cdf0e10cSrcweir     rOpt.SetDetectSpecialNumber(aCkbDetectNumber.IsChecked());
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
SetTextToColumnsMode()523cdf0e10cSrcweir void ScImportAsciiDlg::SetTextToColumnsMode()
524cdf0e10cSrcweir {
525cdf0e10cSrcweir     SetText( maStrTextToColumns );
526cdf0e10cSrcweir     aFtCharSet.Disable();
527cdf0e10cSrcweir     aLbCharSet.Disable();
528cdf0e10cSrcweir     aFtCustomLang.Disable();
529cdf0e10cSrcweir     aLbCustomLang.SelectLanguage(LANGUAGE_SYSTEM);
530cdf0e10cSrcweir     aLbCustomLang.Disable();
531cdf0e10cSrcweir     aFtRow.Disable();
532cdf0e10cSrcweir     aNfRow.Disable();
533cdf0e10cSrcweir 
534cdf0e10cSrcweir     // Quoted field as text option is not used for text-to-columns mode.
535cdf0e10cSrcweir     aCkbQuotedAsText.Check(false);
536cdf0e10cSrcweir     aCkbQuotedAsText.Disable();
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     // Always detect special numbers for text-to-columns mode.
539cdf0e10cSrcweir     aCkbDetectNumber.Check();
540cdf0e10cSrcweir     aCkbDetectNumber.Disable();
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
SaveParameters()543cdf0e10cSrcweir void ScImportAsciiDlg::SaveParameters()
544cdf0e10cSrcweir {
545cdf0e10cSrcweir     if (!mbFileImport)
546cdf0e10cSrcweir         // We save parameters only for file import.
547cdf0e10cSrcweir         return;
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     save_Separators( maFieldSeparators, aCbTextSep.GetText(), aCkbAsOnce.IsChecked(),
550cdf0e10cSrcweir                      aCkbQuotedAsText.IsChecked(), aCkbDetectNumber.IsChecked(),
551cdf0e10cSrcweir                      aRbFixed.IsChecked(),
552cdf0e10cSrcweir                      static_cast<sal_Int32>(aNfRow.GetValue()),
553cdf0e10cSrcweir                      static_cast<sal_Int32>(aLbCharSet.GetSelectEntryPos()),
554cdf0e10cSrcweir                      static_cast<sal_Int32>(aLbCustomLang.GetSelectLanguage()) );
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
SetSelectedCharSet()557cdf0e10cSrcweir void ScImportAsciiDlg::SetSelectedCharSet()
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     meCharSet = aLbCharSet.GetSelectTextEncoding();
560cdf0e10cSrcweir     mbCharSetSystem = (meCharSet == RTL_TEXTENCODING_DONTKNOW);
561cdf0e10cSrcweir     if( mbCharSetSystem )
562cdf0e10cSrcweir         meCharSet = gsl_getSystemTextEncoding();
563cdf0e10cSrcweir }
564cdf0e10cSrcweir 
GetSeparators() const565cdf0e10cSrcweir String ScImportAsciiDlg::GetSeparators() const
566cdf0e10cSrcweir {
567cdf0e10cSrcweir     String aSepChars;
568cdf0e10cSrcweir     if( aCkbTab.IsChecked() )
569cdf0e10cSrcweir         aSepChars += '\t';
570cdf0e10cSrcweir     if( aCkbSemicolon.IsChecked() )
571cdf0e10cSrcweir         aSepChars += ';';
572cdf0e10cSrcweir     if( aCkbComma.IsChecked() )
573cdf0e10cSrcweir         aSepChars += ',';
574cdf0e10cSrcweir     if( aCkbSpace.IsChecked() )
575cdf0e10cSrcweir         aSepChars += ' ';
576cdf0e10cSrcweir     if( aCkbOther.IsChecked() )
577cdf0e10cSrcweir         aSepChars += aEdOther.GetText();
578cdf0e10cSrcweir     return aSepChars;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
SetupSeparatorCtrls()581cdf0e10cSrcweir void ScImportAsciiDlg::SetupSeparatorCtrls()
582cdf0e10cSrcweir {
583cdf0e10cSrcweir     sal_Bool bEnable = aRbSeparated.IsChecked();
584cdf0e10cSrcweir     aCkbTab.Enable( bEnable );
585cdf0e10cSrcweir     aCkbSemicolon.Enable( bEnable );
586cdf0e10cSrcweir     aCkbComma.Enable( bEnable );
587cdf0e10cSrcweir     aCkbSpace.Enable( bEnable );
588cdf0e10cSrcweir     aCkbOther.Enable( bEnable );
589cdf0e10cSrcweir     aEdOther.Enable( bEnable );
590cdf0e10cSrcweir     aCkbAsOnce.Enable( bEnable );
591cdf0e10cSrcweir     aFtTextSep.Enable( bEnable );
592cdf0e10cSrcweir     aCbTextSep.Enable( bEnable );
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
UpdateVertical()595cdf0e10cSrcweir void ScImportAsciiDlg::UpdateVertical()
596cdf0e10cSrcweir {
597cdf0e10cSrcweir     mnRowPosCount = 0;
598cdf0e10cSrcweir     if (mpDatStream)
599cdf0e10cSrcweir         mpDatStream->SetStreamCharSet(meCharSet);
600cdf0e10cSrcweir }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 
603cdf0e10cSrcweir // ----------------------------------------------------------------------------
604cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,RbSepFixHdl,RadioButton *,pButton)605cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, RbSepFixHdl, RadioButton*, pButton )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir     DBG_ASSERT( pButton, "ScImportAsciiDlg::RbSepFixHdl - missing sender" );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     if( (pButton == &aRbFixed) || (pButton == &aRbSeparated) )
610cdf0e10cSrcweir 	{
611cdf0e10cSrcweir         SetPointer( Pointer( POINTER_WAIT ) );
612cdf0e10cSrcweir         if( aRbFixed.IsChecked() )
613cdf0e10cSrcweir             maTableBox.SetFixedWidthMode();
614cdf0e10cSrcweir         else
615cdf0e10cSrcweir             maTableBox.SetSeparatorsMode();
616cdf0e10cSrcweir         SetPointer( Pointer( POINTER_ARROW ) );
617cdf0e10cSrcweir 
618cdf0e10cSrcweir         SetupSeparatorCtrls();
619cdf0e10cSrcweir 	}
620cdf0e10cSrcweir 	return 0;
621cdf0e10cSrcweir }
622cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,SeparatorHdl,Control *,pCtrl)623cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, SeparatorHdl, Control*, pCtrl )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir     DBG_ASSERT( pCtrl, "ScImportAsciiDlg::SeparatorHdl - missing sender" );
626cdf0e10cSrcweir     DBG_ASSERT( !aRbFixed.IsChecked(), "ScImportAsciiDlg::SeparatorHdl - not allowed in fixed width" );
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     /*  #i41550# First update state of the controls. The GetSeparators()
629cdf0e10cSrcweir         function needs final state of the check boxes. */
630cdf0e10cSrcweir     if( (pCtrl == &aCkbOther) && aCkbOther.IsChecked() )
631cdf0e10cSrcweir         aEdOther.GrabFocus();
632cdf0e10cSrcweir     else if( pCtrl == &aEdOther )
633cdf0e10cSrcweir         aCkbOther.Check( aEdOther.GetText().Len() > 0 );
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     String aOldFldSeps( maFieldSeparators);
636cdf0e10cSrcweir     maFieldSeparators = GetSeparators();
637cdf0e10cSrcweir     sal_Unicode cOldSep = mcTextSep;
638cdf0e10cSrcweir     mcTextSep = lcl_CharFromCombo( aCbTextSep, aTextSepList );
639cdf0e10cSrcweir     // Any separator changed may result in completely different lines due to
640cdf0e10cSrcweir     // embedded line breaks.
641cdf0e10cSrcweir     if (cOldSep != mcTextSep || aOldFldSeps != maFieldSeparators)
642cdf0e10cSrcweir         UpdateVertical();
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
645cdf0e10cSrcweir 	return 0;
646cdf0e10cSrcweir }
647cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,CharSetHdl,SvxTextEncodingBox *,pCharSetBox)648cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, CharSetHdl, SvxTextEncodingBox*, pCharSetBox )
649cdf0e10cSrcweir {
650cdf0e10cSrcweir     DBG_ASSERT( pCharSetBox, "ScImportAsciiDlg::CharSetHdl - missing sender" );
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     if( (pCharSetBox == &aLbCharSet) && (pCharSetBox->GetSelectEntryCount() == 1) )
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         SetPointer( Pointer( POINTER_WAIT ) );
655cdf0e10cSrcweir         CharSet eOldCharSet = meCharSet;
656cdf0e10cSrcweir         SetSelectedCharSet();
657cdf0e10cSrcweir         // switching char-set invalidates 8bit -> String conversions
658cdf0e10cSrcweir         if (eOldCharSet != meCharSet)
659cdf0e10cSrcweir             UpdateVertical();
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         maTableBox.Execute( CSVCMD_NEWCELLTEXTS );
662cdf0e10cSrcweir         SetPointer( Pointer( POINTER_ARROW ) );
663cdf0e10cSrcweir     }
664cdf0e10cSrcweir 	return 0;
665cdf0e10cSrcweir }
666cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,FirstRowHdl,NumericField *,pNumField)667cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, FirstRowHdl, NumericField*, pNumField )
668cdf0e10cSrcweir {
669cdf0e10cSrcweir     DBG_ASSERT( pNumField, "ScImportAsciiDlg::FirstRowHdl - missing sender" );
670cdf0e10cSrcweir     maTableBox.Execute( CSVCMD_SETFIRSTIMPORTLINE, sal::static_int_cast<sal_Int32>( pNumField->GetValue() - 1 ) );
671cdf0e10cSrcweir     return 0;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,LbColTypeHdl,ListBox *,pListBox)674cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, LbColTypeHdl, ListBox*, pListBox )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir     DBG_ASSERT( pListBox, "ScImportAsciiDlg::LbColTypeHdl - missing sender" );
677cdf0e10cSrcweir     if( pListBox == &aLbType )
678cdf0e10cSrcweir         maTableBox.Execute( CSVCMD_SETCOLUMNTYPE, pListBox->GetSelectEntryPos() );
679cdf0e10cSrcweir 	return 0;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,UpdateTextHdl,ScCsvTableBox *,EMPTYARG)682cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, UpdateTextHdl, ScCsvTableBox*, EMPTYARG )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir     sal_Int32 nBaseLine = maTableBox.GetFirstVisLine();
685cdf0e10cSrcweir     sal_Int32 nRead = maTableBox.GetVisLineCount();
686cdf0e10cSrcweir     // If mnRowPosCount==0, this is an initializing call, read ahead for row
687cdf0e10cSrcweir     // count and resulting scroll bar size and position to be able to scroll at
688cdf0e10cSrcweir     // all. When adding lines, read only the amount of next lines to be
689cdf0e10cSrcweir     // displayed.
690cdf0e10cSrcweir     if (!mnRowPosCount || nRead > CSV_PREVIEW_LINES)
691cdf0e10cSrcweir         nRead = CSV_PREVIEW_LINES;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir     sal_Int32 i;
694cdf0e10cSrcweir     for (i = 0; i < nRead; i++)
695cdf0e10cSrcweir     {
696cdf0e10cSrcweir         if (!GetLine( nBaseLine + i, maPreviewLine[i]))
697cdf0e10cSrcweir             break;
698cdf0e10cSrcweir     }
699cdf0e10cSrcweir     for (; i < CSV_PREVIEW_LINES; i++)
700cdf0e10cSrcweir         maPreviewLine[i].Erase();
701cdf0e10cSrcweir 
702cdf0e10cSrcweir     maTableBox.Execute( CSVCMD_SETLINECOUNT, mnRowPosCount);
703cdf0e10cSrcweir     bool bMergeSep = (aCkbAsOnce.IsChecked() == sal_True);
704cdf0e10cSrcweir     maTableBox.SetUniStrings( maPreviewLine, maFieldSeparators, mcTextSep, bMergeSep);
705cdf0e10cSrcweir 
706cdf0e10cSrcweir     return 0;
707cdf0e10cSrcweir }
708cdf0e10cSrcweir 
IMPL_LINK(ScImportAsciiDlg,ColTypeHdl,ScCsvTableBox *,pTableBox)709cdf0e10cSrcweir IMPL_LINK( ScImportAsciiDlg, ColTypeHdl, ScCsvTableBox*, pTableBox )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir     DBG_ASSERT( pTableBox, "ScImportAsciiDlg::ColTypeHdl - missing sender" );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     sal_Int32 nType = pTableBox->GetSelColumnType();
714cdf0e10cSrcweir     sal_Int32 nTypeCount = aLbType.GetEntryCount();
715cdf0e10cSrcweir     bool bEmpty = (nType == CSV_TYPE_MULTI);
716cdf0e10cSrcweir     bool bEnable = ((0 <= nType) && (nType < nTypeCount)) || bEmpty;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     aFtType.Enable( bEnable );
719cdf0e10cSrcweir     aLbType.Enable( bEnable );
720cdf0e10cSrcweir 
721cdf0e10cSrcweir     Link aSelHdl = aLbType.GetSelectHdl();
722cdf0e10cSrcweir     aLbType.SetSelectHdl( Link() );
723cdf0e10cSrcweir     if( bEmpty )
724cdf0e10cSrcweir         aLbType.SetNoSelection();
725cdf0e10cSrcweir     else if( bEnable )
726cdf0e10cSrcweir         aLbType.SelectEntryPos( static_cast< sal_uInt16 >( nType ) );
727cdf0e10cSrcweir     aLbType.SetSelectHdl( aSelHdl );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     return 0;
730cdf0e10cSrcweir }
731