File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <config_features.h> | |||
21 | #include <vcl/gdimtf.hxx> | |||
22 | #include <vcl/window.hxx> | |||
23 | #include <vcl/virdev.hxx> | |||
24 | #include <vcl/cursor.hxx> | |||
25 | #include <vcl/settings.hxx> | |||
26 | #include <vcl/syswin.hxx> | |||
27 | ||||
28 | #include <sal/types.h> | |||
29 | #include <sal/log.hxx> | |||
30 | ||||
31 | #include <window.h> | |||
32 | #include <salgdi.hxx> | |||
33 | #include <salframe.hxx> | |||
34 | #include <svdata.hxx> | |||
35 | #include <comphelper/lok.hxx> | |||
36 | #include <comphelper/profilezone.hxx> | |||
37 | #if HAVE_FEATURE_OPENGL1 | |||
38 | #include <vcl/opengl/OpenGLHelper.hxx> | |||
39 | #endif | |||
40 | ||||
41 | // PaintBufferGuard | |||
42 | ||||
43 | namespace vcl | |||
44 | { | |||
45 | PaintBufferGuard::PaintBufferGuard(ImplFrameData* pFrameData, vcl::Window* pWindow) | |||
46 | : mpFrameData(pFrameData), | |||
47 | m_pWindow(pWindow), | |||
48 | mbBackground(false), | |||
49 | mnOutOffX(0), | |||
50 | mnOutOffY(0) | |||
51 | { | |||
52 | if (!pFrameData->mpBuffer) | |||
53 | return; | |||
54 | ||||
55 | // transfer various settings | |||
56 | // FIXME: this must disappear as we move to RenderContext only, | |||
57 | // the painting must become state-less, so that no actual | |||
58 | // vcl::Window setting affects this | |||
59 | mbBackground = pFrameData->mpBuffer->IsBackground(); | |||
60 | if (pWindow->IsBackground()) | |||
61 | { | |||
62 | maBackground = pFrameData->mpBuffer->GetBackground(); | |||
63 | pFrameData->mpBuffer->SetBackground(pWindow->GetBackground()); | |||
64 | } | |||
65 | //else | |||
66 | //SAL_WARN("vcl.window", "the root of the double-buffering hierarchy should not have a transparent background"); | |||
67 | ||||
68 | PushFlags nFlags = PushFlags::NONE; | |||
69 | nFlags |= PushFlags::CLIPREGION; | |||
70 | nFlags |= PushFlags::FILLCOLOR; | |||
71 | nFlags |= PushFlags::FONT; | |||
72 | nFlags |= PushFlags::LINECOLOR; | |||
73 | nFlags |= PushFlags::MAPMODE; | |||
74 | maSettings = pFrameData->mpBuffer->GetSettings(); | |||
75 | nFlags |= PushFlags::REFPOINT; | |||
76 | nFlags |= PushFlags::TEXTCOLOR; | |||
77 | nFlags |= PushFlags::TEXTLINECOLOR; | |||
78 | nFlags |= PushFlags::OVERLINECOLOR; | |||
79 | nFlags |= PushFlags::TEXTFILLCOLOR; | |||
80 | nFlags |= PushFlags::TEXTALIGN; | |||
81 | nFlags |= PushFlags::RASTEROP; | |||
82 | nFlags |= PushFlags::TEXTLAYOUTMODE; | |||
83 | nFlags |= PushFlags::TEXTLANGUAGE; | |||
84 | pFrameData->mpBuffer->Push(nFlags); | |||
85 | pFrameData->mpBuffer->SetClipRegion(pWindow->GetClipRegion()); | |||
86 | pFrameData->mpBuffer->SetFillColor(pWindow->GetFillColor()); | |||
87 | pFrameData->mpBuffer->SetFont(pWindow->GetFont()); | |||
88 | pFrameData->mpBuffer->SetLineColor(pWindow->GetLineColor()); | |||
89 | pFrameData->mpBuffer->SetMapMode(pWindow->GetMapMode()); | |||
90 | pFrameData->mpBuffer->SetRefPoint(pWindow->GetRefPoint()); | |||
91 | pFrameData->mpBuffer->SetSettings(pWindow->GetSettings()); | |||
92 | pFrameData->mpBuffer->SetTextColor(pWindow->GetTextColor()); | |||
93 | pFrameData->mpBuffer->SetTextLineColor(pWindow->GetTextLineColor()); | |||
94 | pFrameData->mpBuffer->SetOverlineColor(pWindow->GetOverlineColor()); | |||
95 | pFrameData->mpBuffer->SetTextFillColor(pWindow->GetTextFillColor()); | |||
96 | pFrameData->mpBuffer->SetTextAlign(pWindow->GetTextAlign()); | |||
97 | pFrameData->mpBuffer->SetRasterOp(pWindow->GetRasterOp()); | |||
98 | pFrameData->mpBuffer->SetLayoutMode(pWindow->GetLayoutMode()); | |||
99 | pFrameData->mpBuffer->SetDigitLanguage(pWindow->GetDigitLanguage()); | |||
100 | ||||
101 | mnOutOffX = pFrameData->mpBuffer->GetOutOffXPixel(); | |||
102 | mnOutOffY = pFrameData->mpBuffer->GetOutOffYPixel(); | |||
103 | pFrameData->mpBuffer->SetOutOffXPixel(pWindow->GetOutOffXPixel()); | |||
104 | pFrameData->mpBuffer->SetOutOffYPixel(pWindow->GetOutOffYPixel()); | |||
105 | pFrameData->mpBuffer->EnableRTL(pWindow->IsRTLEnabled()); | |||
106 | } | |||
107 | ||||
108 | PaintBufferGuard::~PaintBufferGuard() | |||
109 | { | |||
110 | if (!mpFrameData->mpBuffer) | |||
111 | return; | |||
112 | ||||
113 | if (!m_aPaintRect.IsEmpty()) | |||
114 | { | |||
115 | // copy the buffer content to the actual window | |||
116 | // export VCL_DOUBLEBUFFERING_AVOID_PAINT=1 to see where we are | |||
117 | // painting directly instead of using Invalidate() | |||
118 | // [ie. everything you can see was painted directly to the | |||
119 | // window either above or in eg. an event handler] | |||
120 | if (!getenv("VCL_DOUBLEBUFFERING_AVOID_PAINT")) | |||
121 | { | |||
122 | // Make sure that the +1 value GetSize() adds to the size is in pixels. | |||
123 | Size aPaintRectSize; | |||
124 | if (m_pWindow->GetMapMode().GetMapUnit() == MapUnit::MapPixel) | |||
125 | { | |||
126 | aPaintRectSize = m_aPaintRect.GetSize(); | |||
127 | } | |||
128 | else | |||
129 | { | |||
130 | tools::Rectangle aRectanglePixel = m_pWindow->LogicToPixel(m_aPaintRect); | |||
131 | aPaintRectSize = m_pWindow->PixelToLogic(aRectanglePixel.GetSize()); | |||
132 | } | |||
133 | ||||
134 | m_pWindow->DrawOutDev(m_aPaintRect.TopLeft(), aPaintRectSize, m_aPaintRect.TopLeft(), aPaintRectSize, *mpFrameData->mpBuffer); | |||
135 | } | |||
136 | } | |||
137 | ||||
138 | // Restore buffer state. | |||
139 | mpFrameData->mpBuffer->SetOutOffXPixel(mnOutOffX); | |||
140 | mpFrameData->mpBuffer->SetOutOffYPixel(mnOutOffY); | |||
141 | ||||
142 | mpFrameData->mpBuffer->Pop(); | |||
143 | mpFrameData->mpBuffer->SetSettings(maSettings); | |||
144 | if (mbBackground) | |||
145 | mpFrameData->mpBuffer->SetBackground(maBackground); | |||
146 | else | |||
147 | mpFrameData->mpBuffer->SetBackground(); | |||
148 | } | |||
149 | ||||
150 | void PaintBufferGuard::SetPaintRect(const tools::Rectangle& rRectangle) | |||
151 | { | |||
152 | m_aPaintRect = rRectangle; | |||
153 | } | |||
154 | ||||
155 | vcl::RenderContext* PaintBufferGuard::GetRenderContext() | |||
156 | { | |||
157 | if (mpFrameData->mpBuffer) | |||
158 | return mpFrameData->mpBuffer; | |||
159 | else | |||
160 | return m_pWindow; | |||
161 | } | |||
162 | } | |||
163 | ||||
164 | class PaintHelper | |||
165 | { | |||
166 | private: | |||
167 | VclPtr<vcl::Window> m_pWindow; | |||
168 | std::unique_ptr<vcl::Region> m_pChildRegion; | |||
169 | tools::Rectangle m_aSelectionRect; | |||
170 | tools::Rectangle m_aPaintRect; | |||
171 | vcl::Region m_aPaintRegion; | |||
172 | ImplPaintFlags m_nPaintFlags; | |||
173 | bool m_bPop : 1; | |||
174 | bool m_bRestoreCursor : 1; | |||
175 | bool m_bStartedBufferedPaint : 1; ///< This PaintHelper started a buffered paint, and should paint it on the screen when being destructed. | |||
176 | public: | |||
177 | PaintHelper(vcl::Window* pWindow, ImplPaintFlags nPaintFlags); | |||
178 | void SetPop() | |||
179 | { | |||
180 | m_bPop = true; | |||
181 | } | |||
182 | void SetPaintRect(const tools::Rectangle& rRect) | |||
183 | { | |||
184 | m_aPaintRect = rRect; | |||
185 | } | |||
186 | void SetSelectionRect(const tools::Rectangle& rRect) | |||
187 | { | |||
188 | m_aSelectionRect = rRect; | |||
189 | } | |||
190 | void SetRestoreCursor(bool bRestoreCursor) | |||
191 | { | |||
192 | m_bRestoreCursor = bRestoreCursor; | |||
193 | } | |||
194 | bool GetRestoreCursor() const | |||
195 | { | |||
196 | return m_bRestoreCursor; | |||
197 | } | |||
198 | ImplPaintFlags GetPaintFlags() const | |||
199 | { | |||
200 | return m_nPaintFlags; | |||
201 | } | |||
202 | vcl::Region& GetPaintRegion() | |||
203 | { | |||
204 | return m_aPaintRegion; | |||
205 | } | |||
206 | void DoPaint(const vcl::Region* pRegion); | |||
207 | ||||
208 | /// Start buffered paint: set it up to have the same settings as m_pWindow. | |||
209 | void StartBufferedPaint(); | |||
210 | ||||
211 | /// Paint the content of the buffer to the current m_pWindow. | |||
212 | void PaintBuffer(); | |||
213 | ||||
214 | ~PaintHelper(); | |||
215 | }; | |||
216 | ||||
217 | PaintHelper::PaintHelper(vcl::Window *pWindow, ImplPaintFlags nPaintFlags) | |||
218 | : m_pWindow(pWindow) | |||
219 | , m_nPaintFlags(nPaintFlags) | |||
220 | , m_bPop(false) | |||
221 | , m_bRestoreCursor(false) | |||
222 | , m_bStartedBufferedPaint(false) | |||
223 | { | |||
224 | } | |||
225 | ||||
226 | void PaintHelper::StartBufferedPaint() | |||
227 | { | |||
228 | ImplFrameData* pFrameData = m_pWindow->mpWindowImpl->mpFrameData; | |||
229 | assert(!pFrameData->mbInBufferedPaint)(static_cast <bool> (!pFrameData->mbInBufferedPaint) ? void (0) : __assert_fail ("!pFrameData->mbInBufferedPaint" , "/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" , 229, __extension__ __PRETTY_FUNCTION__)); | |||
230 | ||||
231 | pFrameData->mbInBufferedPaint = true; | |||
232 | pFrameData->maBufferedRect = tools::Rectangle(); | |||
233 | m_bStartedBufferedPaint = true; | |||
234 | } | |||
235 | ||||
236 | void PaintHelper::PaintBuffer() | |||
237 | { | |||
238 | ImplFrameData* pFrameData = m_pWindow->mpWindowImpl->mpFrameData; | |||
239 | assert(pFrameData->mbInBufferedPaint)(static_cast <bool> (pFrameData->mbInBufferedPaint) ? void (0) : __assert_fail ("pFrameData->mbInBufferedPaint" , "/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" , 239, __extension__ __PRETTY_FUNCTION__)); | |||
240 | assert(m_bStartedBufferedPaint)(static_cast <bool> (m_bStartedBufferedPaint) ? void (0 ) : __assert_fail ("m_bStartedBufferedPaint", "/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" , 240, __extension__ __PRETTY_FUNCTION__)); | |||
241 | ||||
242 | vcl::PaintBufferGuard aGuard(pFrameData, m_pWindow); | |||
243 | aGuard.SetPaintRect(pFrameData->maBufferedRect); | |||
244 | } | |||
245 | ||||
246 | void PaintHelper::DoPaint(const vcl::Region* pRegion) | |||
247 | { | |||
248 | WindowImpl* pWindowImpl = m_pWindow->ImplGetWindowImpl(); | |||
249 | ||||
250 | vcl::Region* pWinChildClipRegion = m_pWindow->ImplGetWinChildClipRegion(); | |||
251 | ImplFrameData* pFrameData = m_pWindow->mpWindowImpl->mpFrameData; | |||
252 | if (pWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll || pFrameData->mbInBufferedPaint) | |||
253 | { | |||
254 | pWindowImpl->maInvalidateRegion = *pWinChildClipRegion; | |||
255 | } | |||
256 | else | |||
257 | { | |||
258 | if (pRegion) | |||
259 | pWindowImpl->maInvalidateRegion.Union( *pRegion ); | |||
260 | ||||
261 | if (pWindowImpl->mpWinData && pWindowImpl->mbTrackVisible) | |||
262 | /* #98602# need to repaint all children within the | |||
263 | * tracking rectangle, so the following invert | |||
264 | * operation takes places without traces of the previous | |||
265 | * one. | |||
266 | */ | |||
267 | pWindowImpl->maInvalidateRegion.Union(*pWindowImpl->mpWinData->mpTrackRect); | |||
268 | ||||
269 | if (pWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAllChildren) | |||
270 | m_pChildRegion.reset( new vcl::Region(pWindowImpl->maInvalidateRegion) ); | |||
271 | pWindowImpl->maInvalidateRegion.Intersect(*pWinChildClipRegion); | |||
272 | } | |||
273 | pWindowImpl->mnPaintFlags = ImplPaintFlags::NONE; | |||
274 | if (pWindowImpl->maInvalidateRegion.IsEmpty()) | |||
275 | return; | |||
276 | ||||
277 | #if HAVE_FEATURE_OPENGL1 | |||
278 | VCL_GL_INFO("PaintHelper::DoPaint on " <<do { if (true && OpenGLHelper::isVCLOpenGLEnabled()) { ::std::ostringstream detail_stream; detail_stream << "PaintHelper::DoPaint on " << typeid( *m_pWindow ).name() << " '" << m_pWindow ->GetText() << "' begin"; OpenGLHelper::debugMsgStream (detail_stream); } } while (false) | |||
279 | typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "' begin")do { if (true && OpenGLHelper::isVCLOpenGLEnabled()) { ::std::ostringstream detail_stream; detail_stream << "PaintHelper::DoPaint on " << typeid( *m_pWindow ).name() << " '" << m_pWindow ->GetText() << "' begin"; OpenGLHelper::debugMsgStream (detail_stream); } } while (false); | |||
280 | #endif | |||
281 | // double-buffering: setup the buffer if it does not exist | |||
282 | if (!pFrameData->mbInBufferedPaint && m_pWindow->SupportsDoubleBuffering()) | |||
283 | StartBufferedPaint(); | |||
284 | ||||
285 | // double-buffering: if this window does not support double-buffering, | |||
286 | // but we are in the middle of double-buffered paint, we might be | |||
287 | // losing information | |||
288 | if (pFrameData->mbInBufferedPaint && !m_pWindow->SupportsDoubleBuffering()) | |||
289 | SAL_WARN("vcl.window", "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "vcl.window")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name()) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "289" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name()), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name(); ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "289" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name()) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "289" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name()), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "non-double buffered window in the double-buffered hierarchy, painting directly: " << typeid(*m_pWindow.get()).name(); ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "289" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
290 | ||||
291 | if (pFrameData->mbInBufferedPaint && m_pWindow->SupportsDoubleBuffering()) | |||
292 | { | |||
293 | // double-buffering | |||
294 | vcl::PaintBufferGuard g(pFrameData, m_pWindow); | |||
295 | m_pWindow->ApplySettings(*pFrameData->mpBuffer); | |||
296 | ||||
297 | m_pWindow->PushPaintHelper(this, *pFrameData->mpBuffer); | |||
298 | m_pWindow->Paint(*pFrameData->mpBuffer, m_aPaintRect); | |||
299 | pFrameData->maBufferedRect.Union(m_aPaintRect); | |||
300 | } | |||
301 | else | |||
302 | { | |||
303 | // direct painting | |||
304 | Wallpaper aBackground = m_pWindow->GetBackground(); | |||
305 | m_pWindow->ApplySettings(*m_pWindow); | |||
306 | // Restore bitmap background if it was lost. | |||
307 | if (aBackground.IsBitmap() && !m_pWindow->GetBackground().IsBitmap()) | |||
308 | { | |||
309 | m_pWindow->SetBackground(aBackground); | |||
310 | } | |||
311 | m_pWindow->PushPaintHelper(this, *m_pWindow); | |||
312 | m_pWindow->Paint(*m_pWindow, m_aPaintRect); | |||
313 | } | |||
314 | #if HAVE_FEATURE_OPENGL1 | |||
315 | VCL_GL_INFO("PaintHelper::DoPaint end on " <<do { if (true && OpenGLHelper::isVCLOpenGLEnabled()) { ::std::ostringstream detail_stream; detail_stream << "PaintHelper::DoPaint end on " << typeid( *m_pWindow ).name() << " '" << m_pWindow ->GetText() << "'"; OpenGLHelper::debugMsgStream(detail_stream ); } } while (false) | |||
316 | typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "'")do { if (true && OpenGLHelper::isVCLOpenGLEnabled()) { ::std::ostringstream detail_stream; detail_stream << "PaintHelper::DoPaint end on " << typeid( *m_pWindow ).name() << " '" << m_pWindow ->GetText() << "'"; OpenGLHelper::debugMsgStream(detail_stream ); } } while (false); | |||
317 | #endif | |||
318 | } | |||
319 | ||||
320 | namespace vcl | |||
321 | { | |||
322 | ||||
323 | void RenderTools::DrawSelectionBackground(vcl::RenderContext& rRenderContext, vcl::Window const & rWindow, | |||
324 | const tools::Rectangle& rRect, sal_uInt16 nHighlight, | |||
325 | bool bChecked, bool bDrawBorder, bool bDrawExtBorderOnly, | |||
326 | Color* pSelectionTextColor, long nCornerRadius, Color const * pPaintColor) | |||
327 | { | |||
328 | if (rRect.IsEmpty()) | |||
329 | return; | |||
330 | ||||
331 | bool bRoundEdges = nCornerRadius > 0; | |||
332 | ||||
333 | const StyleSettings& rStyles = rRenderContext.GetSettings().GetStyleSettings(); | |||
334 | ||||
335 | // colors used for item highlighting | |||
336 | Color aSelectionBorderColor(pPaintColor ? *pPaintColor : rStyles.GetHighlightColor()); | |||
337 | Color aSelectionFillColor(aSelectionBorderColor); | |||
338 | ||||
339 | bool bDark = rStyles.GetFaceColor().IsDark(); | |||
340 | bool bBright = ( rStyles.GetFaceColor() == COL_WHITE ); | |||
341 | ||||
342 | int c1 = aSelectionBorderColor.GetLuminance(); | |||
343 | int c2 = rWindow.GetBackgroundColor().GetLuminance(); | |||
344 | ||||
345 | if (!bDark && !bBright && std::abs(c2 - c1) < (pPaintColor ? 40 : 75)) | |||
346 | { | |||
347 | // contrast too low | |||
348 | sal_uInt16 h, s, b; | |||
349 | aSelectionFillColor.RGBtoHSB( h, s, b ); | |||
350 | if( b > 50 ) b -= 40; | |||
351 | else b += 40; | |||
352 | aSelectionFillColor = Color::HSBtoRGB( h, s, b ); | |||
353 | aSelectionBorderColor = aSelectionFillColor; | |||
354 | } | |||
355 | ||||
356 | if (bRoundEdges) | |||
357 | { | |||
358 | if (aSelectionBorderColor.IsDark()) | |||
359 | aSelectionBorderColor.IncreaseLuminance(128); | |||
360 | else | |||
361 | aSelectionBorderColor.DecreaseLuminance(128); | |||
362 | } | |||
363 | ||||
364 | tools::Rectangle aRect(rRect); | |||
365 | if (bDrawExtBorderOnly) | |||
366 | { | |||
367 | aRect.AdjustLeft( -1 ); | |||
368 | aRect.AdjustTop( -1 ); | |||
369 | aRect.AdjustRight(1 ); | |||
370 | aRect.AdjustBottom(1 ); | |||
371 | } | |||
372 | rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR); | |||
373 | ||||
374 | if (bDrawBorder) | |||
375 | rRenderContext.SetLineColor(bDark ? COL_WHITE : (bBright ? COL_BLACK : aSelectionBorderColor)); | |||
376 | else | |||
377 | rRenderContext.SetLineColor(); | |||
378 | ||||
379 | sal_uInt16 nPercent = 0; | |||
380 | if (!nHighlight) | |||
381 | { | |||
382 | if (bDark) | |||
383 | aSelectionFillColor = COL_BLACK; | |||
384 | else | |||
385 | nPercent = 80; // just checked (light) | |||
386 | } | |||
387 | else | |||
388 | { | |||
389 | if (bChecked && nHighlight == 2) | |||
390 | { | |||
391 | if (bDark) | |||
392 | aSelectionFillColor = COL_LIGHTGRAY; | |||
393 | else if (bBright) | |||
394 | { | |||
395 | aSelectionFillColor = COL_BLACK; | |||
396 | rRenderContext.SetLineColor(COL_BLACK); | |||
397 | nPercent = 0; | |||
398 | } | |||
399 | else | |||
400 | nPercent = bRoundEdges ? 40 : 20; // selected, pressed or checked ( very dark ) | |||
401 | } | |||
402 | else if (bChecked || nHighlight == 1) | |||
403 | { | |||
404 | if (bDark) | |||
405 | aSelectionFillColor = COL_GRAY; | |||
406 | else if (bBright) | |||
407 | { | |||
408 | aSelectionFillColor = COL_BLACK; | |||
409 | rRenderContext.SetLineColor(COL_BLACK); | |||
410 | nPercent = 0; | |||
411 | } | |||
412 | else | |||
413 | nPercent = bRoundEdges ? 60 : 35; // selected, pressed or checked ( very dark ) | |||
414 | } | |||
415 | else | |||
416 | { | |||
417 | if (bDark) | |||
418 | aSelectionFillColor = COL_LIGHTGRAY; | |||
419 | else if (bBright) | |||
420 | { | |||
421 | aSelectionFillColor = COL_BLACK; | |||
422 | rRenderContext.SetLineColor(COL_BLACK); | |||
423 | if (nHighlight == 3) | |||
424 | nPercent = 80; | |||
425 | else | |||
426 | nPercent = 0; | |||
427 | } | |||
428 | else | |||
429 | nPercent = 70; // selected ( dark ) | |||
430 | } | |||
431 | } | |||
432 | ||||
433 | if (bDark && bDrawExtBorderOnly) | |||
434 | { | |||
435 | rRenderContext.SetFillColor(); | |||
436 | if (pSelectionTextColor) | |||
437 | *pSelectionTextColor = rStyles.GetHighlightTextColor(); | |||
438 | } | |||
439 | else | |||
440 | { | |||
441 | rRenderContext.SetFillColor(aSelectionFillColor); | |||
442 | if (pSelectionTextColor) | |||
443 | { | |||
444 | Color aTextColor = rWindow.IsControlBackground() ? rWindow.GetControlForeground() : rStyles.GetButtonTextColor(); | |||
445 | Color aHLTextColor = rStyles.GetHighlightTextColor(); | |||
446 | int nTextDiff = std::abs(aSelectionFillColor.GetLuminance() - aTextColor.GetLuminance()); | |||
447 | int nHLDiff = std::abs(aSelectionFillColor.GetLuminance() - aHLTextColor.GetLuminance()); | |||
448 | *pSelectionTextColor = (nHLDiff >= nTextDiff) ? aHLTextColor : aTextColor; | |||
449 | } | |||
450 | } | |||
451 | ||||
452 | if (bDark) | |||
453 | { | |||
454 | rRenderContext.DrawRect(aRect); | |||
455 | } | |||
456 | else | |||
457 | { | |||
458 | if (bRoundEdges) | |||
459 | { | |||
460 | tools::Polygon aPoly(aRect, nCornerRadius, nCornerRadius); | |||
461 | tools::PolyPolygon aPolyPoly(aPoly); | |||
462 | rRenderContext.DrawTransparent(aPolyPoly, nPercent); | |||
463 | } | |||
464 | else | |||
465 | { | |||
466 | tools::Polygon aPoly(aRect); | |||
467 | tools::PolyPolygon aPolyPoly(aPoly); | |||
468 | rRenderContext.DrawTransparent(aPolyPoly, nPercent); | |||
469 | } | |||
470 | } | |||
471 | ||||
472 | rRenderContext.Pop(); // LINECOLOR | FILLCOLOR | |||
473 | } | |||
474 | ||||
475 | void Window::PushPaintHelper(PaintHelper *pHelper, vcl::RenderContext& rRenderContext) | |||
476 | { | |||
477 | pHelper->SetPop(); | |||
478 | ||||
479 | if ( mpWindowImpl->mpCursor ) | |||
480 | pHelper->SetRestoreCursor(mpWindowImpl->mpCursor->ImplSuspend()); | |||
481 | ||||
482 | mbInitClipRegion = true; | |||
483 | mpWindowImpl->mbInPaint = true; | |||
484 | ||||
485 | // restore Paint-Region | |||
486 | vcl::Region &rPaintRegion = pHelper->GetPaintRegion(); | |||
487 | rPaintRegion = mpWindowImpl->maInvalidateRegion; | |||
488 | tools::Rectangle aPaintRect = rPaintRegion.GetBoundRect(); | |||
489 | ||||
490 | // RTL: re-mirror paint rect and region at this window | |||
491 | if (ImplIsAntiparallel()) | |||
492 | { | |||
493 | rRenderContext.ReMirror(aPaintRect); | |||
494 | rRenderContext.ReMirror(rPaintRegion); | |||
495 | } | |||
496 | aPaintRect = ImplDevicePixelToLogic(aPaintRect); | |||
497 | mpWindowImpl->mpPaintRegion = &rPaintRegion; | |||
498 | mpWindowImpl->maInvalidateRegion.SetEmpty(); | |||
499 | ||||
500 | if ((pHelper->GetPaintFlags() & ImplPaintFlags::Erase) && rRenderContext.IsBackground()) | |||
501 | { | |||
502 | if (rRenderContext.IsClipRegion()) | |||
503 | { | |||
504 | vcl::Region aOldRegion = rRenderContext.GetClipRegion(); | |||
505 | rRenderContext.SetClipRegion(); | |||
506 | Erase(rRenderContext); | |||
507 | rRenderContext.SetClipRegion(aOldRegion); | |||
508 | } | |||
509 | else | |||
510 | Erase(rRenderContext); | |||
511 | } | |||
512 | ||||
513 | // #98943# trigger drawing of toolbox selection after all children are painted | |||
514 | if (mpWindowImpl->mbDrawSelectionBackground) | |||
515 | pHelper->SetSelectionRect(aPaintRect); | |||
516 | pHelper->SetPaintRect(aPaintRect); | |||
517 | } | |||
518 | ||||
519 | void Window::PopPaintHelper(PaintHelper const *pHelper) | |||
520 | { | |||
521 | if (mpWindowImpl->mpWinData) | |||
522 | { | |||
523 | if (mpWindowImpl->mbFocusVisible) | |||
524 | ImplInvertFocus(*mpWindowImpl->mpWinData->mpFocusRect); | |||
525 | } | |||
526 | mpWindowImpl->mbInPaint = false; | |||
527 | mbInitClipRegion = true; | |||
528 | mpWindowImpl->mpPaintRegion = nullptr; | |||
529 | if (mpWindowImpl->mpCursor) | |||
530 | mpWindowImpl->mpCursor->ImplResume(pHelper->GetRestoreCursor()); | |||
531 | } | |||
532 | ||||
533 | } /* namespace vcl */ | |||
534 | ||||
535 | PaintHelper::~PaintHelper() | |||
536 | { | |||
537 | WindowImpl* pWindowImpl = m_pWindow->ImplGetWindowImpl(); | |||
538 | if (m_bPop) | |||
539 | { | |||
540 | m_pWindow->PopPaintHelper(this); | |||
541 | } | |||
542 | ||||
543 | ImplFrameData* pFrameData = m_pWindow->mpWindowImpl->mpFrameData; | |||
544 | if ( m_nPaintFlags & (ImplPaintFlags::PaintAllChildren | ImplPaintFlags::PaintChildren) ) | |||
545 | { | |||
546 | // Paint from the bottom child window and frontward. | |||
547 | vcl::Window* pTempWindow = pWindowImpl->mpLastChild; | |||
548 | while (pTempWindow) | |||
549 | { | |||
550 | if (pTempWindow->mpWindowImpl->mbVisible) | |||
551 | pTempWindow->ImplCallPaint(m_pChildRegion.get(), m_nPaintFlags); | |||
552 | pTempWindow = pTempWindow->mpWindowImpl->mpPrev; | |||
553 | } | |||
554 | } | |||
555 | ||||
556 | if ( pWindowImpl->mpWinData && pWindowImpl->mbTrackVisible && (pWindowImpl->mpWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) | |||
557 | /* #98602# need to invert the tracking rect AFTER | |||
558 | * the children have painted | |||
559 | */ | |||
560 | m_pWindow->InvertTracking( *pWindowImpl->mpWinData->mpTrackRect, pWindowImpl->mpWinData->mnTrackFlags ); | |||
561 | ||||
562 | // double-buffering: paint in case we created the buffer, the children are | |||
563 | // already painted inside | |||
564 | if (m_bStartedBufferedPaint && pFrameData->mbInBufferedPaint) | |||
565 | { | |||
566 | PaintBuffer(); | |||
567 | pFrameData->mbInBufferedPaint = false; | |||
568 | pFrameData->maBufferedRect = tools::Rectangle(); | |||
569 | } | |||
570 | ||||
571 | // #98943# draw toolbox selection | |||
572 | if( !m_aSelectionRect.IsEmpty() ) | |||
573 | m_pWindow->DrawSelectionBackground( m_aSelectionRect, 3, false, true ); | |||
574 | } | |||
575 | ||||
576 | namespace vcl { | |||
577 | ||||
578 | void Window::ImplCallPaint(const vcl::Region* pRegion, ImplPaintFlags nPaintFlags) | |||
579 | { | |||
580 | // call PrePaint. PrePaint may add to the invalidate region as well as | |||
581 | // other parameters used below. | |||
582 | PrePaint(*this); | |||
583 | ||||
584 | mpWindowImpl->mbPaintFrame = false; | |||
585 | ||||
586 | if (nPaintFlags & ImplPaintFlags::PaintAllChildren) | |||
587 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::Paint | ImplPaintFlags::PaintAllChildren | (nPaintFlags & ImplPaintFlags::PaintAll); | |||
588 | if (nPaintFlags & ImplPaintFlags::PaintChildren) | |||
589 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::PaintChildren; | |||
590 | if (nPaintFlags & ImplPaintFlags::Erase) | |||
591 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::Erase; | |||
592 | if (nPaintFlags & ImplPaintFlags::CheckRtl) | |||
593 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::CheckRtl; | |||
594 | if (!mpWindowImpl->mpFirstChild) | |||
595 | mpWindowImpl->mnPaintFlags &= ~ImplPaintFlags::PaintAllChildren; | |||
596 | ||||
597 | if (mpWindowImpl->mbPaintDisabled) | |||
598 | { | |||
599 | if (mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll) | |||
600 | Invalidate(InvalidateFlags::NoChildren | InvalidateFlags::NoErase | InvalidateFlags::NoTransparent | InvalidateFlags::NoClipChildren); | |||
601 | else if ( pRegion ) | |||
602 | Invalidate(*pRegion, InvalidateFlags::NoChildren | InvalidateFlags::NoErase | InvalidateFlags::NoTransparent | InvalidateFlags::NoClipChildren); | |||
603 | ||||
604 | // call PostPaint before returning | |||
605 | PostPaint(*this); | |||
606 | ||||
607 | return; | |||
608 | } | |||
609 | ||||
610 | nPaintFlags = mpWindowImpl->mnPaintFlags & ~ImplPaintFlags::Paint; | |||
611 | ||||
612 | PaintHelper aHelper(this, nPaintFlags); | |||
613 | ||||
614 | if (mpWindowImpl->mnPaintFlags & ImplPaintFlags::Paint) | |||
615 | aHelper.DoPaint(pRegion); | |||
616 | else | |||
617 | mpWindowImpl->mnPaintFlags = ImplPaintFlags::NONE; | |||
618 | ||||
619 | // call PostPaint | |||
620 | PostPaint(*this); | |||
621 | } | |||
622 | ||||
623 | void Window::ImplCallOverlapPaint() | |||
624 | { | |||
625 | // emit overlapping windows first | |||
626 | vcl::Window* pTempWindow = mpWindowImpl->mpFirstOverlap; | |||
627 | while ( pTempWindow ) | |||
628 | { | |||
629 | if ( pTempWindow->mpWindowImpl->mbReallyVisible ) | |||
630 | pTempWindow->ImplCallOverlapPaint(); | |||
631 | pTempWindow = pTempWindow->mpWindowImpl->mpNext; | |||
632 | } | |||
633 | ||||
634 | // only then ourself | |||
635 | if ( mpWindowImpl->mnPaintFlags & (ImplPaintFlags::Paint | ImplPaintFlags::PaintChildren) ) | |||
636 | { | |||
637 | // RTL: notify ImplCallPaint to check for re-mirroring | |||
638 | // because we were called from the Sal layer | |||
639 | ImplCallPaint(nullptr, mpWindowImpl->mnPaintFlags /*| ImplPaintFlags::CheckRtl */); | |||
640 | } | |||
641 | } | |||
642 | ||||
643 | IMPL_LINK_NOARG(Window, ImplHandlePaintHdl, Timer *, void)void Window::LinkStubImplHandlePaintHdl(void * instance, Timer * data) { return static_cast<Window *>(instance)->ImplHandlePaintHdl (data); } void Window::ImplHandlePaintHdl(__attribute__ ((unused )) Timer *) | |||
644 | { | |||
645 | comphelper::ProfileZone aZone("VCL idle re-paint"); | |||
646 | ||||
647 | // save paint events until layout is done | |||
648 | if (IsSystemWindow() && static_cast<const SystemWindow*>(this)->hasPendingLayout()) | |||
649 | { | |||
650 | mpWindowImpl->mpFrameData->maPaintIdle.Start(); | |||
651 | return; | |||
652 | } | |||
653 | ||||
654 | // save paint events until resizing or initial sizing done | |||
655 | if (mpWindowImpl->mbFrame && | |||
656 | mpWindowImpl->mpFrameData->maResizeIdle.IsActive()) | |||
657 | { | |||
658 | mpWindowImpl->mpFrameData->maPaintIdle.Start(); | |||
659 | } | |||
660 | else if ( mpWindowImpl->mbReallyVisible ) | |||
661 | { | |||
662 | ImplCallOverlapPaint(); | |||
663 | if (comphelper::LibreOfficeKit::isActive() && | |||
664 | mpWindowImpl->mpFrameData->maPaintIdle.IsActive()) | |||
665 | mpWindowImpl->mpFrameData->maPaintIdle.Stop(); | |||
666 | } | |||
667 | } | |||
668 | ||||
669 | IMPL_LINK_NOARG(Window, ImplHandleResizeTimerHdl, Timer *, void)void Window::LinkStubImplHandleResizeTimerHdl(void * instance , Timer * data) { return static_cast<Window *>(instance )->ImplHandleResizeTimerHdl(data); } void Window::ImplHandleResizeTimerHdl (__attribute__ ((unused)) Timer *) | |||
670 | { | |||
671 | comphelper::ProfileZone aZone("VCL idle resize"); | |||
672 | ||||
673 | if( mpWindowImpl->mbReallyVisible ) | |||
674 | { | |||
675 | ImplCallResize(); | |||
676 | if( mpWindowImpl->mpFrameData->maPaintIdle.IsActive() ) | |||
677 | { | |||
678 | mpWindowImpl->mpFrameData->maPaintIdle.Stop(); | |||
679 | mpWindowImpl->mpFrameData->maPaintIdle.Invoke( nullptr ); | |||
680 | } | |||
681 | } | |||
682 | } | |||
683 | ||||
684 | void Window::ImplInvalidateFrameRegion( const vcl::Region* pRegion, InvalidateFlags nFlags ) | |||
685 | { | |||
686 | // set PAINTCHILDREN for all parent windows till the first OverlapWindow | |||
687 | if ( !ImplIsOverlapWindow() ) | |||
688 | { | |||
689 | vcl::Window* pTempWindow = this; | |||
690 | ImplPaintFlags nTranspPaint = IsPaintTransparent() ? ImplPaintFlags::Paint : ImplPaintFlags::NONE; | |||
691 | do | |||
692 | { | |||
693 | pTempWindow = pTempWindow->ImplGetParent(); | |||
694 | if ( pTempWindow->mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintChildren ) | |||
695 | break; | |||
696 | pTempWindow->mpWindowImpl->mnPaintFlags |= ImplPaintFlags::PaintChildren | nTranspPaint; | |||
697 | if( ! pTempWindow->IsPaintTransparent() ) | |||
698 | nTranspPaint = ImplPaintFlags::NONE; | |||
699 | } | |||
700 | while ( !pTempWindow->ImplIsOverlapWindow() ); | |||
701 | } | |||
702 | ||||
703 | // set Paint-Flags | |||
704 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::Paint; | |||
705 | if ( nFlags & InvalidateFlags::Children ) | |||
706 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::PaintAllChildren; | |||
707 | if ( !(nFlags & InvalidateFlags::NoErase) ) | |||
708 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::Erase; | |||
709 | ||||
710 | if ( !pRegion ) | |||
711 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::PaintAll; | |||
712 | else if ( !(mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll) ) | |||
713 | { | |||
714 | // if not everything has to be redrawn, add the region to it | |||
715 | mpWindowImpl->maInvalidateRegion.Union( *pRegion ); | |||
716 | } | |||
717 | ||||
718 | // Handle transparent windows correctly: invalidate must be done on the first opaque parent | |||
719 | if( ((IsPaintTransparent() && !(nFlags & InvalidateFlags::NoTransparent)) || (nFlags & InvalidateFlags::Transparent) ) | |||
720 | && ImplGetParent() ) | |||
721 | { | |||
722 | vcl::Window *pParent = ImplGetParent(); | |||
723 | while( pParent && pParent->IsPaintTransparent() ) | |||
724 | pParent = pParent->ImplGetParent(); | |||
725 | if( pParent ) | |||
726 | { | |||
727 | vcl::Region *pChildRegion; | |||
728 | if ( mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll ) | |||
729 | // invalidate the whole child window region in the parent | |||
730 | pChildRegion = ImplGetWinChildClipRegion(); | |||
731 | else | |||
732 | // invalidate the same region in the parent that has to be repainted in the child | |||
733 | pChildRegion = &mpWindowImpl->maInvalidateRegion; | |||
734 | ||||
735 | nFlags |= InvalidateFlags::Children; // paint should also be done on all children | |||
736 | nFlags &= ~InvalidateFlags::NoErase; // parent should paint and erase to create proper background | |||
737 | pParent->ImplInvalidateFrameRegion( pChildRegion, nFlags ); | |||
738 | } | |||
739 | } | |||
740 | ||||
741 | if ( !mpWindowImpl->mpFrameData->maPaintIdle.IsActive() ) | |||
742 | mpWindowImpl->mpFrameData->maPaintIdle.Start(); | |||
743 | } | |||
744 | ||||
745 | void Window::ImplInvalidateOverlapFrameRegion( const vcl::Region& rRegion ) | |||
746 | { | |||
747 | vcl::Region aRegion = rRegion; | |||
748 | ||||
749 | ImplClipBoundaries( aRegion, true, true ); | |||
750 | if ( !aRegion.IsEmpty() ) | |||
751 | ImplInvalidateFrameRegion( &aRegion, InvalidateFlags::Children ); | |||
752 | ||||
753 | // now we invalidate the overlapping windows | |||
754 | vcl::Window* pTempWindow = mpWindowImpl->mpFirstOverlap; | |||
755 | while ( pTempWindow ) | |||
756 | { | |||
757 | if ( pTempWindow->IsVisible() ) | |||
758 | pTempWindow->ImplInvalidateOverlapFrameRegion( rRegion ); | |||
759 | ||||
760 | pTempWindow = pTempWindow->mpWindowImpl->mpNext; | |||
761 | } | |||
762 | } | |||
763 | ||||
764 | void Window::ImplInvalidateParentFrameRegion( vcl::Region& rRegion ) | |||
765 | { | |||
766 | if ( mpWindowImpl->mbOverlapWin ) | |||
767 | mpWindowImpl->mpFrameWindow->ImplInvalidateOverlapFrameRegion( rRegion ); | |||
768 | else | |||
769 | { | |||
770 | if( ImplGetParent() ) | |||
771 | ImplGetParent()->ImplInvalidateFrameRegion( &rRegion, InvalidateFlags::Children ); | |||
772 | } | |||
773 | } | |||
774 | ||||
775 | void Window::ImplInvalidate( const vcl::Region* pRegion, InvalidateFlags nFlags ) | |||
776 | { | |||
777 | // check what has to be redrawn | |||
778 | bool bInvalidateAll = !pRegion; | |||
779 | ||||
780 | // take Transparent-Invalidate into account | |||
781 | vcl::Window* pOpaqueWindow = this; | |||
782 | if ( (mpWindowImpl->mbPaintTransparent && !(nFlags & InvalidateFlags::NoTransparent)) || (nFlags & InvalidateFlags::Transparent) ) | |||
783 | { | |||
784 | vcl::Window* pTempWindow = pOpaqueWindow->ImplGetParent(); | |||
785 | while ( pTempWindow ) | |||
786 | { | |||
787 | if ( !pTempWindow->IsPaintTransparent() ) | |||
788 | { | |||
789 | pOpaqueWindow = pTempWindow; | |||
790 | nFlags |= InvalidateFlags::Children; | |||
791 | bInvalidateAll = false; | |||
792 | break; | |||
793 | } | |||
794 | ||||
795 | if ( pTempWindow->ImplIsOverlapWindow() ) | |||
796 | break; | |||
797 | ||||
798 | pTempWindow = pTempWindow->ImplGetParent(); | |||
799 | } | |||
800 | } | |||
801 | ||||
802 | // assemble region | |||
803 | InvalidateFlags nOrgFlags = nFlags; | |||
804 | if ( !(nFlags & (InvalidateFlags::Children | InvalidateFlags::NoChildren)) ) | |||
805 | { | |||
806 | if ( GetStyle() & WB_CLIPCHILDREN ) | |||
807 | nFlags |= InvalidateFlags::NoChildren; | |||
808 | else | |||
809 | nFlags |= InvalidateFlags::Children; | |||
810 | } | |||
811 | if ( (nFlags & InvalidateFlags::NoChildren) && mpWindowImpl->mpFirstChild ) | |||
812 | bInvalidateAll = false; | |||
813 | if ( bInvalidateAll ) | |||
814 | ImplInvalidateFrameRegion( nullptr, nFlags ); | |||
815 | else | |||
816 | { | |||
817 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
818 | vcl::Region aRegion( aRect ); | |||
819 | if ( pRegion ) | |||
820 | { | |||
821 | // RTL: remirror region before intersecting it | |||
822 | if ( ImplIsAntiparallel() ) | |||
823 | { | |||
824 | const OutputDevice *pOutDev = GetOutDev(); | |||
825 | ||||
826 | vcl::Region aRgn( *pRegion ); | |||
827 | pOutDev->ReMirror( aRgn ); | |||
828 | aRegion.Intersect( aRgn ); | |||
829 | } | |||
830 | else | |||
831 | aRegion.Intersect( *pRegion ); | |||
832 | } | |||
833 | ImplClipBoundaries( aRegion, true, true ); | |||
834 | if ( nFlags & InvalidateFlags::NoChildren ) | |||
835 | { | |||
836 | nFlags &= ~InvalidateFlags::Children; | |||
837 | if ( !(nFlags & InvalidateFlags::NoClipChildren) ) | |||
838 | { | |||
839 | if ( nOrgFlags & InvalidateFlags::NoChildren ) | |||
840 | ImplClipAllChildren( aRegion ); | |||
841 | else | |||
842 | { | |||
843 | if ( ImplClipChildren( aRegion ) ) | |||
844 | nFlags |= InvalidateFlags::Children; | |||
845 | } | |||
846 | } | |||
847 | } | |||
848 | if ( !aRegion.IsEmpty() ) | |||
849 | ImplInvalidateFrameRegion( &aRegion, nFlags ); // transparency is handled here, pOpaqueWindow not required | |||
850 | } | |||
851 | ||||
852 | if ( nFlags & InvalidateFlags::Update ) | |||
853 | pOpaqueWindow->PaintImmediately(); // start painting at the opaque parent | |||
854 | } | |||
855 | ||||
856 | void Window::ImplMoveInvalidateRegion( const tools::Rectangle& rRect, | |||
857 | long nHorzScroll, long nVertScroll, | |||
858 | bool bChildren ) | |||
859 | { | |||
860 | if ( (mpWindowImpl->mnPaintFlags & (ImplPaintFlags::Paint | ImplPaintFlags::PaintAll)) == ImplPaintFlags::Paint ) | |||
861 | { | |||
862 | vcl::Region aTempRegion = mpWindowImpl->maInvalidateRegion; | |||
863 | aTempRegion.Intersect( rRect ); | |||
864 | aTempRegion.Move( nHorzScroll, nVertScroll ); | |||
865 | mpWindowImpl->maInvalidateRegion.Union( aTempRegion ); | |||
866 | } | |||
867 | ||||
868 | if ( bChildren && (mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintChildren) ) | |||
869 | { | |||
870 | vcl::Window* pWindow = mpWindowImpl->mpFirstChild; | |||
871 | while ( pWindow ) | |||
872 | { | |||
873 | pWindow->ImplMoveInvalidateRegion( rRect, nHorzScroll, nVertScroll, true ); | |||
874 | pWindow = pWindow->mpWindowImpl->mpNext; | |||
875 | } | |||
876 | } | |||
877 | } | |||
878 | ||||
879 | void Window::ImplMoveAllInvalidateRegions( const tools::Rectangle& rRect, | |||
880 | long nHorzScroll, long nVertScroll, | |||
881 | bool bChildren ) | |||
882 | { | |||
883 | // also shift Paint-Region when paints need processing | |||
884 | ImplMoveInvalidateRegion( rRect, nHorzScroll, nVertScroll, bChildren ); | |||
885 | // Paint-Region should be shifted, as drawn by the parents | |||
886 | if ( ImplIsOverlapWindow() ) | |||
887 | return; | |||
888 | ||||
889 | vcl::Region aPaintAllRegion; | |||
890 | vcl::Window* pPaintAllWindow = this; | |||
891 | do | |||
892 | { | |||
893 | pPaintAllWindow = pPaintAllWindow->ImplGetParent(); | |||
894 | if ( pPaintAllWindow->mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAllChildren ) | |||
895 | { | |||
896 | if ( pPaintAllWindow->mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll ) | |||
897 | { | |||
898 | aPaintAllRegion.SetEmpty(); | |||
899 | break; | |||
900 | } | |||
901 | else | |||
902 | aPaintAllRegion.Union( pPaintAllWindow->mpWindowImpl->maInvalidateRegion ); | |||
903 | } | |||
904 | } | |||
905 | while ( !pPaintAllWindow->ImplIsOverlapWindow() ); | |||
906 | if ( !aPaintAllRegion.IsEmpty() ) | |||
907 | { | |||
908 | aPaintAllRegion.Move( nHorzScroll, nVertScroll ); | |||
909 | InvalidateFlags nPaintFlags = InvalidateFlags::NONE; | |||
910 | if ( bChildren ) | |||
911 | nPaintFlags |= InvalidateFlags::Children; | |||
912 | ImplInvalidateFrameRegion( &aPaintAllRegion, nPaintFlags ); | |||
913 | } | |||
914 | } | |||
915 | ||||
916 | void Window::ImplValidateFrameRegion( const vcl::Region* pRegion, ValidateFlags nFlags ) | |||
917 | { | |||
918 | if ( !pRegion ) | |||
919 | mpWindowImpl->maInvalidateRegion.SetEmpty(); | |||
920 | else | |||
921 | { | |||
922 | // when all child windows have to be drawn we need to invalidate them before doing so | |||
923 | if ( (mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAllChildren) && mpWindowImpl->mpFirstChild ) | |||
924 | { | |||
925 | vcl::Region aChildRegion = mpWindowImpl->maInvalidateRegion; | |||
926 | if ( mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll ) | |||
927 | { | |||
928 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
929 | aChildRegion = aRect; | |||
930 | } | |||
931 | vcl::Window* pChild = mpWindowImpl->mpFirstChild; | |||
932 | while ( pChild ) | |||
933 | { | |||
934 | pChild->Invalidate( aChildRegion, InvalidateFlags::Children | InvalidateFlags::NoTransparent ); | |||
935 | pChild = pChild->mpWindowImpl->mpNext; | |||
936 | } | |||
937 | } | |||
938 | if ( mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAll ) | |||
939 | { | |||
940 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
941 | mpWindowImpl->maInvalidateRegion = aRect; | |||
942 | } | |||
943 | mpWindowImpl->maInvalidateRegion.Exclude( *pRegion ); | |||
944 | } | |||
945 | mpWindowImpl->mnPaintFlags &= ~ImplPaintFlags::PaintAll; | |||
946 | ||||
947 | if ( nFlags & ValidateFlags::Children ) | |||
948 | { | |||
949 | vcl::Window* pChild = mpWindowImpl->mpFirstChild; | |||
950 | while ( pChild ) | |||
951 | { | |||
952 | pChild->ImplValidateFrameRegion( pRegion, nFlags ); | |||
953 | pChild = pChild->mpWindowImpl->mpNext; | |||
954 | } | |||
955 | } | |||
956 | } | |||
957 | ||||
958 | void Window::ImplValidate() | |||
959 | { | |||
960 | // assemble region | |||
961 | bool bValidateAll = true; | |||
962 | ValidateFlags nFlags = ValidateFlags::NONE; | |||
963 | if ( GetStyle() & WB_CLIPCHILDREN ) | |||
964 | nFlags |= ValidateFlags::NoChildren; | |||
965 | else | |||
966 | nFlags |= ValidateFlags::Children; | |||
967 | if ( (nFlags & ValidateFlags::NoChildren) && mpWindowImpl->mpFirstChild ) | |||
968 | bValidateAll = false; | |||
969 | if ( bValidateAll ) | |||
970 | ImplValidateFrameRegion( nullptr, nFlags ); | |||
971 | else | |||
972 | { | |||
973 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
974 | vcl::Region aRegion( aRect ); | |||
975 | ImplClipBoundaries( aRegion, true, true ); | |||
976 | if ( nFlags & ValidateFlags::NoChildren ) | |||
977 | { | |||
978 | nFlags &= ~ValidateFlags::Children; | |||
979 | if ( ImplClipChildren( aRegion ) ) | |||
980 | nFlags |= ValidateFlags::Children; | |||
981 | } | |||
982 | if ( !aRegion.IsEmpty() ) | |||
983 | ImplValidateFrameRegion( &aRegion, nFlags ); | |||
984 | } | |||
985 | } | |||
986 | ||||
987 | void Window::ImplUpdateAll() | |||
988 | { | |||
989 | if ( !mpWindowImpl->mbReallyVisible ) | |||
990 | return; | |||
991 | ||||
992 | bool bFlush = false; | |||
993 | if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame ) | |||
994 | { | |||
995 | Point aPoint( 0, 0 ); | |||
996 | vcl::Region aRegion( tools::Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) ); | |||
997 | ImplInvalidateOverlapFrameRegion( aRegion ); | |||
998 | if ( mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) ) | |||
999 | bFlush = true; | |||
1000 | } | |||
1001 | ||||
1002 | // an update changes the OverlapWindow, such that for later paints | |||
1003 | // not too much has to be drawn, if ALLCHILDREN etc. is set | |||
1004 | vcl::Window* pWindow = ImplGetFirstOverlapWindow(); | |||
1005 | pWindow->ImplCallOverlapPaint(); | |||
1006 | ||||
1007 | if ( bFlush ) | |||
1008 | Flush(); | |||
1009 | } | |||
1010 | ||||
1011 | void Window::PrePaint(vcl::RenderContext& /*rRenderContext*/) | |||
1012 | { | |||
1013 | } | |||
1014 | ||||
1015 | void Window::PostPaint(vcl::RenderContext& /*rRenderContext*/) | |||
1016 | { | |||
1017 | } | |||
1018 | ||||
1019 | void Window::Paint(vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& rRect) | |||
1020 | { | |||
1021 | CallEventListeners(VclEventId::WindowPaint, const_cast<tools::Rectangle *>(&rRect)); | |||
1022 | } | |||
1023 | ||||
1024 | void Window::SetPaintTransparent( bool bTransparent ) | |||
1025 | { | |||
1026 | // transparency is not useful for frames as the background would have to be provided by a different frame | |||
1027 | if( bTransparent && mpWindowImpl->mbFrame ) | |||
1028 | return; | |||
1029 | ||||
1030 | if ( mpWindowImpl->mpBorderWindow ) | |||
1031 | mpWindowImpl->mpBorderWindow->SetPaintTransparent( bTransparent ); | |||
1032 | ||||
1033 | mpWindowImpl->mbPaintTransparent = bTransparent; | |||
1034 | } | |||
1035 | ||||
1036 | void Window::SetWindowRegionPixel() | |||
1037 | { | |||
1038 | ||||
1039 | if ( mpWindowImpl->mpBorderWindow ) | |||
1040 | mpWindowImpl->mpBorderWindow->SetWindowRegionPixel(); | |||
1041 | else if( mpWindowImpl->mbFrame ) | |||
1042 | { | |||
1043 | mpWindowImpl->maWinRegion = vcl::Region(true); | |||
1044 | mpWindowImpl->mbWinRegion = false; | |||
1045 | mpWindowImpl->mpFrame->ResetClipRegion(); | |||
1046 | } | |||
1047 | else | |||
1048 | { | |||
1049 | if ( mpWindowImpl->mbWinRegion ) | |||
1050 | { | |||
1051 | mpWindowImpl->maWinRegion = vcl::Region(true); | |||
1052 | mpWindowImpl->mbWinRegion = false; | |||
1053 | ImplSetClipFlag(); | |||
1054 | ||||
1055 | if ( IsReallyVisible() ) | |||
1056 | { | |||
1057 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
1058 | vcl::Region aRegion( aRect ); | |||
1059 | ImplInvalidateParentFrameRegion( aRegion ); | |||
1060 | } | |||
1061 | } | |||
1062 | } | |||
1063 | } | |||
1064 | ||||
1065 | void Window::SetWindowRegionPixel( const vcl::Region& rRegion ) | |||
1066 | { | |||
1067 | ||||
1068 | if ( mpWindowImpl->mpBorderWindow ) | |||
1069 | mpWindowImpl->mpBorderWindow->SetWindowRegionPixel( rRegion ); | |||
1070 | else if( mpWindowImpl->mbFrame ) | |||
1071 | { | |||
1072 | if( !rRegion.IsNull() ) | |||
1073 | { | |||
1074 | mpWindowImpl->maWinRegion = rRegion; | |||
1075 | mpWindowImpl->mbWinRegion = ! rRegion.IsEmpty(); | |||
1076 | ||||
1077 | if( mpWindowImpl->mbWinRegion ) | |||
1078 | { | |||
1079 | // set/update ClipRegion | |||
1080 | RectangleVector aRectangles; | |||
1081 | mpWindowImpl->maWinRegion.GetRegionRectangles(aRectangles); | |||
1082 | mpWindowImpl->mpFrame->BeginSetClipRegion(aRectangles.size()); | |||
1083 | ||||
1084 | for (auto const& rectangle : aRectangles) | |||
1085 | { | |||
1086 | mpWindowImpl->mpFrame->UnionClipRegion( | |||
1087 | rectangle.Left(), | |||
1088 | rectangle.Top(), | |||
1089 | rectangle.GetWidth(), // orig nWidth was ((R - L) + 1), same as GetWidth does | |||
1090 | rectangle.GetHeight()); // same for height | |||
1091 | } | |||
1092 | ||||
1093 | mpWindowImpl->mpFrame->EndSetClipRegion(); | |||
1094 | ||||
1095 | //long nX; | |||
1096 | //long nY; | |||
1097 | //long nWidth; | |||
1098 | //long nHeight; | |||
1099 | //sal_uLong nRectCount; | |||
1100 | //ImplRegionInfo aInfo; | |||
1101 | //sal_Bool bRegionRect; | |||
1102 | ||||
1103 | //nRectCount = mpWindowImpl->maWinRegion.GetRectCount(); | |||
1104 | //mpWindowImpl->mpFrame->BeginSetClipRegion( nRectCount ); | |||
1105 | //bRegionRect = mpWindowImpl->maWinRegion.ImplGetFirstRect( aInfo, nX, nY, nWidth, nHeight ); | |||
1106 | //while ( bRegionRect ) | |||
1107 | //{ | |||
1108 | // mpWindowImpl->mpFrame->UnionClipRegion( nX, nY, nWidth, nHeight ); | |||
1109 | // bRegionRect = mpWindowImpl->maWinRegion.ImplGetNextRect( aInfo, nX, nY, nWidth, nHeight ); | |||
1110 | //} | |||
1111 | //mpWindowImpl->mpFrame->EndSetClipRegion(); | |||
1112 | } | |||
1113 | else | |||
1114 | SetWindowRegionPixel(); | |||
1115 | } | |||
1116 | else | |||
1117 | SetWindowRegionPixel(); | |||
1118 | } | |||
1119 | else | |||
1120 | { | |||
1121 | if ( rRegion.IsNull() ) | |||
1122 | { | |||
1123 | if ( mpWindowImpl->mbWinRegion ) | |||
1124 | { | |||
1125 | mpWindowImpl->maWinRegion = vcl::Region(true); | |||
1126 | mpWindowImpl->mbWinRegion = false; | |||
1127 | ImplSetClipFlag(); | |||
1128 | } | |||
1129 | } | |||
1130 | else | |||
1131 | { | |||
1132 | mpWindowImpl->maWinRegion = rRegion; | |||
1133 | mpWindowImpl->mbWinRegion = true; | |||
1134 | ImplSetClipFlag(); | |||
1135 | } | |||
1136 | ||||
1137 | if ( IsReallyVisible() ) | |||
1138 | { | |||
1139 | tools::Rectangle aRect( Point( mnOutOffX, mnOutOffY ), Size( mnOutWidth, mnOutHeight ) ); | |||
1140 | vcl::Region aRegion( aRect ); | |||
1141 | ImplInvalidateParentFrameRegion( aRegion ); | |||
1142 | } | |||
1143 | } | |||
1144 | } | |||
1145 | ||||
1146 | vcl::Region Window::GetPaintRegion() const | |||
1147 | { | |||
1148 | ||||
1149 | if ( mpWindowImpl->mpPaintRegion ) | |||
1150 | { | |||
1151 | vcl::Region aRegion = *mpWindowImpl->mpPaintRegion; | |||
1152 | aRegion.Move( -mnOutOffX, -mnOutOffY ); | |||
1153 | return PixelToLogic( aRegion ); | |||
1154 | } | |||
1155 | else | |||
1156 | { | |||
1157 | vcl::Region aPaintRegion(true); | |||
1158 | return aPaintRegion; | |||
1159 | } | |||
1160 | } | |||
1161 | ||||
1162 | void Window::Invalidate( InvalidateFlags nFlags ) | |||
1163 | { | |||
1164 | if ( !comphelper::LibreOfficeKit::isActive() && (!IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight) ) | |||
1165 | return; | |||
1166 | ||||
1167 | ImplInvalidate( nullptr, nFlags ); | |||
1168 | LogicInvalidate(nullptr); | |||
1169 | } | |||
1170 | ||||
1171 | void Window::Invalidate( const tools::Rectangle& rRect, InvalidateFlags nFlags ) | |||
1172 | { | |||
1173 | if ( !comphelper::LibreOfficeKit::isActive() && (!IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight) ) | |||
1174 | return; | |||
1175 | ||||
1176 | OutputDevice *pOutDev = GetOutDev(); | |||
1177 | tools::Rectangle aRect = pOutDev->ImplLogicToDevicePixel( rRect ); | |||
1178 | if ( !aRect.IsEmpty() ) | |||
1179 | { | |||
1180 | vcl::Region aRegion( aRect ); | |||
1181 | ImplInvalidate( &aRegion, nFlags ); | |||
1182 | tools::Rectangle aLogicRectangle(rRect); | |||
1183 | LogicInvalidate(&aLogicRectangle); | |||
1184 | } | |||
1185 | } | |||
1186 | ||||
1187 | void Window::Invalidate( const vcl::Region& rRegion, InvalidateFlags nFlags ) | |||
1188 | { | |||
1189 | if ( !comphelper::LibreOfficeKit::isActive() && (!IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight) ) | |||
1190 | return; | |||
1191 | ||||
1192 | if ( rRegion.IsNull() ) | |||
1193 | { | |||
1194 | ImplInvalidate( nullptr, nFlags ); | |||
1195 | LogicInvalidate(nullptr); | |||
1196 | } | |||
1197 | else | |||
1198 | { | |||
1199 | vcl::Region aRegion = ImplPixelToDevicePixel( LogicToPixel( rRegion ) ); | |||
1200 | if ( !aRegion.IsEmpty() ) | |||
1201 | { | |||
1202 | ImplInvalidate( &aRegion, nFlags ); | |||
1203 | tools::Rectangle aLogicRectangle = rRegion.GetBoundRect(); | |||
1204 | LogicInvalidate(&aLogicRectangle); | |||
1205 | } | |||
1206 | } | |||
1207 | } | |||
1208 | ||||
1209 | void Window::LogicInvalidate(const tools::Rectangle* pRectangle) | |||
1210 | { | |||
1211 | if(pRectangle) | |||
1212 | { | |||
1213 | tools::Rectangle aRect = GetOutDev()->ImplLogicToDevicePixel( *pRectangle ); | |||
1214 | PixelInvalidate(&aRect); | |||
1215 | } | |||
1216 | else | |||
1217 | PixelInvalidate(nullptr); | |||
1218 | } | |||
1219 | ||||
1220 | void Window::PixelInvalidate(const tools::Rectangle* pRectangle) | |||
1221 | { | |||
1222 | if (comphelper::LibreOfficeKit::isDialogPainting() || !comphelper::LibreOfficeKit::isActive()) | |||
1223 | return; | |||
1224 | ||||
1225 | Size aSize = GetSizePixel(); | |||
1226 | if (aSize.IsEmpty()) | |||
1227 | return; | |||
1228 | ||||
1229 | if (const vcl::ILibreOfficeKitNotifier* pNotifier = GetLOKNotifier()) | |||
1230 | { | |||
1231 | // In case we are routing the window, notify the client | |||
1232 | std::vector<vcl::LOKPayloadItem> aPayload; | |||
1233 | if (pRectangle) | |||
1234 | aPayload.emplace_back("rectangle", pRectangle->toString()); | |||
1235 | else | |||
1236 | { | |||
1237 | const tools::Rectangle aRect(Point(0, 0), aSize); | |||
1238 | aPayload.emplace_back("rectangle", aRect.toString()); | |||
1239 | } | |||
1240 | ||||
1241 | pNotifier->notifyWindow(GetLOKWindowId(), "invalidate", aPayload); | |||
1242 | } | |||
1243 | // Added for dialog items. Pass invalidation to the parent window. | |||
1244 | else if (VclPtr<vcl::Window> pParent = GetParentWithLOKNotifier()) | |||
1245 | { | |||
1246 | const tools::Rectangle aRect(Point(GetOutOffXPixel(), GetOutOffYPixel()), GetSizePixel()); | |||
1247 | pParent->PixelInvalidate(&aRect); | |||
1248 | } | |||
1249 | } | |||
1250 | ||||
1251 | void Window::Validate() | |||
1252 | { | |||
1253 | if ( !comphelper::LibreOfficeKit::isActive() && (!IsDeviceOutputNecessary() || !mnOutWidth || !mnOutHeight) ) | |||
1254 | return; | |||
1255 | ||||
1256 | ImplValidate(); | |||
1257 | } | |||
1258 | ||||
1259 | bool Window::HasPaintEvent() const | |||
1260 | { | |||
1261 | ||||
1262 | if ( !mpWindowImpl->mbReallyVisible ) | |||
1263 | return false; | |||
1264 | ||||
1265 | if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame ) | |||
1266 | return true; | |||
1267 | ||||
1268 | if ( mpWindowImpl->mnPaintFlags & ImplPaintFlags::Paint ) | |||
1269 | return true; | |||
1270 | ||||
1271 | if ( !ImplIsOverlapWindow() ) | |||
1272 | { | |||
1273 | const vcl::Window* pTempWindow = this; | |||
1274 | do | |||
1275 | { | |||
1276 | pTempWindow = pTempWindow->ImplGetParent(); | |||
1277 | if ( pTempWindow->mpWindowImpl->mnPaintFlags & (ImplPaintFlags::PaintChildren | ImplPaintFlags::PaintAllChildren) ) | |||
1278 | return true; | |||
1279 | } | |||
1280 | while ( !pTempWindow->ImplIsOverlapWindow() ); | |||
1281 | } | |||
1282 | ||||
1283 | return false; | |||
1284 | } | |||
1285 | ||||
1286 | void Window::PaintImmediately() | |||
1287 | { | |||
1288 | if ( mpWindowImpl->mpBorderWindow ) | |||
1289 | { | |||
1290 | mpWindowImpl->mpBorderWindow->PaintImmediately(); | |||
1291 | return; | |||
1292 | } | |||
1293 | ||||
1294 | if ( !mpWindowImpl->mbReallyVisible ) | |||
1295 | return; | |||
1296 | ||||
1297 | bool bFlush = false; | |||
1298 | if ( mpWindowImpl->mpFrameWindow->mpWindowImpl->mbPaintFrame ) | |||
1299 | { | |||
1300 | Point aPoint( 0, 0 ); | |||
1301 | vcl::Region aRegion( tools::Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) ); | |||
1302 | ImplInvalidateOverlapFrameRegion( aRegion ); | |||
1303 | if ( mpWindowImpl->mbFrame || (mpWindowImpl->mpBorderWindow && mpWindowImpl->mpBorderWindow->mpWindowImpl->mbFrame) ) | |||
1304 | bFlush = true; | |||
1305 | } | |||
1306 | ||||
1307 | // First we should skip all windows which are Paint-Transparent | |||
1308 | vcl::Window* pUpdateWindow = this; | |||
1309 | vcl::Window* pWindow = pUpdateWindow; | |||
1310 | while ( !pWindow->ImplIsOverlapWindow() ) | |||
1311 | { | |||
1312 | if ( !pWindow->mpWindowImpl->mbPaintTransparent ) | |||
1313 | { | |||
1314 | pUpdateWindow = pWindow; | |||
1315 | break; | |||
1316 | } | |||
1317 | pWindow = pWindow->ImplGetParent(); | |||
1318 | } | |||
1319 | // In order to limit drawing, an update only draws the window which | |||
1320 | // has PAINTALLCHILDREN set | |||
1321 | pWindow = pUpdateWindow; | |||
1322 | do | |||
1323 | { | |||
1324 | if ( pWindow->mpWindowImpl->mnPaintFlags & ImplPaintFlags::PaintAllChildren ) | |||
1325 | pUpdateWindow = pWindow; | |||
1326 | if ( pWindow->ImplIsOverlapWindow() ) | |||
1327 | break; | |||
1328 | pWindow = pWindow->ImplGetParent(); | |||
1329 | } | |||
1330 | while ( pWindow ); | |||
1331 | ||||
1332 | // if there is something to paint, trigger a Paint | |||
1333 | if ( pUpdateWindow->mpWindowImpl->mnPaintFlags & (ImplPaintFlags::Paint | ImplPaintFlags::PaintChildren) ) | |||
1334 | { | |||
1335 | VclPtr<vcl::Window> xWindow(this); | |||
1336 | ||||
1337 | // trigger an update also for system windows on top of us, | |||
1338 | // otherwise holes would remain | |||
1339 | vcl::Window* pUpdateOverlapWindow = ImplGetFirstOverlapWindow()->mpWindowImpl->mpFirstOverlap; | |||
1340 | while ( pUpdateOverlapWindow ) | |||
1341 | { | |||
1342 | pUpdateOverlapWindow->PaintImmediately(); | |||
1343 | pUpdateOverlapWindow = pUpdateOverlapWindow->mpWindowImpl->mpNext; | |||
1344 | } | |||
1345 | ||||
1346 | pUpdateWindow->ImplCallPaint(nullptr, pUpdateWindow->mpWindowImpl->mnPaintFlags); | |||
1347 | ||||
1348 | if (comphelper::LibreOfficeKit::isActive() && pUpdateWindow->GetParentDialog()) | |||
1349 | pUpdateWindow->LogicInvalidate(nullptr); | |||
1350 | ||||
1351 | if (xWindow->IsDisposed()) | |||
1352 | return; | |||
1353 | ||||
1354 | bFlush = true; | |||
1355 | } | |||
1356 | ||||
1357 | if ( bFlush ) | |||
1358 | Flush(); | |||
1359 | } | |||
1360 | ||||
1361 | void Window::ImplPaintToDevice( OutputDevice* i_pTargetOutDev, const Point& i_rPos ) | |||
1362 | { | |||
1363 | // Special drawing when called through LOKit | |||
1364 | // TODO: Move to its own method | |||
1365 | if (comphelper::LibreOfficeKit::isActive()) | |||
1366 | { | |||
1367 | VclPtrInstance<VirtualDevice> pDevice(*i_pTargetOutDev); | |||
1368 | ||||
1369 | Size aSize(GetOutputSizePixel()); | |||
1370 | pDevice->SetOutputSizePixel(aSize); | |||
1371 | ||||
1372 | vcl::Font aCopyFont = GetFont(); | |||
1373 | pDevice->SetFont(aCopyFont); | |||
1374 | ||||
1375 | pDevice->SetTextColor(GetTextColor()); | |||
1376 | if (IsLineColor()) | |||
1377 | pDevice->SetLineColor(GetLineColor()); | |||
1378 | else | |||
1379 | pDevice->SetLineColor(); | |||
1380 | ||||
1381 | if (IsFillColor()) | |||
1382 | pDevice->SetFillColor(GetFillColor()); | |||
1383 | else | |||
1384 | pDevice->SetFillColor(); | |||
1385 | ||||
1386 | if (IsTextLineColor()) | |||
1387 | pDevice->SetTextLineColor(GetTextLineColor()); | |||
1388 | else | |||
1389 | pDevice->SetTextLineColor(); | |||
1390 | ||||
1391 | if (IsOverlineColor()) | |||
1392 | pDevice->SetOverlineColor(GetOverlineColor()); | |||
1393 | else | |||
1394 | pDevice->SetOverlineColor(); | |||
1395 | ||||
1396 | if (IsTextFillColor()) | |||
1397 | pDevice->SetTextFillColor(GetTextFillColor()); | |||
1398 | else | |||
1399 | pDevice->SetTextFillColor(); | |||
1400 | ||||
1401 | pDevice->SetTextAlign(GetTextAlign()); | |||
1402 | pDevice->SetRasterOp(GetRasterOp()); | |||
1403 | ||||
1404 | tools::Rectangle aPaintRect(Point(), GetOutputSizePixel()); | |||
1405 | ||||
1406 | vcl::Region aClipRegion(GetClipRegion()); | |||
1407 | pDevice->SetClipRegion(); | |||
1408 | aClipRegion.Intersect(aPaintRect); | |||
1409 | pDevice->SetClipRegion(aClipRegion); | |||
1410 | ||||
1411 | if (!IsPaintTransparent() && IsBackground() && ! (GetParentClipMode() & ParentClipMode::NoClip)) | |||
1412 | Erase(*pDevice); | |||
1413 | ||||
1414 | pDevice->SetMapMode(GetMapMode()); | |||
1415 | ||||
1416 | Paint(*pDevice, tools::Rectangle(Point(), GetOutputSizePixel())); | |||
1417 | ||||
1418 | i_pTargetOutDev->DrawOutDev(i_rPos, aSize, Point(), pDevice->PixelToLogic(aSize), *pDevice); | |||
1419 | ||||
1420 | // get rid of virtual device now so they don't pile up during recursive calls | |||
1421 | pDevice.disposeAndClear(); | |||
1422 | ||||
1423 | ||||
1424 | for( vcl::Window* pChild = mpWindowImpl->mpFirstChild; pChild; pChild = pChild->mpWindowImpl->mpNext ) | |||
1425 | { | |||
1426 | if( pChild->mpWindowImpl->mpFrame == mpWindowImpl->mpFrame && pChild->IsVisible() ) | |||
1427 | { | |||
1428 | long nDeltaX = pChild->mnOutOffX - mnOutOffX; | |||
1429 | long nDeltaY = pChild->mnOutOffY - mnOutOffY; | |||
1430 | ||||
1431 | Point aPos( i_rPos ); | |||
1432 | aPos += Point(nDeltaX, nDeltaY); | |||
1433 | ||||
1434 | pChild->ImplPaintToDevice( i_pTargetOutDev, aPos ); | |||
1435 | } | |||
1436 | } | |||
1437 | return; | |||
1438 | } | |||
1439 | ||||
1440 | ||||
1441 | bool bRVisible = mpWindowImpl->mbReallyVisible; | |||
1442 | mpWindowImpl->mbReallyVisible = mpWindowImpl->mbVisible; | |||
1443 | bool bDevOutput = mbDevOutput; | |||
1444 | mbDevOutput = true; | |||
1445 | ||||
1446 | const OutputDevice *pOutDev = GetOutDev(); | |||
1447 | long nOldDPIX = pOutDev->GetDPIX(); | |||
1448 | long nOldDPIY = pOutDev->GetDPIY(); | |||
1449 | mnDPIX = i_pTargetOutDev->GetDPIX(); | |||
1450 | mnDPIY = i_pTargetOutDev->GetDPIY(); | |||
1451 | bool bOutput = IsOutputEnabled(); | |||
1452 | EnableOutput(); | |||
1453 | ||||
1454 | SAL_WARN_IF( GetMapMode().GetMapUnit() != MapUnit::MapPixel, "vcl.window", "MapMode must be PIXEL based" )do { if (true && (GetMapMode().GetMapUnit() != MapUnit ::MapPixel)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "vcl.window")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "MapMode must be PIXEL based" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window" ), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1454" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "MapMode must be PIXEL based"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "MapMode must be PIXEL based"; ::sal::detail::log( ( ::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1454" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "MapMode must be PIXEL based") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1454" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "MapMode must be PIXEL based"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "MapMode must be PIXEL based"; ::sal::detail::log( ( ::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1454" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1455 | if ( GetMapMode().GetMapUnit() != MapUnit::MapPixel ) | |||
1456 | return; | |||
1457 | ||||
1458 | // preserve graphicsstate | |||
1459 | Push(); | |||
1460 | vcl::Region aClipRegion( GetClipRegion() ); | |||
1461 | SetClipRegion(); | |||
1462 | ||||
1463 | GDIMetaFile* pOldMtf = GetConnectMetaFile(); | |||
1464 | GDIMetaFile aMtf; | |||
1465 | SetConnectMetaFile( &aMtf ); | |||
1466 | ||||
1467 | // put a push action to metafile | |||
1468 | Push(); | |||
1469 | // copy graphics state to metafile | |||
1470 | vcl::Font aCopyFont = GetFont(); | |||
1471 | if( nOldDPIX != mnDPIX || nOldDPIY != mnDPIY ) | |||
1472 | { | |||
1473 | aCopyFont.SetFontHeight( aCopyFont.GetFontHeight() * mnDPIY / nOldDPIY ); | |||
1474 | aCopyFont.SetAverageFontWidth( aCopyFont.GetAverageFontWidth() * mnDPIX / nOldDPIX ); | |||
1475 | } | |||
1476 | SetFont( aCopyFont ); | |||
1477 | SetTextColor( GetTextColor() ); | |||
1478 | if( IsLineColor() ) | |||
1479 | SetLineColor( GetLineColor() ); | |||
1480 | else | |||
1481 | SetLineColor(); | |||
1482 | if( IsFillColor() ) | |||
1483 | SetFillColor( GetFillColor() ); | |||
1484 | else | |||
1485 | SetFillColor(); | |||
1486 | if( IsTextLineColor() ) | |||
1487 | SetTextLineColor( GetTextLineColor() ); | |||
1488 | else | |||
1489 | SetTextLineColor(); | |||
1490 | if( IsOverlineColor() ) | |||
1491 | SetOverlineColor( GetOverlineColor() ); | |||
1492 | else | |||
1493 | SetOverlineColor(); | |||
1494 | if( IsTextFillColor() ) | |||
1495 | SetTextFillColor( GetTextFillColor() ); | |||
1496 | else | |||
1497 | SetTextFillColor(); | |||
1498 | SetTextAlign( GetTextAlign() ); | |||
1499 | SetRasterOp( GetRasterOp() ); | |||
1500 | if( IsRefPoint() ) | |||
1501 | SetRefPoint( GetRefPoint() ); | |||
1502 | else | |||
1503 | SetRefPoint(); | |||
1504 | SetLayoutMode( GetLayoutMode() ); | |||
1505 | ||||
1506 | SetDigitLanguage( GetDigitLanguage() ); | |||
1507 | tools::Rectangle aPaintRect(Point(0, 0), GetOutputSizePixel()); | |||
1508 | aClipRegion.Intersect( aPaintRect ); | |||
1509 | SetClipRegion( aClipRegion ); | |||
1510 | ||||
1511 | // do the actual paint | |||
1512 | ||||
1513 | // background | |||
1514 | if( ! IsPaintTransparent() && IsBackground() && ! (GetParentClipMode() & ParentClipMode::NoClip ) ) | |||
1515 | { | |||
1516 | Erase(*this); | |||
1517 | } | |||
1518 | // foreground | |||
1519 | Paint(*this, aPaintRect); | |||
1520 | // put a pop action to metafile | |||
1521 | Pop(); | |||
1522 | ||||
1523 | SetConnectMetaFile( pOldMtf ); | |||
1524 | EnableOutput( bOutput ); | |||
1525 | mpWindowImpl->mbReallyVisible = bRVisible; | |||
1526 | ||||
1527 | // paint metafile to VDev | |||
1528 | VclPtrInstance<VirtualDevice> pMaskedDevice(*i_pTargetOutDev, | |||
1529 | DeviceFormat::DEFAULT, | |||
1530 | DeviceFormat::DEFAULT); | |||
1531 | ||||
1532 | pMaskedDevice->SetOutputSizePixel( GetOutputSizePixel() ); | |||
1533 | pMaskedDevice->EnableRTL( IsRTLEnabled() ); | |||
1534 | aMtf.WindStart(); | |||
1535 | aMtf.Play( pMaskedDevice ); | |||
1536 | BitmapEx aBmpEx( pMaskedDevice->GetBitmapEx( Point( 0, 0 ), aPaintRect.GetSize() ) ); | |||
1537 | i_pTargetOutDev->DrawBitmapEx( i_rPos, aBmpEx ); | |||
1538 | // get rid of virtual device now so they don't pile up during recursive calls | |||
1539 | pMaskedDevice.disposeAndClear(); | |||
1540 | ||||
1541 | for( vcl::Window* pChild = mpWindowImpl->mpFirstChild; pChild; pChild = pChild->mpWindowImpl->mpNext ) | |||
1542 | { | |||
1543 | if( pChild->mpWindowImpl->mpFrame == mpWindowImpl->mpFrame && pChild->IsVisible() ) | |||
1544 | { | |||
1545 | long nDeltaX = pChild->mnOutOffX - mnOutOffX; | |||
1546 | ||||
1547 | if( pOutDev->HasMirroredGraphics() ) | |||
1548 | nDeltaX = mnOutWidth - nDeltaX - pChild->mnOutWidth; | |||
1549 | long nDeltaY = pChild->GetOutOffYPixel() - GetOutOffYPixel(); | |||
1550 | Point aPos( i_rPos ); | |||
1551 | Point aDelta( nDeltaX, nDeltaY ); | |||
1552 | aPos += aDelta; | |||
1553 | pChild->ImplPaintToDevice( i_pTargetOutDev, aPos ); | |||
1554 | } | |||
1555 | } | |||
1556 | ||||
1557 | // restore graphics state | |||
1558 | Pop(); | |||
1559 | ||||
1560 | EnableOutput( bOutput ); | |||
1561 | mpWindowImpl->mbReallyVisible = bRVisible; | |||
1562 | mbDevOutput = bDevOutput; | |||
1563 | mnDPIX = nOldDPIX; | |||
1564 | mnDPIY = nOldDPIY; | |||
1565 | } | |||
1566 | ||||
1567 | void Window::PaintToDevice(OutputDevice* pDev, const Point& rPos) | |||
1568 | { | |||
1569 | SAL_WARN_IF( pDev->HasMirroredGraphics(), "vcl.window", "PaintToDevice to mirroring graphics" )do { if (true && (pDev->HasMirroredGraphics())) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl.window" )) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "PaintToDevice to mirroring graphics") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window") , ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1569" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "PaintToDevice to mirroring graphics" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "PaintToDevice to mirroring graphics"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1569" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "PaintToDevice to mirroring graphics") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window") , ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1569" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "PaintToDevice to mirroring graphics" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "PaintToDevice to mirroring graphics"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1569" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
| ||||
1570 | SAL_WARN_IF( pDev->IsRTLEnabled(), "vcl.window", "PaintToDevice to mirroring device" )do { if (true && (pDev->IsRTLEnabled())) { switch ( sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl.window" )) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "PaintToDevice to mirroring device") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1570" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "PaintToDevice to mirroring device") , 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "PaintToDevice to mirroring device"; ::sal::detail:: log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1570" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "PaintToDevice to mirroring device") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1570" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "PaintToDevice to mirroring device") , 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "PaintToDevice to mirroring device"; ::sal::detail:: log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.window"), ("/home/maarten/src/libreoffice/core/vcl/source/window/paint.cxx" ":" "1570" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1571 | ||||
1572 | vcl::Window* pRealParent = nullptr; | |||
1573 | if( ! mpWindowImpl->mbVisible ) | |||
1574 | { | |||
1575 | vcl::Window* pTempParent = ImplGetDefaultWindow(); | |||
1576 | pTempParent->EnableChildTransparentMode(); | |||
1577 | pRealParent = GetParent(); | |||
1578 | SetParent( pTempParent ); | |||
1579 | // trigger correct visibility flags for children | |||
1580 | Show(); | |||
1581 | Hide(); | |||
1582 | } | |||
1583 | ||||
1584 | bool bVisible = mpWindowImpl->mbVisible; | |||
1585 | mpWindowImpl->mbVisible = true; | |||
1586 | ||||
1587 | if( mpWindowImpl->mpBorderWindow ) | |||
1588 | mpWindowImpl->mpBorderWindow->ImplPaintToDevice( pDev, rPos ); | |||
1589 | else | |||
1590 | ImplPaintToDevice( pDev, rPos ); | |||
1591 | ||||
1592 | mpWindowImpl->mbVisible = bVisible; | |||
1593 | ||||
1594 | if( pRealParent ) | |||
1595 | SetParent( pRealParent ); | |||
1596 | } | |||
1597 | ||||
1598 | void Window::Erase(vcl::RenderContext& rRenderContext) | |||
1599 | { | |||
1600 | if (!IsDeviceOutputNecessary() || ImplIsRecordLayout()) | |||
1601 | return; | |||
1602 | ||||
1603 | bool bNativeOK = false; | |||
1604 | ||||
1605 | ControlPart aCtrlPart = ImplGetWindowImpl()->mnNativeBackground; | |||
1606 | ||||
1607 | if (aCtrlPart == ControlPart::Entire && IsControlBackground()) | |||
1608 | { | |||
1609 | // nothing to do here; background is drawn in corresponding drawNativeControl implementation | |||
1610 | bNativeOK = true; | |||
1611 | } | |||
1612 | else if (aCtrlPart != ControlPart::NONE && ! IsControlBackground()) | |||
1613 | { | |||
1614 | tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel()); | |||
1615 | ControlState nState = ControlState::NONE; | |||
1616 | ||||
1617 | if (IsEnabled()) | |||
1618 | nState |= ControlState::ENABLED; | |||
1619 | ||||
1620 | bNativeOK = rRenderContext.DrawNativeControl(ControlType::WindowBackground, aCtrlPart, aCtrlRegion, | |||
1621 | nState, ImplControlValue(), OUString()); | |||
1622 | } | |||
1623 | ||||
1624 | if (mbBackground && !bNativeOK) | |||
1625 | { | |||
1626 | RasterOp eRasterOp = GetRasterOp(); | |||
1627 | if (eRasterOp != RasterOp::OverPaint) | |||
1628 | SetRasterOp(RasterOp::OverPaint); | |||
1629 | rRenderContext.DrawWallpaper(0, 0, mnOutWidth, mnOutHeight, maBackground); | |||
1630 | if (eRasterOp != RasterOp::OverPaint) | |||
1631 | rRenderContext.SetRasterOp(eRasterOp); | |||
1632 | } | |||
1633 | ||||
1634 | if (mpAlphaVDev) | |||
1635 | mpAlphaVDev->Erase(); | |||
1636 | } | |||
1637 | ||||
1638 | void Window::ImplScroll( const tools::Rectangle& rRect, | |||
1639 | long nHorzScroll, long nVertScroll, ScrollFlags nFlags ) | |||
1640 | { | |||
1641 | if ( !IsDeviceOutputNecessary() ) | |||
1642 | return; | |||
1643 | ||||
1644 | nHorzScroll = ImplLogicWidthToDevicePixel( nHorzScroll ); | |||
1645 | nVertScroll = ImplLogicHeightToDevicePixel( nVertScroll ); | |||
1646 | ||||
1647 | if ( !nHorzScroll && !nVertScroll ) | |||
1648 | return; | |||
1649 | ||||
1650 | if ( mpWindowImpl->mpCursor ) | |||
1651 | mpWindowImpl->mpCursor->ImplSuspend(); | |||
1652 | ||||
1653 | ScrollFlags nOrgFlags = nFlags; | |||
1654 | if ( !(nFlags & (ScrollFlags::Children | ScrollFlags::NoChildren)) ) | |||
1655 | { | |||
1656 | if ( GetStyle() & WB_CLIPCHILDREN ) | |||
1657 | nFlags |= ScrollFlags::NoChildren; | |||
1658 | else | |||
1659 | nFlags |= ScrollFlags::Children; | |||
1660 | } | |||
1661 | ||||
1662 | vcl::Region aInvalidateRegion; | |||
1663 | bool bScrollChildren(nFlags & ScrollFlags::Children); | |||
1664 | ||||
1665 | if ( !mpWindowImpl->mpFirstChild ) | |||
1666 | bScrollChildren = false; | |||
1667 | ||||
1668 | OutputDevice *pOutDev = GetOutDev(); | |||
1669 | ||||
1670 | // RTL: check if this window requires special action | |||
1671 | bool bReMirror = ImplIsAntiparallel(); | |||
1672 | ||||
1673 | tools::Rectangle aRectMirror( rRect ); | |||
1674 | if( bReMirror ) | |||
1675 | { | |||
1676 | // make sure the invalidate region of this window is | |||
1677 | // computed in the same coordinate space as the one from the overlap windows | |||
1678 | pOutDev->ReMirror( aRectMirror ); | |||
1679 | } | |||
1680 | ||||
1681 | // adapt paint areas | |||
1682 | ImplMoveAllInvalidateRegions( aRectMirror, nHorzScroll, nVertScroll, bScrollChildren ); | |||
1683 | ||||
1684 | ImplCalcOverlapRegion( aRectMirror, aInvalidateRegion, !bScrollChildren, false ); | |||
1685 | ||||
1686 | // if the scrolling on the device is performed in the opposite direction | |||
1687 | // then move the overlaps in that direction to compute the invalidate region | |||
1688 | // on the correct side, i.e., revert nHorzScroll | |||
1689 | if (!aInvalidateRegion.IsEmpty()) | |||
1690 | { | |||
1691 | aInvalidateRegion.Move(bReMirror ? -nHorzScroll : nHorzScroll, nVertScroll); | |||
1692 | } | |||
1693 | ||||
1694 | tools::Rectangle aDestRect(aRectMirror); | |||
1695 | aDestRect.Move(bReMirror ? -nHorzScroll : nHorzScroll, nVertScroll); | |||
1696 | vcl::Region aWinInvalidateRegion(aRectMirror); | |||
1697 | if (!SupportsDoubleBuffering()) | |||
1698 | { | |||
1699 | // There will be no CopyArea() call below, so invalidate the | |||
1700 | // whole visible area, not only the smaller one that was just | |||
1701 | // scrolled in. | |||
1702 | aWinInvalidateRegion.Exclude(aDestRect); | |||
1703 | } | |||
1704 | ||||
1705 | aInvalidateRegion.Union(aWinInvalidateRegion); | |||
1706 | ||||
1707 | Point aPoint( mnOutOffX, mnOutOffY ); | |||
1708 | vcl::Region aRegion( tools::Rectangle( aPoint, Size( mnOutWidth, mnOutHeight ) ) ); | |||
1709 | if ( nFlags & ScrollFlags::Clip ) | |||
1710 | aRegion.Intersect( rRect ); | |||
1711 | if ( mpWindowImpl->mbWinRegion ) | |||
1712 | aRegion.Intersect( ImplPixelToDevicePixel( mpWindowImpl->maWinRegion ) ); | |||
1713 | ||||
1714 | aRegion.Exclude( aInvalidateRegion ); | |||
1715 | ||||
1716 | ImplClipBoundaries( aRegion, false, true ); | |||
1717 | if ( !bScrollChildren ) | |||
1718 | { | |||
1719 | if ( nOrgFlags & ScrollFlags::NoChildren ) | |||
1720 | ImplClipAllChildren( aRegion ); | |||
1721 | else | |||
1722 | ImplClipChildren( aRegion ); | |||
1723 | } | |||
1724 | if ( mbClipRegion && (nFlags & ScrollFlags::UseClipRegion) ) | |||
1725 | aRegion.Intersect( maRegion ); | |||
1726 | if ( !aRegion.IsEmpty() ) | |||
1727 | { | |||
1728 | if ( mpWindowImpl->mpWinData ) | |||
1729 | { | |||
1730 | if ( mpWindowImpl->mbFocusVisible ) | |||
1731 | ImplInvertFocus( *mpWindowImpl->mpWinData->mpFocusRect ); | |||
1732 | if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) | |||
1733 | InvertTracking( *mpWindowImpl->mpWinData->mpTrackRect, mpWindowImpl->mpWinData->mnTrackFlags ); | |||
1734 | } | |||
1735 | #ifndef IOS | |||
1736 | // This seems completely unnecessary with tiled rendering, and | |||
1737 | // causes the "AquaSalGraphics::copyArea() for non-layered | |||
1738 | // graphics" message. Presumably we should bypass this on all | |||
1739 | // platforms when dealing with a "window" that uses tiled | |||
1740 | // rendering at the moment. Unclear how to figure that out, | |||
1741 | // though. Also unclear whether we actually could just not | |||
1742 | // create a "frame window", whatever that exactly is, in the | |||
1743 | // tiled rendering case, or at least for platforms where tiles | |||
1744 | // rendering is all there is. | |||
1745 | ||||
1746 | SalGraphics* pGraphics = ImplGetFrameGraphics(); | |||
1747 | // The invalidation area contains the area what would be copied here, | |||
1748 | // so avoid copying in case of double buffering. | |||
1749 | if (pGraphics && !SupportsDoubleBuffering()) | |||
1750 | { | |||
1751 | if( bReMirror ) | |||
1752 | { | |||
1753 | pOutDev->ReMirror( aRegion ); | |||
1754 | } | |||
1755 | ||||
1756 | pOutDev->SelectClipRegion( aRegion, pGraphics ); | |||
1757 | pGraphics->CopyArea( rRect.Left()+nHorzScroll, rRect.Top()+nVertScroll, | |||
1758 | rRect.Left(), rRect.Top(), | |||
1759 | rRect.GetWidth(), rRect.GetHeight(), | |||
1760 | this ); | |||
1761 | } | |||
1762 | #endif | |||
1763 | if ( mpWindowImpl->mpWinData ) | |||
1764 | { | |||
1765 | if ( mpWindowImpl->mbFocusVisible ) | |||
1766 | ImplInvertFocus( *mpWindowImpl->mpWinData->mpFocusRect ); | |||
1767 | if ( mpWindowImpl->mbTrackVisible && (mpWindowImpl->mpWinData->mnTrackFlags & ShowTrackFlags::TrackWindow) ) | |||
1768 | InvertTracking( *mpWindowImpl->mpWinData->mpTrackRect, mpWindowImpl->mpWinData->mnTrackFlags ); | |||
1769 | } | |||
1770 | } | |||
1771 | ||||
1772 | if ( !aInvalidateRegion.IsEmpty() ) | |||
1773 | { | |||
1774 | // RTL: the invalidate region for this windows is already computed in frame coordinates | |||
1775 | // so it has to be re-mirrored before calling the Paint-handler | |||
1776 | mpWindowImpl->mnPaintFlags |= ImplPaintFlags::CheckRtl; | |||
1777 | ||||
1778 | if ( !bScrollChildren ) | |||
1779 | { | |||
1780 | if ( nOrgFlags & ScrollFlags::NoChildren ) | |||
1781 | ImplClipAllChildren( aInvalidateRegion ); | |||
1782 | else | |||
1783 | ImplClipChildren( aInvalidateRegion ); | |||
1784 | } | |||
1785 | ImplInvalidateFrameRegion( &aInvalidateRegion, InvalidateFlags::Children ); | |||
1786 | } | |||
1787 | ||||
1788 | if ( bScrollChildren ) | |||
1789 | { | |||
1790 | vcl::Window* pWindow = mpWindowImpl->mpFirstChild; | |||
1791 | while ( pWindow ) | |||
1792 | { | |||
1793 | Point aPos = pWindow->GetPosPixel(); | |||
1794 | aPos += Point( nHorzScroll, nVertScroll ); | |||
1795 | pWindow->SetPosPixel( aPos ); | |||
1796 | ||||
1797 | pWindow = pWindow->mpWindowImpl->mpNext; | |||
1798 | } | |||
1799 | } | |||
1800 | ||||
1801 | if ( nFlags & ScrollFlags::Update ) | |||
1802 | PaintImmediately(); | |||
1803 | ||||
1804 | if ( mpWindowImpl->mpCursor ) | |||
1805 | mpWindowImpl->mpCursor->ImplResume(); | |||
1806 | } | |||
1807 | ||||
1808 | } /* namespace vcl */ | |||
1809 | ||||
1810 | ||||
1811 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |