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// Qt-Security score:significant reason:default
4
7#include <QtCore/qvariant.h>
8#include <qpa/qwindowsysteminterface.h>
9#include <QtCore/private/qjnihelpers_p.h>
10#include <QtCore/qjnitypes.h>
11
13
14QAndroidPlatformForeignWindow::QAndroidPlatformForeignWindow(QWindow *window, WId nativeHandle)
15 : QAndroidPlatformWindow(window)
16 , m_view(reinterpret_cast<jobject>(nativeHandle))
17 , m_nativeViewInserted(false)
18{
19}
20
21void QAndroidPlatformForeignWindow::initialize()
22{
23 QAndroidPlatformWindow::initialize();
24
25 if (isEmbeddingContainer()) {
26 m_nativeViewId = m_view.callMethod<jint>("getId");
27 return;
28 }
29
30 if (m_view.isValid())
31 QtAndroid::setViewVisibility(m_view.object(), false);
32}
33
34QAndroidPlatformForeignWindow::~QAndroidPlatformForeignWindow()
35{
36 if (isEmbeddingContainer())
37 return;
38
39 if (m_view.isValid())
40 QtAndroid::setViewVisibility(m_view.object(), false);
41
42 m_nativeQtWindow.callMethod<void>("removeNativeView");
43
44}
45
46void QAndroidPlatformForeignWindow::setVisible(bool visible)
47{
48 if (isEmbeddingContainer()) {
49 QAndroidPlatformWindow::setVisible(visible);
50 return;
51 }
52
53 if (!m_view.isValid())
54 return;
55
56 QtAndroid::setViewVisibility(m_view.object(), visible);
57 m_nativeQtWindow.callMethod<void>("setVisible", visible);
58
59 if (!visible && m_nativeViewInserted) {
60 m_nativeQtWindow.callMethod<void>("removeNativeView");
61 m_nativeViewInserted = false;
62 } else if (!m_nativeViewInserted) {
63 addViewToWindow();
64 }
65}
66
67void QAndroidPlatformForeignWindow::applicationStateChanged(Qt::ApplicationState state)
68{
69 if (!isEmbeddingContainer()) {
70 if (state <= Qt::ApplicationHidden
71 && m_nativeViewInserted) {
72 m_nativeQtWindow.callMethod<void>("removeNativeView");
73 m_nativeViewInserted = false;
74 } else if (m_view.isValid() && !m_nativeViewInserted){
75 addViewToWindow();
76 }
77 }
78
79 QAndroidPlatformWindow::applicationStateChanged(state);
80}
81
82WId QAndroidPlatformForeignWindow::winId() const
83{
84 if (isEmbeddingContainer() && m_view.isValid())
85 return reinterpret_cast<WId>(m_view.object());
86 if (m_nativeQtWindow.isValid())
87 return reinterpret_cast<WId>(m_nativeQtWindow.object());
88 return 0L;
89}
90
91void QAndroidPlatformForeignWindow::addViewToWindow()
92{
93 if (isEmbeddingContainer())
94 return;
95
96 m_nativeQtWindow.callMethod<void>("setNativeView", m_view);
97 m_nativeViewInserted = true;
98}
99
100QT_END_NAMESPACE
Combined button and popup list for selecting options.