1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <com/sun/star/accessibility/XAccessible.hpp>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
27 
28 #include "AccFrameEventListener.hxx"
29 #include "AccObjectManagerAgent.hxx"
30 #include "unomsaaevent.hxx"
31 
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::accessibility;
34 
35 #include <vcl/window.hxx>
36 #include <toolkit/awt/Vclxwindow.hxx>
37 
38 #ifndef _SV_SYSDATA_HXX
39 #if defined( WIN ) || defined( WNT ) || defined( OS2 )
40 typedef sal_Int32 HWND;
41 typedef sal_Int32 HMENU;
42 typedef sal_Int32 HDC;
43 typedef void *PVOID;
44 typedef PVOID HANDLE;
45 typedef HANDLE HFONT;
46 #endif
47 #include <vcl/sysdata.hxx>
48 #endif
49 
50 
AccFrameEventListener(com::sun::star::accessibility::XAccessible * pAcc,AccObjectManagerAgent * Agent)51 AccFrameEventListener::AccFrameEventListener(com::sun::star::accessibility::XAccessible* pAcc, AccObjectManagerAgent* Agent)
52         :AccEventListener(pAcc, Agent)
53 {
54 }
55 
~AccFrameEventListener()56 AccFrameEventListener::~AccFrameEventListener()
57 {
58 }
59 
60 /**
61  *	Uno's event notifier when event is captured
62  *	@param AccessibleEventObject	the event object which contains information about event
63  */
notifyEvent(const::com::sun::star::accessibility::AccessibleEventObject & aEvent)64 void  AccFrameEventListener::notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
65 throw (::com::sun::star::uno::RuntimeException)
66 {
67     switch (aEvent.EventId)
68     {
69     case AccessibleEventId::CHILD:
70         handleChildChangedEvent(aEvent.OldValue, aEvent.NewValue);
71         break;
72     case AccessibleEventId::VISIBLE_DATA_CHANGED:
73         handleVisibleDataChangedEvent();
74         break;
75     case AccessibleEventId::BOUNDRECT_CHANGED:
76         handleBoundrectChangedEvent();
77         break;
78     default:
79         AccEventListener::notifyEvent(aEvent);
80         break;
81     }
82 }
83 
84 /**
85  *	handle the VISIBLE_DATA_CHANGED event
86  */
handleVisibleDataChangedEvent()87 void AccFrameEventListener::handleVisibleDataChangedEvent()
88 {
89     AccEventListener::handleVisibleDataChangedEvent();
90 }
91 
92 /**
93  *	handle the BOUNDRECT_CHANGED event
94  */
handleBoundrectChangedEvent()95 void AccFrameEventListener::handleBoundrectChangedEvent()
96 {
97     AccEventListener::handleBoundrectChangedEvent();
98 }
99 
100 /**
101  *	handle the CHILD event
102  *  @param	oldValue	the child to be deleted
103  *  @param	newValue	the child to be added
104  */
handleChildChangedEvent(Any oldValue,Any newValue)105 void AccFrameEventListener::handleChildChangedEvent(Any oldValue, Any newValue)
106 {
107     Reference< XAccessible > xChild;
108     if( newValue >>= xChild)
109     {
110         //create a new child
111         if(xChild.is())
112         {
113             XAccessible* pAcc = xChild.get();
114 
115             VCLXWindow* pvclwindow = (VCLXWindow*)pAccessible;
116             Window* window = pvclwindow->GetWindow();
117             const SystemEnvData* systemdata=window->GetSystemData();
118 
119             //add this child
120             pAgent->InsertAccObj( pAcc,pAccessible,(HWND)systemdata->hWnd);
121             //add all oldValue's existing children
122             pAgent->InsertChildrenAccObj(pAcc);
123             pAgent->NotifyAccEvent(UM_EVENT_CHILD_ADDED, pAcc);
124         }
125         else
126         {}
127     }
128     else if (oldValue >>= xChild)
129     {
130         //delete a existing child
131         if(xChild.is())
132         {
133             XAccessible* pAcc = xChild.get();
134             pAgent->NotifyAccEvent(UM_EVENT_CHILD_REMOVED, pAcc);
135             //delete all oldValue's existing children
136             pAgent->DeleteChildrenAccObj( pAcc );
137             //delete this child
138             pAgent->DeleteAccObj( pAcc );
139         }
140         else
141         {}
142     }
143 
144 }
145 
146 /**
147  *	set the new state and fire the MSAA event
148  *	@param state	new state id
149  *	@param enable	true if state is set, false if state is unset
150  */
setComponentState(short state,bool enable)151 void AccFrameEventListener::setComponentState(short state, bool enable )
152 {
153     // only the following state can be fired state event.
154     switch (state)
155     {
156     case AccessibleStateType::ICONIFIED:
157         // no msaa state
158         break;
159     case AccessibleStateType::VISIBLE:
160         // UNO !VISIBLE == MSAA INVISIBLE
161         if( enable )
162             pAgent->IncreaseState( pAccessible, AccessibleStateType::VISIBLE );
163         else
164             pAgent->DecreaseState( pAccessible, AccessibleStateType::VISIBLE );
165         break;
166     case AccessibleStateType::ACTIVE:
167         // Only frames should be active
168         // no msaa state mapping
169         break;
170     default:
171         break;
172     }
173 }
174