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 "stdafx.h"
23 #include "AccComponentBase.h"
24 #include <com/sun/star/accessibility/XAccessible.hpp>
25 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
26 #include "MAccessible.h"
27 
28 using namespace com::sun::star::accessibility;
29 using namespace com::sun::star::uno;
30 
31 //////////////////////////////////////////////////////////////////////
32 // Construction/Destruction
33 //////////////////////////////////////////////////////////////////////
34 
CAccComponentBase()35 CAccComponentBase::CAccComponentBase()
36 {}
37 
~CAccComponentBase()38 CAccComponentBase::~CAccComponentBase()
39 {}
40 
41 
42 /**
43  * Returns the location of the upper left corner of the object's bounding
44  * box relative to the parent.
45  *
46  * @param    Location    the upper left corner of the object's bounding box.
47  */
get_locationInParent(long * x,long * y)48 STDMETHODIMP CAccComponentBase::get_locationInParent(long *x, long *y)
49 {
50 
51 	CHECK_ENABLE_INF
52 
53     try
54     {
55         if (x == NULL || y == NULL)
56             return E_INVALIDARG;
57         // #CHECK XInterface#
58         if(!pRXComp.is())
59             return E_FAIL;
60 
61         const ::com::sun::star::awt::Point& pt = GetXInterface()->getLocation();
62         *x = pt.X;
63         *y = pt.Y;
64         return S_OK;
65     }
66     catch(...)
67     {
68         return E_FAIL;
69     }
70 }
71 
72 /**
73  * Returns the location of the upper left corner of the object's bounding
74  * box in screen.
75  *
76  * @param    Location    the upper left corner of the object's bounding
77  *                       box in screen coordinates.
78  */
get_locationOnScreen(long * x,long * y)79 STDMETHODIMP CAccComponentBase::get_locationOnScreen(long *x, long *y)
80 {
81 
82 	CHECK_ENABLE_INF
83 
84     try
85     {
86         if (x == NULL || y == NULL)
87             return E_INVALIDARG;
88         // #CHECK XInterface#
89         if(!pRXComp.is())
90             return E_FAIL;
91 
92         const ::com::sun::star::awt::Point& pt = GetXInterface()->getLocationOnScreen();
93         *x = pt.X;
94         *y = pt.Y;
95         return S_OK;
96 
97     }
98     catch(...)
99     {
100         return E_FAIL;
101     }
102 }
103 
104 /**
105  * Grabs the focus to this object.
106  *
107  * @param    success    the boolean result to be returned.
108  */
grabFocus(boolean * success)109 STDMETHODIMP CAccComponentBase::grabFocus(boolean * success)
110 {
111 
112 	CHECK_ENABLE_INF
113 
114     ENTER_PROTECTED_BLOCK
115 
116     if (success == NULL)
117         return E_INVALIDARG;
118     // #CHECK XInterface#
119     if(!pRXComp.is())
120     {
121         return E_FAIL;
122     }
123     GetXInterface()->grabFocus();
124     *success = TRUE;
125 
126     return S_OK;
127 
128     LEAVE_PROTECTED_BLOCK
129 }
130 
131 /**
132  * Returns the foreground color of this object.
133  *
134  * @param    Color    the color of foreground.
135  */
get_foreground(IA2Color * foreground)136 STDMETHODIMP CAccComponentBase::get_foreground(IA2Color * foreground)
137 {
138 
139 	CHECK_ENABLE_INF
140 
141     ENTER_PROTECTED_BLOCK
142 
143     if (foreground == NULL)
144         return E_INVALIDARG;
145     // #CHECK XInterface#
146     if(!pRXComp.is())
147     {
148         return E_FAIL;
149     }
150     *foreground = (long)GetXInterface()->getForeground();
151 
152     return S_OK;
153 
154     LEAVE_PROTECTED_BLOCK
155 }
156 
157 /**
158  * Returns the background color of this object.
159  *
160  * @param    Color    the color of background.
161  */
get_background(IA2Color * background)162 STDMETHODIMP CAccComponentBase::get_background(IA2Color * background)
163 {
164 
165 	CHECK_ENABLE_INF
166 
167     ENTER_PROTECTED_BLOCK
168 
169     if (background == NULL)
170         return E_INVALIDARG;
171     // #CHECK XInterface#
172     if(!pRXComp.is())
173     {
174         return E_FAIL;
175     }
176     *background = (long)GetXInterface()->getBackground();
177 
178     return S_OK;
179 
180     LEAVE_PROTECTED_BLOCK
181 }
182 
183 /**
184  * Overide of IUNOXWrapper.
185  *
186  * @param    pXInterface    the pointer of UNO interface.
187  */
put_XInterface(long pXInterface)188 STDMETHODIMP CAccComponentBase::put_XInterface(long pXInterface)
189 {
190 
191 	CHECK_ENABLE_INF
192 
193     ENTER_PROTECTED_BLOCK
194 
195     CUNOXWrapper::put_XInterface(pXInterface);
196     //special query.
197     if(pUNOInterface == NULL)
198         return E_FAIL;
199     Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
200     if( !pRContext.is() )
201     {
202         return E_FAIL;
203     }
204     Reference<XAccessibleComponent> pRXI(pRContext,UNO_QUERY);
205     if( !pRXI.is() )
206         pRXComp = NULL;
207     else
208         pRXComp = pRXI.get();
209 
210     return S_OK;
211 
212     LEAVE_PROTECTED_BLOCK
213 }
214