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