Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePreviewCell.cxx
blob23650ecbc8e8b610acec41159d509ae0d287a5c4
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 "scitems.hxx"
21 #include <editeng/eeitem.hxx>
22 #include <tools/gen.hxx>
23 #include "AccessibleText.hxx"
24 #include "editsrc.hxx"
25 #include "AccessiblePreviewCell.hxx"
26 #include "AccessibilityHints.hxx"
27 #include "prevwsh.hxx"
28 #include "prevloc.hxx"
29 #include "document.hxx"
30 #include <svx/AccessibleTextHelper.hxx>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <editeng/brushitem.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/svapp.hxx>
35 #include <toolkit/helper/convert.hxx>
36 #include <comphelper/servicehelper.hxx>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
42 //===== internal ============================================================
44 ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
45 ::com::sun::star::accessibility::XAccessible>& rxParent,
46 ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
47 sal_Int32 nIndex ) :
48 ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
49 mpViewShell( pViewShell ),
50 mpTextHelper(NULL)
52 if (mpViewShell)
53 mpViewShell->AddAccessibilityObject(*this);
56 ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
58 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
60 // increment refcount to prevent double call off dtor
61 osl_atomic_increment( &m_refCount );
62 // call dispose to inform object which have a weak reference to this object
63 dispose();
67 void SAL_CALL ScAccessiblePreviewCell::disposing()
69 SolarMutexGuard aGuard;
70 if (mpViewShell)
72 mpViewShell->RemoveAccessibilityObject(*this);
73 mpViewShell = NULL;
76 if (mpTextHelper)
77 DELETEZ(mpTextHelper);
79 ScAccessibleCellBase::disposing();
82 void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
84 if (rHint.ISA( SfxSimpleHint ))
86 const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
87 if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
89 if (mpTextHelper)
90 mpTextHelper->UpdateChildren();
94 ScAccessibleContextBase::Notify(rBC, rHint);
97 //===== XAccessibleComponent ============================================
99 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
100 throw (uno::RuntimeException, std::exception)
102 uno::Reference<XAccessible> xRet;
103 if (containsPoint(rPoint))
105 SolarMutexGuard aGuard;
106 IsObjectValid();
108 if(!mpTextHelper)
109 CreateTextHelper();
111 xRet = mpTextHelper->GetAt(rPoint);
114 return xRet;
117 void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException, std::exception)
119 SolarMutexGuard aGuard;
120 IsObjectValid();
121 if (getAccessibleParent().is())
123 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
124 if (xAccessibleComponent.is())
125 xAccessibleComponent->grabFocus();
129 //===== XAccessibleContext ==============================================
131 sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException, std::exception)
133 SolarMutexGuard aGuard;
134 IsObjectValid();
135 if (!mpTextHelper)
136 CreateTextHelper();
137 return mpTextHelper->GetChildCount();
140 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
141 throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
143 SolarMutexGuard aGuard;
144 IsObjectValid();
145 if (!mpTextHelper)
146 CreateTextHelper();
147 return mpTextHelper->GetChild(nIndex);
150 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
151 throw(uno::RuntimeException, std::exception)
153 SolarMutexGuard aGuard;
155 uno::Reference<XAccessibleStateSet> xParentStates;
156 if (getAccessibleParent().is())
158 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
159 xParentStates = xParentContext->getAccessibleStateSet();
161 utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
162 if (IsDefunc(xParentStates))
163 pStateSet->AddState(AccessibleStateType::DEFUNC);
164 else
166 pStateSet->AddState(AccessibleStateType::ENABLED);
167 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
168 if (IsOpaque(xParentStates))
169 pStateSet->AddState(AccessibleStateType::OPAQUE);
170 if (isShowing())
171 pStateSet->AddState(AccessibleStateType::SHOWING);
172 pStateSet->AddState(AccessibleStateType::TRANSIENT);
173 if (isVisible())
174 pStateSet->AddState(AccessibleStateType::VISIBLE);
175 // MANAGES_DESCENDANTS (for paragraphs)
176 pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
178 return pStateSet;
181 //===== XServiceInfo ====================================================
183 OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException, std::exception)
185 return OUString("ScAccessiblePreviewCell");
188 uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
189 throw(uno::RuntimeException, std::exception)
191 uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
192 sal_Int32 nOldSize(aSequence.getLength());
193 aSequence.realloc(nOldSize + 1);
195 aSequence[nOldSize] = "com.sun.star.table.AccessibleCellView";
197 return aSequence;
200 //===== XTypeProvider =======================================================
202 uno::Sequence<sal_Int8> SAL_CALL
203 ScAccessiblePreviewCell::getImplementationId(void)
204 throw (uno::RuntimeException, std::exception)
206 return css::uno::Sequence<sal_Int8>();
209 //==== internal =========================================================
211 Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException, std::exception)
213 Rectangle aCellRect;
214 if (mpViewShell)
216 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
217 Window* pWindow = mpViewShell->GetWindow();
218 if (pWindow)
220 Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
221 aCellRect.setX(aCellRect.getX() + aRect.getX());
222 aCellRect.setY(aCellRect.getY() + aRect.getY());
225 return aCellRect;
228 Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException, std::exception)
230 Rectangle aCellRect;
231 if (mpViewShell)
233 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
234 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
235 if (xAccParent.is())
237 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
238 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
239 if (xAccParentComp.is())
241 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
242 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
243 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
247 return aCellRect;
250 bool ScAccessiblePreviewCell::IsDefunc(
251 const uno::Reference<XAccessibleStateSet>& rxParentStates)
253 return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
254 (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
257 bool ScAccessiblePreviewCell::IsEditable(
258 const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
260 return false;
263 bool ScAccessiblePreviewCell::IsOpaque(
264 const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
266 // test whether there is a background color
267 //! could be moved to ScAccessibleCellBase
269 bool bOpaque(true);
270 if (mpDoc)
272 const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
273 maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
274 if (pItem)
275 bOpaque = pItem->GetColor() != COL_TRANSPARENT;
277 return bOpaque;
280 void ScAccessiblePreviewCell::CreateTextHelper()
282 if (!mpTextHelper)
284 SAL_WNODEPRECATED_DECLARATIONS_PUSH
285 ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
286 (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
287 ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
288 SAL_WNODEPRECATED_DECLARATIONS_POP
290 mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
291 mpTextHelper->SetEventSource( this );
293 // paragraphs in preview are transient
294 ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
295 aChildStates.push_back( AccessibleStateType::TRANSIENT );
296 mpTextHelper->SetAdditionalChildStates( aChildStates );
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */