nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / outdev / clipping.cxx
blob3823d2505fa5fa256fd01769695bb939e1eb0cf4
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 <sal/config.h>
21 #include <osl/diagnose.h>
23 #include <tools/debug.hxx>
24 #include <vcl/metaact.hxx>
25 #include <vcl/virdev.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <vcl/outdev.hxx>
29 #include <salgdi.hxx>
31 void OutputDevice::SaveBackground(VirtualDevice& rSaveDevice,
32 const Point& rPos, const Size& rSize, const Size& rBackgroundSize) const
34 rSaveDevice.DrawOutDev(Point(), rBackgroundSize, rPos, rSize, *this);
37 vcl::Region OutputDevice::GetClipRegion() const
40 return PixelToLogic( maRegion );
43 void OutputDevice::SetClipRegion()
46 if ( mpMetaFile )
47 mpMetaFile->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
49 SetDeviceClipRegion( nullptr );
51 if( mpAlphaVDev )
52 mpAlphaVDev->SetClipRegion();
55 void OutputDevice::SetClipRegion( const vcl::Region& rRegion )
58 if ( mpMetaFile )
59 mpMetaFile->AddAction( new MetaClipRegionAction( rRegion, true ) );
61 if ( rRegion.IsNull() )
63 SetDeviceClipRegion( nullptr );
65 else
67 vcl::Region aRegion = LogicToPixel( rRegion );
68 SetDeviceClipRegion( &aRegion );
71 if( mpAlphaVDev )
72 mpAlphaVDev->SetClipRegion( rRegion );
75 bool OutputDevice::SelectClipRegion( const vcl::Region& rRegion, SalGraphics* pGraphics )
77 DBG_TESTSOLARMUTEX();
79 if( !pGraphics )
81 if( !mpGraphics && !AcquireGraphics() )
82 return false;
83 pGraphics = mpGraphics;
86 bool bClipRegion = pGraphics->SetClipRegion( rRegion, this );
87 OSL_ENSURE( bClipRegion, "OutputDevice::SelectClipRegion() - can't create region" );
88 return bClipRegion;
91 void OutputDevice::MoveClipRegion( tools::Long nHorzMove, tools::Long nVertMove )
94 if ( mbClipRegion )
96 if( mpMetaFile )
97 mpMetaFile->AddAction( new MetaMoveClipRegionAction( nHorzMove, nVertMove ) );
99 maRegion.Move( ImplLogicWidthToDevicePixel( nHorzMove ),
100 ImplLogicHeightToDevicePixel( nVertMove ) );
101 mbInitClipRegion = true;
104 if( mpAlphaVDev )
105 mpAlphaVDev->MoveClipRegion( nHorzMove, nVertMove );
108 void OutputDevice::IntersectClipRegion( const tools::Rectangle& rRect )
111 if ( mpMetaFile )
112 mpMetaFile->AddAction( new MetaISectRectClipRegionAction( rRect ) );
114 tools::Rectangle aRect = LogicToPixel( rRect );
115 maRegion.Intersect( aRect );
116 mbClipRegion = true;
117 mbInitClipRegion = true;
119 if( mpAlphaVDev )
120 mpAlphaVDev->IntersectClipRegion( rRect );
123 void OutputDevice::IntersectClipRegion( const vcl::Region& rRegion )
126 if(!rRegion.IsNull())
128 if ( mpMetaFile )
129 mpMetaFile->AddAction( new MetaISectRegionClipRegionAction( rRegion ) );
131 vcl::Region aRegion = LogicToPixel( rRegion );
132 maRegion.Intersect( aRegion );
133 mbClipRegion = true;
134 mbInitClipRegion = true;
137 if( mpAlphaVDev )
138 mpAlphaVDev->IntersectClipRegion( rRegion );
141 void OutputDevice::InitClipRegion()
143 DBG_TESTSOLARMUTEX();
145 if ( mbClipRegion )
147 if ( maRegion.IsEmpty() )
148 mbOutputClipped = true;
149 else
151 mbOutputClipped = false;
153 // #102532# Respect output offset also for clip region
154 vcl::Region aRegion = ClipToDeviceBounds(ImplPixelToDevicePixel(maRegion));
156 if ( aRegion.IsEmpty() )
158 mbOutputClipped = true;
160 else
162 mbOutputClipped = false;
163 SelectClipRegion( aRegion );
167 mbClipRegionSet = true;
169 else
171 if ( mbClipRegionSet )
173 if (mpGraphics)
174 mpGraphics->ResetClipRegion();
175 mbClipRegionSet = false;
178 mbOutputClipped = false;
181 mbInitClipRegion = false;
184 vcl::Region OutputDevice::ClipToDeviceBounds(vcl::Region aRegion) const
186 aRegion.Intersect(tools::Rectangle{mnOutOffX,
187 mnOutOffY,
188 mnOutOffX + GetOutputWidthPixel() - 1,
189 mnOutOffY + GetOutputHeightPixel() - 1
191 return aRegion;
194 vcl::Region OutputDevice::GetActiveClipRegion() const
196 return GetClipRegion();
199 void OutputDevice::ClipToPaintRegion(tools::Rectangle& /*rDstRect*/)
201 // this is only used in Window, but we still need it as it's called
202 // on in other clipping functions
205 void OutputDevice::SetDeviceClipRegion( const vcl::Region* pRegion )
207 DBG_TESTSOLARMUTEX();
209 if ( !pRegion )
211 if ( mbClipRegion )
213 maRegion = vcl::Region(true);
214 mbClipRegion = false;
215 mbInitClipRegion = true;
218 else
220 maRegion = *pRegion;
221 mbClipRegion = true;
222 mbInitClipRegion = true;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */