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 <tools/gen.hxx>
26 #include "AccessiblePageHeaderArea.hxx"
27 #include "AccessibleText.hxx"
28 #include "AccessibilityHints.hxx"
29 #include "editsrc.hxx"
30 #include "prevwsh.hxx"
31 #include "prevloc.hxx"
32 #include "scresid.hxx"
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
38 #include <editeng/editobj.hxx>
39 #include <svx/AccessibleTextHelper.hxx>
40 #include <comphelper/servicehelper.hxx>
41 #include <unotools/accessiblestatesethelper.hxx>
42 #include <rtl/ustrbuf.hxx>
43 #include <toolkit/helper/convert.hxx>
44 #include <vcl/svapp.hxx>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::accessibility
;
49 //===== internal ========================================================
51 ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
52 const uno::Reference
<XAccessible
>& rxParent
,
53 ScPreviewShell
* pViewShell
,
54 const EditTextObject
* pEditObj
,
57 : ScAccessibleContextBase(rxParent
, AccessibleRole::TEXT
),
58 mpEditObj(pEditObj
->Clone()),
60 mpViewShell(pViewShell
),
65 mpViewShell
->AddAccessibilityObject(*this);
68 ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea()
70 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper
.bInDispose
)
72 // increment refcount to prevent double call off dtor
73 osl_atomic_increment( &m_refCount
);
78 void SAL_CALL
ScAccessiblePageHeaderArea::disposing()
80 SolarMutexGuard aGuard
;
83 mpViewShell
->RemoveAccessibilityObject(*this);
87 DELETEZ(mpTextHelper
);
91 ScAccessibleContextBase::disposing();
94 //===== SfxListener =====================================================
96 void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
98 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
101 // only notify if child exist, otherwise it is not necessary
102 if (pSimpleHint
->GetId() == SC_HINT_ACC_VISAREACHANGED
)
105 mpTextHelper
->UpdateChildren();
107 AccessibleEventObject aEvent
;
108 aEvent
.EventId
= AccessibleEventId::VISIBLE_DATA_CHANGED
;
109 aEvent
.Source
= uno::Reference
< XAccessibleContext
>(this);
110 CommitChange(aEvent
);
113 ScAccessibleContextBase::Notify(rBC
, rHint
);
115 //===== XAccessibleComponent ============================================
117 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePageHeaderArea::getAccessibleAtPoint(
118 const awt::Point
& rPoint
)
119 throw (uno::RuntimeException
, std::exception
)
121 uno::Reference
<XAccessible
> xRet
;
122 if (containsPoint(rPoint
))
124 SolarMutexGuard aGuard
;
130 xRet
= mpTextHelper
->GetAt(rPoint
);
136 //===== XAccessibleContext ==============================================
139 ScAccessiblePageHeaderArea::getAccessibleChildCount()
140 throw (uno::RuntimeException
, std::exception
)
142 SolarMutexGuard aGuard
;
146 return mpTextHelper
->GetChildCount();
149 uno::Reference
< XAccessible
> SAL_CALL
150 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex
)
151 throw (uno::RuntimeException
,
152 lang::IndexOutOfBoundsException
, std::exception
)
154 SolarMutexGuard aGuard
;
158 return mpTextHelper
->GetChild(nIndex
);
161 uno::Reference
<XAccessibleStateSet
> SAL_CALL
162 ScAccessiblePageHeaderArea::getAccessibleStateSet()
163 throw (uno::RuntimeException
, std::exception
)
165 SolarMutexGuard aGuard
;
166 uno::Reference
<XAccessibleStateSet
> xParentStates
;
167 if (getAccessibleParent().is())
169 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
170 xParentStates
= xParentContext
->getAccessibleStateSet();
172 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
174 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
177 pStateSet
->AddState(AccessibleStateType::ENABLED
);
178 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
180 pStateSet
->AddState(AccessibleStateType::SHOWING
);
182 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
190 ScAccessiblePageHeaderArea::getImplementationName()
191 throw (uno::RuntimeException
, std::exception
)
193 return OUString("ScAccessiblePageHeaderArea");
196 uno::Sequence
< OUString
> SAL_CALL
197 ScAccessiblePageHeaderArea::getSupportedServiceNames()
198 throw (uno::RuntimeException
, std::exception
)
200 uno::Sequence
< OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
201 sal_Int32
nOldSize(aSequence
.getLength());
202 aSequence
.realloc(nOldSize
+ 1);
204 aSequence
[nOldSize
] = "com.sun.star.sheet.AccessiblePageHeaderFooterAreasView";
209 //===== XTypeProvider =======================================================
211 uno::Sequence
<sal_Int8
> SAL_CALL
212 ScAccessiblePageHeaderArea::getImplementationId()
213 throw (uno::RuntimeException
, std::exception
)
215 return css::uno::Sequence
<sal_Int8
>();
218 //===== internal ==============================================================
219 OUString SAL_CALL
ScAccessiblePageHeaderArea::createAccessibleDescription()
220 throw(uno::RuntimeException
)
225 case SVX_ADJUST_LEFT
:
226 sDesc
= OUString(ScResId(STR_ACC_LEFTAREA_DESCR
));
228 case SVX_ADJUST_RIGHT
:
229 sDesc
= OUString(ScResId(STR_ACC_RIGHTAREA_DESCR
));
231 case SVX_ADJUST_CENTER
:
232 sDesc
= OUString(ScResId(STR_ACC_CENTERAREA_DESCR
));
235 OSL_FAIL("wrong adjustment found");
241 OUString SAL_CALL
ScAccessiblePageHeaderArea::createAccessibleName()
242 throw (uno::RuntimeException
, std::exception
)
247 case SVX_ADJUST_LEFT
:
248 sName
= OUString(ScResId(STR_ACC_LEFTAREA_NAME
));
250 case SVX_ADJUST_RIGHT
:
251 sName
= OUString(ScResId(STR_ACC_RIGHTAREA_NAME
));
253 case SVX_ADJUST_CENTER
:
254 sName
= OUString(ScResId(STR_ACC_CENTERAREA_NAME
));
257 OSL_FAIL("wrong adjustment found");
263 Rectangle
ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen() const
264 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
269 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
270 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
273 // has the same size and position on screen like the parent
274 aRect
= Rectangle(VCLPoint(xComp
->getLocationOnScreen()), VCLRectangle(xComp
->getBounds()).GetSize());
280 Rectangle
ScAccessiblePageHeaderArea::GetBoundingBox() const
281 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
286 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
287 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
290 // has the same size and position on screen like the parent and so the pos is (0, 0)
291 Rectangle
aNewRect(Point(0, 0), VCLRectangle(xComp
->getBounds()).GetSize());
299 void ScAccessiblePageHeaderArea::CreateTextHelper()
303 ::std::unique_ptr
< ScAccessibleTextData
> pAccessibleHeaderTextData
304 (new ScAccessibleHeaderTextData(mpViewShell
, mpEditObj
, mbHeader
, meAdjust
));
305 ::std::unique_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(std::move(pAccessibleHeaderTextData
)));
307 mpTextHelper
= new ::accessibility::AccessibleTextHelper(std::move(pEditSource
));
308 mpTextHelper
->SetEventSource(this);
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */