xref: /aoo41x/main/sc/source/ui/dbgui/imoptdlg.cxx (revision b3f79822)
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 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "imoptdlg.hxx"
30cdf0e10cSrcweir #include "scresid.hxx"
31cdf0e10cSrcweir #include "imoptdlg.hrc"
32cdf0e10cSrcweir #include <rtl/tencinfo.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir static const sal_Char pStrFix[] = "FIX";
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //------------------------------------------------------------------------
37cdf0e10cSrcweir //	Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
38cdf0e10cSrcweir //	darum ab Version 336 Komma stattdessen
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
ScImportOptions(const String & rStr)41cdf0e10cSrcweir ScImportOptions::ScImportOptions( const String& rStr )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     // Use the same string format as ScAsciiOptions,
44cdf0e10cSrcweir     // because the import options string is passed here when a CSV file is loaded and saved again.
45cdf0e10cSrcweir     // The old format is still supported because it might be used in macros.
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     bFixedWidth = sal_False;
48cdf0e10cSrcweir     nFieldSepCode = 0;
49cdf0e10cSrcweir     nTextSepCode = 0;
50cdf0e10cSrcweir     eCharSet = RTL_TEXTENCODING_DONTKNOW;
51cdf0e10cSrcweir     bSaveAsShown = sal_True;    // "true" if not in string (after CSV import)
52cdf0e10cSrcweir     bQuoteAllText = sal_False;
53cdf0e10cSrcweir     xub_StrLen nTokenCount = rStr.GetTokenCount(',');
54cdf0e10cSrcweir     if ( nTokenCount >= 3 )
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir         // first 3 tokens: common
57cdf0e10cSrcweir         String aToken( rStr.GetToken( 0, ',' ) );
58cdf0e10cSrcweir         if( aToken.EqualsIgnoreCaseAscii( pStrFix ) )
59cdf0e10cSrcweir             bFixedWidth = sal_True;
60cdf0e10cSrcweir         else
61cdf0e10cSrcweir             nFieldSepCode = (sal_Unicode) aToken.ToInt32();
62cdf0e10cSrcweir 		nTextSepCode  = (sal_Unicode) rStr.GetToken(1,',').ToInt32();
63cdf0e10cSrcweir 		aStrFont	  = rStr.GetToken(2,',');
64cdf0e10cSrcweir 		eCharSet	  = ScGlobal::GetCharsetValue(aStrFont);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         if ( nTokenCount == 4 )
67cdf0e10cSrcweir         {
68cdf0e10cSrcweir             // compatibility with old options string: "Save as shown" as 4th token, numeric
69cdf0e10cSrcweir             bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : sal_False);
70cdf0e10cSrcweir             bQuoteAllText = sal_True;   // use old default then
71cdf0e10cSrcweir         }
72cdf0e10cSrcweir         else
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             // look at the same positions as in ScAsciiOptions
75cdf0e10cSrcweir             if ( nTokenCount >= 7 )
76cdf0e10cSrcweir                 bQuoteAllText = rStr.GetToken(6, ',').EqualsAscii("true");
77cdf0e10cSrcweir             if ( nTokenCount >= 9 )
78cdf0e10cSrcweir                 bSaveAsShown = rStr.GetToken(8, ',').EqualsAscii("true");
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //------------------------------------------------------------------------
84cdf0e10cSrcweir 
BuildString() const85cdf0e10cSrcweir String ScImportOptions::BuildString() const
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	String	aResult;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     if( bFixedWidth )
90cdf0e10cSrcweir         aResult.AppendAscii( pStrFix );
91cdf0e10cSrcweir     else
92cdf0e10cSrcweir         aResult += String::CreateFromInt32(nFieldSepCode);
93cdf0e10cSrcweir 	aResult += ',';
94cdf0e10cSrcweir 	aResult += String::CreateFromInt32(nTextSepCode);
95cdf0e10cSrcweir 	aResult += ',';
96cdf0e10cSrcweir 	aResult += aStrFont;
97cdf0e10cSrcweir                                                             // use the same string format as ScAsciiOptions:
98cdf0e10cSrcweir     aResult.AppendAscii( ",1,,0," );                        // first row, no column info, default language
99cdf0e10cSrcweir     aResult.AppendAscii(bQuoteAllText ? "true" : "false");  // same as "quoted field as text" in ScAsciiOptions
100cdf0e10cSrcweir     aResult.AppendAscii( ",true," );                        // "detect special numbers"
101cdf0e10cSrcweir     aResult.AppendAscii(bSaveAsShown ? "true" : "false");   // "save as shown": not in ScAsciiOptions
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	return aResult;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //------------------------------------------------------------------------
107cdf0e10cSrcweir 
SetTextEncoding(rtl_TextEncoding nEnc)108cdf0e10cSrcweir void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ?
111cdf0e10cSrcweir 		gsl_getSystemTextEncoding() : nEnc);
112cdf0e10cSrcweir 	aStrFont = ScGlobal::GetCharsetString( nEnc );
113cdf0e10cSrcweir }
114