1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <cmdid.h>
21 #include <hintids.hxx>
22
23 #include <svl/stritem.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <editeng/ulspitem.hxx>
27 #include <editeng/shaditem.hxx>
28 #include <svx/swframevalidation.hxx>
29 #include <svx/xdef.hxx>
30 #include <tools/globname.hxx>
31 #include <comphelper/classids.hxx>
32 #include <osl/diagnose.h>
33 #include <fmtclds.hxx>
34 #include <wrtsh.hxx>
35 #include <view.hxx>
36 #include <viewopt.hxx>
37 #include <uitool.hxx>
38 #include <frmmgr.hxx>
39 #include <format.hxx>
40 #include <mdiexp.hxx>
41 #include <poolfmt.hxx>
42 #include <com/sun/star/text/HoriOrientation.hpp>
43 #include <com/sun/star/text/VertOrientation.hpp>
44 #include <com/sun/star/text/RelOrientation.hpp>
45 #include <grfatr.hxx>
46
47 using namespace ::com::sun::star;
48
49 static sal_uInt16 aFrameMgrRange[] = {
50 RES_FRMATR_BEGIN, RES_FRMATR_END-1, // 87-129
51
52 // RotGrfFlyFrame: Support here, but seems not to be
53 // added in range of m_pOwnSh->GetFlyFrameAttr result
54 // (see below). Tried to find, but could not identify
55 RES_GRFATR_ROTATION, RES_GRFATR_ROTATION, // 132
56
57 // FillAttribute support
58 XATTR_FILL_FIRST, XATTR_FILL_LAST, // 1014-1033
59
60 SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
61 FN_SET_FRM_NAME, FN_SET_FRM_NAME,
62 0};
63
64 // determine frame attributes via Shell
SwFlyFrameAttrMgr(bool bNew,SwWrtShell * pSh,Frmmgr_Type nType,const SvGlobalName * pName)65 SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nType, const SvGlobalName* pName ) :
66 m_aSet( static_cast<SwAttrPool&>(pSh->GetAttrPool()), aFrameMgrRange ),
67 m_pOwnSh( pSh ),
68 m_bAbsPos( false ),
69 m_bNewFrame( bNew ),
70 m_bIsInVertical( false ),
71 m_bIsInVerticalL2R( false )
72 {
73 if ( m_bNewFrame )
74 {
75 sal_uInt16 nId;
76 switch ( nType )
77 {
78 case Frmmgr_Type::TEXT: nId = RES_POOLFRM_FRAME; break;
79 case Frmmgr_Type::OLE: nId = RES_POOLFRM_OLE; break;
80 case Frmmgr_Type::GRF: nId = RES_POOLFRM_GRAPHIC; break;
81 // set defaults:
82 default: nId=0; break;
83 }
84 m_aSet.SetParent( &m_pOwnSh->GetFormatFromPool( nId )->GetAttrSet());
85 m_aSet.Put( SwFormatFrameSize( SwFrameSize::Minimum, DFLT_WIDTH, DFLT_HEIGHT ));
86 if ( 0 != ::GetHtmlMode(pSh->GetView().GetDocShell()) )
87 m_aSet.Put( SwFormatHoriOrient( 0, text::HoriOrientation::LEFT, text::RelOrientation::PRINT_AREA ) );
88
89 if (nType == Frmmgr_Type::GRF || nType == Frmmgr_Type::OLE)
90 {
91 if (!pName || *pName != SvGlobalName( SO3_SM_CLASSID ))
92 {
93 // Default anchor for new graphics and objects is at-char, except for Math objects.
94 SwViewOption aViewOpt(*pSh->GetViewOptions());
95
96 RndStdIds eAnchorType = aViewOpt.GetDefaultAnchorType();
97
98 const SwFormatAnchor rStyleAnchor
99 = m_pOwnSh->GetFormatFromPool(nId)->GetAttrSet().GetAnchor();
100 if (rStyleAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA)
101 {
102 // The style has a custom anchor type, prefer that over the user profile
103 // default.
104 eAnchorType = rStyleAnchor.GetAnchorId();
105 }
106
107 m_aSet.Put(SwFormatAnchor(eAnchorType));
108 }
109 }
110 }
111 else if ( nType == Frmmgr_Type::NONE )
112 {
113 m_pOwnSh->GetFlyFrameAttr( m_aSet );
114 bool bRightToLeft;
115 m_bIsInVertical = m_pOwnSh->IsFrameVertical(true, bRightToLeft, m_bIsInVerticalL2R);
116 }
117 ::PrepareBoxInfo( m_aSet, *m_pOwnSh );
118 }
119
SwFlyFrameAttrMgr(bool bNew,SwWrtShell * pSh,const SfxItemSet & rSet)120 SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, const SfxItemSet &rSet ) :
121 m_aSet( rSet ),
122 m_pOwnSh( pSh ),
123 m_bAbsPos( false ),
124 m_bNewFrame( bNew ),
125 m_bIsInVertical(false),
126 m_bIsInVerticalL2R(false)
127 {
128 if(!bNew)
129 {
130 bool bRightToLeft;
131 m_bIsInVertical = pSh->IsFrameVertical(true, bRightToLeft, m_bIsInVerticalL2R);
132 }
133 }
134
135 // Initialise
UpdateAttrMgr()136 void SwFlyFrameAttrMgr::UpdateAttrMgr()
137 {
138 if ( !m_bNewFrame && m_pOwnSh->IsFrameSelected() )
139 m_pOwnSh->GetFlyFrameAttr( m_aSet );
140 ::PrepareBoxInfo( m_aSet, *m_pOwnSh );
141 }
142
UpdateFlyFrame_()143 void SwFlyFrameAttrMgr::UpdateFlyFrame_()
144 {
145 const SfxPoolItem* pItem = nullptr;
146
147 if (m_aSet.GetItemState(FN_SET_FRM_NAME, false, &pItem) == SfxItemState::SET)
148 m_pOwnSh->SetFlyName(static_cast<const SfxStringItem *>(pItem)->GetValue());
149
150 m_pOwnSh->SetModified();
151
152 if ( m_bAbsPos )
153 {
154 m_pOwnSh->SetFlyPos( m_aAbsPos );
155 m_bAbsPos = false;
156 }
157 }
158
159 // change existing Fly-Frame
UpdateFlyFrame()160 void SwFlyFrameAttrMgr::UpdateFlyFrame()
161 {
162 OSL_ENSURE( m_pOwnSh->IsFrameSelected(),
163 "no frame selected or no shell, update not possible");
164
165 if( !m_pOwnSh->IsFrameSelected() )
166 return;
167
168 //JP 6.8.2001: set never an invalid anchor into the core.
169 const SfxPoolItem *pGItem, *pItem;
170 if( SfxItemState::SET == m_aSet.GetItemState( RES_ANCHOR, false, &pItem ))
171 {
172 SfxItemSet aGetSet( *m_aSet.GetPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} );
173 if( m_pOwnSh->GetFlyFrameAttr( aGetSet ) && 1 == aGetSet.Count() &&
174 SfxItemState::SET == aGetSet.GetItemState( RES_ANCHOR, false, &pGItem )
175 && static_cast<const SwFormatAnchor*>(pGItem)->GetAnchorId() ==
176 static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId() )
177 m_aSet.ClearItem( RES_ANCHOR );
178 }
179
180 // return wg. BASIC
181 if( m_aSet.Count() )
182 {
183 m_pOwnSh->StartAllAction();
184 m_pOwnSh->SetFlyFrameAttr( m_aSet );
185 UpdateFlyFrame_();
186 m_pOwnSh->EndAllAction();
187 }
188 }
189
190 // insert frame
InsertFlyFrame()191 void SwFlyFrameAttrMgr::InsertFlyFrame()
192 {
193 m_pOwnSh->StartAllAction();
194
195 bool bRet = nullptr != m_pOwnSh->NewFlyFrame( m_aSet );
196
197 // turn on the right mode at the shell, frame got selected automatically.
198 if ( bRet )
199 {
200 UpdateFlyFrame_();
201 m_pOwnSh->EnterSelFrameMode();
202 FrameNotify(m_pOwnSh, FLY_DRAG_START);
203 }
204 m_pOwnSh->EndAllAction();
205 }
206
207 // Insert frames of type eAnchorType. Position and size are being set explicitly.
208 // Not-allowed values of the enumeration type get corrected.
InsertFlyFrame(RndStdIds eAnchorType,const Point & rPos,const Size & rSize)209 void SwFlyFrameAttrMgr::InsertFlyFrame(RndStdIds eAnchorType,
210 const Point &rPos,
211 const Size &rSize )
212 {
213 OSL_ENSURE( eAnchorType == RndStdIds::FLY_AT_PAGE ||
214 eAnchorType == RndStdIds::FLY_AT_PARA ||
215 eAnchorType == RndStdIds::FLY_AT_CHAR ||
216 eAnchorType == RndStdIds::FLY_AT_FLY ||
217 eAnchorType == RndStdIds::FLY_AS_CHAR, "invalid frame type" );
218
219 SetPos( rPos );
220
221 SetSize( rSize );
222 SetAnchor( eAnchorType );
223 InsertFlyFrame();
224 }
225
226 // set anchor
SetAnchor(RndStdIds eId)227 void SwFlyFrameAttrMgr::SetAnchor( RndStdIds eId )
228 {
229 sal_uInt16 nPhyPageNum, nVirtPageNum;
230 m_pOwnSh->GetPageNum( nPhyPageNum, nVirtPageNum );
231
232 m_aSet.Put( SwFormatAnchor( eId, nPhyPageNum ) );
233 if ((RndStdIds::FLY_AT_PAGE == eId) || (RndStdIds::FLY_AT_PARA == eId) || (RndStdIds::FLY_AT_CHAR == eId)
234 || (RndStdIds::FLY_AT_FLY == eId))
235 {
236 SwFormatVertOrient aVertOrient( GetVertOrient() );
237 SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
238 aHoriOrient.SetRelationOrient( text::RelOrientation::FRAME );
239 aVertOrient.SetRelationOrient( text::RelOrientation::FRAME );
240 m_aSet.Put( aVertOrient );
241 m_aSet.Put( aHoriOrient );
242 }
243 }
244
245 // set the attribute for columns
SetCol(const SwFormatCol & rCol)246 void SwFlyFrameAttrMgr::SetCol( const SwFormatCol &rCol )
247 {
248 m_aSet.Put( rCol );
249 }
250
251 // set absolute position
SetAbsPos(const Point & rPoint)252 void SwFlyFrameAttrMgr::SetAbsPos( const Point& rPoint )
253 {
254 m_bAbsPos = true;
255 m_aAbsPos = rPoint;
256 SwFormatVertOrient aVertOrient( GetVertOrient() );
257 SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
258 aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
259 aVertOrient.SetVertOrient( text::VertOrientation::NONE );
260 m_aSet.Put( aVertOrient );
261 m_aSet.Put( aHoriOrient );
262 }
263
264 // check metrics for correctness
ValidateMetrics(SvxSwFrameValidation & rVal,const SwPosition * pToCharContentPos,bool bOnlyPercentRefValue)265 void SwFlyFrameAttrMgr::ValidateMetrics( SvxSwFrameValidation& rVal,
266 const SwPosition* pToCharContentPos,
267 bool bOnlyPercentRefValue )
268 {
269 if (!bOnlyPercentRefValue)
270 {
271 rVal.nMinHeight = MINFLY + CalcTopSpace() + CalcBottomSpace();
272 rVal.nMinWidth = MINFLY + CalcLeftSpace()+ CalcRightSpace();
273 }
274
275 SwRect aBoundRect;
276
277 // OD 18.09.2003 #i18732# - adjustment for allowing vertical position
278 // aligned to page for fly frame anchored to paragraph or to character.
279 const RndStdIds eAnchorType = rVal.nAnchorType;
280 const SwFormatFrameSize& rSize = m_aSet.Get(RES_FRM_SIZE);
281 m_pOwnSh->CalcBoundRect( aBoundRect, eAnchorType,
282 rVal.nHRelOrient,
283 rVal.nVRelOrient,
284 pToCharContentPos,
285 rVal.bFollowTextFlow,
286 rVal.bMirror, nullptr, &rVal.aPercentSize,
287 &rSize);
288
289 if (bOnlyPercentRefValue)
290 return;
291
292 // #mongolianlayout#
293 if ( m_bIsInVertical || m_bIsInVerticalL2R )
294 {
295 Point aPos(aBoundRect.Pos());
296 tools::Long nTmp = aPos.X();
297 aPos.setX( aPos.Y() );
298 aPos.setY( nTmp );
299 Size aSize(aBoundRect.SSize());
300 nTmp = aSize.Width();
301 aSize.setWidth( aSize.Height() );
302 aSize.setHeight( nTmp );
303 aBoundRect.Chg( aPos, aSize );
304 //exchange width/height to enable correct values
305 nTmp = rVal.nWidth;
306 rVal.nWidth = rVal.nHeight;
307 rVal.nHeight = nTmp;
308 }
309 if ((eAnchorType == RndStdIds::FLY_AT_PAGE) || (eAnchorType == RndStdIds::FLY_AT_FLY))
310 {
311 // MinimalPosition
312 rVal.nMinHPos = aBoundRect.Left();
313 rVal.nMinVPos = aBoundRect.Top();
314 SwTwips nH = rVal.nHPos;
315 SwTwips nV = rVal.nVPos;
316
317 if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
318 {
319 if (rVal.nHoriOrient == text::HoriOrientation::NONE)
320 {
321 rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
322 nH = rVal.nHPos;
323 }
324 else
325 rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
326 }
327
328 if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
329 rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
330
331 if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
332 {
333 if (rVal.nVertOrient == text::VertOrientation::NONE)
334 {
335 rVal.nVPos -= ((rVal.nVPos + rVal.nHeight) - aBoundRect.Bottom());
336 nV = rVal.nVPos;
337 }
338 else
339 rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
340 }
341
342 if (rVal.nVPos + rVal.nHeight > aBoundRect.Bottom())
343 rVal.nHeight = aBoundRect.Bottom() - rVal.nVPos;
344
345 if ( rVal.nVertOrient != text::VertOrientation::NONE )
346 nV = aBoundRect.Top();
347
348 if ( rVal.nHoriOrient != text::HoriOrientation::NONE )
349 nH = aBoundRect.Left();
350
351 rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
352 rVal.nMaxHeight = aBoundRect.Bottom() - nV;
353
354 rVal.nMaxVPos = aBoundRect.Bottom() - rVal.nHeight;
355 rVal.nMaxWidth = aBoundRect.Right() - nH;
356 }
357 // OD 12.11.2003 #i22341# - handle to character anchored objects vertical
358 // aligned at character or top of line in a special case
359 else if ((eAnchorType == RndStdIds::FLY_AT_PARA) ||
360 ((eAnchorType == RndStdIds::FLY_AT_CHAR) &&
361 (rVal.nVRelOrient != text::RelOrientation::CHAR) &&
362 (rVal.nVRelOrient != text::RelOrientation::TEXT_LINE) ) )
363 {
364 if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
365 {
366 if (rVal.nHoriOrient == text::HoriOrientation::NONE)
367 {
368 rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
369 }
370 else
371 rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
372 }
373
374 // OD 29.09.2003 #i17567#, #i18732# - consider following the text flow
375 // and alignment at page areas.
376 const bool bMaxVPosAtBottom = !rVal.bFollowTextFlow ||
377 rVal.nVRelOrient == text::RelOrientation::PAGE_FRAME ||
378 rVal.nVRelOrient == text::RelOrientation::PAGE_PRINT_AREA;
379 {
380 SwTwips nTmpMaxVPos = ( bMaxVPosAtBottom
381 ? aBoundRect.Bottom()
382 : aBoundRect.Height() ) -
383 rVal.nHeight;
384 if ( rVal.nVPos > nTmpMaxVPos )
385 {
386 if (rVal.nVertOrient == text::VertOrientation::NONE)
387 {
388 rVal.nVPos = nTmpMaxVPos;
389 }
390 else
391 {
392 rVal.nHeight = ( bMaxVPosAtBottom
393 ? aBoundRect.Bottom()
394 : aBoundRect.Height() ) - rVal.nVPos;
395 }
396 }
397 }
398
399 rVal.nMinHPos = aBoundRect.Left();
400 rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
401
402 rVal.nMinVPos = aBoundRect.Top();
403 // OD 26.09.2003 #i17567#, #i18732# - determine maximum vertical position
404 if ( bMaxVPosAtBottom )
405 {
406 rVal.nMaxVPos = aBoundRect.Bottom() - rVal.nHeight;
407 }
408 else
409 {
410 rVal.nMaxVPos = aBoundRect.Height() - rVal.nHeight;
411 }
412
413 // maximum width height
414 const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
415 ? aBoundRect.Left()
416 : rVal.nHPos;
417 const SwTwips nV = ( rVal.nVertOrient != text::VertOrientation::NONE )
418 ? aBoundRect.Top()
419 : rVal.nVPos;
420 rVal.nMaxHeight = rVal.nMaxVPos + rVal.nHeight - nV;
421 rVal.nMaxWidth = rVal.nMaxHPos + rVal.nWidth - nH;
422 }
423 // OD 12.11.2003 #i22341# - special case for to character anchored objects
424 // vertical aligned at character or top of line.
425 // Note: (1) positive vertical values are positions above the top of line
426 // (2) negative vertical values are positions below the top of line
427 else if ( (eAnchorType == RndStdIds::FLY_AT_CHAR) &&
428 ( rVal.nVRelOrient == text::RelOrientation::CHAR ||
429 rVal.nVRelOrient == text::RelOrientation::TEXT_LINE ) )
430 {
431 // determine horizontal values
432 rVal.nMinHPos = aBoundRect.Left();
433
434 rVal.nMaxHPos = aBoundRect.Right() - rVal.nWidth;
435 if (rVal.nHPos + rVal.nWidth > aBoundRect.Right())
436 {
437 if (rVal.nHoriOrient == text::HoriOrientation::NONE)
438 {
439 rVal.nHPos -= ((rVal.nHPos + rVal.nWidth) - aBoundRect.Right());
440 }
441 else
442 rVal.nWidth = aBoundRect.Right() - rVal.nHPos;
443 }
444
445 const SwTwips nH = ( rVal.nHoriOrient != text::HoriOrientation::NONE )
446 ? aBoundRect.Left()
447 : rVal.nHPos;
448 rVal.nMaxWidth = rVal.nMaxHPos + rVal.nWidth - nH;
449
450 // determine vertical values
451 rVal.nMinVPos = -( aBoundRect.Bottom() - rVal.nHeight );
452 if ( rVal.nVPos < rVal.nMinVPos &&
453 rVal.nVertOrient == text::VertOrientation::NONE )
454 {
455 rVal.nVPos = rVal.nMinVPos;
456 }
457
458 rVal.nMaxVPos = -aBoundRect.Top();
459 if ( rVal.nVPos > rVal.nMaxVPos &&
460 rVal.nVertOrient == text::VertOrientation::NONE )
461 {
462 rVal.nVPos = rVal.nMaxVPos;
463 }
464
465 if ( rVal.nVertOrient == text::VertOrientation::NONE )
466 {
467 rVal.nMaxHeight = aBoundRect.Bottom() + rVal.nVPos;
468 }
469 else
470 {
471 rVal.nMaxHeight = aBoundRect.Height();
472 }
473 }
474 else if ( eAnchorType == RndStdIds::FLY_AS_CHAR )
475 {
476 rVal.nMinHPos = 0;
477 rVal.nMaxHPos = 0;
478
479 rVal.nMaxHeight = aBoundRect.Height();
480 rVal.nMaxWidth = aBoundRect.Width();
481
482 rVal.nMaxVPos = aBoundRect.Height();
483 rVal.nMinVPos = -aBoundRect.Height() + rVal.nHeight;
484 if (rVal.nMaxVPos < rVal.nMinVPos)
485 {
486 rVal.nMinVPos = rVal.nMaxVPos;
487 rVal.nMaxVPos = -aBoundRect.Height();
488 }
489 }
490 // #mongolianlayout#
491 if ( m_bIsInVertical || m_bIsInVerticalL2R )
492 {
493 //restore width/height exchange
494 tools::Long nTmp = rVal.nWidth;
495 rVal.nWidth = rVal.nHeight;
496 rVal.nHeight = nTmp;
497 }
498
499 if (rVal.nMaxWidth < rVal.nWidth)
500 rVal.nWidth = rVal.nMaxWidth;
501 if (rVal.nMaxHeight < rVal.nHeight)
502 rVal.nHeight = rVal.nMaxHeight;
503 }
504
505 // correction for border
CalcTopSpace()506 SwTwips SwFlyFrameAttrMgr::CalcTopSpace()
507 {
508 const SvxShadowItem& rShadow = GetShadow();
509 const SvxBoxItem& rBox = GetBox();
510 return rShadow.CalcShadowSpace(SvxShadowItemSide::TOP ) + rBox.CalcLineSpace(SvxBoxItemLine::TOP);
511 }
512
CalcBottomSpace()513 SwTwips SwFlyFrameAttrMgr::CalcBottomSpace()
514 {
515 const SvxShadowItem& rShadow = GetShadow();
516 const SvxBoxItem& rBox = GetBox();
517 return rShadow.CalcShadowSpace(SvxShadowItemSide::BOTTOM) + rBox.CalcLineSpace(SvxBoxItemLine::BOTTOM);
518 }
519
CalcLeftSpace()520 SwTwips SwFlyFrameAttrMgr::CalcLeftSpace()
521 {
522 const SvxShadowItem& rShadow = GetShadow();
523 const SvxBoxItem& rBox = GetBox();
524 return rShadow.CalcShadowSpace(SvxShadowItemSide::LEFT) + rBox.CalcLineSpace(SvxBoxItemLine::LEFT);
525 }
526
CalcRightSpace()527 SwTwips SwFlyFrameAttrMgr::CalcRightSpace()
528 {
529 const SvxShadowItem& rShadow = GetShadow();
530 const SvxBoxItem& rBox = GetBox();
531 return rShadow.CalcShadowSpace(SvxShadowItemSide::RIGHT) + rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
532 }
533
534 // erase attribute from the set
DelAttr(sal_uInt16 nId)535 void SwFlyFrameAttrMgr::DelAttr( sal_uInt16 nId )
536 {
537 m_aSet.ClearItem( nId );
538 }
539
SetLRSpace(tools::Long nLeft,tools::Long nRight)540 void SwFlyFrameAttrMgr::SetLRSpace( tools::Long nLeft, tools::Long nRight )
541 {
542 OSL_ENSURE( LONG_MAX != nLeft && LONG_MAX != nRight, "Which border to set?" );
543
544 SvxLRSpaceItem aTmp( m_aSet.Get( RES_LR_SPACE ) );
545 if( LONG_MAX != nLeft )
546 aTmp.SetLeft( sal_uInt16(nLeft) );
547 if( LONG_MAX != nRight )
548 aTmp.SetRight( sal_uInt16(nRight) );
549 m_aSet.Put( aTmp );
550 }
551
SetULSpace(tools::Long nTop,tools::Long nBottom)552 void SwFlyFrameAttrMgr::SetULSpace( tools::Long nTop, tools::Long nBottom )
553 {
554 OSL_ENSURE(LONG_MAX != nTop && LONG_MAX != nBottom, "Which border to set?" );
555
556 SvxULSpaceItem aTmp( m_aSet.Get( RES_UL_SPACE ) );
557 if( LONG_MAX != nTop )
558 aTmp.SetUpper( sal_uInt16(nTop) );
559 if( LONG_MAX != nBottom )
560 aTmp.SetLower( sal_uInt16(nBottom) );
561 m_aSet.Put( aTmp );
562 }
563
SetPos(const Point & rPoint)564 void SwFlyFrameAttrMgr::SetPos( const Point& rPoint )
565 {
566 SwFormatVertOrient aVertOrient( GetVertOrient() );
567 SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
568
569 aHoriOrient.SetPos ( rPoint.X() );
570 aHoriOrient.SetHoriOrient( text::HoriOrientation::NONE );
571
572 aVertOrient.SetPos ( rPoint.Y() );
573 aVertOrient.SetVertOrient( text::VertOrientation::NONE );
574
575 m_aSet.Put( aVertOrient );
576 m_aSet.Put( aHoriOrient );
577 }
578
SetHorzOrientation(sal_Int16 eOrient)579 void SwFlyFrameAttrMgr::SetHorzOrientation( sal_Int16 eOrient )
580 {
581 SwFormatHoriOrient aHoriOrient( GetHoriOrient() );
582 aHoriOrient.SetHoriOrient( eOrient );
583 m_aSet.Put( aHoriOrient );
584 }
585
SetVertOrientation(sal_Int16 eOrient)586 void SwFlyFrameAttrMgr::SetVertOrientation( sal_Int16 eOrient )
587 {
588 SwFormatVertOrient aVertOrient( GetVertOrient() );
589 aVertOrient.SetVertOrient( eOrient );
590 m_aSet.Put( aVertOrient );
591 }
592
SetHeightSizeType(SwFrameSize eType)593 void SwFlyFrameAttrMgr::SetHeightSizeType( SwFrameSize eType )
594 {
595 SwFormatFrameSize aSize( GetFrameSize() );
596 aSize.SetHeightSizeType( eType );
597 m_aSet.Put( aSize );
598 }
599
SetRotation(Degree10 nOld,Degree10 nNew,const Size & rUnrotatedSize)600 void SwFlyFrameAttrMgr::SetRotation(Degree10 nOld, Degree10 nNew, const Size& rUnrotatedSize)
601 {
602 // RotGrfFlyFrame: Central handling of real change of rotation here, all adaptations use this.
603 // Adaptation of pos/size may be wanted in the future. Already tried to keep last Size in
604 // UnrotatedSize in the SwRotationGrf Item, but this will lead to various problems. Also tried
605 // to use m_aSet.Put(...) as in other methods (also tried read methods for Rotation/UnrotatedSize) but
606 // somehow the needed ID (RES_GRFATR_ROTATION) is *not* in the SfxItemSet of the Frame, so for
607 // now set directly. Undo/Redo is preserved by AttributeChange
608 if(nOld != nNew)
609 {
610 m_pOwnSh->SetAttrItem(SwRotationGrf(nNew, rUnrotatedSize));
611 }
612 }
613
SetSize(const Size & rSize)614 void SwFlyFrameAttrMgr::SetSize( const Size& rSize )
615 {
616 SwFormatFrameSize aSize( GetFrameSize() );
617 aSize.SetSize(Size(std::max(rSize.Width(), tools::Long(MINFLY)), std::max(rSize.Height(), tools::Long(MINFLY))));
618 m_aSet.Put( aSize );
619 }
620
SetAttrSet(const SfxItemSet & rSet)621 void SwFlyFrameAttrMgr::SetAttrSet(const SfxItemSet& rSet)
622 {
623 m_aSet.ClearItem();
624 m_aSet.Put( rSet );
625 }
626
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
628