LibreOffice Module sw (master) 1
vdraw.cxx
Go to the documentation of this file.
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 <officecfg/Office/Common.hxx>
21#include <svx/svdmodel.hxx>
22#include <svx/svdpage.hxx>
23#include <svx/svdpagv.hxx>
24#include <fmtanchr.hxx>
25#include <frmfmt.hxx>
26
27#include <svx/svdoutl.hxx>
28
29#include <drawdoc.hxx>
30#include <fesh.hxx>
31#include <pagefrm.hxx>
32#include <rootfrm.hxx>
33#include <viewimp.hxx>
34#include <dflyobj.hxx>
35#include <printdata.hxx>
36#include <dcontact.hxx>
37#include <dview.hxx>
38#include <flyfrm.hxx>
39#include <vcl/svapp.hxx>
40#include <vcl/settings.hxx>
41#include <vcl/canvastools.hxx>
42#include <sal/log.hxx>
43#include <osl/diagnose.h>
44
46
48
50{
51 if ( HasDrawView() )
52 {
53 CurrShell aCurr( GetShell() );
54 if ( auto pFEShell = dynamic_cast<SwFEShell*>( m_pShell) )
55 pFEShell->HideChainMarker(); // might have changed
56 }
57}
58
60{
61 if ( HasDrawView() )
62 {
63 CurrShell aCurr( GetShell() );
64 if ( auto pFEShell = dynamic_cast<SwFEShell*>(m_pShell) )
65 pFEShell->SetChainMarker(); // might have changed
66 }
67}
68
70{
71 if ( HasDrawView() )
72 {
75 }
76 else
77 {
79 }
80}
81
83{
86}
87
89 SwPrintData const*const pPrintData,
90 SwPageFrame const& rPageFrame,
91 const SwRect& aPaintRect,
92 const Color* _pPageBackgrdColor,
93 const bool _bIsPageRightToLeft,
95{
96 if ( !HasDrawView() )
97 return;
98
99 //change the draw mode in high contrast mode
100 OutputDevice* pOutDev = GetShell()->GetOut();
101 DrawModeFlags nOldDrawMode = pOutDev->GetDrawMode();
102 if( GetShell()->GetWin() &&
103 Application::GetSettings().GetStyleSettings().GetHighContrastMode() &&
105 {
106 pOutDev->SetDrawMode( nOldDrawMode | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill |
107 DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient );
108 }
109
110 // For correct handling of accessibility, high contrast, the
111 // page background color is set as the background color at the
112 // outliner of the draw view. Only necessary for the layers
113 // hell and heaven
114 Color aOldOutlinerBackgroundColor;
115 // set default horizontal text direction on painting <hell> or
116 // <heaven>.
117 EEHorizontalTextDirection aOldEEHoriTextDir = EEHorizontalTextDirection::L2R;
119 if ( (_nLayerID == rIDDMA.GetHellId()) ||
120 (_nLayerID == rIDDMA.GetHeavenId()) )
121 {
122 OSL_ENSURE( _pPageBackgrdColor,
123 "incorrect usage of SwViewShellImp::PaintLayer: pPageBackgrdColor have to be set for painting layer <hell> or <heaven>");
124 if ( _pPageBackgrdColor )
125 {
126 aOldOutlinerBackgroundColor =
127 GetDrawView()->GetModel()->GetDrawOutliner().GetBackgroundColor();
128 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( *_pPageBackgrdColor );
129 }
130
131 aOldEEHoriTextDir =
132 GetDrawView()->GetModel()->GetDrawOutliner().GetDefaultHorizontalTextDirection();
133 EEHorizontalTextDirection aEEHoriTextDirOfPage =
134 _bIsPageRightToLeft ? EEHorizontalTextDirection::R2L : EEHorizontalTextDirection::L2R;
135 GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aEEHoriTextDirOfPage );
136 }
137
139 if (pPrintData)
140 {
141 // hide drawings but not form controls (form controls are handled elsewhere)
142 SdrView &rSdrView = GetPageView()->GetView();
143 rSdrView.setHideDraw( !pPrintData->IsPrintDraw() );
144 }
146 GetPageView()->DrawLayer(_nLayerID, pOutDev, pRedirector, aPaintRect.SVRect(), &pageFrame);
147 pOutDev->Pop();
148
149 // reset background color of the outliner & default horiz. text dir.
150 if ( (_nLayerID == rIDDMA.GetHellId()) ||
151 (_nLayerID == rIDDMA.GetHeavenId()) )
152 {
153 GetDrawView()->GetModel()->GetDrawOutliner().SetBackgroundColor( aOldOutlinerBackgroundColor );
154 GetDrawView()->GetModel()->GetDrawOutliner().SetDefaultHorizontalTextDirection( aOldEEHoriTextDir );
155 }
156
157 pOutDev->SetDrawMode( nOldDrawMode );
158
159}
160
161#define FUZZY_EDGE 400
162
163bool SwViewShellImp::IsDragPossible( const Point &rPoint )
164{
165 if ( !HasDrawView() )
166 return false;
167
168 const SdrMarkList &rMrkList = GetDrawView()->GetMarkedObjectList();
169
170 if( !rMrkList.GetMarkCount() )
171 return false;
172
173 SdrObject *pO = rMrkList.GetMark(rMrkList.GetMarkCount()-1)->GetMarkedSdrObj();
174
175 SwRect aRect;
176 if( pO && ::CalcClipRect( pO, aRect, false ) )
177 {
178 SwRect aTmp;
179 ::CalcClipRect( pO, aTmp );
180 aRect.Union( aTmp );
181 }
182 else
183 aRect = GetShell()->GetLayout()->getFrameArea();
184
185 aRect.AddTop (- FUZZY_EDGE );
186 aRect.AddBottom( FUZZY_EDGE );
187 aRect.AddLeft (- FUZZY_EDGE );
188 aRect.AddRight ( FUZZY_EDGE );
189 return aRect.Contains( rPoint );
190}
191
193{
194 if ( !HasDrawView() )
195 return;
196
197 if ( GetPageView() )
198 GetPageView()->GetPage()->SetSize( rNewSz );
199
200 // Limitation of the work area
201 const tools::Rectangle aDocRect( Point( DOCUMENTBORDER, DOCUMENTBORDER ), rNewSz );
202 const tools::Rectangle &rOldWork = GetDrawView()->GetWorkArea();
203 bool bCheckDrawObjs = false;
204 if ( aDocRect != rOldWork )
205 {
206 if ( rOldWork.Bottom() > aDocRect.Bottom() || rOldWork.Right() > aDocRect.Right())
207 bCheckDrawObjs = true;
208 GetDrawView()->SetWorkArea( aDocRect );
209 }
210 if ( !bCheckDrawObjs )
211 return;
212
213 OSL_ENSURE( m_pShell->getIDocumentDrawModelAccess().GetDrawModel(), "NotifySizeChg without DrawModel" );
215 const size_t nObjs = pPage->GetObjCount();
216 for( size_t nObj = 0; nObj < nObjs; ++nObj )
217 {
218 SdrObject *pObj = pPage->GetObj( nObj );
219 if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) == nullptr )
220 {
221 // Objects not anchored to the frame, do not need to be adjusted
222 const SwContact *pCont = GetUserCall(pObj);
223 // this function might be called by the InsertDocument, when
224 // a PageDesc-Attribute is set on a node. Then the SdrObject
225 // must not have an UserCall.
226 if( !pCont )
227 continue;
228 auto pDrawContact = dynamic_cast<const SwDrawContact*>( pCont);
229 if( !pDrawContact )
230 continue;
231
232 const SwFrame *pAnchor = pDrawContact->GetAnchorFrame();
233 if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->isFrameAreaDefinitionValid() ||
234 !pAnchor->GetUpper() || !pAnchor->FindPageFrame() ||
235 (RndStdIds::FLY_AS_CHAR == pCont->GetFormat()->GetAnchor().GetAnchorId()) )
236 {
237 continue;
238 }
239 else
240 {
241 // Actually this should never happen but currently layouting
242 // is broken. So don't move anchors, if the page is invalid.
243 // This should be turned into a DBG_ASSERT, once layouting is fixed!
244 const SwPageFrame *pPageFrame = pAnchor->FindPageFrame();
245 if (!pPageFrame || pPageFrame->IsInvalid() ) {
246 SAL_WARN( "sw.core", "Trying to move anchor from invalid page - fix layouting!" );
247 continue;
248 }
249 }
250
251 // no move for drawing objects in header/footer
252 if ( pAnchor->FindFooterOrHeader() )
253 {
254 continue;
255 }
256
257 const tools::Rectangle aObjBound( pObj->GetCurrentBoundRect() );
258 if ( !aDocRect.Contains( aObjBound ) )
259 {
260 Size aSz;
261 if ( aObjBound.Left() > aDocRect.Right() )
262 aSz.setWidth( (aDocRect.Right() - aObjBound.Left()) - MINFLY );
263 if ( aObjBound.Top() > aDocRect.Bottom() )
264 aSz.setHeight( (aDocRect.Bottom() - aObjBound.Top()) - MINFLY );
265 if ( aSz.Width() || aSz.Height() )
266 pObj->Move( aSz );
267
268 // Don't let large objects disappear to the top
269 aSz.setWidth(0);
270 aSz.setHeight(0);
271 if ( aObjBound.Right() < aDocRect.Left() )
272 aSz.setWidth( (aDocRect.Left() - aObjBound.Right()) + MINFLY );
273 if ( aObjBound.Bottom() < aDocRect.Top() )
274 aSz.setHeight( (aDocRect.Top() - aObjBound.Bottom()) + MINFLY );
275 if ( aSz.Width() || aSz.Height() )
276 pObj->Move( aSz );
277 }
278 }
279 }
280}
281
282/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawModeFlags
static const AllSettings & GetSettings()
virtual SdrLayerID GetHellId() const =0
virtual SdrLayerID GetHeavenId() const =0
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
void SetDrawMode(DrawModeFlags nDrawMode)
DrawModeFlags GetDrawMode() const
const tools::Rectangle & GetWorkArea() const
void SetWorkArea(const tools::Rectangle &rRect)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
void showMarkHandles()
void hideMarkHandles()
bool areMarkHandlesHidden() const
SdrObject * GetMarkedSdrObj() const
SdrOutliner & GetDrawOutliner(const SdrTextObj *pObj=nullptr) const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
virtual void Move(const Size &rSiz)
virtual const tools::Rectangle & GetCurrentBoundRect() const
void DrawLayer(SdrLayerID nID, OutputDevice *pGivenTarget, sdr::contact::ViewObjectContactRedirector *pRedirector=nullptr, const tools::Rectangle &rRect=tools::Rectangle(), basegfx::B2IRectangle const *pPageFrame=nullptr)
SdrView & GetView()
SdrPage * GetPage() const
virtual void SetSize(const Size &aSiz)
SdrModel * GetModel() const
void setHideDraw(bool bNew)
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
Base class for the following contact objects (frame + draw objects).
Definition: dcontact.hxx:67
SwFrameFormat * GetFormat()
Definition: dcontact.hxx:112
ContactObject for connection of formats as representatives of draw objects in SwClient and the object...
Definition: dcontact.hxx:305
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:88
const SwRect & getFrameArea() const
Definition: frame.hxx:179
bool isFrameAreaDefinitionValid() const
Definition: frame.hxx:171
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsInFly() const
Definition: frame.hxx:961
SwLayoutFrame * GetUpper()
Definition: frame.hxx:678
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
SwFrame * FindFooterOrHeader()
Definition: findfrm.cxx:602
A page of the document layout.
Definition: pagefrm.hxx:58
bool IsInvalid() const
Definition: pagefrm.hxx:439
bool IsPrintDraw() const
Definition: printdata.hxx:133
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
SwRect & Union(const SwRect &rRect)
Definition: swrect.cxx:35
void AddLeft(const tools::Long nAdd)
Definition: swrect.cxx:125
bool Contains(const Point &rPOINT) const
Definition: swrect.hxx:356
void AddBottom(const tools::Long nAdd)
Definition: swrect.cxx:130
void AddRight(const tools::Long nAdd)
Definition: swrect.cxx:127
void AddTop(const tools::Long nAdd)
Definition: swrect.cxx:128
tools::Rectangle SVRect() const
Definition: swrect.hxx:292
bool m_bResetHdlHiddenPaint
Definition: viewimp.hxx:81
bool HasDrawView() const
New Interface for StarView Drawing.
Definition: viewimp.hxx:163
void LockPaint()
Definition: vdraw.cxx:69
void StartAction()
Definition: vdraw.cxx:49
void UnlockPaint()
Definition: vdraw.cxx:82
bool IsDragPossible(const Point &rPoint)
Is passed to the DrawEngine as a Link and decides what is painted or not and in what way.
Definition: vdraw.cxx:163
void EndAction()
Definition: vdraw.cxx:59
SwViewShell * m_pShell
Definition: viewimp.hxx:61
SwDrawView * GetDrawView()
Definition: viewimp.hxx:164
SdrPageView * GetPageView()
Definition: viewimp.hxx:166
const SwViewShell * GetShell() const
Only for SwViewShell::Init()
Definition: viewimp.hxx:141
void PaintLayer(const SdrLayerID _nLayerID, SwPrintData const *const pPrintData, SwPageFrame const &rPageFrame, const SwRect &_rRect, const Color *_pPageBackgrdColor, const bool _bIsPageRightToLeft, sdr::contact::ViewObjectContactRedirector *pRedirector)
Definition: vdraw.cxx:88
void NotifySizeChg(const Size &rNewSz)
Definition: vdraw.cxx:192
vcl::RenderContext * GetOut() const
Definition: viewsh.hxx:347
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2160
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2813
bool Contains(const Point &rPOINT) const
constexpr tools::Long Top() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
SwContact * GetUserCall(const SdrObject *pObj)
Returns the UserCall if applicable from the group object.
Definition: dcontact.cxx:172
EEHorizontalTextDirection
bool CalcClipRect(const SdrObject *pSdrObj, SwRect &rRect, bool bMove=true)
calculate rectangle in that the object can be moved or rather be resized
Definition: flylay.cxx:1195
#define SAL_WARN(area, stream)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
basegfx::B2IRectangle b2IRectangleFromRectangle(tools::Rectangle const &rRect)
constexpr SwTwips DOCUMENTBORDER
Definition: swtypes.hxx:79
#define MINFLY
Definition: swtypes.hxx:61
#define FUZZY_EDGE
Definition: vdraw.cxx:161