impress: don't exit textbox editing when new slide was added
[LibreOffice.git] / vcl / headless / svpvd.cxx
blob9025326827a616bf199da508d6f366d33f2717e0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef IOS
22 #include <headless/svpbmp.hxx>
23 #include <headless/svpinst.hxx>
24 #include <headless/svpvd.hxx>
25 #include <headless/svpgdi.hxx>
27 #include <basegfx/vector/b2ivector.hxx>
28 #include <comphelper/lok.hxx>
30 #include <cairo.h>
32 using namespace basegfx;
34 SvpSalVirtualDevice::SvpSalVirtualDevice(DeviceFormat eFormat, cairo_surface_t* pRefSurface, cairo_surface_t* pPreExistingTarget)
35 : m_eFormat(eFormat)
36 , m_pRefSurface(pRefSurface)
37 , m_pSurface(pPreExistingTarget)
38 , m_bOwnsSurface(!pPreExistingTarget)
40 cairo_surface_reference(m_pRefSurface);
43 SvpSalVirtualDevice::~SvpSalVirtualDevice()
45 if (m_bOwnsSurface)
46 cairo_surface_destroy(m_pSurface);
47 cairo_surface_destroy(m_pRefSurface);
50 SvpSalGraphics* SvpSalVirtualDevice::AddGraphics(SvpSalGraphics* pGraphics)
52 pGraphics->setSurface(m_pSurface, m_aFrameSize);
53 m_aGraphics.push_back(pGraphics);
54 return pGraphics;
57 SalGraphics* SvpSalVirtualDevice::AcquireGraphics()
59 return AddGraphics(new SvpSalGraphics());
62 void SvpSalVirtualDevice::ReleaseGraphics( SalGraphics* pGraphics )
64 m_aGraphics.erase(std::remove(m_aGraphics.begin(), m_aGraphics.end(), dynamic_cast<SvpSalGraphics*>(pGraphics)), m_aGraphics.end());
65 delete pGraphics;
68 bool SvpSalVirtualDevice::SetSize( tools::Long nNewDX, tools::Long nNewDY )
70 return SetSizeUsingBuffer(nNewDX, nNewDY, nullptr);
73 void SvpSalVirtualDevice::CreateSurface(tools::Long nNewDX, tools::Long nNewDY, sal_uInt8 *const pBuffer)
75 if (m_pSurface)
77 cairo_surface_destroy(m_pSurface);
80 if (m_eFormat == DeviceFormat::BITMASK)
82 m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_ALPHA,
83 nNewDX, nNewDY);
85 else if (pBuffer)
87 double fXScale, fYScale;
88 if (comphelper::LibreOfficeKit::isActive())
90 // Force scaling of the painting
91 fXScale = fYScale = comphelper::LibreOfficeKit::getDPIScale();
93 else
95 dl_cairo_surface_get_device_scale(m_pRefSurface, &fXScale, &fYScale);
96 nNewDX *= fXScale;
97 nNewDY *= fYScale;
100 m_pSurface = cairo_image_surface_create_for_data(pBuffer, CAIRO_FORMAT_ARGB32,
101 nNewDX, nNewDY, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, nNewDX));
103 dl_cairo_surface_set_device_scale(m_pSurface, fXScale, fYScale);
105 else
107 m_pSurface = cairo_surface_create_similar(m_pRefSurface, CAIRO_CONTENT_COLOR_ALPHA, nNewDX, nNewDY);
111 bool SvpSalVirtualDevice::SetSizeUsingBuffer( tools::Long nNewDX, tools::Long nNewDY,
112 sal_uInt8 *const pBuffer)
114 if (nNewDX == 0)
115 nNewDX = 1;
116 if (nNewDY == 0)
117 nNewDY = 1;
119 if (!m_pSurface || m_aFrameSize.getX() != nNewDX ||
120 m_aFrameSize.getY() != nNewDY)
122 m_aFrameSize = basegfx::B2IVector(nNewDX, nNewDY);
124 if (m_bOwnsSurface)
125 CreateSurface(nNewDX, nNewDY, pBuffer);
127 assert(m_pSurface);
129 // update device in existing graphics
130 for (auto const& graphic : m_aGraphics)
131 graphic->setSurface(m_pSurface, m_aFrameSize);
133 return true;
136 tools::Long SvpSalVirtualDevice::GetWidth() const
138 return m_pSurface ? m_aFrameSize.getX() : 0;
141 tools::Long SvpSalVirtualDevice::GetHeight() const
143 return m_pSurface ? m_aFrameSize.getY() : 0;
146 #endif
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */