Files
libreoffice/svx/source/svdraw/svdotxed.cxx

337 lines
11 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: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 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 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +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 <svx/svdotext.hxx>
#include <svx/svdmodel.hxx>
#include <svx/svdoutl.hxx>
#include <editeng/editdata.hxx>
#include <editeng/outliner.hxx>
#include <editeng/editstat.hxx>
#include <svl/itemset.hxx>
#include <editeng/eeitem.hxx>
CWS-TOOLING: integrate CWS impress166 2009-01-27 11:42:29 +0100 af r266972 : #i98508# Handle non DrawViewShell view shells correctly. 2009-01-21 10:41:32 +0100 af r266635 : #i98069# Do not call PreModelChange() for every ModelLock. 2009-01-20 15:25:41 +0100 af r266588 : #i98069# Added friend declaration that became necessary on Solaris after recent changes. 2009-01-19 13:48:47 +0100 af r266493 : #i97478# Prevent SID_PARASPACE_(DE|IN)CREASE from crashing when style sheet is missing. 2009-01-16 11:52:37 +0100 af r266411 : #i97338# Check the dispatcher before using it to show a context menu. 2009-01-15 14:33:55 +0100 sj r266373 : #153716# taking care of font-independent line spacing (editmode and hittest) 2009-01-15 14:29:46 +0100 sj r266372 : #153716# taking care of font-independent line spacing also in presentation styles 2009-01-14 14:04:16 +0100 af r266301 : #i97634# Do view change synchronously. Use shared pointers for view shells. 2009-01-14 14:01:27 +0100 af r266300 : #i97634# Added non-API methods that update the configuration synchronously. 2009-01-14 13:34:40 +0100 af r266295 : #i98069# Be more carefull with handling model updates to avoid assertion regarding number of selected pages. 2009-01-14 11:34:57 +0100 cl r266270 : #i97261# force outliner para oibject after text edit 2009-01-14 10:49:08 +0100 cl r266269 : #i97413# dispose cell undo action if shape dies 2009-01-13 18:50:05 +0100 cl r266247 : #i97347# fixed cell undo crash 2009-01-12 14:16:56 +0100 af r266156 : #i97296# Using is() method to check WeakReference for validity. 2009-01-12 13:52:00 +0100 af r266155 : #i97190# Turned static_cast to dynamic_cast in CreateChildList. 2009-01-12 13:06:57 +0100 af r266153 : #i97552# Catching Exceptions caught while accessing OLE-Object that is to be inserted. 2009-01-12 13:06:37 +0100 cl r266152 : #i96164# applied patch to fix ambiguous operation
2009-02-12 12:44:26 +00:00
#include <svx/sdtfchim.hxx>
2000-09-18 16:07:07 +00:00
2010-10-05 07:57:54 -05:00
bool SdrTextObj::HasTextEdit() const
2000-09-18 16:07:07 +00:00
{
2012-01-24 12:54:39 +05:30
// linked text objects may be changed (no automatic reload)
2010-10-05 07:57:54 -05:00
return true;
2000-09-18 16:07:07 +00:00
}
bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
2000-09-18 16:07:07 +00:00
{
if (pEdtOutl!=NULL) return false; // Textedit might already run in another View!
2000-09-18 16:07:07 +00:00
pEdtOutl=&rOutl;
mbInEditMode = true;
sal_uInt16 nOutlinerMode = OUTLINERMODE_OUTLINEOBJECT;
2000-09-18 16:07:07 +00:00
if ( !IsOutlText() )
nOutlinerMode = OUTLINERMODE_TEXTOBJECT;
rOutl.Init( nOutlinerMode );
rOutl.SetRefDevice( pModel->GetRefDevice() );
2010-10-05 07:57:54 -05:00
bool bFitToSize(IsFitToSize());
bool bContourFrame=IsContourTextFrame();
2000-09-18 16:07:07 +00:00
ImpSetTextEditParams();
if (!bContourFrame) {
EEControlBits nStat=rOutl.GetControlWord();
nStat|=EEControlBits::AUTOPAGESIZE;
if (bFitToSize || IsAutoFit())
nStat|=EEControlBits::STRETCHING;
else
nStat&=~EEControlBits::STRETCHING;
2000-09-18 16:07:07 +00:00
rOutl.SetControlWord(nStat);
}
OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
if(pOutlinerParaObject!=NULL)
{
rOutl.SetText(*GetOutlinerParaObject());
rOutl.SetFixedCellHeight(static_cast<const SdrTextFixedCellHeightItem&>(GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
2000-09-18 16:07:07 +00:00
}
CWS-TOOLING: integrate CWS impress166 2009-01-27 11:42:29 +0100 af r266972 : #i98508# Handle non DrawViewShell view shells correctly. 2009-01-21 10:41:32 +0100 af r266635 : #i98069# Do not call PreModelChange() for every ModelLock. 2009-01-20 15:25:41 +0100 af r266588 : #i98069# Added friend declaration that became necessary on Solaris after recent changes. 2009-01-19 13:48:47 +0100 af r266493 : #i97478# Prevent SID_PARASPACE_(DE|IN)CREASE from crashing when style sheet is missing. 2009-01-16 11:52:37 +0100 af r266411 : #i97338# Check the dispatcher before using it to show a context menu. 2009-01-15 14:33:55 +0100 sj r266373 : #153716# taking care of font-independent line spacing (editmode and hittest) 2009-01-15 14:29:46 +0100 sj r266372 : #153716# taking care of font-independent line spacing also in presentation styles 2009-01-14 14:04:16 +0100 af r266301 : #i97634# Do view change synchronously. Use shared pointers for view shells. 2009-01-14 14:01:27 +0100 af r266300 : #i97634# Added non-API methods that update the configuration synchronously. 2009-01-14 13:34:40 +0100 af r266295 : #i98069# Be more carefull with handling model updates to avoid assertion regarding number of selected pages. 2009-01-14 11:34:57 +0100 cl r266270 : #i97261# force outliner para oibject after text edit 2009-01-14 10:49:08 +0100 cl r266269 : #i97413# dispose cell undo action if shape dies 2009-01-13 18:50:05 +0100 cl r266247 : #i97347# fixed cell undo crash 2009-01-12 14:16:56 +0100 af r266156 : #i97296# Using is() method to check WeakReference for validity. 2009-01-12 13:52:00 +0100 af r266155 : #i97190# Turned static_cast to dynamic_cast in CreateChildList. 2009-01-12 13:06:57 +0100 af r266153 : #i97552# Catching Exceptions caught while accessing OLE-Object that is to be inserted. 2009-01-12 13:06:37 +0100 cl r266152 : #i96164# applied patch to fix ambiguous operation
2009-02-12 12:44:26 +00:00
2012-01-24 12:54:39 +05:30
// if necessary, set frame attributes for the first (new) paragraph of the
// outliner
if( !HasTextImpl( &rOutl ) )
{
// Outliner has no text so we must set some
// empty text so the outliner initialise itself
rOutl.SetText( "", rOutl.GetParagraph( 0 ) );
if(GetStyleSheet())
rOutl.SetStyleSheet( 0, GetStyleSheet());
2012-01-24 12:54:39 +05:30
// When setting the "hard" attributes for first paragraph, the Parent
// pOutlAttr (i. e. the template) has to be removed temporarily. Else,
// at SetParaAttribs(), all attributes contained in the parent become
// attributed hard to the paragraph.
const SfxItemSet& rSet = GetObjectItemSet();
SfxItemSet aFilteredSet(*rSet.GetPool(), EE_ITEMS_START, EE_ITEMS_END);
aFilteredSet.Put(rSet);
rOutl.SetParaAttribs(0, aFilteredSet);
2000-09-18 16:07:07 +00:00
}
if (bFitToSize)
{
2000-09-18 16:07:07 +00:00
Rectangle aAnchorRect;
Rectangle aTextRect;
TakeTextRect(rOutl, aTextRect, false,
2011-05-12 11:03:28 +02:00
&aAnchorRect);
Fraction aFitXKorreg(1,1);
ImpSetCharStretching(rOutl,aTextRect.GetSize(),aAnchorRect.GetSize(),aFitXKorreg);
}
else if (IsAutoFit())
{
ImpAutoFitText(rOutl);
2000-09-18 16:07:07 +00:00
}
if(pOutlinerParaObject)
{
if(aGeo.nRotationAngle || IsFontwork())
{
// only repaint here, no real objectchange
BroadcastObjectChange();
}
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
rOutl.UpdateFields();
rOutl.ClearModifyFlag();
2002-02-28 09:05:49 +00:00
return true;
2000-09-18 16:07:07 +00:00
}
void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
{
2010-10-05 07:57:54 -05:00
bool bFitToSize(IsFitToSize());
2000-09-18 16:07:07 +00:00
Size aPaperMin,aPaperMax;
Rectangle aViewInit;
TakeTextAnchorRect(aViewInit);
if (aGeo.nRotationAngle!=0) {
2000-09-18 16:07:07 +00:00
Point aCenter(aViewInit.Center());
aCenter-=aViewInit.TopLeft();
Point aCenter0(aCenter);
RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
aCenter-=aCenter0;
aViewInit.Move(aCenter.X(),aCenter.Y());
}
Size aAnkSiz(aViewInit.GetSize());
2012-01-24 12:54:39 +05:30
aAnkSiz.Width()--; aAnkSiz.Height()--; // because GetSize() adds 1
2000-09-18 16:07:07 +00:00
Size aMaxSiz(1000000,1000000);
if (pModel!=NULL) {
Size aTmpSiz(pModel->GetMaxObjSize());
if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
}
// Done earlier since used in else tree below
SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
SdrTextVertAdjust eVAdj(GetTextVerticalAdjust());
if(IsTextFrame())
{
2000-09-18 16:07:07 +00:00
long nMinWdt=GetMinTextFrameWidth();
long nMinHgt=GetMinTextFrameHeight();
long nMaxWdt=GetMaxTextFrameWidth();
long nMaxHgt=GetMaxTextFrameHeight();
if (nMinWdt<1) nMinWdt=1;
if (nMinHgt<1) nMinHgt=1;
if (!bFitToSize) {
if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
if (!IsAutoGrowWidth() )
{
nMinWdt = aAnkSiz.Width();
nMaxWdt = nMinWdt;
}
if (!IsAutoGrowHeight())
{
nMinHgt = aAnkSiz.Height();
nMaxHgt = nMinHgt;
}
2000-09-18 16:07:07 +00:00
SdrTextAniKind eAniKind=GetTextAniKind();
SdrTextAniDirection eAniDirection=GetTextAniDirection();
bool bInEditMode = IsInEditMode();
if (!bInEditMode && (eAniKind==SDRTEXTANI_SCROLL || eAniKind==SDRTEXTANI_ALTERNATE || eAniKind==SDRTEXTANI_SLIDE))
{
2012-01-24 12:54:39 +05:30
// ticker text uses an unlimited paper size
2000-09-18 16:07:07 +00:00
if (eAniDirection==SDRTEXTANI_LEFT || eAniDirection==SDRTEXTANI_RIGHT) nMaxWdt=1000000;
if (eAniDirection==SDRTEXTANI_UP || eAniDirection==SDRTEXTANI_DOWN) nMaxHgt=1000000;
}
// #i119885# Do not limit/force height to geometrical frame (vice versa for vertical writing)
if(IsVerticalWriting())
{
nMaxWdt = 1000000;
}
else
{
nMaxHgt = 1000000;
}
2000-09-18 16:07:07 +00:00
aPaperMax.Width()=nMaxWdt;
aPaperMax.Height()=nMaxHgt;
}
else
{
2000-09-18 16:07:07 +00:00
aPaperMax=aMaxSiz;
}
aPaperMin.Width()=nMinWdt;
aPaperMin.Height()=nMinHgt;
}
else
{
// aPaperMin needs to be set to object's size if full width is activated
// for hor or ver writing respectively
if((SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
|| (SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting()))
{
aPaperMin = aAnkSiz;
}
2000-09-18 16:07:07 +00:00
aPaperMax=aMaxSiz;
}
if (pViewMin!=NULL) {
*pViewMin=aViewInit;
long nXFree=aAnkSiz.Width()-aPaperMin.Width();
if (eHAdj==SDRTEXTHORZADJUST_LEFT) pViewMin->Right()-=nXFree;
else if (eHAdj==SDRTEXTHORZADJUST_RIGHT) pViewMin->Left()+=nXFree;
else { pViewMin->Left()+=nXFree/2; pViewMin->Right()=pViewMin->Left()+aPaperMin.Width(); }
long nYFree=aAnkSiz.Height()-aPaperMin.Height();
if (eVAdj==SDRTEXTVERTADJUST_TOP) pViewMin->Bottom()-=nYFree;
else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM) pViewMin->Top()+=nYFree;
else { pViewMin->Top()+=nYFree/2; pViewMin->Bottom()=pViewMin->Top()+aPaperMin.Height(); }
}
2012-01-24 12:54:39 +05:30
// PaperSize should grow automatically in most cases
if(IsVerticalWriting())
aPaperMin.Width() = 0;
else
2011-05-12 11:03:28 +02:00
aPaperMin.Height() = 0;
if(eHAdj!=SDRTEXTHORZADJUST_BLOCK || bFitToSize) {
2000-09-18 16:07:07 +00:00
aPaperMin.Width()=0;
}
2012-01-24 12:54:39 +05:30
// For complete vertical adjustment support, set paper min height to 0, here.
if(SDRTEXTVERTADJUST_BLOCK != eVAdj || bFitToSize)
{
aPaperMin.Height() = 0;
}
2000-09-18 16:07:07 +00:00
if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
if (pViewInit!=NULL) *pViewInit=aViewInit;
}
void SdrTextObj::EndTextEdit(SdrOutliner& rOutl)
{
if(rOutl.IsModified())
{
OutlinerParaObject* pNewText = NULL;
// to make the gray field background vanish again
rOutl.UpdateFields();
2000-09-18 16:07:07 +00:00
sal_Int32 nParaAnz = rOutl.GetParagraphCount();
pNewText = rOutl.CreateParaObject( 0, nParaAnz );
// need to end edit mode early since SetOutlinerParaObject already
// uses GetCurrentBoundRect() which needs to take the text into account
// to work correct
mbInEditMode = false;
2000-09-18 16:07:07 +00:00
SetOutlinerParaObject(pNewText);
}
pEdtOutl = NULL;
rOutl.Clear();
EEControlBits nStat = rOutl.GetControlWord();
nStat &= ~EEControlBits::AUTOPAGESIZE;
2000-09-18 16:07:07 +00:00
rOutl.SetControlWord(nStat);
mbInEditMode = false;
2000-09-18 16:07:07 +00:00
}
sal_uInt16 SdrTextObj::GetOutlinerViewAnchorMode() const
2000-09-18 16:07:07 +00:00
{
SdrTextHorzAdjust eH=GetTextHorizontalAdjust();
SdrTextVertAdjust eV=GetTextVerticalAdjust();
EVAnchorMode eRet=ANCHOR_TOP_LEFT;
if (IsContourTextFrame()) return (sal_uInt16)eRet;
2000-09-18 16:07:07 +00:00
if (eH==SDRTEXTHORZADJUST_LEFT) {
if (eV==SDRTEXTVERTADJUST_TOP) {
eRet=ANCHOR_TOP_LEFT;
} else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
eRet=ANCHOR_BOTTOM_LEFT;
} else {
eRet=ANCHOR_VCENTER_LEFT;
}
} else if (eH==SDRTEXTHORZADJUST_RIGHT) {
if (eV==SDRTEXTVERTADJUST_TOP) {
eRet=ANCHOR_TOP_RIGHT;
} else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
eRet=ANCHOR_BOTTOM_RIGHT;
} else {
eRet=ANCHOR_VCENTER_RIGHT;
}
} else {
if (eV==SDRTEXTVERTADJUST_TOP) {
eRet=ANCHOR_TOP_HCENTER;
} else if (eV==SDRTEXTVERTADJUST_BOTTOM) {
eRet=ANCHOR_BOTTOM_HCENTER;
} else {
eRet=ANCHOR_VCENTER_HCENTER;
}
}
return (sal_uInt16)eRet;
2000-09-18 16:07:07 +00:00
}
void SdrTextObj::ImpSetTextEditParams() const
{
if (pEdtOutl!=NULL) {
2010-10-05 07:57:54 -05:00
bool bUpdMerk=pEdtOutl->GetUpdateMode();
if (bUpdMerk) pEdtOutl->SetUpdateMode(false);
2000-09-18 16:07:07 +00:00
Size aPaperMin;
Size aPaperMax;
Rectangle aEditArea;
TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,NULL);
2010-10-05 07:57:54 -05:00
bool bContourFrame=IsContourTextFrame();
2000-09-18 16:07:07 +00:00
pEdtOutl->SetMinAutoPaperSize(aPaperMin);
pEdtOutl->SetMaxAutoPaperSize(aPaperMax);
pEdtOutl->SetPaperSize(Size());
if (bContourFrame) {
Rectangle aAnchorRect;
TakeTextAnchorRect(aAnchorRect);
ImpSetContourPolygon(*pEdtOutl,aAnchorRect, true);
2000-09-18 16:07:07 +00:00
}
if (bUpdMerk) pEdtOutl->SetUpdateMode(true);
2000-09-18 16:07:07 +00:00
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */