1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
48 ScAccessibleCellBase( rxParent
, ( pViewShell
? pViewShell
->GetDocument() : NULL
), rCellAddress
, nIndex
),
49 mpViewShell( pViewShell
),
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
67 void SAL_CALL
ScAccessiblePreviewCell::disposing()
69 SolarMutexGuard aGuard
;
72 mpViewShell
->RemoveAccessibilityObject(*this);
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
)
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
;
111 xRet
= mpTextHelper
->GetAt(rPoint
);
117 void SAL_CALL
ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException
, std::exception
)
119 SolarMutexGuard aGuard
;
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
;
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
;
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
);
166 pStateSet
->AddState(AccessibleStateType::ENABLED
);
167 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
168 if (IsOpaque(xParentStates
))
169 pStateSet
->AddState(AccessibleStateType::OPAQUE
);
171 pStateSet
->AddState(AccessibleStateType::SHOWING
);
172 pStateSet
->AddState(AccessibleStateType::TRANSIENT
);
174 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
175 // MANAGES_DESCENDANTS (for paragraphs)
176 pStateSet
->AddState(AccessibleStateType::MANAGES_DESCENDANTS
);
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";
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
)
216 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
217 Window
* pWindow
= mpViewShell
->GetWindow();
220 Rectangle aRect
= pWindow
->GetWindowExtentsRelative(NULL
);
221 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
222 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
228 Rectangle
ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException
, std::exception
)
233 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
234 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewCell
*>(this)->getAccessibleParent();
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());
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 */)
263 bool ScAccessiblePreviewCell::IsOpaque(
264 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
266 // test whether there is a background color
267 //! could be moved to ScAccessibleCellBase
272 const SvxBrushItem
* pItem
= (const SvxBrushItem
*)mpDoc
->GetAttr(
273 maCellAddress
.Col(), maCellAddress
.Row(), maCellAddress
.Tab(), ATTR_BACKGROUND
);
275 bOpaque
= pItem
->GetColor() != COL_TRANSPARENT
;
280 void ScAccessiblePreviewCell::CreateTextHelper()
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: */