LibreOffice Module accessibility (master) 1
vclxaccessibletextcomponent.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23
24#include <com/sun/star/accessibility/AccessibleEventId.hpp>
25#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29#include <vcl/window.hxx>
30#include <vcl/mnemonic.hxx>
31#include <vcl/svapp.hxx>
32#include <vcl/unohelp2.hxx>
33#include <vcl/ctrl.hxx>
34#include <vcl/settings.hxx>
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::lang;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::accessibility;
42using namespace ::comphelper;
43
44
45
46
48 :ImplInheritanceHelper( pVCLXWindow )
49{
50 VclPtr<vcl::Window> pWindow = GetWindow();
51 if ( pWindow )
52 m_sText = removeMnemonicFromString( pWindow->GetText() );
53}
54
55
56void VCLXAccessibleTextComponent::SetText( const OUString& sText )
57{
58 Any aOldValue, aNewValue;
59 if ( implInitTextChangedEvent( m_sText, sText, aOldValue, aNewValue ) )
60 {
61 m_sText = sText;
62 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
63 }
64}
65
66
68{
69 switch ( rVclWindowEvent.GetId() )
70 {
71 case VclEventId::WindowFrameTitleChanged:
72 {
73 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
75 }
76 break;
77 default:
78 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
79 }
80}
81
82
83// OCommonAccessibleText
84
85
87{
88 OUString aText;
89 VclPtr<vcl::Window> pWindow = GetWindow();
90 if ( pWindow )
91 aText = removeMnemonicFromString( pWindow->GetText() );
92
93 return aText;
94}
95
96
98{
100}
101
102
103void VCLXAccessibleTextComponent::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
104{
105 nStartIndex = 0;
106 nEndIndex = 0;
107}
108
109
110// XComponent
111
112
114{
115 VCLXAccessibleComponent::disposing();
116
117 m_sText.clear();
118}
119
120
121// XAccessibleText
122
123
125{
126 return -1;
127}
128
129
131{
132 return setSelection( nIndex, nIndex );
133}
134
135
137{
138 OExternalLockGuard aGuard( this );
139
140 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
141}
142
143
144Sequence< PropertyValue > VCLXAccessibleTextComponent::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
145{
146 OExternalLockGuard aGuard( this );
147
148 Sequence< PropertyValue > aValues;
149 OUString sText( implGetText() );
150
151 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
152 throw IndexOutOfBoundsException();
153
154 VclPtr<vcl::Window> pWindow = GetWindow();
155 if ( pWindow )
156 {
157 vcl::Font aFont = pWindow->GetControlFont();
158
159 Color nBackColor = pWindow->GetControlBackground();
160 Color nColor = pWindow->GetControlForeground();
161
162 // MT: Code with default font was introduced with the IA2 CWS, but I am not convinced that this is the correct font...
163 // Decide what to do when we have a concrete issue.
164 /*
165 Font aDefaultVCLFont;
166 OutputDevice* pDev = Application::GetDefaultDevice();
167 if ( pDev )
168 {
169 aDefaultVCLFont = pDev->GetSettings().GetStyleSettings().GetAppFont();
170 if ( !aFont.GetName().Len() )
171 {
172 String aDefaultName = aDefaultVCLFont.GetName();
173 aFont.SetName( aDefaultName );
174 }
175 if ( !aFont.GetHeight() )
176 {
177 aFont.SetHeight( aDefaultVCLFont.GetHeight() );
178 }
179 if ( aFont.GetWeight() == WEIGHT_DONTKNOW )
180 {
181 aFont.SetWeight( aDefaultVCLFont.GetWeight() );
182 }
183
184 //if nColor is -1, it may indicate that the default color black is using.
185 if ( nColor == -1)
186 {
187 nColor = aDefaultVCLFont.GetColor().GetColor();
188 }
189 }
190 */
191
192 // MT: Adjustment stuff was introduced with the IA2 CWS, but adjustment is not a character attribute...
193 // In case we reintroduce it, use adjustment as extra parameter for the CharacterAttributesHelper...
194 /*
195 WinBits aBits = GetWindow()->GetStyle();
196 sal_Int16 nAdjust = -1;
197 if ( aBits & WB_LEFT )
198 {
199 nAdjust = style::ParagraphAdjust_LEFT;
200 }
201 else if ( aBits & WB_RIGHT )
202 {
203 nAdjust = style::ParagraphAdjust_RIGHT;
204 }
205 else if ( aBits & WB_CENTER )
206 {
207 nAdjust = style::ParagraphAdjust_CENTER;
208 }
209 */
210
211 aValues = CharacterAttributesHelper( aFont, sal_Int32(nBackColor), sal_Int32(nColor) )
212 .GetCharacterAttributes( aRequestedAttributes );
213 }
214
215 return aValues;
216}
217
218
219awt::Rectangle VCLXAccessibleTextComponent::getCharacterBounds( sal_Int32 nIndex )
220{
221 OExternalLockGuard aGuard( this );
222
224 throw IndexOutOfBoundsException();
225
226 awt::Rectangle aRect;
227 VclPtr< Control > pControl = GetAs< Control >();
228 if ( pControl )
229 aRect = AWTRectangle( pControl->GetCharacterBounds( nIndex ) );
230
231 return aRect;
232}
233
234
236{
237 OExternalLockGuard aGuard( this );
238
239 return implGetText().getLength();
240}
241
242
243sal_Int32 VCLXAccessibleTextComponent::getIndexAtPoint( const awt::Point& aPoint )
244{
245 OExternalLockGuard aGuard( this );
246
247 sal_Int32 nIndex = -1;
248 VclPtr< Control > pControl = GetAs< Control >();
249 if ( pControl )
250 nIndex = pControl->GetIndexForPoint( VCLPoint( aPoint ) );
251
252 return nIndex;
253}
254
255
257{
258 OExternalLockGuard aGuard( this );
259
260 return OCommonAccessibleText::getSelectedText();
261}
262
263
265{
266 OExternalLockGuard aGuard( this );
267
268 return OCommonAccessibleText::getSelectionStart();
269}
270
271
273{
274 OExternalLockGuard aGuard( this );
275
276 return OCommonAccessibleText::getSelectionEnd();
277}
278
279
280sal_Bool VCLXAccessibleTextComponent::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
281{
282 OExternalLockGuard aGuard( this );
283
284 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
285 throw IndexOutOfBoundsException();
286
287 return false;
288}
289
290
292{
293 OExternalLockGuard aGuard( this );
294
295 return implGetText();
296}
297
298
299OUString VCLXAccessibleTextComponent::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
300{
301 OExternalLockGuard aGuard( this );
302
303 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
304}
305
306
307css::accessibility::TextSegment VCLXAccessibleTextComponent::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
308{
309 OExternalLockGuard aGuard( this );
310
311 return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
312}
313
314
315css::accessibility::TextSegment VCLXAccessibleTextComponent::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
316{
317 OExternalLockGuard aGuard( this );
318
319 return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
320}
321
322
323css::accessibility::TextSegment VCLXAccessibleTextComponent::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
324{
325 OExternalLockGuard aGuard( this );
326
327 return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
328}
329
330
331sal_Bool VCLXAccessibleTextComponent::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
332{
333 OExternalLockGuard aGuard( this );
334
335 bool bReturn = false;
336
337 VclPtr<vcl::Window> pWindow = GetWindow();
338 if ( pWindow )
339 {
340 Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard();
341 if ( xClipboard.is() )
342 {
343 OUString sText( OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex ) );
344
346
347 SolarMutexReleaser aReleaser;
348 xClipboard->setContents( pDataObj, nullptr );
349
350 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
351 if( xFlushableClipboard.is() )
352 xFlushableClipboard->flushClipboard();
353
354 bReturn = true;
355 }
356 }
357
358 return bReturn;
359}
360
361sal_Bool VCLXAccessibleTextComponent::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
362{
363 return false;
364}
365
366/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
std::vector< css::beans::PropertyValue > GetCharacterAttributes()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
virtual OUString implGetText() override
virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
virtual css::lang::Locale implGetLocale() override
virtual void implGetSelection(sal_Int32 &nStartIndex, sal_Int32 &nEndIndex) override
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
virtual OUString SAL_CALL getSelectedText() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
virtual sal_Int32 SAL_CALL getSelectionStart() override
virtual sal_Int32 SAL_CALL getCaretPosition() override
virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
void SetText(const OUString &sText)
virtual sal_Int32 SAL_CALL getSelectionEnd() override
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex(sal_Int32 nIndex, sal_Int16 aTextType) override
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual OUString SAL_CALL getText() override
virtual sal_Int32 SAL_CALL getCharacterCount() override
VCLXAccessibleTextComponent(VCLXWindow *pVCLXWindow)
virtual sal_Bool SAL_CALL scrollSubstringTo(sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override
VclEventId GetId() const
static bool implIsValidIndex(sal_Int32 nIndex, sal_Int32 nLength)
static bool implIsValidRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength)
static bool implInitTextChangedEvent(std::u16string_view rOldString, std::u16string_view rNewString, css::uno::Any &rDeleted, css::uno::Any &rInserted)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
sal_Int32 nIndex
VCL_DLLPUBLIC OUString removeMnemonicFromString(OUString const &rStr, sal_Int32 &rMnemonicPos)
double getLength(const B2DPolygon &rCandidate)
unsigned char sal_Bool
sal_uInt16 sal_Unicode