fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePageHeaderArea.cxx
blob0d0209ec71c3264884ea6591e4b39e0374329eea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <memory>
23 #include <utility>
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"
33 #include "sc.hrc"
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,
55 bool bHeader,
56 SvxAdjust eAdjust)
57 : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
58 mpEditObj(pEditObj->Clone()),
59 mpTextHelper(NULL),
60 mpViewShell(pViewShell),
61 mbHeader(bHeader),
62 meAdjust(eAdjust)
64 if (mpViewShell)
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 );
74 dispose();
78 void SAL_CALL ScAccessiblePageHeaderArea::disposing()
80 SolarMutexGuard aGuard;
81 if (mpViewShell)
83 mpViewShell->RemoveAccessibilityObject(*this);
84 mpViewShell = NULL;
86 if (mpTextHelper)
87 DELETEZ(mpTextHelper);
88 if (mpEditObj)
89 DELETEZ(mpEditObj);
91 ScAccessibleContextBase::disposing();
94 //===== SfxListener =====================================================
96 void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
98 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
99 if (pSimpleHint)
101 // only notify if child exist, otherwise it is not necessary
102 if (pSimpleHint->GetId() == SC_HINT_ACC_VISAREACHANGED)
104 if (mpTextHelper)
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;
125 IsObjectValid();
127 if(!mpTextHelper)
128 CreateTextHelper();
130 xRet = mpTextHelper->GetAt(rPoint);
133 return xRet;
136 //===== XAccessibleContext ==============================================
138 sal_Int32 SAL_CALL
139 ScAccessiblePageHeaderArea::getAccessibleChildCount()
140 throw (uno::RuntimeException, std::exception)
142 SolarMutexGuard aGuard;
143 IsObjectValid();
144 if (!mpTextHelper)
145 CreateTextHelper();
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;
155 IsObjectValid();
156 if (!mpTextHelper)
157 CreateTextHelper();
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();
173 if (IsDefunc())
174 pStateSet->AddState(AccessibleStateType::DEFUNC);
175 else
177 pStateSet->AddState(AccessibleStateType::ENABLED);
178 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
179 if (isShowing())
180 pStateSet->AddState(AccessibleStateType::SHOWING);
181 if (isVisible())
182 pStateSet->AddState(AccessibleStateType::VISIBLE);
184 return pStateSet;
187 // XServiceInfo
189 OUString SAL_CALL
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";
206 return aSequence;
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)
222 OUString sDesc;
223 switch (meAdjust)
225 case SVX_ADJUST_LEFT :
226 sDesc = OUString(ScResId(STR_ACC_LEFTAREA_DESCR));
227 break;
228 case SVX_ADJUST_RIGHT:
229 sDesc = OUString(ScResId(STR_ACC_RIGHTAREA_DESCR));
230 break;
231 case SVX_ADJUST_CENTER:
232 sDesc = OUString(ScResId(STR_ACC_CENTERAREA_DESCR));
233 break;
234 default:
235 OSL_FAIL("wrong adjustment found");
238 return sDesc;
241 OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleName()
242 throw (uno::RuntimeException, std::exception)
244 OUString sName;
245 switch (meAdjust)
247 case SVX_ADJUST_LEFT :
248 sName = OUString(ScResId(STR_ACC_LEFTAREA_NAME));
249 break;
250 case SVX_ADJUST_RIGHT:
251 sName = OUString(ScResId(STR_ACC_RIGHTAREA_NAME));
252 break;
253 case SVX_ADJUST_CENTER:
254 sName = OUString(ScResId(STR_ACC_CENTERAREA_NAME));
255 break;
256 default:
257 OSL_FAIL("wrong adjustment found");
260 return sName;
263 Rectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen() const
264 throw(::com::sun::star::uno::RuntimeException, std::exception)
266 Rectangle aRect;
267 if (mxParent.is())
269 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
270 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
271 if (xComp.is())
273 // has the same size and position on screen like the parent
274 aRect = Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
277 return aRect;
280 Rectangle ScAccessiblePageHeaderArea::GetBoundingBox() const
281 throw (::com::sun::star::uno::RuntimeException, std::exception)
283 Rectangle aRect;
284 if (mxParent.is())
286 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
287 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
288 if (xComp.is())
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());
292 aRect = aNewRect;
296 return aRect;
299 void ScAccessiblePageHeaderArea::CreateTextHelper()
301 if (!mpTextHelper)
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: */