nss: upgrade to release 3.73
[LibreOffice.git] / vcl / qt5 / Qt5Object.cxx
blob631321681daa272b2abf8d8479a9c3e37149a299
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <Qt5Object.hxx>
21 #include <Qt5Object.moc>
23 #include <Qt5Frame.hxx>
24 #include <Qt5Widget.hxx>
26 #include <QtGui/QGuiApplication>
28 Qt5Object::Qt5Object(Qt5Frame* pParent, bool bShow)
29 : m_pParent(pParent)
30 , m_pQWidget(nullptr)
31 , m_pQWindow(nullptr)
33 if (!m_pParent || !pParent->GetQWidget())
34 return;
36 m_pQWindow = new Qt5ObjectWindow(*this);
37 m_pQWidget = QWidget::createWindowContainer(m_pQWindow, pParent->GetQWidget());
38 m_pQWidget->setAttribute(Qt::WA_NoSystemBackground);
39 connect(m_pQWidget, &QObject::destroyed, this, [this]() { m_pQWidget = nullptr; });
41 if (bShow)
42 m_pQWidget->show();
44 m_aSystemData.aShellWindow = reinterpret_cast<sal_IntPtr>(this);
45 //m_aSystemData.pSalFrame = this;
46 m_aSystemData.pWidget = m_pQWidget;
47 //m_aSystemData.nScreen = m_nXScreen.getXScreen();
48 m_aSystemData.toolkit = SystemEnvData::Toolkit::Qt5;
49 m_aSystemData.platform = SystemEnvData::Platform::Xcb;
50 const bool bWayland = QGuiApplication::platformName() == "wayland";
51 if (!bWayland)
53 m_aSystemData.platform = SystemEnvData::Platform::Xcb;
54 m_aSystemData.SetWindowHandle(m_pQWindow->winId()); // ID of the embedded window
56 else
58 m_aSystemData.platform = SystemEnvData::Platform::Wayland;
59 // TODO implement as needed for Wayland,
60 // s.a. commit c0d4f3ad3307c which did this for gtk3
61 // QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
62 // m_aSystemData.pDisplay = native->nativeResourceForWindow("display", nullptr);
63 // m_aSystemData.aWindow = reinterpret_cast<unsigned long>(
64 // native->nativeResourceForWindow("surface", m_pQWidget->windowHandle()));
68 Qt5Object::~Qt5Object()
70 if (m_pQWidget)
72 m_pQWidget->setParent(nullptr);
73 delete m_pQWidget;
77 void Qt5Object::ResetClipRegion()
79 if (m_pQWidget)
80 m_pRegion = QRegion(m_pQWidget->geometry());
81 else
82 m_pRegion = QRegion();
85 void Qt5Object::BeginSetClipRegion(sal_uInt32) { m_pRegion = QRegion(); }
87 void Qt5Object::UnionClipRegion(tools::Long nX, tools::Long nY, tools::Long nWidth,
88 tools::Long nHeight)
90 m_pRegion += QRect(nX, nY, nWidth, nHeight);
93 void Qt5Object::EndSetClipRegion()
95 if (m_pQWidget)
96 m_pRegion = m_pRegion.intersected(m_pQWidget->geometry());
99 void Qt5Object::SetPosSize(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight)
101 if (m_pQWidget)
103 m_pQWidget->move(nX, nY);
104 m_pQWidget->setFixedSize(nWidth, nHeight);
108 void Qt5Object::Show(bool bVisible)
110 if (m_pQWidget)
111 m_pQWidget->setVisible(bVisible);
114 void Qt5Object::SetForwardKey(bool /*bEnable*/) {}
116 Qt5ObjectWindow::Qt5ObjectWindow(Qt5Object& rParent)
117 : m_rParent(rParent)
119 assert(m_rParent.frame() && m_rParent.frame()->GetQWidget());
122 void Qt5ObjectWindow::focusInEvent(QFocusEvent* pEvent)
124 m_rParent.CallCallback(SalObjEvent::GetFocus);
125 QWindow::focusInEvent(pEvent);
128 void Qt5ObjectWindow::focusOutEvent(QFocusEvent* pEvent)
130 m_rParent.CallCallback(SalObjEvent::LoseFocus);
131 QWindow::focusOutEvent(pEvent);
134 void Qt5ObjectWindow::mousePressEvent(QMouseEvent* pEvent)
136 m_rParent.CallCallback(SalObjEvent::ToTop);
137 Qt5Widget::handleMousePressEvent(*m_rParent.frame(), pEvent);
140 void Qt5ObjectWindow::mouseReleaseEvent(QMouseEvent* pEvent)
142 Qt5Widget::handleMouseReleaseEvent(*m_rParent.frame(), pEvent);
145 bool Qt5ObjectWindow::event(QEvent* pEvent)
147 return Qt5Widget::handleEvent(*m_rParent.frame(), *m_rParent.widget(), pEvent)
148 || QWindow::event(pEvent);
151 void Qt5ObjectWindow::keyReleaseEvent(QKeyEvent* pEvent)
153 if (!Qt5Widget::handleKeyReleaseEvent(*m_rParent.frame(), *m_rParent.widget(), pEvent))
154 QWindow::keyReleaseEvent(pEvent);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */