Files
libreoffice/sc/source/ui/dbgui/asciiopt.cxx

386 lines
10 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Herbert Duerr i#118735 prevent endless loop if vlookup/hlookup doesn't find anything http://svn.apache.org/viewvc?view=revision&revision=1239673 Patches contributed by Andre Fischer remove lp_solver http://svn.apache.org/viewvc?view=revision&revision=1199180 i#118160: Added external CoinMP library. http://svn.apache.org/viewvc?view=revision&revision=1233909 Patches contributed by Armin Le-Grand i#118485 - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 i#118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 Patches contributed by lihuiibm i#108860 - Fix range validation. http://svn.apache.org/viewvc?view=revision&revision=1242846 i#118954 Chart data will lost after copy to different file http://svn.apache.org/viewvc?view=revision&revision=1301345 Patches contributed by Ariel Constenla-Haile Fix Linux build breaker: extra qualification on member http://svn.apache.org/viewvc?view=revision&revision=1301591 i#118696 - i#118697 - Fix some Sheet Tab Color API issues http://svn.apache.org/viewvc?view=revision&revision=1225428 i#118697 - Fix uninitialized variable http://svn.apache.org/viewvc?view=revision&revision=1225859 i#118771 - ScUndoImportTab should preserve tab background color http://svn.apache.org/viewvc?view=revision&revision=1230356 i#118921 - Repaint linked sheet tab background color after updating link http://svn.apache.org/viewvc?view=revision&revision=1245177 i#118927 - Undo/Redo "Update Link" does not reset sheet tab color http://svn.apache.org/viewvc?view=revision&revision=1245241 i#118747 - Copy tab color when transferring sheets across documents http://svn.apache.org/viewvc?view=revision&revision=1230355 Patch contributed by Oliver Rainer-Wittman i#118012 - methods <ScBroadcastAreaSlot::AreaBroadcast(..)> and <ScBroadcastAreaSlot::AreaBroadcastInRange(..)> adapt stl-container iteration in order to avoid destroyed iterators during iteration. http://svn.apache.org/viewvc?view=revision&revision=1297916 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 Patch contributed by Daniel Rentz calc69: #i116936# fix VBA symbol Cells http://svn.apache.org/viewvc?view=revision&revision=1172135 Patches contributed by leiw: i#118546 CPU 100% on switched off AutoCalculate with Conditional Formatting on date values http://svn.apache.org/viewvc?view=revision&revision=1301380 Re-add new function documentation. Many various cleanups. Add missing calc66: #o11817313# also look at formula result number format, remove redundant binaries.
2012-11-30 12:23:25 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
#include "global.hxx"
#include "scresid.hxx"
#include "impex.hxx"
#include "asciiopt.hxx"
#include "asciiopt.hrc"
#include <comphelper/string.hxx>
2000-12-20 11:18:06 +00:00
#include <rtl/tencinfo.h>
#include <unotools/transliterationwrapper.hxx>
// ause
#include "editutil.hxx"
2000-09-18 16:07:07 +00:00
// ============================================================================
2000-09-18 16:07:07 +00:00
2010-12-06 10:36:07 +00:00
static const sal_Char pStrFix[] = "FIX";
static const sal_Char pStrMrg[] = "MRG";
2000-09-18 16:07:07 +00:00
// ============================================================================
2000-09-18 16:07:07 +00:00
ScAsciiOptions::ScAsciiOptions() :
bFixedLen ( false ),
aFieldSeps ( OUString(';') ),
bMergeFieldSeps ( false ),
bQuotedFieldAsText(false),
bDetectSpecialNumber(false),
cTextSep ( cDefaultTextSep ),
eCharSet ( osl_getThreadTextEncoding() ),
eLang ( LANGUAGE_SYSTEM ),
bCharSetSystem ( false ),
2000-09-18 16:07:07 +00:00
nStartRow ( 1 ),
nInfoCount ( 0 ),
pColStart ( NULL ),
pColFormat ( NULL )
{
}
ScAsciiOptions::ScAsciiOptions(const ScAsciiOptions& rOpt) :
bFixedLen ( rOpt.bFixedLen ),
aFieldSeps ( rOpt.aFieldSeps ),
bMergeFieldSeps ( rOpt.bMergeFieldSeps ),
bQuotedFieldAsText(rOpt.bQuotedFieldAsText),
bDetectSpecialNumber(rOpt.bDetectSpecialNumber),
2000-09-18 16:07:07 +00:00
cTextSep ( rOpt.cTextSep ),
eCharSet ( rOpt.eCharSet ),
eLang ( rOpt.eLang ),
2000-12-20 11:18:06 +00:00
bCharSetSystem ( rOpt.bCharSetSystem ),
2000-09-18 16:07:07 +00:00
nStartRow ( rOpt.nStartRow ),
nInfoCount ( rOpt.nInfoCount )
{
if (nInfoCount)
{
pColStart = new sal_Int32[nInfoCount];
pColFormat = new sal_uInt8[nInfoCount];
for (sal_uInt16 i=0; i<nInfoCount; i++)
2000-09-18 16:07:07 +00:00
{
pColStart[i] = rOpt.pColStart[i];
pColFormat[i] = rOpt.pColFormat[i];
}
}
else
{
pColStart = NULL;
pColFormat = NULL;
}
}
ScAsciiOptions::~ScAsciiOptions()
{
delete[] pColStart;
delete[] pColFormat;
}
void ScAsciiOptions::SetColInfo( sal_uInt16 nCount, const sal_Int32* pStart, const sal_uInt8* pFormat )
2000-09-18 16:07:07 +00:00
{
delete[] pColStart;
delete[] pColFormat;
nInfoCount = nCount;
if (nInfoCount)
{
pColStart = new sal_Int32[nInfoCount];
pColFormat = new sal_uInt8[nInfoCount];
for (sal_uInt16 i=0; i<nInfoCount; i++)
2000-09-18 16:07:07 +00:00
{
pColStart[i] = pStart[i];
pColFormat[i] = pFormat[i];
}
}
else
{
pColStart = NULL;
pColFormat = NULL;
}
}
2002-08-15 08:29:12 +00:00
void ScAsciiOptions::SetColumnInfo( const ScCsvExpDataVec& rDataVec )
{
delete[] pColStart;
pColStart = NULL;
delete[] pColFormat;
pColFormat = NULL;
2002-08-15 08:29:12 +00:00
nInfoCount = static_cast< sal_uInt16 >( rDataVec.size() );
if( nInfoCount )
{
pColStart = new sal_Int32[ nInfoCount ];
pColFormat = new sal_uInt8[ nInfoCount ];
for( sal_uInt16 nIx = 0; nIx < nInfoCount; ++nIx )
{
2002-08-15 08:29:12 +00:00
pColStart[ nIx ] = rDataVec[ nIx ].mnIndex;
pColFormat[ nIx ] = rDataVec[ nIx ].mnType;
}
}
}
2000-09-18 16:07:07 +00:00
ScAsciiOptions& ScAsciiOptions::operator=( const ScAsciiOptions& rCpy )
{
SetColInfo( rCpy.nInfoCount, rCpy.pColStart, rCpy.pColFormat );
bFixedLen = rCpy.bFixedLen;
aFieldSeps = rCpy.aFieldSeps;
bMergeFieldSeps = rCpy.bMergeFieldSeps;
bQuotedFieldAsText = rCpy.bQuotedFieldAsText;
2000-09-18 16:07:07 +00:00
cTextSep = rCpy.cTextSep;
eCharSet = rCpy.eCharSet;
2000-12-20 11:18:06 +00:00
bCharSetSystem = rCpy.bCharSetSystem;
2000-09-18 16:07:07 +00:00
nStartRow = rCpy.nStartRow;
return *this;
}
sal_Bool ScAsciiOptions::operator==( const ScAsciiOptions& rCmp ) const
2000-09-18 16:07:07 +00:00
{
if ( bFixedLen == rCmp.bFixedLen &&
aFieldSeps == rCmp.aFieldSeps &&
bMergeFieldSeps == rCmp.bMergeFieldSeps &&
bQuotedFieldAsText == rCmp.bQuotedFieldAsText &&
2000-09-18 16:07:07 +00:00
cTextSep == rCmp.cTextSep &&
eCharSet == rCmp.eCharSet &&
2000-12-20 11:18:06 +00:00
bCharSetSystem == rCmp.bCharSetSystem &&
2000-09-18 16:07:07 +00:00
nStartRow == rCmp.nStartRow &&
nInfoCount == rCmp.nInfoCount )
{
OSL_ENSURE( !nInfoCount || (pColStart && pColFormat && rCmp.pColStart && rCmp.pColFormat),
2000-09-18 16:07:07 +00:00
"0-Zeiger in ScAsciiOptions" );
for (sal_uInt16 i=0; i<nInfoCount; i++)
2000-09-18 16:07:07 +00:00
if ( pColStart[i] != rCmp.pColStart[i] ||
pColFormat[i] != rCmp.pColFormat[i] )
return false;
2000-09-18 16:07:07 +00:00
return sal_True;
2000-09-18 16:07:07 +00:00
}
return false;
2000-09-18 16:07:07 +00:00
}
//
// Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
// darum ab Version 336 Komma stattdessen
//
void ScAsciiOptions::ReadFromString( const String& rString )
{
xub_StrLen nCount = comphelper::string::getTokenCount(rString, ',');
2000-09-18 16:07:07 +00:00
String aToken;
xub_StrLen nSub;
xub_StrLen i;
//
// Feld-Trenner
//
if ( nCount >= 1 )
{
bFixedLen = bMergeFieldSeps = false;
2000-09-18 16:07:07 +00:00
aFieldSeps.Erase();
aToken = rString.GetToken(0,',');
if ( aToken.EqualsAscii(pStrFix) )
bFixedLen = sal_True;
nSub = comphelper::string::getTokenCount(aToken, '/');
2000-09-18 16:07:07 +00:00
for ( i=0; i<nSub; i++ )
{
String aCode = aToken.GetToken( i, '/' );
if ( aCode.EqualsAscii(pStrMrg) )
bMergeFieldSeps = sal_True;
2000-09-18 16:07:07 +00:00
else
{
sal_Int32 nVal = aCode.ToInt32();
if ( nVal )
aFieldSeps += (sal_Unicode) nVal;
}
}
}
//
// Text-Trenner
//
if ( nCount >= 2 )
{
aToken = rString.GetToken(1,',');
sal_Int32 nVal = aToken.ToInt32();
cTextSep = (sal_Unicode) nVal;
}
//
// Zeichensatz
//
if ( nCount >= 3 )
{
aToken = rString.GetToken(2,',');
2000-12-20 11:18:06 +00:00
eCharSet = ScGlobal::GetCharsetValue( aToken );
2000-09-18 16:07:07 +00:00
}
//
// Startzeile
//
if ( nCount >= 4 )
2000-09-18 16:07:07 +00:00
{
aToken = rString.GetToken(3,',');
2000-09-18 16:07:07 +00:00
nStartRow = aToken.ToInt32();
}
//
// Spalten-Infos
//
if ( nCount >= 5 )
2000-09-18 16:07:07 +00:00
{
delete[] pColStart;
delete[] pColFormat;
aToken = rString.GetToken(4,',');
nSub = comphelper::string::getTokenCount(aToken, '/');
2000-09-18 16:07:07 +00:00
nInfoCount = nSub / 2;
if (nInfoCount)
{
pColStart = new sal_Int32[nInfoCount];
pColFormat = new sal_uInt8[nInfoCount];
for (sal_uInt16 nInfo=0; nInfo<nInfoCount; nInfo++)
2000-09-18 16:07:07 +00:00
{
pColStart[nInfo] = (sal_Int32) aToken.GetToken( 2*nInfo, '/' ).ToInt32();
pColFormat[nInfo] = (sal_uInt8) aToken.GetToken( 2*nInfo+1, '/' ).ToInt32();
2000-09-18 16:07:07 +00:00
}
}
else
{
pColStart = NULL;
pColFormat = NULL;
}
}
// Language
if (nCount >= 6)
{
aToken = rString.GetToken(5, ',');
eLang = static_cast<LanguageType>(aToken.ToInt32());
}
// Import quoted field as text.
if (nCount >= 7)
{
aToken = rString.GetToken(6, ',');
bQuotedFieldAsText = aToken.EqualsAscii("true") ? true : false;
}
// Detect special nubmers.
if (nCount >= 8)
{
aToken = rString.GetToken(7, ',');
bDetectSpecialNumber = aToken.EqualsAscii("true") ? true : false;
}
else
bDetectSpecialNumber = sal_True; // default of versions that didn't add the parameter
// 9th token is used for "Save as shown" in export options
// 10th token is used for "Save cell formulas" in export options
2000-09-18 16:07:07 +00:00
}
String ScAsciiOptions::WriteToString() const
{
OUString aOutStr;
2000-09-18 16:07:07 +00:00
//
// Feld-Trenner
//
if ( bFixedLen )
aOutStr += pStrFix;
2000-09-18 16:07:07 +00:00
else if ( !aFieldSeps.Len() )
aOutStr += "0";
2000-09-18 16:07:07 +00:00
else
{
xub_StrLen nLen = aFieldSeps.Len();
for (xub_StrLen i=0; i<nLen; i++)
{
if (i)
aOutStr += "/";
aOutStr += OUString::number(aFieldSeps.GetChar(i));
2000-09-18 16:07:07 +00:00
}
if ( bMergeFieldSeps )
{
aOutStr += "/";
aOutStr += pStrMrg;
2000-09-18 16:07:07 +00:00
}
}
aOutStr += "," +
// Text-Trenner
OUString::number(cTextSep) + ",";
2000-09-18 16:07:07 +00:00
//
// Zeichensatz
//
2000-12-20 11:18:06 +00:00
if ( bCharSetSystem ) // force "SYSTEM"
aOutStr += ScGlobal::GetCharsetString( RTL_TEXTENCODING_DONTKNOW );
else
aOutStr += ScGlobal::GetCharsetString( eCharSet );
aOutStr += "," +
// Startzeile
OUString::number(nStartRow) + ",";
2000-09-18 16:07:07 +00:00
//
// Spalten-Infos
//
OSL_ENSURE( !nInfoCount || (pColStart && pColFormat), "0-Zeiger in ScAsciiOptions" );
for (sal_uInt16 nInfo=0; nInfo<nInfoCount; nInfo++)
2000-09-18 16:07:07 +00:00
{
if (nInfo)
aOutStr += "/";
aOutStr += OUString::number(pColStart[nInfo]) +
"/" +
OUString::number(pColFormat[nInfo]);
2000-09-18 16:07:07 +00:00
}
// #i112025# the options string is used in macros and linked sheets,
// so new options must be added at the end, to remain compatible
aOutStr += "," +
// Language
OUString::number(eLang) + "," +
// Import quoted field as text.
OUString::boolean( bQuotedFieldAsText ) + "," +
// Detect special numbers.
OUString::boolean( bDetectSpecialNumber );
// 9th token is used for "Save as shown" in export options
// 10th token is used for "Save cell formulas" in export options
2000-09-18 16:07:07 +00:00
return aOutStr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */