Avoid potential negative array index access to cached text.
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccComponentBase.cxx
blob1cd6cdc1c8ac322a1baf6f5de676d57f846205a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "stdafx.h"
21 #include "AccComponentBase.h"
22 #include <com/sun/star/accessibility/XAccessible.hpp>
23 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
24 #include <vcl/svapp.hxx>
25 #include "MAccessible.h"
27 using namespace com::sun::star::accessibility;
28 using namespace com::sun::star::uno;
30 // Construction/Destruction
32 CAccComponentBase::CAccComponentBase() {}
34 CAccComponentBase::~CAccComponentBase() {}
36 /**
37 * Returns the location of the upper left corner of the object's bounding
38 * box relative to the parent.
40 * @param Location the upper left corner of the object's bounding box.
42 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::get_locationInParent(long* x, long* y)
44 SolarMutexGuard g;
46 try
48 if (x == nullptr || y == nullptr)
49 return E_INVALIDARG;
51 if (!pRXComp.is())
52 return E_FAIL;
54 const css::awt::Point& pt = GetXInterface()->getLocation();
55 *x = pt.X;
56 *y = pt.Y;
57 return S_OK;
59 catch (...)
61 return E_FAIL;
65 /**
66 * Returns the location of the upper left corner of the object's bounding
67 * box in screen.
69 * @param Location the upper left corner of the object's bounding
70 * box in screen coordinates.
72 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::get_locationOnScreen(long* x, long* y)
74 SolarMutexGuard g;
76 try
78 if (x == nullptr || y == nullptr)
79 return E_INVALIDARG;
81 if (!pRXComp.is())
82 return E_FAIL;
84 const css::awt::Point& pt = GetXInterface()->getLocationOnScreen();
85 *x = pt.X;
86 *y = pt.Y;
87 return S_OK;
89 catch (...)
91 return E_FAIL;
95 /**
96 * Grabs the focus to this object.
98 * @param success the boolean result to be returned.
100 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::grabFocus(boolean* success)
102 SolarMutexGuard g;
106 if (success == nullptr)
107 return E_INVALIDARG;
109 if (!pRXComp.is())
111 return E_FAIL;
113 GetXInterface()->grabFocus();
114 *success = TRUE;
116 return S_OK;
118 catch (...)
120 return E_FAIL;
125 * Returns the foreground color of this object.
127 * @param Color the color of foreground.
129 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::get_foreground(IA2Color* foreground)
131 SolarMutexGuard g;
135 if (foreground == nullptr)
136 return E_INVALIDARG;
138 if (!pRXComp.is())
140 return E_FAIL;
142 *foreground = static_cast<long>(GetXInterface()->getForeground());
144 return S_OK;
146 catch (...)
148 return E_FAIL;
153 * Returns the background color of this object.
155 * @param Color the color of background.
157 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::get_background(IA2Color* background)
159 SolarMutexGuard g;
163 if (background == nullptr)
164 return E_INVALIDARG;
166 if (!pRXComp.is())
168 return E_FAIL;
170 *background = static_cast<long>(GetXInterface()->getBackground());
172 return S_OK;
174 catch (...)
176 return E_FAIL;
181 * Override of IUNOXWrapper.
183 * @param pXInterface the pointer of UNO interface.
185 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccComponentBase::put_XInterface(hyper pXInterface)
187 // internal IUNOXWrapper - no mutex meeded
191 CUNOXWrapper::put_XInterface(pXInterface);
192 //special query.
193 if (pUNOInterface == nullptr)
194 return E_FAIL;
195 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
196 if (!pRContext.is())
198 return E_FAIL;
200 Reference<XAccessibleComponent> pRXI(pRContext, UNO_QUERY);
201 if (!pRXI.is())
202 pRXComp = nullptr;
203 else
204 pRXComp = pRXI.get();
206 return S_OK;
208 catch (...)
210 return E_FAIL;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */