bump product version to 6.4.0.3
[LibreOffice.git] / vcl / qt5 / Qt5Object.cxx
blob5bbfef5a5870d19a296c785dcdd82581241a266b
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.aWindow = 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(long nX, long nY, long nWidth, long nHeight)
89 m_pRegion += QRect(nX, nY, nWidth, nHeight);
92 void Qt5Object::EndSetClipRegion()
94 if (m_pQWidget)
95 m_pRegion = m_pRegion.intersected(m_pQWidget->geometry());
98 void Qt5Object::SetPosSize(long nX, long nY, long nWidth, long nHeight)
100 if (m_pQWidget)
102 m_pQWidget->move(nX, nY);
103 m_pQWidget->setFixedSize(nWidth, nHeight);
107 void Qt5Object::Show(bool bVisible)
109 if (m_pQWidget)
110 m_pQWidget->setVisible(bVisible);
113 void Qt5Object::SetForwardKey(bool /*bEnable*/) {}
115 Qt5ObjectWindow::Qt5ObjectWindow(Qt5Object& rParent)
116 : m_rParent(rParent)
118 assert(m_rParent.frame() && m_rParent.frame()->GetQWidget());
121 void Qt5ObjectWindow::focusInEvent(QFocusEvent* pEvent)
123 m_rParent.CallCallback(SalObjEvent::GetFocus);
124 QWindow::focusInEvent(pEvent);
127 void Qt5ObjectWindow::focusOutEvent(QFocusEvent* pEvent)
129 m_rParent.CallCallback(SalObjEvent::LoseFocus);
130 QWindow::focusOutEvent(pEvent);
133 void Qt5ObjectWindow::mousePressEvent(QMouseEvent* pEvent)
135 m_rParent.CallCallback(SalObjEvent::ToTop);
136 Qt5Widget::handleMousePressEvent(*m_rParent.frame(), pEvent);
139 void Qt5ObjectWindow::mouseReleaseEvent(QMouseEvent* pEvent)
141 Qt5Widget::handleMouseReleaseEvent(*m_rParent.frame(), pEvent);
144 bool Qt5ObjectWindow::event(QEvent* pEvent)
146 return Qt5Widget::handleEvent(*m_rParent.frame(), *m_rParent.widget(), pEvent)
147 || QWindow::event(pEvent);
150 void Qt5ObjectWindow::keyReleaseEvent(QKeyEvent* pEvent)
152 if (!Qt5Widget::handleKeyReleaseEvent(*m_rParent.frame(), *m_rParent.widget(), pEvent))
153 QWindow::keyReleaseEvent(pEvent);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */