resolves tdf#164985 Incorrect bookmarks list in bookmark dialog after
[LibreOffice.git] / vcl / source / outdev / stack.cxx
blob72ef63af551da7348d7595716f505b643b02732f
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 <sal/log.hxx>
22 #include <tools/debug.hxx>
24 #include <vcl/metaact.hxx>
25 #include <vcl/rendercontext/State.hxx>
26 #include <vcl/virdev.hxx>
27 #include <vcl/settings.hxx>
29 #include <drawmode.hxx>
30 #include <salgdi.hxx>
32 void OutputDevice::Push(vcl::PushFlags nFlags)
34 if (mpMetaFile)
35 mpMetaFile->AddAction(new MetaPushAction(nFlags));
37 maOutDevStateStack.emplace_back();
38 vcl::State& rState = maOutDevStateStack.back();
40 rState.mnFlags = nFlags;
42 if (nFlags & vcl::PushFlags::LINECOLOR && mbLineColor)
43 rState.mpLineColor = maLineColor;
45 if (nFlags & vcl::PushFlags::FILLCOLOR && mbFillColor)
46 rState.mpFillColor = maFillColor;
48 if (nFlags & vcl::PushFlags::FONT)
49 rState.mpFont = maFont;
51 if (nFlags & vcl::PushFlags::TEXTCOLOR)
52 rState.mpTextColor = GetTextColor();
54 if (nFlags & vcl::PushFlags::TEXTFILLCOLOR && IsTextFillColor())
55 rState.mpTextFillColor = GetTextFillColor();
57 if (nFlags & vcl::PushFlags::TEXTLINECOLOR && IsTextLineColor())
58 rState.mpTextLineColor = GetTextLineColor();
60 if (nFlags & vcl::PushFlags::OVERLINECOLOR && IsOverlineColor())
61 rState.mpOverlineColor = GetOverlineColor();
63 if (nFlags & vcl::PushFlags::TEXTALIGN)
64 rState.meTextAlign = GetTextAlign();
66 if (nFlags & vcl::PushFlags::TEXTLAYOUTMODE)
67 rState.mnTextLayoutMode = GetLayoutMode();
69 if (nFlags & vcl::PushFlags::TEXTLANGUAGE)
70 rState.meTextLanguage = GetDigitLanguage();
72 if (nFlags & vcl::PushFlags::RASTEROP)
73 rState.meRasterOp = GetRasterOp();
75 if (nFlags & vcl::PushFlags::MAPMODE)
77 rState.mpMapMode = maMapMode;
78 rState.mbMapActive = mbMap;
81 if (nFlags & vcl::PushFlags::CLIPREGION && mbClipRegion)
82 rState.mpClipRegion.reset(new vcl::Region(maRegion));
84 if (nFlags & vcl::PushFlags::REFPOINT && mbRefPoint)
85 rState.mpRefPoint = maRefPoint;
87 if (mpAlphaVDev)
88 mpAlphaVDev->Push();
91 void OutputDevice::Pop()
93 if( mpMetaFile )
94 mpMetaFile->AddAction( new MetaPopAction() );
96 GDIMetaFile* pOldMetaFile = mpMetaFile;
97 mpMetaFile = nullptr;
99 if ( maOutDevStateStack.empty() )
101 SAL_WARN( "vcl.gdi", "OutputDevice::Pop() without OutputDevice::Push()" );
102 return;
104 const vcl::State& rState = maOutDevStateStack.back();
106 if( mpAlphaVDev )
107 mpAlphaVDev->Pop();
109 if ( rState.mnFlags & vcl::PushFlags::LINECOLOR )
111 if ( rState.mpLineColor )
112 SetLineColor( *rState.mpLineColor );
113 else
114 SetLineColor();
117 if ( rState.mnFlags & vcl::PushFlags::FILLCOLOR )
119 if ( rState.mpFillColor )
120 SetFillColor( *rState.mpFillColor );
121 else
122 SetFillColor();
125 if ( rState.mnFlags & vcl::PushFlags::FONT )
126 SetFont( *rState.mpFont );
128 if ( rState.mnFlags & vcl::PushFlags::TEXTCOLOR )
129 SetTextColor( *rState.mpTextColor );
131 if ( rState.mnFlags & vcl::PushFlags::TEXTFILLCOLOR )
133 if ( rState.mpTextFillColor )
134 SetTextFillColor( *rState.mpTextFillColor );
135 else
136 SetTextFillColor();
139 if ( rState.mnFlags & vcl::PushFlags::TEXTLINECOLOR )
141 if ( rState.mpTextLineColor )
142 SetTextLineColor( *rState.mpTextLineColor );
143 else
144 SetTextLineColor();
147 if ( rState.mnFlags & vcl::PushFlags::OVERLINECOLOR )
149 if ( rState.mpOverlineColor )
150 SetOverlineColor( *rState.mpOverlineColor );
151 else
152 SetOverlineColor();
155 if ( rState.mnFlags & vcl::PushFlags::TEXTALIGN )
156 SetTextAlign( rState.meTextAlign );
158 if( rState.mnFlags & vcl::PushFlags::TEXTLAYOUTMODE )
159 SetLayoutMode( rState.mnTextLayoutMode );
161 if( rState.mnFlags & vcl::PushFlags::TEXTLANGUAGE )
162 SetDigitLanguage( rState.meTextLanguage );
164 if ( rState.mnFlags & vcl::PushFlags::RASTEROP )
165 SetRasterOp( rState.meRasterOp );
167 if ( rState.mnFlags & vcl::PushFlags::MAPMODE )
169 if ( rState.mpMapMode )
170 SetMapMode( *rState.mpMapMode );
171 else
172 SetMapMode();
173 mbMap = rState.mbMapActive;
176 if ( rState.mnFlags & vcl::PushFlags::CLIPREGION )
177 SetDeviceClipRegion( rState.mpClipRegion.get() );
179 if ( rState.mnFlags & vcl::PushFlags::REFPOINT )
181 if ( rState.mpRefPoint )
182 SetRefPoint( *rState.mpRefPoint );
183 else
184 SetRefPoint();
187 maOutDevStateStack.pop_back();
189 mpMetaFile = pOldMetaFile;
192 void OutputDevice::ClearStack()
194 sal_uInt32 nCount = maOutDevStateStack.size();
195 while( nCount-- )
196 Pop();
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */