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 "scitems.hxx"
27cdf0e10cSrcweir #include <editeng/eeitem.hxx>
28cdf0e10cSrcweir #include <tools/gen.hxx>
29cdf0e10cSrcweir #include "AccessibleText.hxx"
30cdf0e10cSrcweir #include "editsrc.hxx"
31cdf0e10cSrcweir #include "AccessiblePreviewCell.hxx"
32cdf0e10cSrcweir #include "AccessibilityHints.hxx"
33cdf0e10cSrcweir #include "prevwsh.hxx"
34cdf0e10cSrcweir #include "unoguard.hxx"
35cdf0e10cSrcweir #include "prevloc.hxx"
36cdf0e10cSrcweir #include "document.hxx"
37cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx>
38cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
39cdf0e10cSrcweir #include <editeng/brshitem.hxx>
40cdf0e10cSrcweir #include <vcl/window.hxx>
41cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
47cdf0e10cSrcweir
48cdf0e10cSrcweir //===== internal ============================================================
49cdf0e10cSrcweir
ScAccessiblePreviewCell(const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & rxParent,ScPreviewShell * pViewShell,ScAddress & rCellAddress,sal_Int32 nIndex)50cdf0e10cSrcweir ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
51cdf0e10cSrcweir ::com::sun::star::accessibility::XAccessible>& rxParent,
52cdf0e10cSrcweir ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
53cdf0e10cSrcweir sal_Int32 nIndex ) :
54cdf0e10cSrcweir ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
55cdf0e10cSrcweir mpViewShell( pViewShell ),
56cdf0e10cSrcweir mpTextHelper(NULL)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir if (mpViewShell)
59cdf0e10cSrcweir mpViewShell->AddAccessibilityObject(*this);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
~ScAccessiblePreviewCell()62cdf0e10cSrcweir ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir // increment refcount to prevent double call off dtor
67cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount );
68cdf0e10cSrcweir // call dispose to inform object wich have a weak reference to this object
69cdf0e10cSrcweir dispose();
70cdf0e10cSrcweir }
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
disposing()73cdf0e10cSrcweir void SAL_CALL ScAccessiblePreviewCell::disposing()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir ScUnoGuard aGuard;
76cdf0e10cSrcweir if (mpViewShell)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir mpViewShell->RemoveAccessibilityObject(*this);
79cdf0e10cSrcweir mpViewShell = NULL;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir if (mpTextHelper)
83cdf0e10cSrcweir DELETEZ(mpTextHelper);
84cdf0e10cSrcweir
85cdf0e10cSrcweir ScAccessibleCellBase::disposing();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)88cdf0e10cSrcweir void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir if (rHint.ISA( SfxSimpleHint ))
91cdf0e10cSrcweir {
92cdf0e10cSrcweir const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
93cdf0e10cSrcweir if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if (mpTextHelper)
96cdf0e10cSrcweir mpTextHelper->UpdateChildren();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir ScAccessibleContextBase::Notify(rBC, rHint);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir //===== XAccessibleComponent ============================================
104cdf0e10cSrcweir
getAccessibleAtPoint(const awt::Point & rPoint)105cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
106cdf0e10cSrcweir throw (uno::RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir uno::Reference<XAccessible> xRet;
109cdf0e10cSrcweir if (containsPoint(rPoint))
110cdf0e10cSrcweir {
111cdf0e10cSrcweir ScUnoGuard aGuard;
112cdf0e10cSrcweir IsObjectValid();
113cdf0e10cSrcweir
114cdf0e10cSrcweir if(!mpTextHelper)
115cdf0e10cSrcweir CreateTextHelper();
116cdf0e10cSrcweir
117cdf0e10cSrcweir xRet = mpTextHelper->GetAt(rPoint);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir return xRet;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
grabFocus()123cdf0e10cSrcweir void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir ScUnoGuard aGuard;
126cdf0e10cSrcweir IsObjectValid();
127cdf0e10cSrcweir if (getAccessibleParent().is())
128cdf0e10cSrcweir {
129cdf0e10cSrcweir uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
130cdf0e10cSrcweir if (xAccessibleComponent.is())
131cdf0e10cSrcweir xAccessibleComponent->grabFocus();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir //===== XAccessibleContext ==============================================
136cdf0e10cSrcweir
getAccessibleChildCount()137cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir ScUnoGuard aGuard;
140cdf0e10cSrcweir IsObjectValid();
141cdf0e10cSrcweir if (!mpTextHelper)
142cdf0e10cSrcweir CreateTextHelper();
143cdf0e10cSrcweir return mpTextHelper->GetChildCount();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
getAccessibleChild(sal_Int32 nIndex)146cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
147cdf0e10cSrcweir throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir ScUnoGuard aGuard;
150cdf0e10cSrcweir IsObjectValid();
151cdf0e10cSrcweir if (!mpTextHelper)
152cdf0e10cSrcweir CreateTextHelper();
153cdf0e10cSrcweir return mpTextHelper->GetChild(nIndex);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
getAccessibleStateSet()156cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
157cdf0e10cSrcweir throw(uno::RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir ScUnoGuard aGuard;
160cdf0e10cSrcweir
161cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> xParentStates;
162cdf0e10cSrcweir if (getAccessibleParent().is())
163cdf0e10cSrcweir {
164cdf0e10cSrcweir uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
165cdf0e10cSrcweir xParentStates = xParentContext->getAccessibleStateSet();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
168cdf0e10cSrcweir if (IsDefunc(xParentStates))
169cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::DEFUNC);
170cdf0e10cSrcweir else
171cdf0e10cSrcweir {
172cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::ENABLED);
173cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::MULTI_LINE);
174cdf0e10cSrcweir if (IsOpaque(xParentStates))
175cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::OPAQUE);
176cdf0e10cSrcweir if (isShowing())
177cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::SHOWING);
178cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::TRANSIENT);
179cdf0e10cSrcweir if (isVisible())
180cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::VISIBLE);
181cdf0e10cSrcweir // #111635# MANAGES_DESCENDANTS (for paragraphs)
182cdf0e10cSrcweir pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
183cdf0e10cSrcweir }
184cdf0e10cSrcweir return pStateSet;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir //===== XServiceInfo ====================================================
188cdf0e10cSrcweir
getImplementationName()189cdf0e10cSrcweir rtl::OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewCell"));
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
getSupportedServiceNames()194cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
195cdf0e10cSrcweir throw(uno::RuntimeException)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
198cdf0e10cSrcweir sal_Int32 nOldSize(aSequence.getLength());
199cdf0e10cSrcweir aSequence.realloc(nOldSize + 1);
200cdf0e10cSrcweir ::rtl::OUString* pNames = aSequence.getArray();
201cdf0e10cSrcweir
202cdf0e10cSrcweir pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
203cdf0e10cSrcweir
204cdf0e10cSrcweir return aSequence;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir //===== XTypeProvider =======================================================
208cdf0e10cSrcweir
209cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
getImplementationId(void)210cdf0e10cSrcweir ScAccessiblePreviewCell::getImplementationId(void)
211cdf0e10cSrcweir throw (uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir ScUnoGuard aGuard;
214cdf0e10cSrcweir IsObjectValid();
215cdf0e10cSrcweir static uno::Sequence<sal_Int8> aId;
216cdf0e10cSrcweir if (aId.getLength() == 0)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir aId.realloc (16);
219cdf0e10cSrcweir rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir return aId;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
224cdf0e10cSrcweir //==== internal =========================================================
225cdf0e10cSrcweir
GetBoundingBoxOnScreen() const226cdf0e10cSrcweir Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir Rectangle aCellRect;
229cdf0e10cSrcweir if (mpViewShell)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
232cdf0e10cSrcweir Window* pWindow = mpViewShell->GetWindow();
233cdf0e10cSrcweir if (pWindow)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
236cdf0e10cSrcweir aCellRect.setX(aCellRect.getX() + aRect.getX());
237cdf0e10cSrcweir aCellRect.setY(aCellRect.getY() + aRect.getY());
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir return aCellRect;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
GetBoundingBox() const243cdf0e10cSrcweir Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir Rectangle aCellRect;
246cdf0e10cSrcweir if (mpViewShell)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
249cdf0e10cSrcweir uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
250cdf0e10cSrcweir if (xAccParent.is())
251cdf0e10cSrcweir {
252cdf0e10cSrcweir uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
253cdf0e10cSrcweir uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
254cdf0e10cSrcweir if (xAccParentComp.is())
255cdf0e10cSrcweir {
256cdf0e10cSrcweir Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
257cdf0e10cSrcweir aCellRect.setX(aCellRect.getX() - aParentRect.getX());
258cdf0e10cSrcweir aCellRect.setY(aCellRect.getY() - aParentRect.getY());
259cdf0e10cSrcweir }
260cdf0e10cSrcweir }
261cdf0e10cSrcweir }
262cdf0e10cSrcweir return aCellRect;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
IsDefunc(const uno::Reference<XAccessibleStateSet> & rxParentStates)265cdf0e10cSrcweir sal_Bool ScAccessiblePreviewCell::IsDefunc(
266cdf0e10cSrcweir const uno::Reference<XAccessibleStateSet>& rxParentStates)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
269cdf0e10cSrcweir (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
IsEditable(const uno::Reference<XAccessibleStateSet> &)272cdf0e10cSrcweir sal_Bool ScAccessiblePreviewCell::IsEditable(
273cdf0e10cSrcweir const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir return sal_False;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir
IsOpaque(const uno::Reference<XAccessibleStateSet> &)278cdf0e10cSrcweir sal_Bool ScAccessiblePreviewCell::IsOpaque(
279cdf0e10cSrcweir const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir // test whether there is a background color
282cdf0e10cSrcweir //! could be moved to ScAccessibleCellBase
283cdf0e10cSrcweir
284cdf0e10cSrcweir sal_Bool bOpaque(sal_True);
285cdf0e10cSrcweir if (mpDoc)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
288cdf0e10cSrcweir maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
289cdf0e10cSrcweir if (pItem)
290cdf0e10cSrcweir bOpaque = pItem->GetColor() != COL_TRANSPARENT;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir return bOpaque;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
CreateTextHelper()295cdf0e10cSrcweir void ScAccessiblePreviewCell::CreateTextHelper()
296cdf0e10cSrcweir {
297cdf0e10cSrcweir if (!mpTextHelper)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
300cdf0e10cSrcweir (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
301cdf0e10cSrcweir ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
302cdf0e10cSrcweir
303cdf0e10cSrcweir mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
304cdf0e10cSrcweir mpTextHelper->SetEventSource( this );
305cdf0e10cSrcweir
306cdf0e10cSrcweir // #111635# paragraphs in preview are transient
307cdf0e10cSrcweir ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
308cdf0e10cSrcweir aChildStates.push_back( AccessibleStateType::TRANSIENT );
309cdf0e10cSrcweir mpTextHelper->SetAdditionalChildStates( aChildStates );
310cdf0e10cSrcweir }
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313