1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2019 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the plugins of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #include <QtGui/qtguiglobal.h> 41 #if QT_CONFIG(accessibility) 42 43 #include "qwindowsuiawindowprovider.h" 44 #include "qwindowsuiautils.h" 45 #include "qwindowscontext.h" 46 47 #include <QtGui/qaccessible.h> 48 #include <QtGui/private/qwindow_p.h> 49 #include <QtCore/qloggingcategory.h> 50 #include <QtCore/qstring.h> 51 52 QT_BEGIN_NAMESPACE 53 54 using namespace QWindowsUiAutomation; 55 56 QWindowsUiaWindowProvider(QAccessible::Id id)57QWindowsUiaWindowProvider::QWindowsUiaWindowProvider(QAccessible::Id id) : 58 QWindowsUiaBaseProvider(id) 59 { 60 } 61 ~QWindowsUiaWindowProvider()62QWindowsUiaWindowProvider::~QWindowsUiaWindowProvider() 63 { 64 } 65 SetVisualState(WindowVisualState state)66HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::SetVisualState(WindowVisualState state) { 67 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 68 QAccessibleInterface *accessible = accessibleInterface(); 69 if (!accessible || !accessible->window()) 70 return UIA_E_ELEMENTNOTAVAILABLE; 71 auto window = accessible->window(); 72 switch (state) { 73 case WindowVisualState_Normal: 74 window->showNormal(); 75 break; 76 case WindowVisualState_Maximized: 77 window->showMaximized(); 78 break; 79 case WindowVisualState_Minimized: 80 window->showMinimized(); 81 break; 82 } 83 return S_OK; 84 } 85 Close()86HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::Close() { 87 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 88 QAccessibleInterface *accessible = accessibleInterface(); 89 if (!accessible || !accessible->window()) 90 return UIA_E_ELEMENTNOTAVAILABLE; 91 accessible->window()->close(); 92 return S_OK; 93 } 94 WaitForInputIdle(int milliseconds,__RPC__out BOOL * pRetVal)95HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::WaitForInputIdle(int milliseconds, __RPC__out BOOL *pRetVal) { 96 Q_UNUSED(milliseconds); 97 Q_UNUSED(pRetVal); 98 return UIA_E_NOTSUPPORTED; 99 } 100 get_CanMaximize(__RPC__out BOOL * pRetVal)101HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_CanMaximize(__RPC__out BOOL *pRetVal) { 102 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 103 QAccessibleInterface *accessible = accessibleInterface(); 104 if (!accessible || !accessible->window()) 105 return UIA_E_ELEMENTNOTAVAILABLE; 106 107 auto window = accessible->window(); 108 auto flags = window->flags(); 109 110 *pRetVal = (!(flags & Qt::MSWindowsFixedSizeDialogHint) 111 && (flags & Qt::WindowMaximizeButtonHint) 112 && ((flags & Qt::CustomizeWindowHint) 113 || window->maximumSize() == QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX))); 114 return S_OK; 115 } 116 get_CanMinimize(__RPC__out BOOL * pRetVal)117HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_CanMinimize(__RPC__out BOOL *pRetVal) { 118 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 119 QAccessibleInterface *accessible = accessibleInterface(); 120 if (!accessible || !accessible->window()) 121 return UIA_E_ELEMENTNOTAVAILABLE; 122 *pRetVal = accessible->window()->flags() & Qt::WindowMinimizeButtonHint; 123 return S_OK; 124 } 125 get_IsModal(__RPC__out BOOL * pRetVal)126HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_IsModal(__RPC__out BOOL *pRetVal) { 127 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 128 QAccessibleInterface *accessible = accessibleInterface(); 129 if (!accessible || !accessible->window()) 130 return UIA_E_ELEMENTNOTAVAILABLE; 131 *pRetVal = accessible->window()->isModal(); 132 return S_OK; 133 } 134 get_WindowVisualState(__RPC__out enum WindowVisualState * pRetVal)135HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_WindowVisualState(__RPC__out enum WindowVisualState *pRetVal) { 136 qCDebug(lcQpaUiAutomation) << __FUNCTION__; 137 QAccessibleInterface *accessible = accessibleInterface(); 138 if (!accessible || !accessible->window()) 139 return UIA_E_ELEMENTNOTAVAILABLE; 140 auto visibility = accessible->window()->visibility(); 141 switch (visibility) { 142 case QWindow::FullScreen: 143 case QWindow::Maximized: 144 *pRetVal = WindowVisualState_Maximized; 145 break; 146 case QWindow::Minimized: 147 *pRetVal = WindowVisualState_Minimized; 148 break; 149 default: 150 *pRetVal = WindowVisualState_Normal; 151 break; 152 } 153 return S_OK; 154 } 155 get_WindowInteractionState(__RPC__out enum WindowInteractionState * pRetVal)156HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_WindowInteractionState(__RPC__out enum WindowInteractionState *pRetVal) { 157 Q_UNUSED(pRetVal); 158 return UIA_E_NOTSUPPORTED; 159 } 160 get_IsTopmost(__RPC__out BOOL * pRetVal)161HRESULT STDMETHODCALLTYPE QWindowsUiaWindowProvider::get_IsTopmost(__RPC__out BOOL *pRetVal) { 162 Q_UNUSED(pRetVal); 163 return UIA_E_NOTSUPPORTED; 164 } 165 166 QT_END_NAMESPACE 167 168 #endif // QT_CONFIG(accessibility) 169