1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2010.
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
32 #include <com/sun/star/accessibility/AccessibleRole.hpp>
33 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
34 
35 #include "AccFrameEventListener.hxx"
36 #include "AccObjectManagerAgent.hxx"
37 #include "unomsaaevent.hxx"
38 
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::accessibility;
41 
42 #include <vcl/window.hxx>
43 #include <toolkit/awt/Vclxwindow.hxx>
44 
45 #ifndef _SV_SYSDATA_HXX
46 #if defined( WIN ) || defined( WNT ) || defined( OS2 )
47 typedef sal_Int32 HWND;
48 typedef sal_Int32 HMENU;
49 typedef sal_Int32 HDC;
50 typedef void *PVOID;
51 typedef PVOID HANDLE;
52 typedef HANDLE HFONT;
53 #endif
54 #include <vcl/sysdata.hxx>
55 #endif
56 
57 
58 AccFrameEventListener::AccFrameEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
59         :AccEventListener(pAcc, Agent)
60 {
61 }
62 
63 AccFrameEventListener::~AccFrameEventListener()
64 {
65 }
66 
67 /**
68  *	Uno's event notifier when event is captured
69  *	@param AccessibleEventObject	the event object which contains information about event
70  */
71 void  AccFrameEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
72 throw (::com::sun::star::uno::RuntimeException)
73 {
74     switch (aEvent.EventId)
75     {
76     case AccessibleEventId::CHILD:
77         handleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
78         break;
79     case AccessibleEventId::VISIBLE_DATA_CHANGED:
80         handleVisibleDataChangedEvent();
81         break;
82     case AccessibleEventId::BOUNDRECT_CHANGED:
83         handleBoundrectChangedEvent();
84         break;
85     default:
86         AccEventListener::notifyEvent(aEvent);
87         break;
88     }
89 }
90 
91 /**
92  *	handle the VISIBLE_DATA_CHANGED event
93  */
94 void AccFrameEventListener::handleVisibleDataChangedEvent()
95 {
96     AccEventListener::handleVisibleDataChangedEvent();
97 }
98 
99 /**
100  *	handle the BOUNDRECT_CHANGED event
101  */
102 void AccFrameEventListener::handleBoundrectChangedEvent()
103 {
104     AccEventListener::handleBoundrectChangedEvent();
105 }
106 
107 /**
108  *	handle the CHILD event
109  *  @param	oldValue	the child to be deleted
110  *  @param	newValue	the child to be added
111  */
112 void AccFrameEventListener::handleChildChangedEvent(Any oldValue, Any newValue)
113 {
114     Reference< XAccessible > xChild;
115     if( newValue >>= xChild)
116     {
117         //create a new child
118         if(xChild.is())
119         {
120             XAccessible* pAcc = xChild.get();
121 
122             VCLXWindow* pvclwindow = (VCLXWindow*)pAccessible;
123             Window* window = pvclwindow->GetWindow();
124             const SystemEnvData* systemdata=window->GetSystemData();
125 
126             //add this child
127             pAgent->InsertAccObj( pAcc,pAccessible,(HWND)systemdata->hWnd);
128             //add all oldValue's existing children
129             pAgent->InsertChildrenAccObj(pAcc);
130             pAgent->NotifyAccEvent(UM_EVENT_CHILD_ADDED, pAcc);
131         }
132         else
133         {}
134     }
135     else if (oldValue >>= xChild)
136     {
137         //delete a existing child
138         if(xChild.is())
139         {
140             XAccessible* pAcc = xChild.get();
141             pAgent->NotifyAccEvent(UM_EVENT_CHILD_REMOVED, pAcc);
142             //delete all oldValue's existing children
143             pAgent->DeleteChildrenAccObj( pAcc );
144             //delete this child
145             pAgent->DeleteAccObj( pAcc );
146         }
147         else
148         {}
149     }
150 
151 }
152 
153 /**
154  *	set the new state and fire the MSAA event
155  *	@param state	new state id
156  *	@param enable	true if state is set, false if state is unset
157  */
158 void AccFrameEventListener::setComponentState(short state, bool enable )
159 {
160     // only the following state can be fired state event.
161     switch (state)
162     {
163     case AccessibleStateType::ICONIFIED:
164         // no msaa state
165         break;
166     case AccessibleStateType::VISIBLE:
167         // UNO !VISIBLE == MSAA INVISIBLE
168         if( enable )
169             pAgent->IncreaseState( pAccessible, AccessibleStateType::VISIBLE );
170         else
171             pAgent->DecreaseState( pAccessible, AccessibleStateType::VISIBLE );
172         break;
173     case AccessibleStateType::ACTIVE:
174         // Only frames should be active
175         // no msaa state mapping
176         break;
177     default:
178         break;
179     }
180 }
181