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     {
operator ()AccObjectWinManager::ltstr155         bool operator()(const void*  s1, const void*  s2) const
56         {
57             return long(s1)<long(s2);
58         }
59     };
60     struct ltstr2
61     {
operator ()AccObjectWinManager::ltstr262         bool operator()(const HWND  s1, const HWND  s2) const
63         {
64             return long(s1)<long(s2);
65         }
66     };
67     struct ltstr3
68     {
operator ()AccObjectWinManager::ltstr369         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 
104 private:
105     long ImpleGenerateResID();
106     AccObject* GetAccObjByXAcc( com::sun::star::accessibility::XAccessible* pXAcc);
107 
108     com::sun::star::accessibility::XAccessible* GetXAccByAccObj(AccObject* pAccObj);
109 
110     AccObject* GetTopWindowAccObj(HWND hWnd);
111 
112     com::sun::star::accessibility::XAccessible* GetAccDocByHWND( long pWnd );
113 
114     void       DeleteAccListener( AccObject* pAccObj );
115     void       InsertAccChildNode(AccObject* pCurObj,AccObject* pParentObj,HWND pWnd);
116     void       DeleteAccChildNode(AccObject* pChild);
117     void       DeleteFromHwndXAcc(com::sun::star::accessibility::XAccessible* pXAcc );
118     int  UpdateAccSelection(com::sun::star::accessibility::XAccessible* pXAcc);
119 
120     AccEventListener* createAccEventListener(com::sun::star::accessibility::XAccessible* pXAcc, AccObjectManagerAgent* Agent);
121 public:
122     virtual ~AccObjectWinManager();
123     sal_Bool InsertAccObj( com::sun::star::accessibility::XAccessible* pXAcc,com::sun::star::accessibility::XAccessible* pParentXAcc,HWND pWnd);
124     sal_Bool InsertChildrenAccObj( com::sun::star::accessibility::XAccessible* pXAcc,HWND pWnd=0);
125     void DeleteAccObj( com::sun::star::accessibility::XAccessible* pXAcc );
126     void DeleteChildrenAccObj(com::sun::star::accessibility::XAccessible* pAccObj);
127 
128     static  AccObjectWinManager* CreateAccObjectWinManagerInstance(AccObjectManagerAgent* Agent);
129 
130     sal_Bool NotifyAccEvent( com::sun::star::accessibility::XAccessible* pXAcc,short state = 0 );
131 
132     long Get_ToATInterface( HWND hWnd, long lParam, long wParam);
133 
134     void  DecreaseState( com::sun::star::accessibility::XAccessible* pXAcc,unsigned short pState );
135     void  IncreaseState( com::sun::star::accessibility::XAccessible* pXAcc,unsigned short pState );
136     void  UpdateState( com::sun::star::accessibility::XAccessible* pXAcc );
137     void  SetLocation( com::sun::star::accessibility::XAccessible* pXAcc,
138                        long Top = 0,long left = 0,long width = 0,long height = 0);
139 
140     void  SetValue( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any pAny );
141     void  UpdateValue( com::sun::star::accessibility::XAccessible* pXAcc );
142 
143     void  SetAccName( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any newName);
144     void  UpdateAccName( com::sun::star::accessibility::XAccessible* pXAcc );
145 
146     void  SetDescription( com::sun::star::accessibility::XAccessible* pXAcc, com::sun::star::uno::Any newDesc );
147     void UpdateDescription( com::sun::star::accessibility::XAccessible* pXAcc );
148 
149     void  SetRole( com::sun::star::accessibility::XAccessible* pXAcc, long Role );
150 
151     void  UpdateAccFocus( com::sun::star::accessibility::XAccessible* newFocus );
152     void  UpdateAction( com::sun::star::accessibility::XAccessible* pXAcc );
153 
154     sal_Bool IsContainer( com::sun::star::accessibility::XAccessible* pAccessible );
155 
156     IMAccessible* GetIMAccByXAcc( com::sun::star::accessibility::XAccessible* pXAcc );
157     IMAccessible* GetIAccessibleFromResID(long resID);
158 
159     void NotifyDestroy( com::sun::star::accessibility::XAccessible* pXAcc );
160     com::sun::star::accessibility::XAccessible* GetParentXAccessible( com::sun::star::accessibility::XAccessible* pXAcc );
161     short GetParentRole( com::sun::star::accessibility::XAccessible* pXAcc );
162 
163     void SaveTopWindowHandle(HWND hWnd, com::sun::star::accessibility::XAccessible* pXAcc);
164 
165     void UpdateChildState(com::sun::star::accessibility::XAccessible* pXAcc);
166 
167     bool IsSpecialToolboItem(com::sun::star::accessibility::XAccessible* pXAcc);
168 
169     short GetRole(com::sun::star::accessibility::XAccessible* pXAcc);
170 
171     com::sun::star::accessibility::XAccessible* GetAccDocByAccTopWin( com::sun::star::accessibility::XAccessible* pXAcc );
172     bool IsTopWinAcc( com::sun::star::accessibility::XAccessible* pXAcc );
173 
174     bool IsStateManageDescendant(com::sun::star::accessibility::XAccessible* pAccessible);
175 
176 };
177 #endif
178