1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir #include "AccessibleEditObject.hxx" 27cdf0e10cSrcweir #include "scitems.hxx" 28cdf0e10cSrcweir #include <editeng/eeitem.hxx> 29cdf0e10cSrcweir #include "unoguard.hxx" 30cdf0e10cSrcweir #include "AccessibleText.hxx" 31cdf0e10cSrcweir #include "editsrc.hxx" 32cdf0e10cSrcweir #include "scmod.hxx" 33cdf0e10cSrcweir #include "inputhdl.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX 36cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_ 39cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp> 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_ 42cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir #include <rtl/uuid.h> 45cdf0e10cSrcweir #include <tools/debug.hxx> 46cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx> 47cdf0e10cSrcweir #include <editeng/editview.hxx> 48cdf0e10cSrcweir #include <editeng/editeng.hxx> 49cdf0e10cSrcweir #include <svx/svdmodel.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace ::com::sun::star; 52cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 53cdf0e10cSrcweir 54cdf0e10cSrcweir //===== internal ============================================================ 55cdf0e10cSrcweir 56cdf0e10cSrcweir ScAccessibleEditObject::ScAccessibleEditObject( 57cdf0e10cSrcweir const uno::Reference<XAccessible>& rxParent, 58cdf0e10cSrcweir EditView* pEditView, Window* pWin, const rtl::OUString& rName, 59cdf0e10cSrcweir const rtl::OUString& rDescription, EditObjectType eObjectType) 60cdf0e10cSrcweir : 61cdf0e10cSrcweir ScAccessibleContextBase(rxParent, AccessibleRole::TEXT_FRAME), 62cdf0e10cSrcweir mpTextHelper(NULL), 63cdf0e10cSrcweir mpEditView(pEditView), 64cdf0e10cSrcweir mpWindow(pWin), 65cdf0e10cSrcweir meObjectType(eObjectType), 66cdf0e10cSrcweir mbHasFocus(sal_False) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir CreateTextHelper(); 69cdf0e10cSrcweir SetName(rName); 70cdf0e10cSrcweir SetDescription(rDescription); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir ScAccessibleEditObject::~ScAccessibleEditObject() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // increment refcount to prevent double call off dtor 78cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 79cdf0e10cSrcweir // call dispose to inform object wich have a weak reference to this object 80cdf0e10cSrcweir dispose(); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir void SAL_CALL ScAccessibleEditObject::disposing() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir ScUnoGuard aGuard; 87cdf0e10cSrcweir if (mpTextHelper) 88cdf0e10cSrcweir DELETEZ(mpTextHelper); 89cdf0e10cSrcweir 90cdf0e10cSrcweir ScAccessibleContextBase::disposing(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir void ScAccessibleEditObject::LostFocus() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir mbHasFocus = sal_False; 96cdf0e10cSrcweir if (mpTextHelper) 97cdf0e10cSrcweir mpTextHelper->SetFocus(sal_False); 98cdf0e10cSrcweir CommitFocusLost(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir void ScAccessibleEditObject::GotFocus() 102cdf0e10cSrcweir { 103cdf0e10cSrcweir mbHasFocus = sal_True; 104cdf0e10cSrcweir CommitFocusGained(); 105cdf0e10cSrcweir if (mpTextHelper) 106cdf0e10cSrcweir mpTextHelper->SetFocus(sal_True); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir //===== XAccessibleComponent ============================================ 110cdf0e10cSrcweir 111cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleEditObject::getAccessibleAtPoint( 112cdf0e10cSrcweir const awt::Point& rPoint ) 113cdf0e10cSrcweir throw (uno::RuntimeException) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir uno::Reference<XAccessible> xRet; 116cdf0e10cSrcweir if (containsPoint(rPoint)) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir ScUnoGuard aGuard; 119cdf0e10cSrcweir IsObjectValid(); 120cdf0e10cSrcweir 121cdf0e10cSrcweir if(!mpTextHelper) 122cdf0e10cSrcweir CreateTextHelper(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir xRet = mpTextHelper->GetAt(rPoint); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir return xRet; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir Rectangle ScAccessibleEditObject::GetBoundingBoxOnScreen(void) const 131cdf0e10cSrcweir throw (uno::RuntimeException) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir Rectangle aScreenBounds; 134cdf0e10cSrcweir 135cdf0e10cSrcweir if ( mpWindow ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir if ( meObjectType == CellInEditMode ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir if ( mpEditView && mpEditView->GetEditEngine() ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir MapMode aMapMode( mpEditView->GetEditEngine()->GetRefMapMode() ); 142cdf0e10cSrcweir aScreenBounds = mpWindow->LogicToPixel( mpEditView->GetOutputArea(), aMapMode ); 143cdf0e10cSrcweir Point aCellLoc = aScreenBounds.TopLeft(); 144cdf0e10cSrcweir Rectangle aWindowRect = mpWindow->GetWindowExtentsRelative( NULL ); 145cdf0e10cSrcweir Point aWindowLoc = aWindowRect.TopLeft(); 146cdf0e10cSrcweir Point aPos( aCellLoc.getX() + aWindowLoc.getX(), aCellLoc.getY() + aWindowLoc.getY() ); 147cdf0e10cSrcweir aScreenBounds.SetPos( aPos ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir else 151cdf0e10cSrcweir { 152cdf0e10cSrcweir aScreenBounds = mpWindow->GetWindowExtentsRelative( NULL ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir return aScreenBounds; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir Rectangle ScAccessibleEditObject::GetBoundingBox(void) const 160cdf0e10cSrcweir throw (uno::RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Rectangle aBounds( GetBoundingBoxOnScreen() ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir if ( mpWindow ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir uno::Reference< XAccessible > xThis( mpWindow->GetAccessible() ); 167cdf0e10cSrcweir if ( xThis.is() ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir uno::Reference< XAccessibleContext > xContext( xThis->getAccessibleContext() ); 170cdf0e10cSrcweir if ( xContext.is() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir uno::Reference< XAccessible > xParent( xContext->getAccessibleParent() ); 173cdf0e10cSrcweir if ( xParent.is() ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir uno::Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY ); 176cdf0e10cSrcweir if ( xParentComponent.is() ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir Point aScreenLoc = aBounds.TopLeft(); 179cdf0e10cSrcweir awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen(); 180cdf0e10cSrcweir Point aPos( aScreenLoc.getX() - aParentScreenLoc.X, aScreenLoc.getY() - aParentScreenLoc.Y ); 181cdf0e10cSrcweir aBounds.SetPos( aPos ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir return aBounds; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir //===== XAccessibleContext ============================================== 192cdf0e10cSrcweir 193cdf0e10cSrcweir sal_Int32 SAL_CALL 194cdf0e10cSrcweir ScAccessibleEditObject::getAccessibleChildCount(void) 195cdf0e10cSrcweir throw (uno::RuntimeException) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir ScUnoGuard aGuard; 198cdf0e10cSrcweir IsObjectValid(); 199cdf0e10cSrcweir if (!mpTextHelper) 200cdf0e10cSrcweir CreateTextHelper(); 201cdf0e10cSrcweir return mpTextHelper->GetChildCount(); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL 205cdf0e10cSrcweir ScAccessibleEditObject::getAccessibleChild(sal_Int32 nIndex) 206cdf0e10cSrcweir throw (uno::RuntimeException, 207cdf0e10cSrcweir lang::IndexOutOfBoundsException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir ScUnoGuard aGuard; 210cdf0e10cSrcweir IsObjectValid(); 211cdf0e10cSrcweir if (!mpTextHelper) 212cdf0e10cSrcweir CreateTextHelper(); 213cdf0e10cSrcweir return mpTextHelper->GetChild(nIndex); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL 217cdf0e10cSrcweir ScAccessibleEditObject::getAccessibleStateSet(void) 218cdf0e10cSrcweir throw (uno::RuntimeException) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir ScUnoGuard aGuard; 221cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> xParentStates; 222cdf0e10cSrcweir if (getAccessibleParent().is()) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext(); 225cdf0e10cSrcweir xParentStates = xParentContext->getAccessibleStateSet(); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper(); 228cdf0e10cSrcweir if (IsDefunc(xParentStates)) 229cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::DEFUNC); 230cdf0e10cSrcweir else 231cdf0e10cSrcweir { 232cdf0e10cSrcweir // all states are const, because this object exists only in one state 233cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::EDITABLE); 234cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::ENABLED); 235cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::SENSITIVE); 236cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::MULTI_LINE); 237cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE); 238cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::SHOWING); 239cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::VISIBLE); 240cdf0e10cSrcweir } 241cdf0e10cSrcweir return pStateSet; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir ::rtl::OUString SAL_CALL 245cdf0e10cSrcweir ScAccessibleEditObject::createAccessibleDescription(void) 246cdf0e10cSrcweir throw (uno::RuntimeException) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir // DBG_ERRORFILE("Should never be called, because is set in the constructor.") 249cdf0e10cSrcweir return rtl::OUString(); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir ::rtl::OUString SAL_CALL 253cdf0e10cSrcweir ScAccessibleEditObject::createAccessibleName(void) 254cdf0e10cSrcweir throw (uno::RuntimeException) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir DBG_ERRORFILE("Should never be called, because is set in the constructor."); 257cdf0e10cSrcweir return rtl::OUString(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir ///===== XAccessibleEventBroadcaster ===================================== 261cdf0e10cSrcweir 262cdf0e10cSrcweir void SAL_CALL 263cdf0e10cSrcweir ScAccessibleEditObject::addEventListener(const uno::Reference<XAccessibleEventListener>& xListener) 264cdf0e10cSrcweir throw (uno::RuntimeException) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir if (!mpTextHelper) 267cdf0e10cSrcweir CreateTextHelper(); 268cdf0e10cSrcweir 269cdf0e10cSrcweir mpTextHelper->AddEventListener(xListener); 270cdf0e10cSrcweir 271cdf0e10cSrcweir ScAccessibleContextBase::addEventListener(xListener); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir void SAL_CALL 275cdf0e10cSrcweir ScAccessibleEditObject::removeEventListener(const uno::Reference<XAccessibleEventListener>& xListener) 276cdf0e10cSrcweir throw (uno::RuntimeException) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir if (!mpTextHelper) 279cdf0e10cSrcweir CreateTextHelper(); 280cdf0e10cSrcweir 281cdf0e10cSrcweir mpTextHelper->RemoveEventListener(xListener); 282cdf0e10cSrcweir 283cdf0e10cSrcweir ScAccessibleContextBase::removeEventListener(xListener); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir //===== XServiceInfo ==================================================== 287cdf0e10cSrcweir 288cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleEditObject::getImplementationName(void) 289cdf0e10cSrcweir throw (uno::RuntimeException) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleEditObject")); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir //===== XTypeProvider ======================================================= 295cdf0e10cSrcweir 296cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL 297cdf0e10cSrcweir ScAccessibleEditObject::getImplementationId(void) 298cdf0e10cSrcweir throw (uno::RuntimeException) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir ScUnoGuard aGuard; 301cdf0e10cSrcweir IsObjectValid(); 302cdf0e10cSrcweir static uno::Sequence<sal_Int8> aId; 303cdf0e10cSrcweir if (aId.getLength() == 0) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir aId.realloc (16); 306cdf0e10cSrcweir rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir return aId; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir //==== internal ========================================================= 312cdf0e10cSrcweir 313cdf0e10cSrcweir sal_Bool ScAccessibleEditObject::IsDefunc( 314cdf0e10cSrcweir const uno::Reference<XAccessibleStateSet>& rxParentStates) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir return ScAccessibleContextBase::IsDefunc() || !getAccessibleParent().is() || 317cdf0e10cSrcweir (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC)); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir void ScAccessibleEditObject::CreateTextHelper() 321cdf0e10cSrcweir { 322cdf0e10cSrcweir if (!mpTextHelper) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir ::std::auto_ptr < ScAccessibleTextData > pAccessibleTextData; 325cdf0e10cSrcweir if (meObjectType == CellInEditMode || meObjectType == EditControl) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir pAccessibleTextData.reset 328cdf0e10cSrcweir (new ScAccessibleEditObjectTextData(mpEditView, mpWindow)); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir else 331cdf0e10cSrcweir { 332cdf0e10cSrcweir pAccessibleTextData.reset 333cdf0e10cSrcweir (new ScAccessibleEditLineTextData(NULL, mpWindow)); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleTextData)); 337cdf0e10cSrcweir mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource ); 338cdf0e10cSrcweir mpTextHelper->SetEventSource(this); 339cdf0e10cSrcweir mpTextHelper->SetFocus(mbHasFocus); 340cdf0e10cSrcweir 341cdf0e10cSrcweir // #i54814# activate cell in edit mode 342cdf0e10cSrcweir if( meObjectType == CellInEditMode ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir // do not activate cell object, if top edit line is active 345cdf0e10cSrcweir const ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(); 346cdf0e10cSrcweir if( pInputHdl && !pInputHdl->IsTopMode() ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir SdrHint aHint( HINT_BEGEDIT ); 349cdf0e10cSrcweir mpTextHelper->GetEditSource().GetBroadcaster().Broadcast( aHint ); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355