fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / winaccessibility / source / service / AccTopWindowListener.cxx
blobe18c0c3463520a78a67d7f4133343f5316da4097
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cppuhelper/bootstrap.hxx>
21 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <vcl/window.hxx>
24 #include <toolkit/awt/Vclxwindow.hxx>
26 #include <vcl/sysdata.hxx>
27 #include <vcl/svapp.hxx>
29 #include "AccTopWindowListener.hxx"
30 #include "unomsaaevent.hxx"
32 #include <com/sun/star/awt/XExtendedToolkit.hpp>
33 #include <com/sun/star/uno/XInterface.hpp>
34 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
35 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
36 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::bridge;
43 using namespace com::sun::star::awt;
44 using namespace cppu;
46 /**
47 * For the new opened window, generate all the UNO accessible's object, COM object and add
48 * accessible listener to monitor all these objects.
49 * @param pAccessible the accessible of the new opened window
51 void AccTopWindowListener::HandleWindowOpened( com::sun::star::accessibility::XAccessible* pAccessible )
53 //get SystemData from window
54 VCLXWindow* pvclwindow = (VCLXWindow*)pAccessible;
55 vcl::Window* window = pvclwindow->GetWindow();
56 // The SalFrame of window may be destructed at this time
57 const SystemEnvData* systemdata = NULL;
58 try
60 systemdata = window->GetSystemData();
62 catch(...)
64 systemdata = NULL;
66 Reference<com::sun::star::accessibility::XAccessibleContext> xContext(pAccessible->getAccessibleContext(),UNO_QUERY);
67 if(!xContext.is())
68 return;
70 com::sun::star::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
71 //Only AccessibleContext exist, add all listeners
72 if(pAccessibleContext != NULL && systemdata != NULL)
74 accManagerAgent.SaveTopWindowHandle(
75 reinterpret_cast<sal_Int64>(systemdata->hWnd), pAccessible);
77 AddAllListeners(pAccessible,NULL,(HWND)systemdata->hWnd);
79 if( window->GetStyle() & WB_MOVEABLE )
80 accManagerAgent.IncreaseState( pAccessible, (unsigned short) -1 /* U_MOVEBLE */ );
82 short role = pAccessibleContext->getAccessibleRole();
84 if (role == com::sun::star::accessibility::AccessibleRole::POPUP_MENU ||
85 role == com::sun::star::accessibility::AccessibleRole::MENU )
87 accManagerAgent.NotifyAccEvent(UM_EVENT_MENUPOPUPSTART, pAccessible);
90 if (role == com::sun::star::accessibility::AccessibleRole::FRAME ||
91 role == com::sun::star::accessibility::AccessibleRole::DIALOG ||
92 role == com::sun::star::accessibility::AccessibleRole::WINDOW ||
93 role == com::sun::star::accessibility::AccessibleRole::ALERT)
95 accManagerAgent.NotifyAccEvent(UM_EVENT_SHOW, pAccessible);
100 AccTopWindowListener::AccTopWindowListener()
101 : accManagerAgent()
105 AccTopWindowListener::~AccTopWindowListener()
110 * It is invoked when a new window is opened, the source of this EventObject is the window
112 void AccTopWindowListener::windowOpened( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException)
114 SAL_INFO( "iacc2", "windowOpened triggered" );
116 if ( !e.Source.is())
117 return;
119 Reference< com::sun::star::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY );
120 com::sun::star::accessibility::XAccessible* pAccessible = xAccessible.get();
121 if ( !pAccessible )
122 return;
124 SolarMutexGuard g;
126 HandleWindowOpened( pAccessible );
130 * Add the accessible event listener to object and all its children objects.
131 * @param pAccessible the accessible object
132 * @param pParentXAcc the parent of current accessible object
133 * @param pWND the handle of top window which current object resides
135 void AccTopWindowListener::AddAllListeners(com::sun::star::accessibility::XAccessible* pAccessible, com::sun::star::accessibility::XAccessible* pParentXAcc, HWND pWND)
137 Reference<com::sun::star::accessibility::XAccessibleContext> xContext(pAccessible->getAccessibleContext(),UNO_QUERY);
138 if(!xContext.is())
140 return;
142 com::sun::star::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
143 if(pAccessibleContext == NULL)
145 return;
148 accManagerAgent.InsertAccObj(pAccessible, pParentXAcc,
149 reinterpret_cast<sal_Int64>(pWND));
151 if (!accManagerAgent.IsContainer(pAccessible))
153 return;
157 short role = pAccessibleContext->getAccessibleRole();
158 if(com::sun::star::accessibility::AccessibleRole::DOCUMENT == role ||
159 com::sun::star::accessibility::AccessibleRole::DOCUMENT_PRESENTATION == role ||
160 com::sun::star::accessibility::AccessibleRole::DOCUMENT_SPREADSHEET == role ||
161 com::sun::star::accessibility::AccessibleRole::DOCUMENT_TEXT == role)
163 if(accManagerAgent.IsStateManageDescendant(pAccessible))
165 return ;
170 int count = pAccessibleContext->getAccessibleChildCount();
171 for (int i=0;i<count;i++)
173 Reference<com::sun::star::accessibility::XAccessible> mxAccessible
174 = pAccessibleContext->getAccessibleChild(i);
176 com::sun::star::accessibility::XAccessible* mpAccessible = mxAccessible.get();
177 if(mpAccessible != NULL)
179 Reference<com::sun::star::accessibility::XAccessibleContext> mxAccessibleContext
180 = mpAccessible->getAccessibleContext();
181 com::sun::star::accessibility::XAccessibleContext* mpContext = mxAccessibleContext.get();
182 if(mpContext != NULL)
183 AddAllListeners( mpAccessible, pAccessible, pWND);
188 void AccTopWindowListener::windowClosing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
190 SAL_INFO( "iacc2", "windowClosing triggered" );
194 * Invoke this method when the top window is closed, remove all the objects and its children
195 * from current manager's cache, and remove the COM object and the accessible event listener
196 * assigned to the accessible objects.
198 void AccTopWindowListener::windowClosed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException)
200 SAL_INFO( "iacc2", "windowClosed triggered" );
202 if ( !e.Source.is())
203 return;
205 Reference< com::sun::star::accessibility::XAccessible > xAccessible ( e.Source, UNO_QUERY );
206 com::sun::star::accessibility::XAccessible* pAccessible = xAccessible.get();
207 if ( pAccessible == NULL)
208 return;
210 Reference<com::sun::star::accessibility::XAccessibleContext> xContext(pAccessible->getAccessibleContext(),UNO_QUERY);
211 if(!xContext.is())
213 return;
215 com::sun::star::accessibility::XAccessibleContext* pAccessibleContext = xContext.get();
217 short role = -1;
218 if(pAccessibleContext != NULL)
220 role = pAccessibleContext->getAccessibleRole();
222 if (role == com::sun::star::accessibility::AccessibleRole::POPUP_MENU ||
223 role == com::sun::star::accessibility::AccessibleRole::MENU)
225 accManagerAgent.NotifyAccEvent(UM_EVENT_MENUPOPUPEND, pAccessible);
230 accManagerAgent.DeleteChildrenAccObj( pAccessible );
231 if( role != com::sun::star::accessibility::AccessibleRole::POPUP_MENU )
232 accManagerAgent.DeleteAccObj( pAccessible );
236 void AccTopWindowListener::windowMinimized( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
240 void AccTopWindowListener::windowNormalized( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
244 void AccTopWindowListener::windowActivated( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
248 void AccTopWindowListener::windowDeactivated( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
252 void AccTopWindowListener::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
256 sal_Int64 AccTopWindowListener::GetMSComPtr(
257 sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
259 return accManagerAgent.Get_ToATInterface(hWnd, lParam, wParam);
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */