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 .
21 #include <sal/log.hxx>
22 #include <vcl/window.hxx>
23 #include <toolkit/awt/vclxwindow.hxx>
25 #include <vcl/accessibility/vclxaccessiblecomponent.hxx>
26 #include <vcl/sysdata.hxx>
27 #include <vcl/svapp.hxx>
29 #include <AccTopWindowListener.hxx>
30 #include <unomsaaevent.hxx>
32 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 using namespace com::sun::star::uno
;
37 * For the new opened window, generate all the UNO accessible's object, COM object and add
38 * accessible listener to monitor all these objects.
39 * @param pWindow the new opened window
41 void AccTopWindowListener::HandleWindowOpened(vcl::Window
* pWindow
)
45 const SystemEnvData
* pSystemData
= pWindow
->GetSystemData();
49 Reference
<css::accessibility::XAccessible
> xAccessible
= pWindow
->GetAccessible();
50 if (!xAccessible
.is())
53 Reference
<css::accessibility::XAccessibleContext
> xContext
= xAccessible
->getAccessibleContext();
58 m_aAccObjectManager
.SaveTopWindowHandle(pSystemData
->hWnd
, xAccessible
.get());
60 AddAllListeners(xAccessible
.get(), nullptr, pSystemData
->hWnd
);
62 if (pWindow
->GetStyle() & WB_MOVEABLE
)
63 m_aAccObjectManager
.IncreaseState(xAccessible
.get(), static_cast<unsigned short>(-1) /* U_MOVEBLE */ );
65 short role
= xContext
->getAccessibleRole();
67 if (role
== css::accessibility::AccessibleRole::POPUP_MENU
||
68 role
== css::accessibility::AccessibleRole::MENU
)
70 m_aAccObjectManager
.NotifyAccEvent(xAccessible
.get(), UnoMSAAEvent::MENUPOPUPSTART
);
73 if (role
== css::accessibility::AccessibleRole::FRAME
||
74 role
== css::accessibility::AccessibleRole::DIALOG
||
75 role
== css::accessibility::AccessibleRole::WINDOW
||
76 role
== css::accessibility::AccessibleRole::ALERT
)
78 m_aAccObjectManager
.NotifyAccEvent(xAccessible
.get(), UnoMSAAEvent::SHOW
);
82 AccTopWindowListener::AccTopWindowListener()
83 : m_aAccObjectManager()
87 AccTopWindowListener::~AccTopWindowListener()
92 * It is invoked when a new window is opened, the source of this EventObject is the window
94 void AccTopWindowListener::windowOpened( const css::lang::EventObject
& e
)
96 SAL_INFO( "iacc2", "windowOpened triggered" );
103 VCLXWindow
* pVCLXWindow
= dynamic_cast<VCLXWindow
*>(e
.Source
.get());
104 assert(pVCLXWindow
&& "Window is not a VCLXWindow");
106 vcl::Window
* pWindow
= pVCLXWindow
->GetWindow();
109 HandleWindowOpened(pWindow
);
113 * Add the accessible event listener to object and all its children objects.
114 * @param pAccessible the accessible object
115 * @param pParentXAcc the parent of current accessible object
116 * @param pWND the handle of top window which current object resides
118 void AccTopWindowListener::AddAllListeners(css::accessibility::XAccessible
* pAccessible
, css::accessibility::XAccessible
* pParentXAcc
, HWND pWND
)
120 Reference
<css::accessibility::XAccessibleContext
> xContext
= pAccessible
->getAccessibleContext();
126 m_aAccObjectManager
.InsertAccObj(pAccessible
, pParentXAcc
, pWND
);
128 if (!AccObjectWinManager::IsContainer(pAccessible
))
134 short role
= xContext
->getAccessibleRole();
135 if(css::accessibility::AccessibleRole::DOCUMENT
== role
||
136 css::accessibility::AccessibleRole::DOCUMENT_PRESENTATION
== role
||
137 css::accessibility::AccessibleRole::DOCUMENT_SPREADSHEET
== role
||
138 css::accessibility::AccessibleRole::DOCUMENT_TEXT
== role
)
140 if(AccObjectWinManager::IsStateManageDescendant(pAccessible
))
146 sal_Int64 nCount
= xContext
->getAccessibleChildCount();
147 for (sal_Int64 i
= 0; i
< nCount
; i
++)
149 Reference
<css::accessibility::XAccessible
> xAccessible
150 = xContext
->getAccessibleChild(i
);
152 if (xAccessible
.is())
153 AddAllListeners(xAccessible
.get(), pAccessible
, pWND
);
157 void AccTopWindowListener::windowClosing( const css::lang::EventObject
& )
159 SAL_INFO( "iacc2", "windowClosing triggered" );
163 * Invoke this method when the top window is closed, remove all the objects and its children
164 * from current manager's cache, and remove the COM object and the accessible event listener
165 * assigned to the accessible objects.
167 void AccTopWindowListener::windowClosed( const css::lang::EventObject
& e
)
169 SAL_INFO( "iacc2", "windowClosed triggered" );
174 VCLXWindow
* pVCLXWindow
= dynamic_cast<VCLXWindow
*>(e
.Source
.get());
175 assert(pVCLXWindow
&& "Window is not a VCLXWindow");
177 vcl::Window
* pWindow
= pVCLXWindow
->GetWindow();
180 Reference
<css::accessibility::XAccessible
> xAccessible
= pWindow
->GetAccessible();
181 if (!xAccessible
.is())
184 Reference
<css::accessibility::XAccessibleContext
> xContext
= xAccessible
->getAccessibleContext();
188 short role
= xContext
->getAccessibleRole();
189 if (role
== css::accessibility::AccessibleRole::POPUP_MENU
||
190 role
== css::accessibility::AccessibleRole::MENU
)
192 m_aAccObjectManager
.NotifyAccEvent(xAccessible
.get(), UnoMSAAEvent::MENUPOPUPEND
);
195 m_aAccObjectManager
.DeleteChildrenAccObj(xAccessible
.get());
196 if( role
!= css::accessibility::AccessibleRole::POPUP_MENU
)
197 m_aAccObjectManager
.DeleteAccObj(xAccessible
.get());
200 void AccTopWindowListener::windowMinimized( const css::lang::EventObject
& )
204 void AccTopWindowListener::windowNormalized( const css::lang::EventObject
& )
208 void AccTopWindowListener::windowActivated( const css::lang::EventObject
& )
212 void AccTopWindowListener::windowDeactivated( const css::lang::EventObject
& )
216 void AccTopWindowListener::disposing( const css::lang::EventObject
& )
220 sal_Int64
AccTopWindowListener::GetMSComPtr(
221 sal_Int64 hWnd
, sal_Int64 lParam
, sal_Int64 wParam
)
223 return m_aAccObjectManager
.Get_ToATInterface(hWnd
, lParam
, wParam
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */