merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / Accessibility / AccessiblePreviewCell.cxx
blob31849fdbc693ff5cdd5fd61f29dd4fa19d01e542
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePreviewCell.cxx,v $
10 * $Revision: 1.21.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "scitems.hxx"
34 #include <svx/eeitem.hxx>
35 #include <tools/gen.hxx>
36 #include "AccessibleText.hxx"
37 #include "editsrc.hxx"
38 #include "AccessiblePreviewCell.hxx"
39 #include "AccessibilityHints.hxx"
40 #include "prevwsh.hxx"
41 #include "unoguard.hxx"
42 #include "prevloc.hxx"
43 #include "document.hxx"
44 #include <svx/AccessibleTextHelper.hxx>
45 #include <unotools/accessiblestatesethelper.hxx>
46 #include <svx/brshitem.hxx>
47 #include <vcl/window.hxx>
48 #include <toolkit/helper/convert.hxx>
50 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::accessibility;
55 //===== internal ============================================================
57 ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
58 ::com::sun::star::accessibility::XAccessible>& rxParent,
59 ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
60 sal_Int32 nIndex ) :
61 ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
62 mpViewShell( pViewShell ),
63 mpTextHelper(NULL)
65 if (mpViewShell)
66 mpViewShell->AddAccessibilityObject(*this);
69 ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
71 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
73 // increment refcount to prevent double call off dtor
74 osl_incrementInterlockedCount( &m_refCount );
75 // call dispose to inform object wich have a weak reference to this object
76 dispose();
80 void SAL_CALL ScAccessiblePreviewCell::disposing()
82 ScUnoGuard aGuard;
83 if (mpViewShell)
85 mpViewShell->RemoveAccessibilityObject(*this);
86 mpViewShell = NULL;
89 if (mpTextHelper)
90 DELETEZ(mpTextHelper);
92 ScAccessibleCellBase::disposing();
95 void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
97 if (rHint.ISA( SfxSimpleHint ))
99 const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
100 if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
102 if (mpTextHelper)
103 mpTextHelper->UpdateChildren();
107 ScAccessibleContextBase::Notify(rBC, rHint);
110 //===== XAccessibleComponent ============================================
112 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
113 throw (uno::RuntimeException)
115 uno::Reference<XAccessible> xRet;
116 if (containsPoint(rPoint))
118 ScUnoGuard aGuard;
119 IsObjectValid();
121 if(!mpTextHelper)
122 CreateTextHelper();
124 xRet = mpTextHelper->GetAt(rPoint);
127 return xRet;
130 void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException)
132 ScUnoGuard aGuard;
133 IsObjectValid();
134 if (getAccessibleParent().is())
136 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
137 if (xAccessibleComponent.is())
138 xAccessibleComponent->grabFocus();
142 //===== XAccessibleContext ==============================================
144 sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException)
146 ScUnoGuard aGuard;
147 IsObjectValid();
148 if (!mpTextHelper)
149 CreateTextHelper();
150 return mpTextHelper->GetChildCount();
153 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
154 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
156 ScUnoGuard aGuard;
157 IsObjectValid();
158 if (!mpTextHelper)
159 CreateTextHelper();
160 return mpTextHelper->GetChild(nIndex);
163 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
164 throw(uno::RuntimeException)
166 ScUnoGuard aGuard;
168 uno::Reference<XAccessibleStateSet> xParentStates;
169 if (getAccessibleParent().is())
171 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
172 xParentStates = xParentContext->getAccessibleStateSet();
174 utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
175 if (IsDefunc(xParentStates))
176 pStateSet->AddState(AccessibleStateType::DEFUNC);
177 else
179 pStateSet->AddState(AccessibleStateType::ENABLED);
180 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
181 if (IsOpaque(xParentStates))
182 pStateSet->AddState(AccessibleStateType::OPAQUE);
183 if (isShowing())
184 pStateSet->AddState(AccessibleStateType::SHOWING);
185 pStateSet->AddState(AccessibleStateType::TRANSIENT);
186 if (isVisible())
187 pStateSet->AddState(AccessibleStateType::VISIBLE);
188 // #111635# MANAGES_DESCENDANTS (for paragraphs)
189 pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
191 return pStateSet;
194 //===== XServiceInfo ====================================================
196 rtl::OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException)
198 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewCell"));
201 uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
202 throw(uno::RuntimeException)
204 uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
205 sal_Int32 nOldSize(aSequence.getLength());
206 aSequence.realloc(nOldSize + 1);
207 ::rtl::OUString* pNames = aSequence.getArray();
209 pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
211 return aSequence;
214 //===== XTypeProvider =======================================================
216 uno::Sequence<sal_Int8> SAL_CALL
217 ScAccessiblePreviewCell::getImplementationId(void)
218 throw (uno::RuntimeException)
220 ScUnoGuard aGuard;
221 IsObjectValid();
222 static uno::Sequence<sal_Int8> aId;
223 if (aId.getLength() == 0)
225 aId.realloc (16);
226 rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
228 return aId;
231 //==== internal =========================================================
233 Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
235 Rectangle aCellRect;
236 if (mpViewShell)
238 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
239 Window* pWindow = mpViewShell->GetWindow();
240 if (pWindow)
242 Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
243 aCellRect.setX(aCellRect.getX() + aRect.getX());
244 aCellRect.setY(aCellRect.getY() + aRect.getY());
247 return aCellRect;
250 Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException)
252 Rectangle aCellRect;
253 if (mpViewShell)
255 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
256 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
257 if (xAccParent.is())
259 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
260 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
261 if (xAccParentComp.is())
263 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
264 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
265 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
269 return aCellRect;
272 sal_Bool ScAccessiblePreviewCell::IsDefunc(
273 const uno::Reference<XAccessibleStateSet>& rxParentStates)
275 return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
276 (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
279 sal_Bool ScAccessiblePreviewCell::IsEditable(
280 const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
282 return sal_False;
285 sal_Bool ScAccessiblePreviewCell::IsOpaque(
286 const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
288 // test whether there is a background color
289 //! could be moved to ScAccessibleCellBase
291 sal_Bool bOpaque(sal_True);
292 if (mpDoc)
294 const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
295 maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
296 if (pItem)
297 bOpaque = pItem->GetColor() != COL_TRANSPARENT;
299 return bOpaque;
302 void ScAccessiblePreviewCell::CreateTextHelper()
304 if (!mpTextHelper)
306 ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
307 (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
308 ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
310 mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
311 mpTextHelper->SetEventSource( this );
313 // #111635# paragraphs in preview are transient
314 ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
315 aChildStates.push_back( AccessibleStateType::TRANSIENT );
316 mpTextHelper->SetAdditionalChildStates( aChildStates );