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