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 #ifndef __ACCOBJECTWINMANAGER_HXX
23 #define __ACCOBJECTWINMANAGER_HXX
24 
25 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLE_HPP_
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #endif
28 #include <map>
29 #include <windows.h>
30 #include <vos/mutex.hxx>
31 #include <vcl/dllapi.h>
32 #include "ResIDGenerator.hxx"
33 #include "UAccCOM2.h"
34 
35 class ResIDGenerator;
36 class AccObjectManagerAgent;
37 class AccEventListener;
38 class AccObject;
39 
40 /*******************************************************************
41 AccObjectWinManager complete the functions:
42 1. Insert, delete,query,update Acc objects
43 2. Create, delete,fire AccEventLister, the lifecycle of AccEventListener is as same as
44    Acc Object
45  3.Return COM interface for AT,by the call back in salframe
46  4.Pass accessible information to Acc objects
47  *******************************************************************/
48 class AccObjectWinManager
49 {
50     friend class AccObjectManagerAgent;
51 
52 private:
53     struct ltstr1
54     {
55         bool operator()(const void*  s1, const void*  s2) const
56         {
57             return long(s1)<long(s2);
58         }
59     };
60     struct ltstr2
61     {
62         bool operator()(const HWND  s1, const HWND  s2) const
63         {
64             return long(s1)<long(s2);
65         }
66     };
67     struct ltstr3
68     {
69         bool operator()(const long  s1, const long  s2) const
70         {
71             return long(s1)<long(s2);
72         }
73     };
74     typedef std::map< void*, AccObject,ltstr1 > XIdToAccObjHash;
75     typedef std::map< HWND,void*,ltstr2 > XHWNDToXAccHash;
76     typedef std::map< const long, AccObject*,ltstr3 > XResIdToAccObjHash;
77 
78     typedef std::map< const long, com::sun::star::accessibility::XAccessible*,ltstr3 > XHWNDToDocumentHash;
79 
80 
81     //XAccessible to AccObject
82     XIdToAccObjHash  XIdAccList;
83 
84     //HWND to All XAccessible pointer
85     XHWNDToXAccHash  HwndXAcc;
86 
87     //id_Child to AccObject
88     XResIdToAccObjHash XResIdAccList;
89 
90     //for file name support
91     XHWNDToDocumentHash XHWNDDocList;
92 
93     com::sun::star::accessibility::XAccessible* oldFocus;
94 
95     AccObjectManagerAgent*	 pAgent;
96     static AccObjectWinManager* me;
97     ResIDGenerator ResIdGen;
98     mutable ::vos::OMutex aDeleteMutex;
99     mutable ::vos::OMutex aNotifyMutex;
100     mutable ::vos::OMutex maATInterfaceMutex;
101 
102     AccObjectWinManager(AccObjectManagerAgent* Agent=NULL);
103 	bool m_bBridgeRegistered;
104 
105 private:
106     long ImpleGenerateResID();
107     AccObject* GetAccObjByXAcc( com::sun::star::accessibility::XAccessible* pXAcc);
108 
109     com::sun::star::accessibility::XAccessible* GetXAccByAccObj(AccObject* pAccObj);
110 
111     AccObject* GetTopWindowAccObj(HWND hWnd);
112 
113     com::sun::star::accessibility::XAccessible* GetAccDocByHWND( long pWnd );
114 
115     void       DeleteAccListener( AccObject* pAccObj );
116     void       InsertAccChildNode(AccObject* pCurObj,AccObject* pParentObj,HWND pWnd);
117     void       DeleteAccChildNode(AccObject* pChild);
118     void       DeleteFromHwndXAcc(com::sun::star::accessibility::XAccessible* pXAcc );
119     int  UpdateAccSelection(com::sun::star::accessibility::XAccessible* pXAcc);
120 
121     AccEventListener* createAccEventListener(com::sun::star::accessibility::XAccessible* pXAcc, AccObjectManagerAgent* Agent);
122 public:
123     virtual ~AccObjectWinManager();
124     sal_Bool InsertAccObj( com::sun::star::accessibility::XAccessible* pXAcc,com::sun::star::accessibility::XAccessible* pParentXAcc,HWND pWnd);
125     sal_Bool InsertChildrenAccObj( com::sun::star::accessibility::XAccessible* pXAcc,HWND pWnd=0);
126     void DeleteAccObj( com::sun::star::accessibility::XAccessible* pXAcc );
127     void DeleteChildrenAccObj(com::sun::star::accessibility::XAccessible* pAccObj);
128 
129     static  AccObjectWinManager* CreateAccObjectWinManagerInstance(AccObjectManagerAgent* Agent);
130 
131     sal_Bool NotifyAccEvent( com::sun::star::accessibility::XAccessible* pXAcc,short state = 0 );
132 
133     long Get_ToATInterface( HWND hWnd, long lParam, long wParam);
134 
135     void  DecreaseState( com::sun::star::accessibility::XAccessible* pXAcc,unsigned short pState );
136     void  IncreaseState( com::sun::star::accessibility::XAccessible* pXAcc,unsigned short pState );
137     void  UpdateState( com::sun::star::accessibility::XAccessible* pXAcc );
138     void  SetLocation( com::sun::star::accessibility::XAccessible* pXAcc,
139                        long Top = 0,long left = 0,long width = 0,long height = 0);
140 
141     void  SetValue( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any pAny );
142     void  UpdateValue( com::sun::star::accessibility::XAccessible* pXAcc );
143 
144     void  SetAccName( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any newName);
145     void  UpdateAccName( com::sun::star::accessibility::XAccessible* pXAcc );
146 
147     void  SetDescription( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any newDesc );
148     void UpdateDescription( com::sun::star::accessibility::XAccessible* pXAcc );
149 
150     void  SetRole( com::sun::star::accessibility::XAccessible* pXAcc, long Role );
151 
152     void  UpdateAccFocus( com::sun::star::accessibility::XAccessible* newFocus );
153     void  UpdateAction( com::sun::star::accessibility::XAccessible* pXAcc );
154 
155     sal_Bool IsContainer( com::sun::star::accessibility::XAccessible* pAccessible );
156 
157     IMAccessible* GetIMAccByXAcc( com::sun::star::accessibility::XAccessible* pXAcc );
158     IMAccessible* GetIAccessibleFromResID(long resID);
159 
160     void NotifyDestroy( com::sun::star::accessibility::XAccessible* pXAcc );
161     com::sun::star::accessibility::XAccessible* GetParentXAccessible( com::sun::star::accessibility::XAccessible* pXAcc );
162     short GetParentRole( com::sun::star::accessibility::XAccessible* pXAcc );
163 
164     void SaveTopWindowHandle(HWND hWnd, com::sun::star::accessibility::XAccessible* pXAcc);
165 
166     void UpdateChildState(com::sun::star::accessibility::XAccessible* pXAcc);
167 
168     bool IsSpecialToolboItem(com::sun::star::accessibility::XAccessible* pXAcc);
169 
170     short GetRole(com::sun::star::accessibility::XAccessible* pXAcc);
171 
172     com::sun::star::accessibility::XAccessible* GetAccDocByAccTopWin( com::sun::star::accessibility::XAccessible* pXAcc );
173     bool IsTopWinAcc( com::sun::star::accessibility::XAccessible* pXAcc );
174 
175     bool IsStateManageDescendant(com::sun::star::accessibility::XAccessible* pAccessible);
176 
177 };
178 #endif
179