Files
libreoffice/sc/source/core/tool/editutil.cxx

794 lines
25 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 23:16:46 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:16:46 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 23:16:46 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:16:46 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:16:46 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 23:16:46 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 23:16:46 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 23:16:46 +00:00
*
************************************************************************/
2000-09-18 23:16:46 +00:00
// System - Includes -----------------------------------------------------
// INCLUDE ---------------------------------------------------------------
#include "scitems.hxx"
2011-11-18 21:03:31 +00:00
#include <comphelper/string.hxx>
#include <editeng/eeitem.hxx>
2000-09-18 23:16:46 +00:00
#include <svx/algitem.hxx>
#include <svtools/colorcfg.hxx>
#include <editeng/editview.hxx>
#include <editeng/editstat.hxx>
#include <editeng/escpitem.hxx>
#include <editeng/flditem.hxx>
#include <editeng/numitem.hxx>
#include <editeng/justifyitem.hxx>
2000-09-18 23:16:46 +00:00
#include <vcl/svapp.hxx>
#include <vcl/outdev.hxx>
#include <svl/inethist.hxx>
#include <unotools/syslocale.hxx>
2000-09-18 23:16:46 +00:00
#include "editutil.hxx"
#include "global.hxx"
#include "attrib.hxx"
#include "document.hxx"
#include "docpool.hxx"
#include "patattr.hxx"
2001-05-11 15:20:22 +00:00
#include "scmod.hxx"
#include "inputopt.hxx"
#include "compiler.hxx"
2000-09-18 23:16:46 +00:00
// STATIC DATA -----------------------------------------------------------
// Delimiters zusaetzlich zu EditEngine-Default:
2010-12-06 10:36:07 +00:00
const sal_Char ScEditUtil::pCalcDelimiters[] = "=()+-*/^&<>";
2000-09-18 23:16:46 +00:00
//------------------------------------------------------------------------
String ScEditUtil::ModifyDelimiters( const String& rOld )
{
2011-11-18 21:03:31 +00:00
// underscore is used in function argument names
String aRet = comphelper::string::remove(rOld, '_');
2000-09-18 23:16:46 +00:00
aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( pCalcDelimiters ) );
aRet.Append(ScCompiler::GetNativeSymbol(ocSep)); // argument separator is localized.
2000-09-18 23:16:46 +00:00
return aRet;
}
static String lcl_GetDelimitedString( const EditEngine& rEngine, const sal_Char c )
2000-09-18 23:16:46 +00:00
{
String aRet;
sal_uInt16 nParCount = rEngine.GetParagraphCount();
for (sal_uInt16 nPar=0; nPar<nParCount; nPar++)
2000-09-18 23:16:46 +00:00
{
if (nPar > 0)
aRet += c;
2000-09-18 23:16:46 +00:00
aRet += rEngine.GetText( nPar );
}
return aRet;
}
String ScEditUtil::GetSpaceDelimitedString( const EditEngine& rEngine )
{
return lcl_GetDelimitedString(rEngine, ' ');
}
String ScEditUtil::GetMultilineString( const EditEngine& rEngine )
{
return lcl_GetDelimitedString(rEngine, '\n');
}
2000-09-18 23:16:46 +00:00
//------------------------------------------------------------------------
Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop )
2000-09-18 23:16:46 +00:00
{
2000-09-25 16:35:04 +00:00
// bForceToTop = always align to top, for editing
// (sal_False for querying URLs etc.)
2000-09-25 16:35:04 +00:00
2000-09-18 23:16:46 +00:00
if (!pPattern)
pPattern = pDoc->GetPattern( nCol, nRow, nTab );
Point aStartPos = aScrPos;
sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
long nLayoutSign = bLayoutRTL ? -1 : 1;
2000-09-18 23:16:46 +00:00
const ScMergeAttr* pMerge = (const ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
long nCellX = (long) ( pDoc->GetColWidth(nCol,nTab) * nPPTX );
if ( pMerge->GetColMerge() > 1 )
{
SCCOL nCountX = pMerge->GetColMerge();
for (SCCOL i=1; i<nCountX; i++)
2000-09-18 23:16:46 +00:00
nCellX += (long) ( pDoc->GetColWidth(nCol+i,nTab) * nPPTX );
}
long nCellY = (long) ( pDoc->GetRowHeight(nRow,nTab) * nPPTY );
if ( pMerge->GetRowMerge() > 1 )
{
SCROW nCountY = pMerge->GetRowMerge();
nCellY += (long) pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY);
2000-09-18 23:16:46 +00:00
}
const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
sal_uInt16 nIndent = 0;
2000-09-18 23:16:46 +00:00
if ( ((const SvxHorJustifyItem&)pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue() ==
SVX_HOR_JUSTIFY_LEFT )
nIndent = ((const SfxUInt16Item&)pPattern->GetItem(ATTR_INDENT)).GetValue();
long nPixDifX = (long) ( ( pMargin->GetLeftMargin() + nIndent ) * nPPTX );
aStartPos.X() += nPixDifX * nLayoutSign;
2000-09-18 23:16:46 +00:00
nCellX -= nPixDifX + (long) ( pMargin->GetRightMargin() * nPPTX ); // wegen Umbruch etc.
// vertikale Position auf die in der Tabelle anpassen
long nPixDifY;
long nTopMargin = (long) ( pMargin->GetTopMargin() * nPPTY );
SvxCellVerJustify eJust = (SvxCellVerJustify) ((const SvxVerJustifyItem&)pPattern->
GetItem(ATTR_VER_JUSTIFY)).GetValue();
2002-04-05 18:21:05 +00:00
// asian vertical is always edited top-aligned
sal_Bool bAsianVertical = ((const SfxBoolItem&)pPattern->GetItem( ATTR_STACKED )).GetValue() &&
2002-04-05 18:21:05 +00:00
((const SfxBoolItem&)pPattern->GetItem( ATTR_VERTICAL_ASIAN )).GetValue();
2001-05-11 15:20:22 +00:00
if ( eJust == SVX_VER_JUSTIFY_TOP ||
2002-04-05 18:21:05 +00:00
( bForceToTop && ( SC_MOD()->GetInputOptions().GetTextWysiwyg() || bAsianVertical ) ) )
2000-09-18 23:16:46 +00:00
nPixDifY = nTopMargin;
else
{
2000-09-25 16:35:04 +00:00
MapMode aMode = pDev->GetMapMode();
pDev->SetMapMode( MAP_PIXEL );
2000-09-18 23:16:46 +00:00
long nTextHeight = pDoc->GetNeededSize( nCol, nRow, nTab,
pDev, nPPTX, nPPTY, aZoomX, aZoomY, false );
2000-09-18 23:16:46 +00:00
if (!nTextHeight)
{ // leere Zelle
Font aFont;
// font color doesn't matter here
pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &aZoomY );
2000-09-18 23:16:46 +00:00
pDev->SetFont(aFont);
nTextHeight = pDev->GetTextHeight() + nTopMargin +
(long) ( pMargin->GetBottomMargin() * nPPTY );
}
2000-09-25 16:35:04 +00:00
pDev->SetMapMode(aMode);
2000-09-18 23:16:46 +00:00
if ( nTextHeight > nCellY + nTopMargin || bForceToTop )
2000-09-18 23:16:46 +00:00
nPixDifY = 0; // zu gross -> oben anfangen
else
{
if ( eJust == SVX_VER_JUSTIFY_CENTER )
nPixDifY = nTopMargin + ( nCellY - nTextHeight ) / 2;
else
nPixDifY = nCellY - nTextHeight + nTopMargin; // JUSTIFY_BOTTOM
}
}
aStartPos.Y() += nPixDifY;
nCellY -= nPixDifY;
if ( bLayoutRTL )
aStartPos.X() -= nCellX - 2; // excluding grid on both sides
2000-09-18 23:16:46 +00:00
// -1 -> Gitter nicht ueberschreiben
return Rectangle( aStartPos, Size(nCellX-1,nCellY-1) );
}
//------------------------------------------------------------------------
ScEditAttrTester::ScEditAttrTester( ScEditEngineDefaulter* pEng ) :
2000-09-18 23:16:46 +00:00
pEngine( pEng ),
pEditAttrs( NULL ),
bNeedsObject( false ),
bNeedsCellAttr( false )
2000-09-18 23:16:46 +00:00
{
if ( pEngine->GetParagraphCount() > 1 )
{
bNeedsObject = sal_True; //! Zellatribute finden ?
2000-09-18 23:16:46 +00:00
}
else
{
const SfxPoolItem* pItem = NULL;
pEditAttrs = new SfxItemSet( pEngine->GetAttribs(
ESelection(0,0,0,pEngine->GetTextLen(0)), EditEngineAttribs_OnlyHard ) );
const SfxItemSet& rEditDefaults = pEngine->GetDefaults();
2000-09-18 23:16:46 +00:00
for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && !bNeedsObject; nId++)
2000-09-18 23:16:46 +00:00
{
SfxItemState eState = pEditAttrs->GetItemState( nId, false, &pItem );
2000-09-18 23:16:46 +00:00
if (eState == SFX_ITEM_DONTCARE)
bNeedsObject = sal_True;
2000-09-18 23:16:46 +00:00
else if (eState == SFX_ITEM_SET)
{
if ( nId == EE_CHAR_ESCAPEMENT || nId == EE_CHAR_PAIRKERNING ||
nId == EE_CHAR_KERNING || nId == EE_CHAR_XMLATTRIBS )
2000-09-18 23:16:46 +00:00
{
// Escapement and kerning are kept in EditEngine because there are no
// corresponding cell format items. User defined attributes are kept in
// EditEngine because "user attributes applied to all the text" is different
// from "user attributes applied to the cell".
if ( *pItem != rEditDefaults.Get(nId) )
bNeedsObject = sal_True;
2000-09-18 23:16:46 +00:00
}
else
if (!bNeedsCellAttr)
if ( *pItem != rEditDefaults.Get(nId) )
bNeedsCellAttr = sal_True;
// rEditDefaults contains the defaults from the cell format
2000-09-18 23:16:46 +00:00
}
}
// Feldbefehle enthalten?
SfxItemState eFieldState = pEditAttrs->GetItemState( EE_FEATURE_FIELD, false );
2000-09-18 23:16:46 +00:00
if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET )
bNeedsObject = sal_True;
2000-09-18 23:16:46 +00:00
// not converted characters?
SfxItemState eConvState = pEditAttrs->GetItemState( EE_FEATURE_NOTCONV, false );
2000-09-18 23:16:46 +00:00
if ( eConvState == SFX_ITEM_DONTCARE || eConvState == SFX_ITEM_SET )
bNeedsObject = sal_True;
2000-09-18 23:16:46 +00:00
}
}
ScEditAttrTester::~ScEditAttrTester()
{
delete pEditAttrs;
}
//------------------------------------------------------------------------
ScEnginePoolHelper::ScEnginePoolHelper( SfxItemPool* pEnginePoolP,
sal_Bool bDeleteEnginePoolP )
2000-09-18 23:16:46 +00:00
:
pEnginePool( pEnginePoolP ),
pDefaults( NULL ),
bDeleteEnginePool( bDeleteEnginePoolP ),
bDeleteDefaults( false )
2000-09-18 23:16:46 +00:00
{
}
ScEnginePoolHelper::ScEnginePoolHelper( const ScEnginePoolHelper& rOrg )
:
pEnginePool( rOrg.bDeleteEnginePool ? rOrg.pEnginePool->Clone() : rOrg.pEnginePool ),
pDefaults( NULL ),
bDeleteEnginePool( rOrg.bDeleteEnginePool ),
bDeleteDefaults( false )
2000-09-18 23:16:46 +00:00
{
}
ScEnginePoolHelper::~ScEnginePoolHelper()
{
if ( bDeleteDefaults )
delete pDefaults;
if ( bDeleteEnginePool )
CWS-TOOLING: integrate CWS aw063 2009-02-12 13:10:24 +0100 aw r267649 : #i99123# when a primitive is invisible, it is not sufficient to produce no output when decomposing, but to add invisible data using HitTestPrimitive2D. This is needed for the slideshow which relies on geometry data in MetaFiles when painting invisible objects 2009-02-12 13:08:39 +0100 aw r267648 : #i99123# do not ignore HitTestPrimitive2D, but draw empty rectangles instead. This is needed since Slideshow is based on getting MetaFile content when painting invisible objects 2009-02-11 16:04:28 +0100 aw r267620 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:04:10 +0100 aw r267619 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:03:56 +0100 aw r267618 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:03:39 +0100 aw r267617 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:03:21 +0100 aw r267615 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:02:48 +0100 aw r267614 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:02:24 +0100 aw r267613 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:02:01 +0100 aw r267612 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:01:32 +0100 aw r267611 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:01:05 +0100 aw r267610 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 16:00:15 +0100 aw r267608 : #i98788# made SfxItemPool destructor protected, added static ::Free method 2009-02-11 11:27:33 +0100 aw r267585 : #i98788# added missing include for STL 2009-02-10 17:46:50 +0100 aw r267570 : #i98788# added reaction on pool destruction 2009-02-10 17:11:58 +0100 aw r267562 : #i98788# added messaging mechanism to register for pool destruction 2009-02-10 13:35:35 +0100 aw r267549 : #i98788# removing changes, too complicated and risky for 3.1 2009-02-10 12:13:48 +0100 aw r267546 : #i98788# 4th round 2009-02-10 12:13:37 +0100 aw r267545 : #i98788# 4th round 2009-02-10 12:13:26 +0100 aw r267544 : #i98788# 4th round 2009-02-10 12:13:14 +0100 aw r267543 : #i98788# 4th round 2009-02-10 12:13:03 +0100 aw r267542 : #i98788# 4th round 2009-02-10 12:12:50 +0100 aw r267541 : #i98788# 4th round 2009-02-10 12:12:37 +0100 aw r267540 : #i98788# 4th round 2009-02-08 14:38:22 +0100 aw r267495 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:38:06 +0100 aw r267494 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:37:48 +0100 aw r267493 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:37:17 +0100 aw r267492 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:36:56 +0100 aw r267491 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:36:44 +0100 aw r267490 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:36:29 +0100 aw r267489 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:36:16 +0100 aw r267488 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:36:02 +0100 aw r267487 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-08 14:35:46 +0100 aw r267486 : #i98788# 3rd round of changes to SfxItemPool handling 2009-02-05 12:20:39 +0100 aw r267415 : #i98788# 2nd batch of adaptions for SfxItemPoolHolder addition 2009-02-04 15:12:54 +0100 aw r267385 : #i98788# added newline at EOF 2009-02-04 13:26:04 +0100 aw r267379 : #i98788# make SfxItemPool holdable 2009-02-04 13:25:40 +0100 aw r267378 : #i98788# make SfxItemPool holdable 2009-02-04 13:25:08 +0100 aw r267377 : #i98788# make SfxItemPool holdable 2009-02-04 13:24:42 +0100 aw r267376 : #i98788# make SfxItemPool holdable 2009-02-04 13:23:14 +0100 aw r267375 : #i98788# make SfxItemPool holdable 2009-02-04 13:23:02 +0100 aw r267374 : #i98788# make SfxItemPool holdable 2009-01-29 17:08:31 +0100 aw r267159 : #i97628# completed the fix 2009-01-29 17:08:15 +0100 aw r267158 : #i97628# completed the fix 2009-01-29 14:09:07 +0100 aw r267132 : #i97628# Corrected usage of ParagraphData in headers 2009-01-29 14:06:58 +0100 iha r267131 : #i98344# incorrect font size in charts 2009-01-29 12:13:46 +0100 aw r267115 : #i97628# back to old state; triggers too many errors in other modules 2009-01-29 12:03:51 +0100 aw r267114 : #i97628# enabled exceptions due to STL vector include 2009-01-29 11:21:37 +0100 aw r267107 : #i97628# added needed include 2009-01-28 17:58:29 +0100 aw r267077 : #i97628# first version of newly implemented OutlinerParaObject and adaptions 2009-01-28 17:58:12 +0100 aw r267076 : #i97628# first version of newly implemented OutlinerParaObject and adaptions 2009-01-28 17:57:51 +0100 aw r267074 : #i97628# first version of newly implemented OutlinerParaObject and adaptions 2009-01-28 17:57:21 +0100 aw r267073 : #i97628# first version of newly implemented OutlinerParaObject and adaptions 2009-01-27 17:07:33 +0100 aw r267011 : #i98402# added support for ViewRange when exporting MetaFiles in ObjectContactOfPageView::DoProcessDisplay to avoid to paint too much 2009-01-27 11:45:48 +0100 aw r266973 : #i98404# Added a warning to a place where a conversion to rectangle should not be copied from 2009-01-26 21:44:36 +0100 iha r266949 : #i98497# 3D charts are rendered with wrong size 2009-01-26 20:47:07 +0100 aw r266947 : #i98404# handle BackgroundColorPrimitive2D directly in PixelRenderers and avoid AA under all circumstances 2009-01-26 14:50:36 +0100 aw r266926 : #i98386# secured cloning of SdrObject in IMapUserData by boost::shared_prt usage 2009-01-26 12:51:30 +0100 aw r266916 : #i96581# added separated FontStretching and fallback for small X!=Y scale differences 2009-01-23 16:14:55 +0100 aw r266834 : #i96475# added missing implementation of TextDecoratedPortionPrimitive2D::getB2DRange 2009-01-23 15:24:34 +0100 aw r266826 : #i98405# fixed fallback to DrawAlphaRect to use the correctly sized rectangle 2009-01-23 13:34:43 +0100 aw r266813 : #i96474# fixed impSplitSingleWords for an unexpected case 2009-01-23 10:47:31 +0100 aw r266786 : #i98289#,#i96474# tooling and new flags for tasks 2009-01-23 10:47:20 +0100 aw r266785 : #i98289#,#i96474# tooling and new flags for tasks 2009-01-23 10:47:09 +0100 aw r266783 : #i98289#,#i96474# tooling and new flags for tasks 2009-01-23 10:46:58 +0100 aw r266782 : #i98289#,#i96474# tooling and new flags for tasks 2009-01-23 10:46:48 +0100 aw r266781 : #i98289#,#i96474# tooling and new flags for tasks
2009-03-04 14:16:02 +00:00
SfxItemPool::Free(pEnginePool);
2000-09-18 23:16:46 +00:00
}
//------------------------------------------------------------------------
ScEditEngineDefaulter::ScEditEngineDefaulter( SfxItemPool* pEnginePoolP,
sal_Bool bDeleteEnginePoolP )
2000-09-18 23:16:46 +00:00
:
ScEnginePoolHelper( pEnginePoolP, bDeleteEnginePoolP ),
EditEngine( pEnginePoolP )
{
// All EditEngines use ScGlobal::GetEditDefaultLanguage as DefaultLanguage.
// DefaultLanguage for InputHandler's EditEngine is updated later.
SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
2000-09-18 23:16:46 +00:00
}
ScEditEngineDefaulter::ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg )
:
ScEnginePoolHelper( rOrg ),
EditEngine( pEnginePool )
{
SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
2000-09-18 23:16:46 +00:00
}
ScEditEngineDefaulter::~ScEditEngineDefaulter()
{
}
void ScEditEngineDefaulter::SetDefaults( const SfxItemSet& rSet, sal_Bool bRememberCopy )
2000-09-18 23:16:46 +00:00
{
if ( bRememberCopy )
{
if ( bDeleteDefaults )
delete pDefaults;
pDefaults = new SfxItemSet( rSet );
bDeleteDefaults = sal_True;
2000-09-18 23:16:46 +00:00
}
const SfxItemSet& rNewSet = bRememberCopy ? *pDefaults : rSet;
sal_Bool bUndo = IsUndoEnabled();
EnableUndo( false );
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
sal_uInt16 nPara = GetParagraphCount();
for ( sal_uInt16 j=0; j<nPara; j++ )
2000-09-18 23:16:46 +00:00
{
SetParaAttribs( j, rNewSet );
}
if ( bUpdateMode )
SetUpdateMode( sal_True );
2000-09-18 23:16:46 +00:00
if ( bUndo )
EnableUndo( sal_True );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetDefaults( SfxItemSet* pSet, sal_Bool bTakeOwnership )
2000-09-18 23:16:46 +00:00
{
if ( bDeleteDefaults )
delete pDefaults;
pDefaults = pSet;
bDeleteDefaults = bTakeOwnership;
if ( pDefaults )
SetDefaults( *pDefaults, false );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetDefaultItem( const SfxPoolItem& rItem )
{
if ( !pDefaults )
{
pDefaults = new SfxItemSet( GetEmptyItemSet() );
bDeleteDefaults = sal_True;
2000-09-18 23:16:46 +00:00
}
pDefaults->Put( rItem );
SetDefaults( *pDefaults, false );
2000-09-18 23:16:46 +00:00
}
const SfxItemSet& ScEditEngineDefaulter::GetDefaults()
{
if ( !pDefaults )
{
pDefaults = new SfxItemSet( GetEmptyItemSet() );
bDeleteDefaults = sal_True;
}
return *pDefaults;
}
2000-09-18 23:16:46 +00:00
void ScEditEngineDefaulter::SetText( const EditTextObject& rTextObject )
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
2000-09-18 23:16:46 +00:00
EditEngine::SetText( rTextObject );
if ( pDefaults )
SetDefaults( *pDefaults, false );
if ( bUpdateMode )
SetUpdateMode( sal_True );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
const SfxItemSet& rSet, sal_Bool bRememberCopy )
2000-09-18 23:16:46 +00:00
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
2000-09-18 23:16:46 +00:00
EditEngine::SetText( rTextObject );
SetDefaults( rSet, bRememberCopy );
if ( bUpdateMode )
SetUpdateMode( sal_True );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
SfxItemSet* pSet, sal_Bool bTakeOwnership )
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
EditEngine::SetText( rTextObject );
SetDefaults( pSet, bTakeOwnership );
if ( bUpdateMode )
SetUpdateMode( sal_True );
}
2000-09-18 23:16:46 +00:00
void ScEditEngineDefaulter::SetText( const String& rText )
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
2000-09-18 23:16:46 +00:00
EditEngine::SetText( rText );
if ( pDefaults )
SetDefaults( *pDefaults, false );
if ( bUpdateMode )
SetUpdateMode( sal_True );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
const SfxItemSet& rSet, sal_Bool bRememberCopy )
2000-09-18 23:16:46 +00:00
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
2000-09-18 23:16:46 +00:00
EditEngine::SetText( rText );
SetDefaults( rSet, bRememberCopy );
if ( bUpdateMode )
SetUpdateMode( sal_True );
2000-09-18 23:16:46 +00:00
}
void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
SfxItemSet* pSet, sal_Bool bTakeOwnership )
{
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
EditEngine::SetText( rText );
SetDefaults( pSet, bTakeOwnership );
if ( bUpdateMode )
SetUpdateMode( sal_True );
}
2000-09-18 23:16:46 +00:00
void ScEditEngineDefaulter::RepeatDefaults()
{
if ( pDefaults )
{
sal_uInt16 nPara = GetParagraphCount();
for ( sal_uInt16 j=0; j<nPara; j++ )
SetParaAttribs( j, *pDefaults );
}
}
void ScEditEngineDefaulter::RemoveParaAttribs()
{
SfxItemSet* pCharItems = NULL;
sal_Bool bUpdateMode = GetUpdateMode();
if ( bUpdateMode )
SetUpdateMode( false );
sal_uInt16 nParCount = GetParagraphCount();
for (sal_uInt16 nPar=0; nPar<nParCount; nPar++)
{
const SfxItemSet& rParaAttribs = GetParaAttribs( nPar );
sal_uInt16 nWhich;
for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
{
const SfxPoolItem* pParaItem;
if ( rParaAttribs.GetItemState( nWhich, false, &pParaItem ) == SFX_ITEM_SET )
{
// if defaults are set, use only items that are different from default
if ( !pDefaults || *pParaItem != pDefaults->Get(nWhich) )
{
if (!pCharItems)
pCharItems = new SfxItemSet( GetEmptyItemSet() );
pCharItems->Put( *pParaItem );
}
}
}
if ( pCharItems )
{
std::vector<sal_uInt16> aPortions;
GetPortions( nPar, aPortions );
// loop through the portions of the paragraph, and set only those items
// that are not overridden by existing character attributes
sal_uInt16 nStart = 0;
for ( std::vector<sal_uInt16>::const_iterator it(aPortions.begin()); it != aPortions.end(); ++it )
{
sal_uInt16 nEnd = *it;
ESelection aSel( nPar, nStart, nPar, nEnd );
SfxItemSet aOldCharAttrs = GetAttribs( aSel );
SfxItemSet aNewCharAttrs = *pCharItems;
for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
{
// Clear those items that are different from existing character attributes.
// Where no character attributes are set, GetAttribs returns the paragraph attributes.
const SfxPoolItem* pItem;
if ( aNewCharAttrs.GetItemState( nWhich, false, &pItem ) == SFX_ITEM_SET &&
*pItem != aOldCharAttrs.Get(nWhich) )
{
aNewCharAttrs.ClearItem(nWhich);
}
}
if ( aNewCharAttrs.Count() )
QuickSetAttribs( aNewCharAttrs, aSel );
nStart = nEnd;
}
DELETEZ( pCharItems );
}
if ( rParaAttribs.Count() )
{
// clear all paragraph attributes (including defaults),
// so they are not contained in resulting EditTextObjects
SetParaAttribs( nPar, SfxItemSet( *rParaAttribs.GetPool(), rParaAttribs.GetRanges() ) );
}
}
if ( bUpdateMode )
SetUpdateMode( sal_True );
}
2000-09-18 23:16:46 +00:00
//------------------------------------------------------------------------
ScTabEditEngine::ScTabEditEngine( ScDocument* pDoc )
: ScEditEngineDefaulter( pDoc->GetEnginePool() )
{
SetEditTextObjectPool( pDoc->GetEditPool() );
Init((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
}
ScTabEditEngine::ScTabEditEngine( const ScPatternAttr& rPattern,
SfxItemPool* pEnginePoolP, SfxItemPool* pTextObjectPool )
: ScEditEngineDefaulter( pEnginePoolP )
2000-09-18 23:16:46 +00:00
{
if ( pTextObjectPool )
SetEditTextObjectPool( pTextObjectPool );
Init( rPattern );
}
void ScTabEditEngine::Init( const ScPatternAttr& rPattern )
{
SetRefMapMode(MAP_100TH_MM);
SfxItemSet* pEditDefaults = new SfxItemSet( GetEmptyItemSet() );
rPattern.FillEditItemSet( pEditDefaults );
SetDefaults( pEditDefaults );
// wir haben keine StyleSheets fuer Text
SetControlWord( GetControlWord() & ~EE_CNTRL_RTFSTYLESHEETS );
}
//------------------------------------------------------------------------
// Feldbefehle fuer Kopf- und Fusszeilen
//------------------------------------------------------------------------
//
// Zahlen aus \sw\source\core\doc\numbers.cxx
//
String lcl_GetCharStr( sal_Int32 nNo )
2000-09-18 23:16:46 +00:00
{
OSL_ENSURE( nNo, "0 ist eine ungueltige Nummer !!" );
2000-09-18 23:16:46 +00:00
String aStr;
const sal_Int32 coDiff = 'Z' - 'A' +1;
sal_Int32 nCalc;
2000-09-18 23:16:46 +00:00
do {
nCalc = nNo % coDiff;
if( !nCalc )
nCalc = coDiff;
aStr.Insert( (sal_Unicode)('a' - 1 + nCalc ), 0 );
nNo = sal::static_int_cast<sal_Int32>( nNo - nCalc );
2000-09-18 23:16:46 +00:00
if( nNo )
nNo /= coDiff;
} while( nNo );
return aStr;
}
String lcl_GetNumStr( sal_Int32 nNo, SvxNumType eType )
2000-09-18 23:16:46 +00:00
{
String aTmpStr( '0' );
if( nNo )
{
switch( eType )
{
case SVX_CHARS_UPPER_LETTER:
case SVX_CHARS_LOWER_LETTER:
aTmpStr = lcl_GetCharStr( nNo );
break;
case SVX_ROMAN_UPPER:
case SVX_ROMAN_LOWER:
if( nNo < 4000 )
aTmpStr = SvxNumberFormat::CreateRomanString( nNo, ( eType == SVX_ROMAN_UPPER ) );
else
aTmpStr.Erase();
2000-09-18 23:16:46 +00:00
break;
case SVX_NUMBER_NONE:
aTmpStr.Erase();
break;
// CHAR_SPECIAL:
// ????
// case ARABIC: ist jetzt default
default:
aTmpStr = String::CreateFromInt32( nNo );
break;
}
if( SVX_CHARS_UPPER_LETTER == eType )
2000-09-18 23:16:46 +00:00
aTmpStr.ToUpperAscii();
}
return aTmpStr;
}
ScHeaderFieldData::ScHeaderFieldData()
:
aDate( Date::EMPTY ),
aTime( Time::EMPTY )
2000-09-18 23:16:46 +00:00
{
nPageNo = nTotalPages = 0;
eNumType = SVX_ARABIC;
}
ScHeaderEditEngine::ScHeaderEditEngine( SfxItemPool* pEnginePoolP, sal_Bool bDeleteEnginePoolP )
: ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
2000-09-18 23:16:46 +00:00
{
}
2010-12-11 23:25:30 +01:00
String ScHeaderEditEngine::CalcFieldValue( const SvxFieldItem& rField,
sal_uInt16 /* nPara */, sal_uInt16 /* nPos */,
Color*& /* rTxtColor */, Color*& /* rFldColor */ )
2000-09-18 23:16:46 +00:00
{
String aRet;
const SvxFieldData* pFieldData = rField.GetField();
if ( pFieldData )
{
TypeId aType = pFieldData->Type();
if (aType == TYPE(SvxPageField))
aRet = lcl_GetNumStr( aData.nPageNo,aData.eNumType );
2000-09-18 23:16:46 +00:00
else if (aType == TYPE(SvxPagesField))
aRet = lcl_GetNumStr( aData.nTotalPages,aData.eNumType );
2000-09-18 23:16:46 +00:00
else if (aType == TYPE(SvxTimeField))
aRet = ScGlobal::pLocaleData->getTime(aData.aTime);
2000-09-18 23:16:46 +00:00
else if (aType == TYPE(SvxFileField))
aRet = aData.aTitle;
else if (aType == TYPE(SvxExtFileField))
{
switch ( ((const SvxExtFileField*)pFieldData)->GetFormat() )
{
case SVXFILEFORMAT_FULLPATH :
aRet = aData.aLongDocName;
break;
default:
aRet = aData.aShortDocName;
}
}
else if (aType == TYPE(SvxTableField))
aRet = aData.aTabName;
else if (aType == TYPE(SvxDateField))
aRet = ScGlobal::pLocaleData->getDate(aData.aDate);
2000-09-18 23:16:46 +00:00
else
{
aRet = '?';
}
}
else
{
2011-03-01 19:05:02 +01:00
OSL_FAIL("FieldData ist 0");
2000-09-18 23:16:46 +00:00
aRet = '?';
}
return aRet;
}
//------------------------------------------------------------------------
//
// Feld-Daten
//
//------------------------------------------------------------------------
ScFieldEditEngine::ScFieldEditEngine(
ScDocument* pDoc, SfxItemPool* pEnginePoolP,
SfxItemPool* pTextObjectPool, bool bDeleteEnginePoolP) :
ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP ),
mpDoc(pDoc), bExecuteURL(true)
2000-09-18 23:16:46 +00:00
{
if ( pTextObjectPool )
SetEditTextObjectPool( pTextObjectPool );
// EE_CNTRL_URLSFXEXECUTE nicht, weil die Edit-Engine den ViewFrame nicht kennt
// wir haben keine StyleSheets fuer Text
SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );
}
2010-12-11 23:25:30 +01:00
String ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField,
sal_uInt16 /* nPara */, sal_uInt16 /* nPos */,
Color*& rTxtColor, Color*& /* rFldColor */ )
2000-09-18 23:16:46 +00:00
{
rtl::OUString aRet;
2000-09-18 23:16:46 +00:00
const SvxFieldData* pFieldData = rField.GetField();
if (!pFieldData)
return rtl::OUString(" ");
2000-09-18 23:16:46 +00:00
sal_uInt16 nClsId = pFieldData->GetClassId();
switch (nClsId)
{
case SVX_URLFIELD:
2000-09-18 23:16:46 +00:00
{
const SvxURLField* pField = static_cast<const SvxURLField*>(pFieldData);
rtl::OUString aURL = pField->GetURL();
2002-05-03 10:58:48 +00:00
switch (pField->GetFormat())
2000-09-18 23:16:46 +00:00
{
case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
case SVXURLFORMAT_REPR:
aRet = pField->GetRepresentation();
break;
2000-09-18 23:16:46 +00:00
case SVXURLFORMAT_URL:
2002-05-03 10:58:48 +00:00
aRet = aURL;
break;
default:
;
2000-09-18 23:16:46 +00:00
}
2002-05-03 10:58:48 +00:00
svtools::ColorConfigEntry eEntry =
INetURLHistory::GetOrCreate()->QueryUrl(String(aURL)) ? svtools::LINKSVISITED : svtools::LINKS;
2002-05-03 10:58:48 +00:00
rTxtColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor );
2000-09-18 23:16:46 +00:00
}
break;
case SVX_EXT_TIMEFIELD:
2000-09-18 23:16:46 +00:00
{
const SvxExtTimeField* pField = static_cast<const SvxExtTimeField*>(pFieldData);
if (mpDoc)
aRet = pField->GetFormatted(*mpDoc->GetFormatTable(), ScGlobal::eLnge);
2000-09-18 23:16:46 +00:00
}
break;
case SVX_DATEFIELD:
{
Date aDate(Date::SYSTEM);
aRet = ScGlobal::pLocaleData->getDate(aDate);
}
break;
default:
aRet = "?";
2000-09-18 23:16:46 +00:00
}
if (aRet.isEmpty()) // leer ist baeh
aRet = " "; // Space ist Default der Editengine
2000-09-18 23:16:46 +00:00
return aRet;
}
void ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField, sal_uInt16, sal_uInt16 )
2000-09-18 23:16:46 +00:00
{
const SvxFieldData* pFld = rField.GetField();
if ( pFld && pFld->ISA( SvxURLField ) && bExecuteURL )
{
const SvxURLField* pURLField = (const SvxURLField*) pFld;
ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
}
}
//------------------------------------------------------------------------
ScNoteEditEngine::ScNoteEditEngine( SfxItemPool* pEnginePoolP,
SfxItemPool* pTextObjectPool, sal_Bool bDeleteEnginePoolP ) :
ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
{
if ( pTextObjectPool )
SetEditTextObjectPool( pTextObjectPool );
SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */