1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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()
47 mpMetaFile
->AddAction( new MetaClipRegionAction( vcl::Region(), false ) );
49 SetDeviceClipRegion( nullptr );
52 mpAlphaVDev
->SetClipRegion();
55 void OutputDevice::SetClipRegion( const vcl::Region
& rRegion
)
59 mpMetaFile
->AddAction( new MetaClipRegionAction( rRegion
, true ) );
61 if ( rRegion
.IsNull() )
63 SetDeviceClipRegion( nullptr );
67 vcl::Region aRegion
= LogicToPixel( rRegion
);
68 SetDeviceClipRegion( &aRegion
);
72 mpAlphaVDev
->SetClipRegion( rRegion
);
75 bool OutputDevice::SelectClipRegion( const vcl::Region
& rRegion
, SalGraphics
* pGraphics
)
81 if( !mpGraphics
&& !AcquireGraphics() )
83 pGraphics
= mpGraphics
;
86 bool bClipRegion
= pGraphics
->SetClipRegion( rRegion
, this );
87 OSL_ENSURE( bClipRegion
, "OutputDevice::SelectClipRegion() - can't create region" );
91 void OutputDevice::MoveClipRegion( tools::Long nHorzMove
, tools::Long nVertMove
)
97 mpMetaFile
->AddAction( new MetaMoveClipRegionAction( nHorzMove
, nVertMove
) );
99 maRegion
.Move( ImplLogicWidthToDevicePixel( nHorzMove
),
100 ImplLogicHeightToDevicePixel( nVertMove
) );
101 mbInitClipRegion
= true;
105 mpAlphaVDev
->MoveClipRegion( nHorzMove
, nVertMove
);
108 void OutputDevice::IntersectClipRegion( const tools::Rectangle
& rRect
)
112 mpMetaFile
->AddAction( new MetaISectRectClipRegionAction( rRect
) );
114 tools::Rectangle aRect
= LogicToPixel( rRect
);
115 maRegion
.Intersect( aRect
);
117 mbInitClipRegion
= true;
120 mpAlphaVDev
->IntersectClipRegion( rRect
);
123 void OutputDevice::IntersectClipRegion( const vcl::Region
& rRegion
)
126 if(!rRegion
.IsNull())
129 mpMetaFile
->AddAction( new MetaISectRegionClipRegionAction( rRegion
) );
131 vcl::Region aRegion
= LogicToPixel( rRegion
);
132 maRegion
.Intersect( aRegion
);
134 mbInitClipRegion
= true;
138 mpAlphaVDev
->IntersectClipRegion( rRegion
);
141 void OutputDevice::InitClipRegion()
143 DBG_TESTSOLARMUTEX();
147 if ( maRegion
.IsEmpty() )
148 mbOutputClipped
= true;
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;
162 mbOutputClipped
= false;
163 SelectClipRegion( aRegion
);
167 mbClipRegionSet
= true;
171 if ( mbClipRegionSet
)
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
,
188 mnOutOffX
+ GetOutputWidthPixel() - 1,
189 mnOutOffY
+ GetOutputHeightPixel() - 1
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();
213 maRegion
= vcl::Region(true);
214 mbClipRegion
= false;
215 mbInitClipRegion
= true;
222 mbInitClipRegion
= true;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */