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
.aWindow
= 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(long nX
, long nY
, long nWidth
, long nHeight
)
89 m_pRegion
+= QRect(nX
, nY
, nWidth
, nHeight
);
92 void Qt5Object::EndSetClipRegion()
95 m_pRegion
= m_pRegion
.intersected(m_pQWidget
->geometry());
98 void Qt5Object::SetPosSize(long nX
, long nY
, long nWidth
, long nHeight
)
102 m_pQWidget
->move(nX
, nY
);
103 m_pQWidget
->setFixedSize(nWidth
, nHeight
);
107 void Qt5Object::Show(bool bVisible
)
110 m_pQWidget
->setVisible(bVisible
);
113 void Qt5Object::SetForwardKey(bool /*bEnable*/) {}
115 Qt5ObjectWindow::Qt5ObjectWindow(Qt5Object
& 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: */