xref: /aoo41x/main/sw/source/ui/frmdlg/frmmgr.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "cmdid.h"
32*cdf0e10cSrcweir #include "hintids.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <svl/stritem.hxx>
35*cdf0e10cSrcweir #include <editeng/protitem.hxx>
36*cdf0e10cSrcweir #include <editeng/boxitem.hxx>
37*cdf0e10cSrcweir #include <editeng/opaqitem.hxx>
38*cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
39*cdf0e10cSrcweir #include <editeng/ulspitem.hxx>
40*cdf0e10cSrcweir #include <editeng/shaditem.hxx>
41*cdf0e10cSrcweir #include <svx/swframevalidation.hxx>
42*cdf0e10cSrcweir #include <fmtclds.hxx>
43*cdf0e10cSrcweir #include "wrtsh.hxx"
44*cdf0e10cSrcweir #include "view.hxx"
45*cdf0e10cSrcweir #include "viewopt.hxx"
46*cdf0e10cSrcweir #include "uitool.hxx"
47*cdf0e10cSrcweir #include "frmmgr.hxx"
48*cdf0e10cSrcweir #include "format.hxx"
49*cdf0e10cSrcweir #include "mdiexp.hxx"
50*cdf0e10cSrcweir #include "poolfmt.hxx"
51*cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/text/HoriOrientation.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/text/VertOrientation.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/text/RelOrientation.hpp>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir //using namespace text;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir static sal_uInt16 __FAR_DATA aFrmMgrRange[] = {
60*cdf0e10cSrcweir 							RES_FRMATR_BEGIN, RES_FRMATR_END-1,
61*cdf0e10cSrcweir 							SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
62*cdf0e10cSrcweir 							FN_SET_FRM_NAME, FN_SET_FRM_NAME,
63*cdf0e10cSrcweir 							0};
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir /*--------------------------------------------------------------------
66*cdf0e10cSrcweir 	 Beschreibung: Rahmen-Attribute ueber Shell ermitteln
67*cdf0e10cSrcweir  --------------------------------------------------------------------*/
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir SwFlyFrmAttrMgr::SwFlyFrmAttrMgr( sal_Bool bNew, SwWrtShell* pSh, sal_uInt8 nType ) :
70*cdf0e10cSrcweir     aSet( (SwAttrPool&)pSh->GetAttrPool(), aFrmMgrRange ),
71*cdf0e10cSrcweir     pOwnSh( pSh ),
72*cdf0e10cSrcweir     bAbsPos( sal_False ),
73*cdf0e10cSrcweir     bNewFrm( bNew ),
74*cdf0e10cSrcweir     bIsInVertical( sal_False ),
75*cdf0e10cSrcweir     bIsInVerticalL2R( sal_False )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir 	if ( bNewFrm )
78*cdf0e10cSrcweir 	{
79*cdf0e10cSrcweir 		// Defaults einstellen:
80*cdf0e10cSrcweir         sal_uInt16 nId = 0;
81*cdf0e10cSrcweir 		switch ( nType )
82*cdf0e10cSrcweir 		{
83*cdf0e10cSrcweir 			case FRMMGR_TYPE_TEXT:	nId = RES_POOLFRM_FRAME;	break;
84*cdf0e10cSrcweir 			case FRMMGR_TYPE_OLE:	nId = RES_POOLFRM_OLE;		break;
85*cdf0e10cSrcweir 			case FRMMGR_TYPE_GRF:	nId = RES_POOLFRM_GRAPHIC;	break;
86*cdf0e10cSrcweir 		}
87*cdf0e10cSrcweir 		aSet.SetParent( &pOwnSh->GetFmtFromPool( nId )->GetAttrSet());
88*cdf0e10cSrcweir 		aSet.Put( SwFmtFrmSize( ATT_MIN_SIZE, DFLT_WIDTH, DFLT_HEIGHT ));
89*cdf0e10cSrcweir 		if ( 0 != ::GetHtmlMode(pSh->GetView().GetDocShell()) )
90*cdf0e10cSrcweir             aSet.Put( SwFmtHoriOrient( 0, text::HoriOrientation::LEFT, text::RelOrientation::PRINT_AREA ) );
91*cdf0e10cSrcweir 	}
92*cdf0e10cSrcweir 	else if ( nType == FRMMGR_TYPE_NONE )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir 		pOwnSh->GetFlyFrmAttr( aSet );
95*cdf0e10cSrcweir         sal_Bool bRightToLeft;
96*cdf0e10cSrcweir         bIsInVertical = pOwnSh->IsFrmVertical(sal_True, bRightToLeft, bIsInVerticalL2R);
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir 	::PrepareBoxInfo( aSet, *pOwnSh );
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir SwFlyFrmAttrMgr::SwFlyFrmAttrMgr( sal_Bool bNew, SwWrtShell* pSh, const SfxItemSet &rSet ) :
102*cdf0e10cSrcweir     aSet( rSet ),
103*cdf0e10cSrcweir     pOwnSh( pSh ),
104*cdf0e10cSrcweir 	bAbsPos( sal_False ),
105*cdf0e10cSrcweir 	bNewFrm( bNew ),
106*cdf0e10cSrcweir 	bIsInVertical(sal_False),
107*cdf0e10cSrcweir     bIsInVerticalL2R(sal_False)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir 	if(!bNew)
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		sal_Bool bRightToLeft;
112*cdf0e10cSrcweir         bIsInVertical = pSh->IsFrmVertical(sal_True, bRightToLeft, bIsInVerticalL2R);
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /*--------------------------------------------------------------------
118*cdf0e10cSrcweir 	 Beschreibung:	Initialisieren
119*cdf0e10cSrcweir  --------------------------------------------------------------------*/
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void SwFlyFrmAttrMgr::UpdateAttrMgr()
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	if ( !bNewFrm && pOwnSh->IsFrmSelected() )
124*cdf0e10cSrcweir 		pOwnSh->GetFlyFrmAttr( aSet );
125*cdf0e10cSrcweir 	::PrepareBoxInfo( aSet, *pOwnSh );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir void SwFlyFrmAttrMgr::_UpdateFlyFrm()
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir 	const SfxPoolItem* pItem = 0;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	if (aSet.GetItemState(FN_SET_FRM_NAME, sal_False, &pItem) == SFX_ITEM_SET)
133*cdf0e10cSrcweir 		pOwnSh->SetFlyName(((SfxStringItem *)pItem)->GetValue());
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	pOwnSh->SetModified();
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	if ( bAbsPos )
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		pOwnSh->SetFlyPos( aAbsPos );
140*cdf0e10cSrcweir 		bAbsPos = sal_False;
141*cdf0e10cSrcweir 	}
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir /*--------------------------------------------------------------------
145*cdf0e10cSrcweir 	Beschreibung: Bestehenden Fly-Frame aendern
146*cdf0e10cSrcweir  --------------------------------------------------------------------*/
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir void SwFlyFrmAttrMgr::UpdateFlyFrm()
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir 	ASSERT( pOwnSh->IsFrmSelected(),
151*cdf0e10cSrcweir 		"Kein Rahmen selektiert oder keine Shell, Update nicht moeglich");
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	if( pOwnSh->IsFrmSelected() )
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir 		//JP 6.8.2001: set never an invalid anchor into the core.
156*cdf0e10cSrcweir 		const SfxPoolItem *pGItem, *pItem;
157*cdf0e10cSrcweir 		if( SFX_ITEM_SET == aSet.GetItemState( RES_ANCHOR, sal_False, &pItem ))
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			SfxItemSet aGetSet( *aSet.GetPool(), RES_ANCHOR, RES_ANCHOR );
160*cdf0e10cSrcweir 			if( pOwnSh->GetFlyFrmAttr( aGetSet ) && 1 == aGetSet.Count() &&
161*cdf0e10cSrcweir 				SFX_ITEM_SET == aGetSet.GetItemState( RES_ANCHOR, sal_False, &pGItem )
162*cdf0e10cSrcweir 				&& ((SwFmtAnchor*)pGItem)->GetAnchorId() ==
163*cdf0e10cSrcweir 				   ((SwFmtAnchor*)pItem)->GetAnchorId() )
164*cdf0e10cSrcweir 				aSet.ClearItem( RES_ANCHOR );
165*cdf0e10cSrcweir 		}
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 		// return wg. BASIC
168*cdf0e10cSrcweir 		if( aSet.Count() )
169*cdf0e10cSrcweir 		{
170*cdf0e10cSrcweir 			pOwnSh->StartAllAction();
171*cdf0e10cSrcweir 			pOwnSh->SetFlyFrmAttr( aSet );
172*cdf0e10cSrcweir 			_UpdateFlyFrm();
173*cdf0e10cSrcweir 			pOwnSh->EndAllAction();
174*cdf0e10cSrcweir 		}
175*cdf0e10cSrcweir 	}
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir /*--------------------------------------------------------------------
179*cdf0e10cSrcweir 	 Beschreibung:	Rahmen einfuegen
180*cdf0e10cSrcweir  --------------------------------------------------------------------*/
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir sal_Bool SwFlyFrmAttrMgr::InsertFlyFrm()
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir 	pOwnSh->StartAllAction();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	sal_Bool bRet = 0 != pOwnSh->NewFlyFrm( aSet );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	// richtigen Mode an der Shell einschalten, Rahmen wurde aut. selektiert.
189*cdf0e10cSrcweir 	if ( bRet )
190*cdf0e10cSrcweir 	{
191*cdf0e10cSrcweir 		_UpdateFlyFrm();
192*cdf0e10cSrcweir 		pOwnSh->EnterSelFrmMode();
193*cdf0e10cSrcweir 		FrameNotify(pOwnSh, FLY_DRAG_START);
194*cdf0e10cSrcweir 	}
195*cdf0e10cSrcweir 	pOwnSh->EndAllAction();
196*cdf0e10cSrcweir 	return bRet;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir /*------------------------------------------------------------------------
200*cdf0e10cSrcweir  Beschreibung:	Rahmen des Typs eAnchorType einfuegen. Position und
201*cdf0e10cSrcweir 				Groesse werden explizit angegeben.
202*cdf0e10cSrcweir 				Nicht erlaubte Werte des Aufzaehlungstypes werden
203*cdf0e10cSrcweir 				korrigiert.
204*cdf0e10cSrcweir ------------------------------------------------------------------------*/
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir void SwFlyFrmAttrMgr::InsertFlyFrm(RndStdIds	eAnchorType,
207*cdf0e10cSrcweir 								   const Point	&rPos,
208*cdf0e10cSrcweir 								   const Size	&rSize,
209*cdf0e10cSrcweir 								   sal_Bool bAbs )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     ASSERT( eAnchorType == FLY_AT_PAGE ||
212*cdf0e10cSrcweir             eAnchorType == FLY_AT_PARA ||
213*cdf0e10cSrcweir             eAnchorType == FLY_AT_CHAR ||
214*cdf0e10cSrcweir             eAnchorType == FLY_AT_FLY  ||
215*cdf0e10cSrcweir             eAnchorType == FLY_AS_CHAR,     "invalid frame type" );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	if ( bAbs )
218*cdf0e10cSrcweir 		SetAbsPos( rPos );
219*cdf0e10cSrcweir 	else
220*cdf0e10cSrcweir 		SetPos( rPos );
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	SetSize( rSize );
223*cdf0e10cSrcweir 	SetAnchor( eAnchorType );
224*cdf0e10cSrcweir 	InsertFlyFrm();
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir /*--------------------------------------------------------------------
228*cdf0e10cSrcweir 	 Beschreibung:	Anker setzen
229*cdf0e10cSrcweir  --------------------------------------------------------------------*/
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetAnchor( RndStdIds eId )
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	sal_uInt16 nPhyPageNum, nVirtPageNum;
234*cdf0e10cSrcweir 	pOwnSh->GetPageNum( nPhyPageNum, nVirtPageNum );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	aSet.Put( SwFmtAnchor( eId, nPhyPageNum ) );
237*cdf0e10cSrcweir     if ((FLY_AT_PAGE == eId) || (FLY_AT_PARA == eId) || (FLY_AT_CHAR == eId)
238*cdf0e10cSrcweir         || (FLY_AT_FLY == eId))
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir 		SwFmtVertOrient aVertOrient( GetVertOrient() );
241*cdf0e10cSrcweir 		SwFmtHoriOrient aHoriOrient( GetHoriOrient() );
242*cdf0e10cSrcweir         aHoriOrient.SetRelationOrient( text::RelOrientation::FRAME );
243*cdf0e10cSrcweir         aVertOrient.SetRelationOrient( text::RelOrientation::FRAME );
244*cdf0e10cSrcweir 		aSet.Put( aVertOrient );
245*cdf0e10cSrcweir 		aSet.Put( aHoriOrient );
246*cdf0e10cSrcweir 	}
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir /*------------------------------------------------------------------------
250*cdf0e10cSrcweir  Beschreibung:	Setzen des Attributs fuer Spalten
251*cdf0e10cSrcweir ------------------------------------------------------------------------*/
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetCol( const SwFmtCol &rCol )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	aSet.Put( rCol );
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir /*--------------------------------------------------------------------
258*cdf0e10cSrcweir 	 Beschreibung:	Absolute Position setzen
259*cdf0e10cSrcweir  --------------------------------------------------------------------*/
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetAbsPos( const Point& rPoint )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	bAbsPos = sal_True;
264*cdf0e10cSrcweir 	aAbsPos = rPoint;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	SwFmtVertOrient aVertOrient( GetVertOrient() );
267*cdf0e10cSrcweir 	SwFmtHoriOrient aHoriOrient( GetHoriOrient() );
268*cdf0e10cSrcweir     aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
269*cdf0e10cSrcweir     aVertOrient.SetVertOrient( text::VertOrientation::NONE );
270*cdf0e10cSrcweir 	aSet.Put( aVertOrient );
271*cdf0e10cSrcweir 	aSet.Put( aHoriOrient );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir /*--------------------------------------------------------------------
275*cdf0e10cSrcweir 	Beschreibung: Metriken auf Korrektheit pruefen
276*cdf0e10cSrcweir  --------------------------------------------------------------------*/
277*cdf0e10cSrcweir void SwFlyFrmAttrMgr::ValidateMetrics( SvxSwFrameValidation& rVal,
278*cdf0e10cSrcweir         const SwPosition* pToCharCntntPos,
279*cdf0e10cSrcweir         sal_Bool bOnlyPercentRefValue )
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	if (!bOnlyPercentRefValue)
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		rVal.nMinHeight = MINFLY + CalcTopSpace() + CalcBottomSpace();
284*cdf0e10cSrcweir 		rVal.nMinWidth =  MINFLY + CalcLeftSpace()+ CalcRightSpace();
285*cdf0e10cSrcweir 	}
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	SwRect aBoundRect;
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
290*cdf0e10cSrcweir     //      aligned to page for fly frame anchored to paragraph or to character.
291*cdf0e10cSrcweir     const RndStdIds eAnchorType = static_cast<RndStdIds >(rVal.nAnchorType);
292*cdf0e10cSrcweir     pOwnSh->CalcBoundRect( aBoundRect, eAnchorType,
293*cdf0e10cSrcweir                            rVal.nHRelOrient,
294*cdf0e10cSrcweir                            rVal.nVRelOrient,
295*cdf0e10cSrcweir                            pToCharCntntPos,
296*cdf0e10cSrcweir                            rVal.bFollowTextFlow,
297*cdf0e10cSrcweir                            rVal.bMirror, NULL, &rVal.aPercentSize);
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	if (bOnlyPercentRefValue)
300*cdf0e10cSrcweir 		return;
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir     // --> OD 2009-09-01 #mongolianlayout#
303*cdf0e10cSrcweir     if ( bIsInVertical || bIsInVerticalL2R )
304*cdf0e10cSrcweir     // <--
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         Point aPos(aBoundRect.Pos());
307*cdf0e10cSrcweir         long nTmp = aPos.X();
308*cdf0e10cSrcweir         aPos.X() = aPos.Y();
309*cdf0e10cSrcweir         aPos.Y() = nTmp;
310*cdf0e10cSrcweir         Size aSize(aBoundRect.SSize());
311*cdf0e10cSrcweir         nTmp = aSize.Width();
312*cdf0e10cSrcweir         aSize.Width() = aSize.Height();
313*cdf0e10cSrcweir         aSize.Height() = nTmp;
314*cdf0e10cSrcweir         aBoundRect.Chg( aPos, aSize );
315*cdf0e10cSrcweir         //exchange width/height to enable correct values
316*cdf0e10cSrcweir         nTmp = rVal.nWidth;
317*cdf0e10cSrcweir         rVal.nWidth = rVal.nHeight;
318*cdf0e10cSrcweir         rVal.nHeight = nTmp;
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir     if ((eAnchorType == FLY_AT_PAGE) || (eAnchorType == FLY_AT_FLY))
321*cdf0e10cSrcweir 	{
322*cdf0e10cSrcweir 		// MinimalPosition
323*cdf0e10cSrcweir 		rVal.nMinHPos = aBoundRect.Left();
324*cdf0e10cSrcweir 		rVal.nMinVPos = aBoundRect.Top();
325*cdf0e10cSrcweir 		SwTwips nH = rVal.nHPos;
326*cdf0e10cSrcweir 		SwTwips nV = rVal.nVPos;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 		if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
329*cdf0e10cSrcweir 		{
330*cdf0e10cSrcweir             if (rVal.nHoriOrient == text::HoriOrientation::NONE)
331*cdf0e10cSrcweir 			{
332*cdf0e10cSrcweir 				rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
333*cdf0e10cSrcweir 				nH = rVal.nHPos;
334*cdf0e10cSrcweir 			}
335*cdf0e10cSrcweir 			else
336*cdf0e10cSrcweir 				rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
337*cdf0e10cSrcweir 		}
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 		if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
340*cdf0e10cSrcweir 			rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
343*cdf0e10cSrcweir 		{
344*cdf0e10cSrcweir             if (rVal.nVertOrient == text::VertOrientation::NONE)
345*cdf0e10cSrcweir 			{
346*cdf0e10cSrcweir 				rVal.nVPos -= ((rVal.nVPos + rVal.nHeight) - aBoundRect.Bottom());
347*cdf0e10cSrcweir 				nV = rVal.nVPos;
348*cdf0e10cSrcweir 			}
349*cdf0e10cSrcweir 			else
350*cdf0e10cSrcweir 				rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
351*cdf0e10cSrcweir 		}
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 		if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
354*cdf0e10cSrcweir 			rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         if ( rVal.nVertOrient != text::VertOrientation::NONE )
357*cdf0e10cSrcweir 			nV = aBoundRect.Top();
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir         if ( rVal.nHoriOrient != text::HoriOrientation::NONE )
360*cdf0e10cSrcweir 			nH = aBoundRect.Left();
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 		rVal.nMaxHPos	= aBoundRect.Right()  - rVal.nWidth;
363*cdf0e10cSrcweir 		rVal.nMaxHeight = aBoundRect.Bottom() - nV;
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 		rVal.nMaxVPos	= aBoundRect.Bottom() - rVal.nHeight;
366*cdf0e10cSrcweir 		rVal.nMaxWidth	= aBoundRect.Right()  - nH;
367*cdf0e10cSrcweir 	}
368*cdf0e10cSrcweir     // OD 12.11.2003 #i22341# - handle to character anchored objects vertical
369*cdf0e10cSrcweir     // aligned at character or top of line in a special case
370*cdf0e10cSrcweir     else if ((eAnchorType == FLY_AT_PARA) ||
371*cdf0e10cSrcweir                 ((eAnchorType == FLY_AT_CHAR) &&
372*cdf0e10cSrcweir                 !(rVal.nVRelOrient == text::RelOrientation::CHAR) &&
373*cdf0e10cSrcweir                 !(rVal.nVRelOrient == text::RelOrientation::TEXT_LINE) ) )
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
376*cdf0e10cSrcweir 		{
377*cdf0e10cSrcweir             if (rVal.nHoriOrient == text::HoriOrientation::NONE)
378*cdf0e10cSrcweir 			{
379*cdf0e10cSrcweir 				rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
380*cdf0e10cSrcweir 			}
381*cdf0e10cSrcweir 			else
382*cdf0e10cSrcweir 				rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
383*cdf0e10cSrcweir 		}
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir         // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
386*cdf0e10cSrcweir         // and alignment at page areas.
387*cdf0e10cSrcweir         const bool bMaxVPosAtBottom = !rVal.bFollowTextFlow ||
388*cdf0e10cSrcweir                                       rVal.nVRelOrient == text::RelOrientation::PAGE_FRAME ||
389*cdf0e10cSrcweir                                       rVal.nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
390*cdf0e10cSrcweir         {
391*cdf0e10cSrcweir             SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
392*cdf0e10cSrcweir                                     ? aBoundRect.Bottom()
393*cdf0e10cSrcweir                                     : aBoundRect.Height() ) -
394*cdf0e10cSrcweir                                   rVal.nHeight;
395*cdf0e10cSrcweir             if ( rVal.nVPos > nTmpMaxVPos )
396*cdf0e10cSrcweir             {
397*cdf0e10cSrcweir                 if (rVal.nVertOrient == text::VertOrientation::NONE)
398*cdf0e10cSrcweir                 {
399*cdf0e10cSrcweir                     rVal.nVPos = nTmpMaxVPos;
400*cdf0e10cSrcweir                 }
401*cdf0e10cSrcweir                 else
402*cdf0e10cSrcweir                 {
403*cdf0e10cSrcweir                     rVal.nHeight = ( bMaxVPosAtBottom
404*cdf0e10cSrcweir                                      ? aBoundRect.Bottom()
405*cdf0e10cSrcweir                                      : aBoundRect.Height() ) - rVal.nVPos;
406*cdf0e10cSrcweir                 }
407*cdf0e10cSrcweir             }
408*cdf0e10cSrcweir         }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir         rVal.nMinHPos  = aBoundRect.Left();
411*cdf0e10cSrcweir         rVal.nMaxHPos  = aBoundRect.Right() - rVal.nWidth;
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 		rVal.nMinVPos  = aBoundRect.Top();
414*cdf0e10cSrcweir         // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
415*cdf0e10cSrcweir         if ( bMaxVPosAtBottom )
416*cdf0e10cSrcweir         {
417*cdf0e10cSrcweir             rVal.nMaxVPos  = aBoundRect.Bottom() - rVal.nHeight;
418*cdf0e10cSrcweir         }
419*cdf0e10cSrcweir         else
420*cdf0e10cSrcweir         {
421*cdf0e10cSrcweir             rVal.nMaxVPos  = aBoundRect.Height() - rVal.nHeight;
422*cdf0e10cSrcweir         }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 		// Maximale Breite Hoehe
425*cdf0e10cSrcweir         const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
426*cdf0e10cSrcweir                            ? aBoundRect.Left()
427*cdf0e10cSrcweir                            : rVal.nHPos;
428*cdf0e10cSrcweir         const SwTwips nV = ( rVal.nVertOrient != text::VertOrientation::NONE )
429*cdf0e10cSrcweir                            ? aBoundRect.Top()
430*cdf0e10cSrcweir                            : rVal.nVPos;
431*cdf0e10cSrcweir 		rVal.nMaxHeight  = rVal.nMaxVPos + rVal.nHeight - nV;
432*cdf0e10cSrcweir 		rVal.nMaxWidth	 = rVal.nMaxHPos + rVal.nWidth - nH;
433*cdf0e10cSrcweir 	}
434*cdf0e10cSrcweir     // OD 12.11.2003 #i22341# - special case for to character anchored objects
435*cdf0e10cSrcweir     // vertical aligned at character or top of line.
436*cdf0e10cSrcweir     // Note: (1) positive vertical values are positions above the top of line
437*cdf0e10cSrcweir     //       (2) negative vertical values are positions below the top of line
438*cdf0e10cSrcweir     else if ( (eAnchorType == FLY_AT_CHAR) &&
439*cdf0e10cSrcweir               ( rVal.nVRelOrient == text::RelOrientation::CHAR ||
440*cdf0e10cSrcweir                 rVal.nVRelOrient == text::RelOrientation::TEXT_LINE ) )
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         // determine horizontal values
443*cdf0e10cSrcweir         rVal.nMinHPos  = aBoundRect.Left();
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir         rVal.nMaxHPos  = aBoundRect.Right() - rVal.nWidth;
446*cdf0e10cSrcweir         if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
447*cdf0e10cSrcweir         {
448*cdf0e10cSrcweir             if (rVal.nHoriOrient == text::HoriOrientation::NONE)
449*cdf0e10cSrcweir             {
450*cdf0e10cSrcweir                 rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
451*cdf0e10cSrcweir             }
452*cdf0e10cSrcweir             else
453*cdf0e10cSrcweir                 rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir         const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
457*cdf0e10cSrcweir                            ? aBoundRect.Left()
458*cdf0e10cSrcweir                            : rVal.nHPos;
459*cdf0e10cSrcweir         rVal.nMaxWidth   = rVal.nMaxHPos + rVal.nWidth - nH;
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         // determine vertical values
462*cdf0e10cSrcweir         rVal.nMinVPos = -( aBoundRect.Bottom() - rVal.nHeight );
463*cdf0e10cSrcweir         if ( rVal.nVPos < rVal.nMinVPos &&
464*cdf0e10cSrcweir              rVal.nVertOrient == text::VertOrientation::NONE )
465*cdf0e10cSrcweir         {
466*cdf0e10cSrcweir             rVal.nVPos = rVal.nMinVPos;
467*cdf0e10cSrcweir         }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir         rVal.nMaxVPos  = -aBoundRect.Top();
470*cdf0e10cSrcweir         if ( rVal.nVPos > rVal.nMaxVPos &&
471*cdf0e10cSrcweir              rVal.nVertOrient == text::VertOrientation::NONE )
472*cdf0e10cSrcweir         {
473*cdf0e10cSrcweir             rVal.nVPos = rVal.nMaxVPos;
474*cdf0e10cSrcweir         }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir         if ( rVal.nVertOrient == text::VertOrientation::NONE )
477*cdf0e10cSrcweir         {
478*cdf0e10cSrcweir             rVal.nMaxHeight = aBoundRect.Bottom() + rVal.nVPos;
479*cdf0e10cSrcweir         }
480*cdf0e10cSrcweir         else
481*cdf0e10cSrcweir         {
482*cdf0e10cSrcweir             rVal.nMaxHeight = aBoundRect.Height();
483*cdf0e10cSrcweir         }
484*cdf0e10cSrcweir     }
485*cdf0e10cSrcweir     else if ( eAnchorType == FLY_AS_CHAR )
486*cdf0e10cSrcweir 	{
487*cdf0e10cSrcweir 		rVal.nMinHPos = 0;
488*cdf0e10cSrcweir 		rVal.nMaxHPos = 0;
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 		rVal.nMaxHeight = aBoundRect.Height();
491*cdf0e10cSrcweir 		rVal.nMaxWidth	= aBoundRect.Width();
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 		rVal.nMaxVPos	= aBoundRect.Height();
494*cdf0e10cSrcweir 		rVal.nMinVPos	= -aBoundRect.Height() + rVal.nHeight;
495*cdf0e10cSrcweir 		if (rVal.nMaxVPos < rVal.nMinVPos)
496*cdf0e10cSrcweir 		{
497*cdf0e10cSrcweir 			rVal.nMinVPos = rVal.nMaxVPos;
498*cdf0e10cSrcweir 			rVal.nMaxVPos = -aBoundRect.Height();
499*cdf0e10cSrcweir 		}
500*cdf0e10cSrcweir 	}
501*cdf0e10cSrcweir     // --> OD 2009-09-01 #mongolianlayout#
502*cdf0e10cSrcweir     if ( bIsInVertical || bIsInVerticalL2R )
503*cdf0e10cSrcweir     // <--
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         //restore width/height exchange
506*cdf0e10cSrcweir         long nTmp = rVal.nWidth;
507*cdf0e10cSrcweir         rVal.nWidth = rVal.nHeight;
508*cdf0e10cSrcweir         rVal.nHeight = nTmp;
509*cdf0e10cSrcweir     }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     if (rVal.nMaxWidth < rVal.nWidth)
512*cdf0e10cSrcweir 		rVal.nWidth = rVal.nMaxWidth;
513*cdf0e10cSrcweir 	if (rVal.nMaxHeight < rVal.nHeight)
514*cdf0e10cSrcweir 		rVal.nHeight = rVal.nMaxHeight;
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir /*--------------------------------------------------------------------
518*cdf0e10cSrcweir 	Beschreibung: Korrektur fuer Umrandung
519*cdf0e10cSrcweir  --------------------------------------------------------------------*/
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir SwTwips SwFlyFrmAttrMgr::CalcTopSpace()
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir 	const SvxShadowItem& rShadow = GetShadow();
524*cdf0e10cSrcweir 	const SvxBoxItem& 	 rBox 	 = GetBox();
525*cdf0e10cSrcweir 	return rShadow.CalcShadowSpace(SHADOW_TOP ) + rBox.CalcLineSpace(BOX_LINE_TOP);
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir SwTwips SwFlyFrmAttrMgr::CalcBottomSpace()
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir 	const SvxShadowItem& rShadow = GetShadow();
531*cdf0e10cSrcweir 	const SvxBoxItem& rBox 		 = GetBox();
532*cdf0e10cSrcweir 	return rShadow.CalcShadowSpace(SHADOW_BOTTOM) + rBox.CalcLineSpace(BOX_LINE_BOTTOM);
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir SwTwips SwFlyFrmAttrMgr::CalcLeftSpace()
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir 	const SvxShadowItem& rShadow = GetShadow();
538*cdf0e10cSrcweir 	const SvxBoxItem&	 rBox 	 = GetBox();
539*cdf0e10cSrcweir 	return rShadow.CalcShadowSpace(SHADOW_LEFT) + rBox.CalcLineSpace(BOX_LINE_LEFT);
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir SwTwips SwFlyFrmAttrMgr::CalcRightSpace()
543*cdf0e10cSrcweir {
544*cdf0e10cSrcweir 	const SvxShadowItem& rShadow = GetShadow();
545*cdf0e10cSrcweir 	const SvxBoxItem&	 rBox 	 = GetBox();
546*cdf0e10cSrcweir 	return rShadow.CalcShadowSpace(SHADOW_RIGHT) + rBox.CalcLineSpace(BOX_LINE_RIGHT);
547*cdf0e10cSrcweir }
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir /*--------------------------------------------------------------------
551*cdf0e10cSrcweir 	Beschreibung: Attribut aus dem Set loeschen
552*cdf0e10cSrcweir  --------------------------------------------------------------------*/
553*cdf0e10cSrcweir void SwFlyFrmAttrMgr::DelAttr( sal_uInt16 nId )
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	aSet.ClearItem( nId );
556*cdf0e10cSrcweir }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetLRSpace( long nLeft, long nRight )
559*cdf0e10cSrcweir {
560*cdf0e10cSrcweir 	ASSERT( LONG_MAX != nLeft && LONG_MAX != nRight, "Welchen Raend setzen?" );
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 	SvxLRSpaceItem aTmp( (SvxLRSpaceItem&)aSet.Get( RES_LR_SPACE ) );
563*cdf0e10cSrcweir 	if( LONG_MAX != nLeft )
564*cdf0e10cSrcweir 		aTmp.SetLeft( sal_uInt16(nLeft) );
565*cdf0e10cSrcweir 	if( LONG_MAX != nRight )
566*cdf0e10cSrcweir 		aTmp.SetRight( sal_uInt16(nRight) );
567*cdf0e10cSrcweir 	aSet.Put( aTmp );
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetULSpace( long nTop, long nBottom )
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir 	ASSERT(LONG_MAX != nTop && LONG_MAX != nBottom, "Welchen Raend setzen?" );
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 	SvxULSpaceItem aTmp( (SvxULSpaceItem&)aSet.Get( RES_UL_SPACE ) );
575*cdf0e10cSrcweir 	if( LONG_MAX != nTop )
576*cdf0e10cSrcweir 		aTmp.SetUpper( sal_uInt16(nTop) );
577*cdf0e10cSrcweir 	if( LONG_MAX != nBottom )
578*cdf0e10cSrcweir 		aTmp.SetLower( sal_uInt16(nBottom) );
579*cdf0e10cSrcweir 	aSet.Put( aTmp );
580*cdf0e10cSrcweir }
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetPos( const Point& rPoint )
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir 	SwFmtVertOrient aVertOrient( GetVertOrient() );
585*cdf0e10cSrcweir 	SwFmtHoriOrient aHoriOrient( GetHoriOrient() );
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 	aHoriOrient.SetPos		 ( rPoint.X() );
588*cdf0e10cSrcweir     aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE  );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 	aVertOrient.SetPos		 ( rPoint.Y() );
591*cdf0e10cSrcweir     aVertOrient.SetVertOrient( text::VertOrientation::NONE  );
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 	aSet.Put( aVertOrient );
594*cdf0e10cSrcweir 	aSet.Put( aHoriOrient );
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetHorzOrientation( sal_Int16 eOrient )
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir 	SwFmtHoriOrient aHoriOrient( GetHoriOrient() );
600*cdf0e10cSrcweir 	aHoriOrient.SetHoriOrient( eOrient );
601*cdf0e10cSrcweir 	aSet.Put( aHoriOrient );
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetVertOrientation( sal_Int16 eOrient )
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir 	SwFmtVertOrient aVertOrient( GetVertOrient() );
607*cdf0e10cSrcweir     aVertOrient.SetVertOrient( eOrient );
608*cdf0e10cSrcweir 	aSet.Put( aVertOrient );
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetHeightSizeType( SwFrmSize eType )
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir 	SwFmtFrmSize aSize( GetFrmSize() );
614*cdf0e10cSrcweir     aSize.SetHeightSizeType( eType );
615*cdf0e10cSrcweir 	aSet.Put( aSize );
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetSize( const Size& rSize )
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir 	SwFmtFrmSize aSize( GetFrmSize() );
621*cdf0e10cSrcweir 	aSize.SetSize(Size(Max(rSize.Width(), long(MINFLY)), Max(rSize.Height(), long(MINFLY))));
622*cdf0e10cSrcweir 	aSet.Put( aSize );
623*cdf0e10cSrcweir }
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir void SwFlyFrmAttrMgr::SetAttrSet(const SfxItemSet& rSet)
626*cdf0e10cSrcweir {
627*cdf0e10cSrcweir 	aSet.ClearItem();
628*cdf0e10cSrcweir 	aSet.Put( rSet );
629*cdf0e10cSrcweir }
630