android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / layout / flyincnt.cxx
blob2455f7a6d130abf73196b9f61ed833a83abc7765
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <doc.hxx>
21 #include <frmtool.hxx>
22 #include <hints.hxx>
23 #include <fmtornt.hxx>
24 #include <rootfrm.hxx>
25 #include <flyfrms.hxx>
26 #include <dflyobj.hxx>
27 #include <IDocumentSettingAccess.hxx>
28 #include <IDocumentDrawModelAccess.hxx>
29 #include <osl/diagnose.h>
30 #include <o3tl/deleter.hxx>
32 SwFlyInContentFrame::SwFlyInContentFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, SwFrame *pAnch ) :
33 SwFlyFrame( pFormat, pSib, pAnch )
35 m_bInCnt = true;
36 SwTwips nRel = pFormat->GetVertOrient().GetPos();
37 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
38 Point aRelPos;
39 if( pAnch && pAnch->IsVertical() )
40 aRelPos.setX(-nRel);
41 else
42 aRelPos.setY(nRel);
43 SetCurrRelPos( aRelPos );
46 void SwFlyInContentFrame::DestroyImpl()
48 if ( !GetFormat()->GetDoc()->IsInDtor() && GetAnchorFrame() )
50 SwRect aTmp( GetObjRectWithSpaces() );
51 SwFlyInContentFrame::NotifyBackground( FindPageFrame(), aTmp, PrepareHint::FlyFrameLeave );
54 SwFlyFrame::DestroyImpl();
57 SwFlyInContentFrame::~SwFlyInContentFrame()
61 // #i28701#
63 void SwFlyInContentFrame::SetRefPoint( const Point& rPoint,
64 const Point& rRelAttr,
65 const Point& rRelPos )
67 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
68 OSL_ENSURE( rPoint != m_aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
69 std::unique_ptr<SwFlyNotify, o3tl::default_delete<SwFlyNotify>> xNotify;
70 // No notify at a locked fly frame, if a fly frame is locked, there's
71 // already a SwFlyNotify object on the stack (MakeAll).
72 if( !IsLocked() )
73 xNotify.reset(new SwFlyNotify( this ));
74 m_aRef = rPoint;
75 SetCurrRelPos( rRelAttr );
76 SwRectFnSet aRectFnSet(GetAnchorFrame());
79 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
80 aRectFnSet.SetPos( aFrm, rPoint + rRelPos );
83 // #i68520#
84 InvalidateObjRectWithSpaces();
85 if (xNotify)
87 InvalidatePage();
88 setFrameAreaPositionValid(false);
89 m_bInvalid = true;
90 Calc(getRootFrame()->GetCurrShell()->GetOut());
91 xNotify.reset();
95 void SwFlyInContentFrame::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
97 if (rHint.GetId() != SfxHintId::SwLegacyModify)
98 return;
99 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
100 std::pair<std::unique_ptr<SwAttrSetChg>, std::unique_ptr<SwAttrSetChg>> aTweakedChgs;
101 std::pair<const SfxPoolItem*, const SfxPoolItem*> aSuperArgs(nullptr, nullptr);
102 switch(pLegacy->GetWhich())
104 case RES_ATTRSET_CHG:
106 auto pOldAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pOld);
107 auto pNewAttrSetChg = static_cast<const SwAttrSetChg*>(pLegacy->m_pNew);
108 if(pOldAttrSetChg
109 && pNewAttrSetChg
110 && ((SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_SURROUND, false))
111 || (SfxItemState::SET == pNewAttrSetChg->GetChgSet()->GetItemState(RES_FRMMACRO, false))))
113 aTweakedChgs.second = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
114 aTweakedChgs.second->ClearItem(RES_SURROUND);
115 aTweakedChgs.second->ClearItem(RES_FRMMACRO);
116 if(aTweakedChgs.second->Count())
118 aTweakedChgs.first = std::make_unique<SwAttrSetChg>(*pOldAttrSetChg);
119 aTweakedChgs.first->ClearItem(RES_SURROUND);
120 aTweakedChgs.first->ClearItem(RES_FRMMACRO);
121 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(aTweakedChgs.first.get(), aTweakedChgs.second.get());
123 } else if (pNewAttrSetChg && pNewAttrSetChg->GetChgSet()->Count())
124 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
125 break;
127 case RES_SURROUND:
128 case RES_FRMMACRO:
129 break;
130 default:
131 aSuperArgs = std::pair<const SfxPoolItem*, const SfxPoolItem*>(pLegacy->m_pOld, pLegacy->m_pNew);
133 if(aSuperArgs.second)
135 SwFlyFrame::SwClientNotify(rMod, sw::LegacyModifyHint(aSuperArgs.first, aSuperArgs.second));
136 if(GetAnchorFrame())
137 AnchorFrame()->Prepare(PrepareHint::FlyFrameAttributesChanged, GetFormat());
141 /// Here the content gets formatted initially.
142 void SwFlyInContentFrame::Format( vcl::RenderContext* pRenderContext, const SwBorderAttrs *pAttrs )
144 if ( !getFrameArea().Height() )
146 Lock(); //don't format the anchor on the crook.
147 SwContentFrame *pContent = ContainsContent();
148 while ( pContent )
149 { pContent->Calc(pRenderContext);
150 pContent = pContent->GetNextContentFrame();
152 Unlock();
154 SwFlyFrame::Format( pRenderContext, pAttrs );
157 /** Calculate object position
159 * @note: In contrast to other Frames, we only calculate the relative position
160 * here. The absolute position is only calculated using SetAbsPos.
162 void SwFlyInContentFrame::MakeObjPos()
164 if ( isFrameAreaPositionValid() )
165 return;
167 setFrameAreaPositionValid(true);
168 SwFlyFrameFormat *pFormat = GetFormat();
169 const SwFormatVertOrient &rVert = pFormat->GetVertOrient();
170 //Update the current values in the format if needed, during this we of
171 //course must not send any Modify.
172 const bool bVert = GetAnchorFrame()->IsVertical();
173 SwTwips nOld = rVert.GetPos();
174 SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
175 if( nAct != nOld )
177 SwFormatVertOrient aVert( rVert );
178 aVert.SetPos( nAct );
179 pFormat->LockModify();
180 pFormat->SetFormatAttr( aVert );
181 pFormat->UnlockModify();
185 void SwFlyInContentFrame::ActionOnInvalidation( const InvalidationType _nInvalid )
187 if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
188 AnchorFrame()->Prepare( PrepareHint::FlyFrameAttributesChanged, &GetFrameFormat() );
191 void SwFlyInContentFrame::NotifyBackground( SwPageFrame *, const SwRect& rRect,
192 PrepareHint eHint)
194 if ( eHint == PrepareHint::FlyFrameAttributesChanged )
195 AnchorFrame()->Prepare( PrepareHint::FlyFrameAttributesChanged );
196 else
197 AnchorFrame()->Prepare( eHint, static_cast<void const *>(&rRect) );
200 Point const & SwFlyInContentFrame::GetRelPos() const
202 Calc(getRootFrame()->GetCurrShell()->GetOut());
203 return GetCurrRelPos();
206 /// @see SwRowFrame::RegistFlys()
207 void SwFlyInContentFrame::RegistFlys()
209 SwPageFrame *pPage = FindPageFrame();
210 OSL_ENSURE( pPage, "Register Flys without pages?" );
211 ::RegistFlys( pPage, this );
214 void SwFlyInContentFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/)
216 // OD 2004-01-19 #110582#
217 if ( !GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
219 return;
222 if ( !GetAnchorFrame() || IsLocked() || IsColLocked() || !FindPageFrame() )
223 return;
225 Lock(); // The curtain falls
227 //does the notification in the DTor
228 const SwFlyNotify aNotify( this );
229 SwBorderAttrAccess aAccess( SwFrame::GetCache(), this );
230 const SwBorderAttrs &rAttrs = *aAccess.Get();
232 if ( IsClipped() )
234 setFrameAreaSizeValid(false);
235 m_bHeightClipped = m_bWidthClipped = false;
238 while ( !isFrameAreaPositionValid() || !isFrameAreaSizeValid() || !isFramePrintAreaValid() || !m_bValidContentPos )
240 //Only stop, if the flag is set!!
241 if ( !isFrameAreaSizeValid() )
243 setFramePrintAreaValid(false);
246 if ( !isFramePrintAreaValid() )
248 MakePrtArea( rAttrs );
249 m_bValidContentPos = false;
252 if ( !isFrameAreaSizeValid() )
254 Format( getRootFrame()->GetCurrShell()->GetOut(), &rAttrs );
257 if ( !isFrameAreaPositionValid() )
259 MakeObjPos();
262 if ( !m_bValidContentPos )
263 MakeContentPos( rAttrs );
265 // re-activate clipping of as-character anchored Writer fly frames
266 // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
267 if ( isFrameAreaPositionValid() &&
268 isFrameAreaSizeValid() &&
269 GetFormat()->getIDocumentSettingAccess().get( DocumentSettingId::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
271 SwFrame* pFrame = AnchorFrame();
272 if ( getFrameArea().Left() == (pFrame->getFrameArea().Left()+pFrame->getFramePrintArea().Left()) &&
273 getFrameArea().Width() > pFrame->getFramePrintArea().Width() )
275 SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this);
276 aFrm.Width( pFrame->getFramePrintArea().Width() );
277 setFramePrintAreaValid(false);
278 m_bWidthClipped = true;
282 Unlock();
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */