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 <sal/config.h>
25 #include "scitems.hxx"
26 #include <editeng/eeitem.hxx>
27 #include <tools/gen.hxx>
28 #include "AccessibleText.hxx"
29 #include "editsrc.hxx"
30 #include "AccessiblePreviewCell.hxx"
31 #include "AccessibilityHints.hxx"
32 #include "prevwsh.hxx"
33 #include "prevloc.hxx"
34 #include "document.hxx"
35 #include <svx/AccessibleTextHelper.hxx>
36 #include <unotools/accessiblestatesethelper.hxx>
37 #include <editeng/brushitem.hxx>
38 #include <vcl/window.hxx>
39 #include <vcl/svapp.hxx>
40 #include <toolkit/helper/convert.hxx>
41 #include <comphelper/servicehelper.hxx>
42 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::accessibility
;
47 //===== internal ============================================================
49 ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference
<
50 ::com::sun::star::accessibility::XAccessible
>& rxParent
,
51 ScPreviewShell
* pViewShell
, /* const */ ScAddress
& rCellAddress
,
53 ScAccessibleCellBase( rxParent
, ( pViewShell
? &pViewShell
->GetDocument() : NULL
), rCellAddress
, nIndex
),
54 mpViewShell( pViewShell
),
58 mpViewShell
->AddAccessibilityObject(*this);
61 ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
63 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper
.bInDispose
)
65 // increment refcount to prevent double call off dtor
66 osl_atomic_increment( &m_refCount
);
67 // call dispose to inform object which have a weak reference to this object
72 void SAL_CALL
ScAccessiblePreviewCell::disposing()
74 SolarMutexGuard aGuard
;
77 mpViewShell
->RemoveAccessibilityObject(*this);
82 DELETEZ(mpTextHelper
);
84 ScAccessibleCellBase::disposing();
87 void ScAccessiblePreviewCell::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
89 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
90 if (pSimpleHint
&& pSimpleHint
->GetId() == SC_HINT_ACC_VISAREACHANGED
)
93 mpTextHelper
->UpdateChildren();
96 ScAccessibleContextBase::Notify(rBC
, rHint
);
99 //===== XAccessibleComponent ============================================
101 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point
& rPoint
)
102 throw (uno::RuntimeException
, std::exception
)
104 uno::Reference
<XAccessible
> xRet
;
105 if (containsPoint(rPoint
))
107 SolarMutexGuard aGuard
;
113 xRet
= mpTextHelper
->GetAt(rPoint
);
119 void SAL_CALL
ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException
, std::exception
)
121 SolarMutexGuard aGuard
;
123 if (getAccessibleParent().is())
125 uno::Reference
<XAccessibleComponent
> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY
);
126 if (xAccessibleComponent
.is())
127 xAccessibleComponent
->grabFocus();
131 //===== XAccessibleContext ==============================================
133 sal_Int32 SAL_CALL
ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException
, std::exception
)
135 SolarMutexGuard aGuard
;
139 return mpTextHelper
->GetChildCount();
142 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex
)
143 throw (uno::RuntimeException
, lang::IndexOutOfBoundsException
, std::exception
)
145 SolarMutexGuard aGuard
;
149 return mpTextHelper
->GetChild(nIndex
);
152 uno::Reference
<XAccessibleStateSet
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleStateSet()
153 throw(uno::RuntimeException
, std::exception
)
155 SolarMutexGuard aGuard
;
157 uno::Reference
<XAccessibleStateSet
> xParentStates
;
158 if (getAccessibleParent().is())
160 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
161 xParentStates
= xParentContext
->getAccessibleStateSet();
163 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
164 if (IsDefunc(xParentStates
))
165 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
168 pStateSet
->AddState(AccessibleStateType::ENABLED
);
169 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
170 if (IsOpaque(xParentStates
))
171 pStateSet
->AddState(AccessibleStateType::OPAQUE
);
173 pStateSet
->AddState(AccessibleStateType::SHOWING
);
174 pStateSet
->AddState(AccessibleStateType::TRANSIENT
);
176 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
177 // MANAGES_DESCENDANTS (for paragraphs)
178 pStateSet
->AddState(AccessibleStateType::MANAGES_DESCENDANTS
);
183 //===== XServiceInfo ====================================================
185 OUString SAL_CALL
ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException
, std::exception
)
187 return OUString("ScAccessiblePreviewCell");
190 uno::Sequence
<OUString
> SAL_CALL
ScAccessiblePreviewCell::getSupportedServiceNames()
191 throw(uno::RuntimeException
, std::exception
)
193 uno::Sequence
< OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
194 sal_Int32
nOldSize(aSequence
.getLength());
195 aSequence
.realloc(nOldSize
+ 1);
197 aSequence
[nOldSize
] = "com.sun.star.table.AccessibleCellView";
202 //===== XTypeProvider =======================================================
204 uno::Sequence
<sal_Int8
> SAL_CALL
205 ScAccessiblePreviewCell::getImplementationId()
206 throw (uno::RuntimeException
, std::exception
)
208 return css::uno::Sequence
<sal_Int8
>();
211 //==== internal =========================================================
213 Rectangle
ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException
, std::exception
)
218 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
219 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
222 Rectangle aRect
= pWindow
->GetWindowExtentsRelative(NULL
);
223 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
224 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
230 Rectangle
ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException
, std::exception
)
235 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
236 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewCell
*>(this)->getAccessibleParent();
239 uno::Reference
<XAccessibleContext
> xAccParentContext
= xAccParent
->getAccessibleContext();
240 uno::Reference
<XAccessibleComponent
> xAccParentComp (xAccParentContext
, uno::UNO_QUERY
);
241 if (xAccParentComp
.is())
243 Rectangle
aParentRect (VCLRectangle(xAccParentComp
->getBounds()));
244 aCellRect
.setX(aCellRect
.getX() - aParentRect
.getX());
245 aCellRect
.setY(aCellRect
.getY() - aParentRect
.getY());
252 bool ScAccessiblePreviewCell::IsDefunc(
253 const uno::Reference
<XAccessibleStateSet
>& rxParentStates
)
255 return ScAccessibleContextBase::IsDefunc() || (mpDoc
== NULL
) || (mpViewShell
== NULL
) || !getAccessibleParent().is() ||
256 (rxParentStates
.is() && rxParentStates
->contains(AccessibleStateType::DEFUNC
));
259 bool ScAccessiblePreviewCell::IsEditable(
260 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
265 bool ScAccessiblePreviewCell::IsOpaque(
266 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
268 // test whether there is a background color
269 //! could be moved to ScAccessibleCellBase
274 const SvxBrushItem
* pItem
= static_cast<const SvxBrushItem
*>(mpDoc
->GetAttr(
275 maCellAddress
.Col(), maCellAddress
.Row(), maCellAddress
.Tab(), ATTR_BACKGROUND
));
277 bOpaque
= pItem
->GetColor() != COL_TRANSPARENT
;
282 void ScAccessiblePreviewCell::CreateTextHelper()
286 ::std::unique_ptr
< ScAccessibleTextData
> pAccessiblePreviewCellTextData
287 (new ScAccessiblePreviewCellTextData(mpViewShell
, maCellAddress
));
288 ::std::unique_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(std::move(pAccessiblePreviewCellTextData
)));
290 mpTextHelper
= new ::accessibility::AccessibleTextHelper( std::move(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: */