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
)
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
)
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
)
133 SolarMutexGuard aGuard
;
137 return mpTextHelper
->GetChildCount();
140 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex
)
141 throw (uno::RuntimeException
, lang::IndexOutOfBoundsException
)
143 SolarMutexGuard aGuard
;
147 return mpTextHelper
->GetChild(nIndex
);
150 uno::Reference
<XAccessibleStateSet
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleStateSet()
151 throw(uno::RuntimeException
)
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
)
185 return OUString("ScAccessiblePreviewCell");
188 uno::Sequence
<OUString
> SAL_CALL
ScAccessiblePreviewCell::getSupportedServiceNames()
189 throw(uno::RuntimeException
)
191 uno::Sequence
< OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
192 sal_Int32
nOldSize(aSequence
.getLength());
193 aSequence
.realloc(nOldSize
+ 1);
194 OUString
* pNames
= aSequence
.getArray();
196 pNames
[nOldSize
] = OUString("com.sun.star.table.AccessibleCellView");
201 //===== XTypeProvider =======================================================
205 class theScAccessiblePreviewCellImplementationId
: public rtl::Static
< UnoTunnelIdInit
, theScAccessiblePreviewCellImplementationId
> {};
208 uno::Sequence
<sal_Int8
> SAL_CALL
209 ScAccessiblePreviewCell::getImplementationId(void)
210 throw (uno::RuntimeException
)
212 return theScAccessiblePreviewCellImplementationId::get().getSeq();
215 //==== internal =========================================================
217 Rectangle
ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException
)
222 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
223 Window
* pWindow
= mpViewShell
->GetWindow();
226 Rectangle aRect
= pWindow
->GetWindowExtentsRelative(NULL
);
227 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
228 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
234 Rectangle
ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException
)
239 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
240 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewCell
*>(this)->getAccessibleParent();
243 uno::Reference
<XAccessibleContext
> xAccParentContext
= xAccParent
->getAccessibleContext();
244 uno::Reference
<XAccessibleComponent
> xAccParentComp (xAccParentContext
, uno::UNO_QUERY
);
245 if (xAccParentComp
.is())
247 Rectangle
aParentRect (VCLRectangle(xAccParentComp
->getBounds()));
248 aCellRect
.setX(aCellRect
.getX() - aParentRect
.getX());
249 aCellRect
.setY(aCellRect
.getY() - aParentRect
.getY());
256 sal_Bool
ScAccessiblePreviewCell::IsDefunc(
257 const uno::Reference
<XAccessibleStateSet
>& rxParentStates
)
259 return ScAccessibleContextBase::IsDefunc() || (mpDoc
== NULL
) || (mpViewShell
== NULL
) || !getAccessibleParent().is() ||
260 (rxParentStates
.is() && rxParentStates
->contains(AccessibleStateType::DEFUNC
));
263 sal_Bool
ScAccessiblePreviewCell::IsEditable(
264 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
269 sal_Bool
ScAccessiblePreviewCell::IsOpaque(
270 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
272 // test whether there is a background color
273 //! could be moved to ScAccessibleCellBase
275 sal_Bool
bOpaque(sal_True
);
278 const SvxBrushItem
* pItem
= (const SvxBrushItem
*)mpDoc
->GetAttr(
279 maCellAddress
.Col(), maCellAddress
.Row(), maCellAddress
.Tab(), ATTR_BACKGROUND
);
281 bOpaque
= pItem
->GetColor() != COL_TRANSPARENT
;
286 void ScAccessiblePreviewCell::CreateTextHelper()
290 SAL_WNODEPRECATED_DECLARATIONS_PUSH
291 ::std::auto_ptr
< ScAccessibleTextData
> pAccessiblePreviewCellTextData
292 (new ScAccessiblePreviewCellTextData(mpViewShell
, maCellAddress
));
293 ::std::auto_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData
));
294 SAL_WNODEPRECATED_DECLARATIONS_POP
296 mpTextHelper
= new ::accessibility::AccessibleTextHelper( pEditSource
);
297 mpTextHelper
->SetEventSource( this );
299 // paragraphs in preview are transient
300 ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates
;
301 aChildStates
.push_back( AccessibleStateType::TRANSIENT
);
302 mpTextHelper
->SetAdditionalChildStates( aChildStates
);
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */