[Libreoffice-commits] core.git: vcl/Library_vcl.mk vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri May 31 18:20:44 UTC 2019


 vcl/Library_vcl.mk                       |    1 
 vcl/source/window/bufferdevice.cxx       |   36 +++++++++++++++++++++++++++++++
 vcl/source/window/bufferdevice.hxx       |   36 +++++++++++++++++++++++++++++++
 vcl/source/window/menubarwindow.cxx      |   11 +--------
 vcl/source/window/menufloatingwindow.cxx |    9 +------
 5 files changed, 77 insertions(+), 16 deletions(-)

New commits:
commit 42bf893a8479f70d7d8f00e03105ce15e8545f8b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri May 31 14:56:46 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri May 31 20:19:56 2019 +0200

    tdf#125550 vcl menu bar / floating window: fix text color
    
    Regression from commit e8d5b8beb5958147235ff955ed38c47b51d860ff
    (tdf#113714 vcl menu bar window: avoid flicker, 2019-05-20), the problem
    was that a freshly created VirtualDevice doesn't have the default text
    color, so we need to initialize that explicitly based on the render
    context text color.
    
    Also introduce a BufferDevice to do this initialization, instead of
    fixing this in MenuBarWindow::Paint(), then copy&pasting the fix to
    MenuFloatingWindow::Paint().
    
    Change-Id: Ib171cd52e7cabe0bc3c639821f558d8303039fe6
    Reviewed-on: https://gerrit.libreoffice.org/73269
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ba82f48deeff..428e69324782 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -124,6 +124,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/window/accel \
     vcl/source/window/accmgr \
     vcl/source/window/brdwin \
+    vcl/source/window/bufferdevice \
     vcl/source/window/accessibility \
     vcl/source/window/legacyaccessibility \
     vcl/source/window/clipping \
diff --git a/vcl/source/window/bufferdevice.cxx b/vcl/source/window/bufferdevice.cxx
new file mode 100644
index 000000000000..5db4cfff458a
--- /dev/null
+++ b/vcl/source/window/bufferdevice.cxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "bufferdevice.hxx"
+
+namespace vcl
+{
+BufferDevice::BufferDevice(const VclPtr<vcl::Window>& pWindow, vcl::RenderContext& rRenderContext)
+    : m_pBuffer(VclPtr<VirtualDevice>::Create())
+    , m_pWindow(pWindow)
+    , m_rRenderContext(rRenderContext)
+{
+    m_pBuffer->SetOutputSizePixel(pWindow->GetOutputSizePixel(), false);
+    m_pBuffer->SetTextColor(rRenderContext.GetTextColor());
+    m_pBuffer->DrawOutDev(Point(0, 0), pWindow->GetOutputSizePixel(), Point(0, 0),
+                          pWindow->GetOutputSizePixel(), rRenderContext);
+}
+
+BufferDevice::~BufferDevice()
+{
+    m_rRenderContext.DrawOutDev(Point(0, 0), m_pWindow->GetOutputSizePixel(), Point(0, 0),
+                                m_pWindow->GetOutputSizePixel(), *m_pBuffer);
+}
+
+vcl::RenderContext* BufferDevice::operator->() { return m_pBuffer.get(); }
+
+vcl::RenderContext& BufferDevice::operator*() { return *m_pBuffer; }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/bufferdevice.hxx b/vcl/source/window/bufferdevice.hxx
new file mode 100644
index 000000000000..26bf28e615fa
--- /dev/null
+++ b/vcl/source/window/bufferdevice.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_SOURCE_WINDOW_BUFFERDEVICE_HXX
+#define INCLUDED_VCL_SOURCE_WINDOW_BUFFERDEVICE_HXX
+
+#include <vcl/virdev.hxx>
+#include <vcl/window.hxx>
+
+namespace vcl
+{
+/// Buffers drawing on a vcl::RenderContext using a VirtualDevice.
+class BufferDevice
+{
+    ScopedVclPtr<VirtualDevice> m_pBuffer;
+    VclPtr<vcl::Window> m_pWindow;
+    vcl::RenderContext& m_rRenderContext;
+
+public:
+    BufferDevice(const VclPtr<vcl::Window>& pWindow, vcl::RenderContext& rRenderContext);
+    ~BufferDevice();
+
+    vcl::RenderContext* operator->();
+    vcl::RenderContext& operator*();
+};
+}
+
+#endif // INCLUDED_VCL_SOURCE_WINDOW_BUFFERDEVICE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx
index b32e38790cd4..81e7cbe573c6 100644
--- a/vcl/source/window/menubarwindow.cxx
+++ b/vcl/source/window/menubarwindow.cxx
@@ -33,6 +33,7 @@
 #include <strings.hrc>
 #include <bitmaps.hlst>
 #include <window.h>
+#include "bufferdevice.hxx"
 
 // document closing button
 #define IID_DOCUMENTCLOSE 1
@@ -914,11 +915,7 @@ void MenuBarWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Recta
     }
 
     // Make sure that all actual rendering happens in one go to avoid flicker.
-    ScopedVclPtrInstance<VirtualDevice> pBuffer;
-    pBuffer->SetOutputSizePixel(aOutputSize, false);
-    // Copy the current state to the buffer.
-    pBuffer->DrawOutDev(Point(0, 0), GetOutputSizePixel(), Point(0, 0), GetOutputSizePixel(),
-                        rRenderContext);
+    vcl::BufferDevice pBuffer(this, rRenderContext);
 
     if (rRenderContext.IsNativeControlSupported(ControlType::Menubar, ControlPart::Entire))
     {
@@ -961,10 +958,6 @@ void MenuBarWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Recta
                           Point(aSize.Width() - 1, aSize.Height() - 1));
         pBuffer->Pop();
     }
-
-    // Copy the current state from the buffer.
-    rRenderContext.DrawOutDev(Point(0, 0), GetOutputSizePixel(), Point(0, 0), GetOutputSizePixel(),
-                              *pBuffer);
 }
 
 void MenuBarWindow::Resize()
diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx
index 631d275e8656..bc1af67bc991 100644
--- a/vcl/source/window/menufloatingwindow.cxx
+++ b/vcl/source/window/menufloatingwindow.cxx
@@ -20,6 +20,7 @@
 #include "menufloatingwindow.hxx"
 #include "menuitemlist.hxx"
 #include "menubarwindow.hxx"
+#include "bufferdevice.hxx"
 
 #include <sal/log.hxx>
 #include <salmenu.hxx>
@@ -1208,10 +1209,7 @@ void MenuFloatingWindow::Paint(vcl::RenderContext& rRenderContext, const tools::
         return;
 
     // Make sure that all actual rendering happens in one go to avoid flicker.
-    ScopedVclPtrInstance<VirtualDevice> pBuffer;
-    pBuffer->SetOutputSizePixel(GetOutputSizePixel(), false);
-    pBuffer->DrawOutDev(Point(0, 0), GetOutputSizePixel(), Point(0, 0), GetOutputSizePixel(),
-                        rRenderContext);
+    vcl::BufferDevice pBuffer(this, rRenderContext);
 
     pBuffer->Push(PushFlags::CLIPREGION);
     pBuffer->SetClipRegion(vcl::Region(rPaintRect));
@@ -1239,9 +1237,6 @@ void MenuFloatingWindow::Paint(vcl::RenderContext& rRenderContext, const tools::
         RenderHighlightItem(*pBuffer, nHighlightedItem);
 
     pBuffer->Pop();
-
-    rRenderContext.DrawOutDev(Point(0, 0), GetOutputSizePixel(), Point(0, 0), GetOutputSizePixel(),
-                              *pBuffer);
 }
 
 void MenuFloatingWindow::ImplDrawScroller(vcl::RenderContext& rRenderContext, bool bUp)


More information about the Libreoffice-commits mailing list