Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
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 : : #include <accessibility/standard/vclxaccessibleedit.hxx>
30 : :
31 : : #include <toolkit/awt/vclxwindows.hxx>
32 : : #include <toolkit/helper/convert.hxx>
33 : : #include <accessibility/helper/accresmgr.hxx>
34 : : #include <accessibility/helper/accessiblestrings.hrc>
35 : :
36 : : #include <unotools/accessiblestatesethelper.hxx>
37 : : #include <unotools/accessiblerelationsethelper.hxx>
38 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 : : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
42 : : #include <cppuhelper/typeprovider.hxx>
43 : : #include <comphelper/sequence.hxx>
44 : : #include <vcl/svapp.hxx>
45 : : #include <vcl/window.hxx>
46 : : #include <vcl/edit.hxx>
47 : : #include <sot/exchange.hxx>
48 : : #include <sot/formats.hxx>
49 : :
50 : : #include <algorithm>
51 : :
52 : : using namespace ::com::sun::star;
53 : : using namespace ::com::sun::star::uno;
54 : : using namespace ::com::sun::star::lang;
55 : : using namespace ::com::sun::star::beans;
56 : : using namespace ::com::sun::star::accessibility;
57 : : using namespace ::comphelper;
58 : :
59 : :
60 : : // -----------------------------------------------------------------------------
61 : : // VCLXAccessibleEdit
62 : : // -----------------------------------------------------------------------------
63 : :
64 : 12 : VCLXAccessibleEdit::VCLXAccessibleEdit( VCLXWindow* pVCLWindow )
65 : 12 : :VCLXAccessibleTextComponent( pVCLWindow )
66 : : {
67 [ + - ]: 12 : m_nSelectionStart = getSelectionStart();
68 [ + - ]: 12 : m_nCaretPosition = getCaretPosition();
69 : 12 : }
70 : :
71 : : // -----------------------------------------------------------------------------
72 : :
73 : 12 : VCLXAccessibleEdit::~VCLXAccessibleEdit()
74 : : {
75 [ - + ]: 24 : }
76 : :
77 : : // -----------------------------------------------------------------------------
78 : :
79 : 12 : void VCLXAccessibleEdit::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
80 : : {
81 [ - - + ]: 12 : switch ( rVclWindowEvent.GetId() )
82 : : {
83 : : case VCLEVENT_EDIT_MODIFY:
84 : : {
85 [ # # ]: 0 : SetText( implGetText() );
86 : : }
87 : 0 : break;
88 : : case VCLEVENT_EDIT_SELECTIONCHANGED:
89 : : {
90 : 0 : sal_Int32 nOldCaretPosition = m_nCaretPosition;
91 : 0 : sal_Int32 nOldSelectionStart = m_nSelectionStart;
92 : :
93 : 0 : m_nCaretPosition = getCaretPosition();
94 : 0 : m_nSelectionStart = getSelectionStart();
95 : :
96 : 0 : Window* pWindow = GetWindow();
97 [ # # ][ # # ]: 0 : if ( pWindow && pWindow->HasChildPathFocus() )
[ # # ]
98 : : {
99 [ # # ]: 0 : if ( m_nCaretPosition != nOldCaretPosition )
100 : : {
101 : 0 : Any aOldValue, aNewValue;
102 [ # # ]: 0 : aOldValue <<= (sal_Int32) nOldCaretPosition;
103 [ # # ]: 0 : aNewValue <<= (sal_Int32) m_nCaretPosition;
104 [ # # ]: 0 : NotifyAccessibleEvent( AccessibleEventId::CARET_CHANGED, aOldValue, aNewValue );
105 : : }
106 : :
107 : : // #i104470# VCL only has SELECTION_CHANGED, but UAA distinguishes between SELECTION_CHANGED and CARET_CHANGED
108 : 0 : sal_Bool bHasSelection = ( m_nSelectionStart != m_nCaretPosition );
109 : 0 : sal_Bool bHadSelection = ( nOldSelectionStart != nOldCaretPosition );
110 [ # # ][ # # ]: 0 : if ( ( bHasSelection != bHadSelection ) || ( bHasSelection && ( ( m_nCaretPosition != nOldCaretPosition ) || ( m_nSelectionStart != nOldSelectionStart ) ) ) )
[ # # ][ # # ]
111 : : {
112 [ # # ]: 0 : NotifyAccessibleEvent( AccessibleEventId::TEXT_SELECTION_CHANGED, Any(), Any() );
113 : : }
114 : :
115 : : }
116 : : }
117 : 0 : break;
118 : : default:
119 : 12 : VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
120 : : }
121 : 12 : }
122 : :
123 : : // -----------------------------------------------------------------------------
124 : :
125 : 18 : void VCLXAccessibleEdit::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
126 : : {
127 : 18 : VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
128 : :
129 [ + - ]: 18 : VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() );
130 [ + - ]: 18 : if ( pVCLXEdit )
131 : : {
132 : 18 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
133 : 18 : rStateSet.AddState( AccessibleStateType::SINGLE_LINE );
134 [ + - ]: 18 : if ( pVCLXEdit->isEditable() )
135 : 18 : rStateSet.AddState( AccessibleStateType::EDITABLE );
136 : : }
137 : 18 : }
138 : :
139 : : // -----------------------------------------------------------------------------
140 : : // OCommonAccessibleText
141 : : // -----------------------------------------------------------------------------
142 : :
143 : 0 : ::rtl::OUString VCLXAccessibleEdit::implGetText()
144 : : {
145 : 0 : ::rtl::OUString aText;
146 : :
147 [ # # ]: 0 : Edit* pEdit = static_cast< Edit* >( GetWindow() );
148 [ # # ]: 0 : if ( pEdit )
149 : : {
150 [ # # ][ # # ]: 0 : aText = OutputDevice::GetNonMnemonicString( pEdit->GetText() );
[ # # ][ # # ]
[ # # ]
151 : :
152 [ # # ][ # # ]: 0 : if ( getAccessibleRole() == AccessibleRole::PASSWORD_TEXT )
153 : : {
154 : 0 : xub_Unicode cEchoChar = pEdit->GetEchoChar();
155 [ # # ]: 0 : if ( !cEchoChar )
156 : 0 : cEchoChar = '*';
157 [ # # ]: 0 : XubString sTmp;
158 [ # # ][ # # ]: 0 : aText = sTmp.Fill( (sal_uInt16)aText.getLength(), cEchoChar );
[ # # ]
159 : : }
160 : : }
161 : :
162 : 0 : return aText;
163 : : }
164 : :
165 : : // -----------------------------------------------------------------------------
166 : :
167 : 24 : void VCLXAccessibleEdit::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
168 : : {
169 : 24 : awt::Selection aSelection;
170 [ + - ]: 24 : VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() );
171 [ + - ]: 24 : if ( pVCLXEdit )
172 [ + - ]: 24 : aSelection = pVCLXEdit->getSelection();
173 : :
174 : 24 : nStartIndex = aSelection.Min;
175 : 24 : nEndIndex = aSelection.Max;
176 : 24 : }
177 : :
178 : : // -----------------------------------------------------------------------------
179 : : // XInterface
180 : : // -----------------------------------------------------------------------------
181 : :
182 [ + + ][ + - ]: 968 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleEdit, VCLXAccessibleTextComponent, VCLXAccessibleEdit_BASE )
183 : :
184 : : // -----------------------------------------------------------------------------
185 : : // XTypeProvider
186 : : // -----------------------------------------------------------------------------
187 : :
188 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleEdit, VCLXAccessibleTextComponent, VCLXAccessibleEdit_BASE )
[ # # ]
189 : :
190 : : // -----------------------------------------------------------------------------
191 : : // XServiceInfo
192 : : // -----------------------------------------------------------------------------
193 : :
194 : 2 : ::rtl::OUString VCLXAccessibleEdit::getImplementationName() throw (RuntimeException)
195 : : {
196 : 2 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleEdit") );
197 : : }
198 : :
199 : : // -----------------------------------------------------------------------------
200 : :
201 : 0 : Sequence< ::rtl::OUString > VCLXAccessibleEdit::getSupportedServiceNames() throw (RuntimeException)
202 : : {
203 : 0 : Sequence< ::rtl::OUString > aNames(1);
204 [ # # ][ # # ]: 0 : aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleEdit") );
205 : 0 : return aNames;
206 : : }
207 : :
208 : : // -----------------------------------------------------------------------------
209 : : // XAccessibleContext
210 : : // -----------------------------------------------------------------------------
211 : :
212 : 12 : sal_Int32 VCLXAccessibleEdit::getAccessibleChildCount() throw (RuntimeException)
213 : : {
214 [ + - ]: 12 : OExternalLockGuard aGuard( this );
215 : :
216 [ + - ]: 12 : return 0;
217 : : }
218 : :
219 : : // -----------------------------------------------------------------------------
220 : :
221 : 0 : Reference< XAccessible > VCLXAccessibleEdit::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
222 : : {
223 [ # # ]: 0 : OExternalLockGuard aGuard( this );
224 : :
225 [ # # ][ # # ]: 0 : if ( i < 0 || i >= getAccessibleChildCount() )
[ # # ][ # # ]
226 [ # # ]: 0 : throw IndexOutOfBoundsException();
227 : :
228 [ # # ]: 0 : return Reference< XAccessible >();
229 : : }
230 : :
231 : : // -----------------------------------------------------------------------------
232 : :
233 : 22 : sal_Int16 VCLXAccessibleEdit::getAccessibleRole( ) throw (RuntimeException)
234 : : {
235 [ + - ]: 22 : OExternalLockGuard aGuard( this );
236 : :
237 : : sal_Int16 nRole;
238 [ + - ]: 22 : Edit* pEdit = static_cast< Edit* >( GetWindow() );
239 [ + - ][ + - ]: 22 : if ( pEdit && ( ( pEdit->GetStyle() & WB_PASSWORD ) || pEdit->GetEchoChar() ) )
[ + - ][ - + ]
[ - + ]
240 : 0 : nRole = AccessibleRole::PASSWORD_TEXT;
241 : : else
242 : 22 : nRole = AccessibleRole::TEXT;
243 : :
244 [ + - ]: 22 : return nRole;
245 : : }
246 : :
247 : : // -----------------------------------------------------------------------------
248 : : // XAccessibleAction
249 : : // -----------------------------------------------------------------------------
250 : :
251 : 0 : sal_Int32 VCLXAccessibleEdit::getAccessibleActionCount( ) throw (RuntimeException)
252 : : {
253 [ # # ]: 0 : OExternalLockGuard aGuard( this );
254 : :
255 : : // There is one action: activate
256 [ # # ]: 0 : return 1;
257 : : }
258 : :
259 : : // -----------------------------------------------------------------------------
260 : :
261 : 0 : sal_Bool VCLXAccessibleEdit::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
262 : : {
263 [ # # ]: 0 : OExternalLockGuard aGuard( this );
264 : :
265 [ # # ][ # # ]: 0 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ # # ][ # # ]
266 [ # # ]: 0 : throw IndexOutOfBoundsException();
267 : :
268 : 0 : sal_Bool bDoAction = sal_False;
269 [ # # ]: 0 : Window* pWindow = GetWindow();
270 [ # # ]: 0 : if ( pWindow )
271 : : {
272 [ # # ]: 0 : pWindow->GrabFocus();
273 : 0 : bDoAction = sal_True;
274 : : }
275 : :
276 [ # # ]: 0 : return bDoAction;
277 : : }
278 : :
279 : : // -----------------------------------------------------------------------------
280 : :
281 : 0 : ::rtl::OUString VCLXAccessibleEdit::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
282 : : {
283 [ # # ]: 0 : OExternalLockGuard aGuard( this );
284 : :
285 [ # # ][ # # ]: 0 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ # # ][ # # ]
286 [ # # ]: 0 : throw IndexOutOfBoundsException();
287 : :
288 [ # # ][ # # ]: 0 : static const ::rtl::OUString sAction( RTL_CONSTASCII_USTRINGPARAM( "activate" ) );
[ # # ][ # # ]
289 [ # # ]: 0 : return sAction;
290 : : }
291 : :
292 : : // -----------------------------------------------------------------------------
293 : :
294 : 0 : Reference< XAccessibleKeyBinding > VCLXAccessibleEdit::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
295 : : {
296 [ # # ]: 0 : OExternalLockGuard aGuard( this );
297 : :
298 [ # # ][ # # ]: 0 : if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
[ # # ][ # # ]
299 [ # # ]: 0 : throw IndexOutOfBoundsException();
300 : :
301 [ # # ]: 0 : return Reference< XAccessibleKeyBinding >();
302 : : }
303 : :
304 : : // -----------------------------------------------------------------------------
305 : : // XAccessibleText
306 : : // -----------------------------------------------------------------------------
307 : :
308 : 12 : sal_Int32 VCLXAccessibleEdit::getCaretPosition( ) throw (RuntimeException)
309 : : {
310 : 12 : return getSelectionEnd();
311 : : }
312 : :
313 : : // -----------------------------------------------------------------------------
314 : :
315 : 0 : sal_Bool VCLXAccessibleEdit::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
316 : : {
317 : 0 : return setSelection( nIndex, nIndex );
318 : : }
319 : :
320 : : // -----------------------------------------------------------------------------
321 : :
322 : 0 : sal_Unicode VCLXAccessibleEdit::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
323 : : {
324 [ # # ]: 0 : OExternalLockGuard aGuard( this );
325 : :
326 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getCharacter( nIndex );
327 : : }
328 : :
329 : : // -----------------------------------------------------------------------------
330 : :
331 : 0 : Sequence< PropertyValue > VCLXAccessibleEdit::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException)
332 : : {
333 [ # # ]: 0 : OExternalLockGuard aGuard( this );
334 : :
335 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getCharacterAttributes( nIndex, aRequestedAttributes );
336 : : }
337 : :
338 : : // -----------------------------------------------------------------------------
339 : :
340 : 0 : awt::Rectangle VCLXAccessibleEdit::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
341 : : {
342 [ # # ]: 0 : OExternalLockGuard aGuard( this );
343 : :
344 : 0 : awt::Rectangle aBounds( 0, 0, 0, 0 );
345 [ # # ]: 0 : sal_Int32 nLength = implGetText().getLength();
346 : :
347 [ # # ][ # # ]: 0 : if ( !implIsValidRange( nIndex, nIndex, nLength ) )
348 [ # # ]: 0 : throw IndexOutOfBoundsException();
349 : :
350 [ # # ]: 0 : Control* pControl = static_cast< Control* >( GetWindow() );
351 [ # # ]: 0 : if ( pControl )
352 : : {
353 [ # # ]: 0 : if ( nIndex == nLength )
354 : : {
355 : : // #108914# calculate virtual bounding rectangle
356 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nLength; ++i )
357 : : {
358 [ # # ]: 0 : Rectangle aRect = pControl->GetCharacterBounds( i );
359 [ # # ]: 0 : sal_Int32 nHeight = aRect.GetHeight();
360 [ # # ]: 0 : if ( aBounds.Height < nHeight )
361 : : {
362 : 0 : aBounds.Y = aRect.Top();
363 : 0 : aBounds.Height = nHeight;
364 : : }
365 [ # # ]: 0 : if ( i == nLength - 1 )
366 : : {
367 : 0 : aBounds.X = aRect.Right() + 1;
368 : 0 : aBounds.Width = 1;
369 : : }
370 : : }
371 : : }
372 : : else
373 : : {
374 [ # # ][ # # ]: 0 : aBounds = AWTRectangle( pControl->GetCharacterBounds( nIndex ) );
375 : : }
376 : : }
377 : :
378 [ # # ]: 0 : return aBounds;
379 : : }
380 : :
381 : : // -----------------------------------------------------------------------------
382 : :
383 : 0 : sal_Int32 VCLXAccessibleEdit::getCharacterCount( ) throw (RuntimeException)
384 : : {
385 [ # # ]: 0 : OExternalLockGuard aGuard( this );
386 : :
387 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getCharacterCount();
388 : : }
389 : :
390 : : // -----------------------------------------------------------------------------
391 : :
392 : 0 : sal_Int32 VCLXAccessibleEdit::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
393 : : {
394 [ # # ]: 0 : OExternalLockGuard aGuard( this );
395 : :
396 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getIndexAtPoint( aPoint );
397 : : }
398 : :
399 : : // -----------------------------------------------------------------------------
400 : :
401 : 0 : ::rtl::OUString VCLXAccessibleEdit::getSelectedText( ) throw (RuntimeException)
402 : : {
403 [ # # ]: 0 : OExternalLockGuard aGuard( this );
404 : :
405 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getSelectedText();
406 : : }
407 : :
408 : : // -----------------------------------------------------------------------------
409 : :
410 : 12 : sal_Int32 VCLXAccessibleEdit::getSelectionStart( ) throw (RuntimeException)
411 : : {
412 [ + - ]: 12 : OExternalLockGuard aGuard( this );
413 : :
414 [ + - ][ + - ]: 12 : return VCLXAccessibleTextComponent::getSelectionStart();
415 : : }
416 : :
417 : : // -----------------------------------------------------------------------------
418 : :
419 : 12 : sal_Int32 VCLXAccessibleEdit::getSelectionEnd( ) throw (RuntimeException)
420 : : {
421 [ + - ]: 12 : OExternalLockGuard aGuard( this );
422 : :
423 [ + - ][ + - ]: 12 : return VCLXAccessibleTextComponent::getSelectionEnd();
424 : : }
425 : :
426 : : // -----------------------------------------------------------------------------
427 : :
428 : 0 : sal_Bool VCLXAccessibleEdit::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
429 : : {
430 [ # # ]: 0 : OExternalLockGuard aGuard( this );
431 : :
432 : 0 : sal_Bool bReturn = sal_False;
433 [ # # ]: 0 : ::rtl::OUString sText( implGetText() );
434 : :
435 [ # # ][ # # ]: 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, sText.getLength() ) )
436 [ # # ]: 0 : throw IndexOutOfBoundsException();
437 : :
438 [ # # ]: 0 : VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() );
439 [ # # ]: 0 : Edit* pEdit = static_cast< Edit* >( GetWindow() );
440 [ # # ][ # # ]: 0 : if ( pVCLXEdit && pEdit && pEdit->IsEnabled() )
[ # # ][ # # ]
[ # # ]
441 : : {
442 [ # # ]: 0 : pVCLXEdit->setSelection( awt::Selection( nStartIndex, nEndIndex ) );
443 : 0 : bReturn = sal_True;
444 : : }
445 : :
446 [ # # ]: 0 : return bReturn;
447 : : }
448 : :
449 : : // -----------------------------------------------------------------------------
450 : :
451 : 0 : ::rtl::OUString VCLXAccessibleEdit::getText( ) throw (RuntimeException)
452 : : {
453 [ # # ]: 0 : OExternalLockGuard aGuard( this );
454 : :
455 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getText();
456 : : }
457 : :
458 : : // -----------------------------------------------------------------------------
459 : :
460 : 0 : ::rtl::OUString VCLXAccessibleEdit::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
461 : : {
462 [ # # ]: 0 : OExternalLockGuard aGuard( this );
463 : :
464 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getTextRange( nStartIndex, nEndIndex );
465 : : }
466 : :
467 : : // -----------------------------------------------------------------------------
468 : :
469 : 0 : ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
470 : : {
471 [ # # ]: 0 : OExternalLockGuard aGuard( this );
472 : :
473 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getTextAtIndex( nIndex, aTextType );
474 : : }
475 : :
476 : : // -----------------------------------------------------------------------------
477 : :
478 : 0 : ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
479 : : {
480 [ # # ]: 0 : OExternalLockGuard aGuard( this );
481 : :
482 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getTextBeforeIndex( nIndex, aTextType );
483 : : }
484 : :
485 : : // -----------------------------------------------------------------------------
486 : :
487 : 0 : ::com::sun::star::accessibility::TextSegment VCLXAccessibleEdit::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
488 : : {
489 [ # # ]: 0 : OExternalLockGuard aGuard( this );
490 : :
491 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::getTextBehindIndex( nIndex, aTextType );
492 : : }
493 : :
494 : : // -----------------------------------------------------------------------------
495 : :
496 : 0 : sal_Bool VCLXAccessibleEdit::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
497 : : {
498 [ # # ]: 0 : OExternalLockGuard aGuard( this );
499 : :
500 [ # # ][ # # ]: 0 : return VCLXAccessibleTextComponent::copyText( nStartIndex, nEndIndex );
501 : : }
502 : :
503 : : // -----------------------------------------------------------------------------
504 : : // XAccessibleEditableText
505 : : // -----------------------------------------------------------------------------
506 : :
507 : 0 : sal_Bool VCLXAccessibleEdit::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
508 : : {
509 [ # # ]: 0 : OExternalLockGuard aGuard( this );
510 : :
511 [ # # ][ # # ]: 0 : return copyText( nStartIndex, nEndIndex ) && deleteText( nStartIndex, nEndIndex );
[ # # ][ # # ]
[ # # ]
512 : : }
513 : :
514 : : // -----------------------------------------------------------------------------
515 : :
516 : 0 : sal_Bool VCLXAccessibleEdit::pasteText( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
517 : : {
518 [ # # ]: 0 : OExternalLockGuard aGuard( this );
519 : :
520 : 0 : sal_Bool bReturn = sal_False;
521 : :
522 [ # # ][ # # ]: 0 : if ( GetWindow() )
523 : : {
524 [ # # ][ # # ]: 0 : Reference< datatransfer::clipboard::XClipboard > xClipboard = GetWindow()->GetClipboard();
525 [ # # ]: 0 : if ( xClipboard.is() )
526 : : {
527 [ # # ]: 0 : const sal_uInt32 nRef = Application::ReleaseSolarMutex();
528 [ # # ][ # # ]: 0 : Reference< datatransfer::XTransferable > xDataObj = xClipboard->getContents();
529 [ # # ]: 0 : Application::AcquireSolarMutex( nRef );
530 [ # # ]: 0 : if ( xDataObj.is() )
531 : : {
532 : 0 : datatransfer::DataFlavor aFlavor;
533 [ # # ]: 0 : SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
534 [ # # ][ # # ]: 0 : if ( xDataObj->isDataFlavorSupported( aFlavor ) )
[ # # ]
535 : : {
536 [ # # ][ # # ]: 0 : Any aData = xDataObj->getTransferData( aFlavor );
537 : 0 : ::rtl::OUString sText;
538 : 0 : aData >>= sText;
539 [ # # ]: 0 : bReturn = replaceText( nIndex, nIndex, sText );
540 : 0 : }
541 : 0 : }
542 : 0 : }
543 : : }
544 : :
545 [ # # ]: 0 : return bReturn;
546 : : }
547 : :
548 : : // -----------------------------------------------------------------------------
549 : :
550 : 0 : sal_Bool VCLXAccessibleEdit::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
551 : : {
552 [ # # ]: 0 : OExternalLockGuard aGuard( this );
553 : :
554 [ # # ][ # # ]: 0 : return replaceText( nStartIndex, nEndIndex, ::rtl::OUString() );
555 : : }
556 : :
557 : : // -----------------------------------------------------------------------------
558 : :
559 : 0 : sal_Bool VCLXAccessibleEdit::insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
560 : : {
561 [ # # ]: 0 : OExternalLockGuard aGuard( this );
562 : :
563 [ # # ][ # # ]: 0 : return replaceText( nIndex, nIndex, sText );
564 : : }
565 : :
566 : : // -----------------------------------------------------------------------------
567 : :
568 : 0 : sal_Bool VCLXAccessibleEdit::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::rtl::OUString& sReplacement ) throw (IndexOutOfBoundsException, RuntimeException)
569 : : {
570 [ # # ]: 0 : OExternalLockGuard aGuard( this );
571 : :
572 : 0 : sal_Bool bReturn = sal_False;
573 [ # # ]: 0 : ::rtl::OUString sText( implGetText() );
574 : :
575 [ # # ][ # # ]: 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, sText.getLength() ) )
576 [ # # ]: 0 : throw IndexOutOfBoundsException();
577 : :
578 [ # # ]: 0 : sal_Int32 nMinIndex = ::std::min( nStartIndex, nEndIndex );
579 [ # # ]: 0 : sal_Int32 nMaxIndex = ::std::max( nStartIndex, nEndIndex );
580 : :
581 [ # # ]: 0 : VCLXEdit* pVCLXEdit = static_cast< VCLXEdit* >( GetVCLXWindow() );
582 [ # # ][ # # ]: 0 : if ( pVCLXEdit && pVCLXEdit->isEditable() )
[ # # ][ # # ]
583 : : {
584 [ # # ]: 0 : pVCLXEdit->setText( sText.replaceAt( nMinIndex, nMaxIndex - nMinIndex, sReplacement ) );
585 : 0 : sal_Int32 nIndex = nMinIndex + sReplacement.getLength();
586 [ # # ]: 0 : setSelection( nIndex, nIndex );
587 : 0 : bReturn = sal_True;
588 : : }
589 : :
590 [ # # ]: 0 : return bReturn;
591 : : }
592 : :
593 : : // -----------------------------------------------------------------------------
594 : :
595 : 0 : sal_Bool VCLXAccessibleEdit::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const Sequence<PropertyValue>& ) throw (IndexOutOfBoundsException, RuntimeException)
596 : : {
597 [ # # ]: 0 : OExternalLockGuard aGuard( this );
598 : :
599 [ # # ][ # # ]: 0 : if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
[ # # ]
600 [ # # ]: 0 : throw IndexOutOfBoundsException();
601 : :
602 [ # # ]: 0 : return sal_False; // attributes cannot be set for an edit
603 : : }
604 : :
605 : : // -----------------------------------------------------------------------------
606 : :
607 : 0 : sal_Bool VCLXAccessibleEdit::setText( const ::rtl::OUString& sText ) throw (RuntimeException)
608 : : {
609 [ # # ]: 0 : OExternalLockGuard aGuard( this );
610 : :
611 : 0 : sal_Bool bSuccess = sal_False;
612 : : try
613 : : {
614 [ # # ][ # # ]: 0 : bSuccess = replaceText( 0, implGetText().getLength(), sText );
[ # # ]
615 : : }
616 [ # # ]: 0 : catch( const IndexOutOfBoundsException& )
617 : : {
618 : : OSL_FAIL( "VCLXAccessibleText::setText: caught an exception!" );
619 : : }
620 [ # # ]: 0 : return bSuccess;
621 : : }
622 : :
623 : : // -----------------------------------------------------------------------------
624 : :
625 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|