1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
33 if (!m_pParent
|| !pParent
->GetQWidget())
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; });
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";
53 m_aSystemData
.platform
= SystemEnvData::Platform::Xcb
;
54 m_aSystemData
.SetWindowHandle(m_pQWindow
->winId()); // ID of the embedded window
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()
72 m_pQWidget
->setParent(nullptr);
77 void Qt5Object::ResetClipRegion()
80 m_pRegion
= QRegion(m_pQWidget
->geometry());
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
,
90 m_pRegion
+= QRect(nX
, nY
, nWidth
, nHeight
);
93 void Qt5Object::EndSetClipRegion()
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
)
103 m_pQWidget
->move(nX
, nY
);
104 m_pQWidget
->setFixedSize(nWidth
, nHeight
);
108 void Qt5Object::Show(bool bVisible
)
111 m_pQWidget
->setVisible(bVisible
);
114 void Qt5Object::SetForwardKey(bool /*bEnable*/) {}
116 Qt5ObjectWindow::Qt5ObjectWindow(Qt5Object
& 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: */