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