Avoid potential negative array index access to cached text.
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccHypertext.cxx
blobc1f81c88849c40c0d9557744b6e36a79b20d2e36
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 <UAccCOM.h>
22 #include "AccHypertext.h"
23 #include "AccHyperLink.h"
24 #include "acccommon.h"
26 #include <vcl/svapp.hxx>
29 using namespace com::sun::star::accessibility;
30 using namespace com::sun::star::uno;
33 /**
34 * Get special selection.
35 * @param startOffset Start selection offset.
36 * @param endOffset End selection offset.
37 * @param success Variant to accept the result of if the method call is successful.
38 * @return Result.
40 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::addSelection(long startOffset, long endOffset)
43 return CAccTextBase::get_addSelection(startOffset, endOffset);
47 /**
48 * Get special attributes.
49 * @param offset Offset.
50 * @param startOffset Variant to accept start offset.
51 * @param endOffset Variant to accept end offset.
52 * @param textAttributes Variant to accept attributes.
53 * @return Result.
55 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_attributes(long offset, long * startOffset, long * endOffset, BSTR * textAttributes)
58 return CAccTextBase::get_attributes(offset, startOffset, endOffset, textAttributes);
61 /**
62 * Get caret position.
63 * @param offset Variant to accept caret offset.
64 * @return Result.
66 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_caretOffset(long * offset)
69 return CAccTextBase::get_caretOffset(offset);
72 /**
73 * Get character extents.
74 * @param offset Offset.
75 * @param x Variant to accept x position.
76 * @param y Variant to accept y position.
77 * @param width Variant to accept width.
78 * @param Height Variant to accept height.
79 * @return Result.
81 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_characterExtents(long offset, IA2CoordinateType coordType, long * x, long * y, long * width, long * height)
84 return CAccTextBase::get_characterExtents(offset, coordType, x, y, width, height);
87 /**
88 * Get selections count.
89 * @param nSelections Variant to accept selections count.
90 * @return Result.
92 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_nSelections(long * nSelections)
95 return CAccTextBase::get_nSelections(nSelections);
98 /**
99 * Get offset of some special point.
100 * @param x X position of one point.
101 * @param x Y position of one point.
102 * @param coordType Type.
103 * @param offset Variant to accept offset.
104 * @return Result.
106 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_offsetAtPoint(long x, long y, IA2CoordinateType coordType, long * offset)
108 return CAccTextBase::get_offsetAtPoint(x, y, coordType, offset);
112 * Get selection range.
113 * @param selection selection count.
114 * @param startOffset Variant to accept the start offset of special selection.
115 * @param endOffset Variant to accept the end offset of special selection.
116 * @return Result.
118 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_selection(long selection, long * startOffset, long * endOffset)
121 return CAccTextBase::get_selection(selection, startOffset, endOffset);
125 * Get special text.
126 * @param startOffset Start position of special range.
127 * @param endOffset End position of special range.
128 * @param text Variant to accept the text of special range.
129 * @return Result.
131 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_text(long startOffset, long endOffset, BSTR * text)
134 return CAccTextBase::get_text(startOffset, endOffset, text);
138 * Get special text before some position.
139 * @param offset Special position.
140 * @param boundaryType Boundary type.
141 * @param startOffset Variant to accept the start offset.
142 * @param endOffset Variant to accept the end offset.
143 * @param text Variant to accept the special text.
144 * @return Result.
146 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_textBeforeOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
149 return CAccTextBase::get_textBeforeOffset(offset, boundaryType,
150 startOffset, endOffset, text);
154 * Get special text after some position.
155 * @param offset Special position.
156 * @param boundaryType Boundary type.
157 * @param startOffset Variant to accept the start offset.
158 * @param endOffset Variant to accept the end offset.
159 * @param text Variant to accept the special text.
160 * @return Result.
162 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_textAfterOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
165 return CAccTextBase::get_textAfterOffset(offset, boundaryType,
166 startOffset, endOffset, text);
170 * Get special text at some position.
171 * @param offset Special position.
172 * @param boundaryType Boundary type.
173 * @param startOffset Variant to accept the start offset.
174 * @param endOffset Variant to accept the end offset.
175 * @param text Variant to accept the special text.
176 * @return Result.
178 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_textAtOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
181 return CAccTextBase::get_textAtOffset(offset, boundaryType,
182 startOffset, endOffset, text);
186 * Remove selection.
187 * @param selectionIndex Special selection index
188 * @param success Variant to accept the method called result.
189 * @return Result.
191 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::removeSelection(long selectionIndex)
194 return CAccTextBase::removeSelection(selectionIndex);
198 * Set caret position.
199 * @param offset Special position.
200 * @param success Variant to accept the method called result.
201 * @return Result.
203 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::setCaretOffset(long offset)
206 return CAccTextBase::setCaretOffset(offset);
210 * Set special selection.
211 * @param selectionIndex Special selection index.
212 * @param startOffset start position.
213 * @param endOffset end position.
214 * @param success Variant to accept the method called result.
215 * @return Result.
217 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::setSelection(long selectionIndex, long startOffset, long endOffset)
220 return CAccTextBase::setSelection(selectionIndex, startOffset,
221 endOffset);
225 * Get characters count.
226 * @param nCharacters Variant to accept the characters count.
227 * @return Result.
229 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_nCharacters(long * nCharacters)
232 return CAccTextBase::get_nCharacters(nCharacters);
235 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_newText( IA2TextSegment *newText)
237 return CAccTextBase::get_newText(newText);
240 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_oldText( IA2TextSegment *oldText)
242 return CAccTextBase::get_oldText(oldText);
246 * Scroll to special sub-string .
247 * @param startIndex Start index of sub string.
248 * @param endIndex End index of sub string.
249 * @return Result.
251 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::scrollSubstringToPoint(long startIndex, long endIndex,enum IA2CoordinateType coordinateType, long x, long y )
254 return CAccTextBase::scrollSubstringToPoint(startIndex, endIndex, coordinateType, x, y);
256 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::scrollSubstringTo(long startIndex, long endIndex,enum IA2ScrollType scrollType)
259 return CAccTextBase::scrollSubstringTo(startIndex, endIndex,scrollType);
263 * Get hyperlink count.
264 * @param hyperlinkCount Variant to accept hyperlink count.
265 * @return Result.
267 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_nHyperlinks(long *hyperlinkCount)
269 SolarMutexGuard g;
271 try {
273 if(hyperlinkCount == nullptr)
274 return E_INVALIDARG;
276 if(!pHyperText.is())
278 return E_FAIL;
281 *hyperlinkCount = pHyperText->getHyperLinkCount();
282 return S_OK;
284 } catch(...) { return E_FAIL; }
288 * Get special hyperlink.
289 * @param index Special hyperlink index.
290 * @param hyperlink Variant to accept special hyperlink via index.
291 * @return Result.
293 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_hyperlink(long index,IAccessibleHyperlink **hyperlink)
295 SolarMutexGuard g;
297 try {
299 if(hyperlink == nullptr)
300 return E_INVALIDARG;
302 if(!pHyperText.is())
304 return E_FAIL;
307 Reference<XAccessibleHyperlink> pRLink = pHyperText->getHyperLink(index);
308 if(!pRLink.is())
310 *hyperlink = nullptr;
311 return E_FAIL;
314 IAccessibleHyperlink* plink = nullptr;
315 HRESULT hr = createInstance<CAccHyperLink>(IID_IAccessibleHyperlink, &plink);
316 if( SUCCEEDED(hr) )
318 IUNOXWrapper* wrapper = nullptr;
319 plink->QueryInterface(IID_IUNOXWrapper, reinterpret_cast<void**>(&wrapper));
320 if(wrapper)
322 wrapper->put_XSubInterface(reinterpret_cast<hyper>(pRLink.get()));
323 wrapper->Release();
325 *hyperlink = plink;
326 return S_OK;
329 return E_FAIL;
331 } catch(...) { return E_FAIL; }
335 * Returns the index of the hyperlink that is associated with this character index.
336 * @param charIndex Special char index.
337 * @param hyperlinkIndex Variant to accept special hyperlink index.
338 * @return Result.
340 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::get_hyperlinkIndex(long charIndex, long *hyperlinkIndex)
342 SolarMutexGuard g;
344 try {
346 if(hyperlinkIndex == nullptr)
347 return E_INVALIDARG;
349 if(!pHyperText.is())
351 return E_FAIL;
354 *hyperlinkIndex = pHyperText->getHyperLinkIndex(charIndex);
355 return S_OK;
357 } catch(...) { return E_FAIL; }
361 * Put UNO interface.
362 * @param pXInterface UNO interface.
363 * @return Result.
365 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccHypertext::put_XInterface(hyper pXInterface)
367 // internal IUNOXWrapper - no mutex meeded
369 try {
371 CAccTextBase::put_XInterface(pXInterface);
372 //special query.
373 if(pUNOInterface == nullptr)
374 return E_FAIL;
375 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
376 if( !pRContext.is() )
378 return E_FAIL;
380 Reference<XAccessibleHypertext> pRXI(pRContext,UNO_QUERY);
381 if( !pRXI.is() )
382 pHyperText = nullptr;
383 else
384 pHyperText = pRXI.get();
385 return S_OK;
387 } catch(...) { return E_FAIL; }
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */