Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qandroidplatformforeignwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include <QtCore/qvariant.h>
7#include <qpa/qwindowsysteminterface.h>
8#include <QtCore/private/qjnihelpers_p.h>
9#include <QtCore/qjnitypes.h>
10
12
13QAndroidPlatformForeignWindow::QAndroidPlatformForeignWindow(QWindow *window, WId nativeHandle)
14 : QAndroidPlatformWindow(window)
15 , m_view(reinterpret_cast<jobject>(nativeHandle))
16 , m_nativeViewInserted(false)
17{
18}
19
20void QAndroidPlatformForeignWindow::initialize()
21{
22 QAndroidPlatformWindow::initialize();
23
24 if (isEmbeddingContainer()) {
25 m_nativeViewId = m_view.callMethod<jint>("getId");
26 return;
27 }
28
29 if (m_view.isValid())
30 QtAndroid::setViewVisibility(m_view.object(), false);
31}
32
33QAndroidPlatformForeignWindow::~QAndroidPlatformForeignWindow()
34{
35 if (isEmbeddingContainer())
36 return;
37
38 if (m_view.isValid())
39 QtAndroid::setViewVisibility(m_view.object(), false);
40
41 m_nativeQtWindow.callMethod<void>("removeNativeView");
42
43}
44
45void QAndroidPlatformForeignWindow::setVisible(bool visible)
46{
47 if (isEmbeddingContainer()) {
48 QAndroidPlatformWindow::setVisible(visible);
49 return;
50 }
51
52 if (!m_view.isValid())
53 return;
54
55 QtAndroid::setViewVisibility(m_view.object(), visible);
56 m_nativeQtWindow.callMethod<void>("setVisible", visible);
57
58 if (!visible && m_nativeViewInserted) {
59 m_nativeQtWindow.callMethod<void>("removeNativeView");
60 m_nativeViewInserted = false;
61 } else if (!m_nativeViewInserted) {
62 addViewToWindow();
63 }
64}
65
66void QAndroidPlatformForeignWindow::applicationStateChanged(Qt::ApplicationState state)
67{
68 if (!isEmbeddingContainer()) {
69 if (state <= Qt::ApplicationHidden
70 && m_nativeViewInserted) {
71 m_nativeQtWindow.callMethod<void>("removeNativeView");
72 m_nativeViewInserted = false;
73 } else if (m_view.isValid() && !m_nativeViewInserted){
74 addViewToWindow();
75 }
76 }
77
78 QAndroidPlatformWindow::applicationStateChanged(state);
79}
80
81WId QAndroidPlatformForeignWindow::winId() const
82{
83 if (isEmbeddingContainer() && m_view.isValid())
84 return reinterpret_cast<WId>(m_view.object());
85 if (m_nativeQtWindow.isValid())
86 return reinterpret_cast<WId>(m_nativeQtWindow.object());
87 return 0L;
88}
89
90void QAndroidPlatformForeignWindow::addViewToWindow()
91{
92 if (isEmbeddingContainer())
93 return;
94
95 m_nativeQtWindow.callMethod<void>("setNativeView", m_view);
96 m_nativeViewInserted = true;
97}
98
99QT_END_NAMESPACE