Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePageHeaderArea.cxx
blob78f8579726b5cf3d7c0c1e2f708b33edbdc92447
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 <tools/gen.hxx>
21 #include "AccessiblePageHeaderArea.hxx"
22 #include "AccessibleText.hxx"
23 #include "AccessibilityHints.hxx"
24 #include "editsrc.hxx"
25 #include "prevwsh.hxx"
26 #include "prevloc.hxx"
27 #include "scresid.hxx"
28 #include "sc.hrc"
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33 #include <editeng/editobj.hxx>
34 #include <svx/AccessibleTextHelper.hxx>
35 #include <comphelper/servicehelper.hxx>
36 #include <unotools/accessiblestatesethelper.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <toolkit/helper/convert.hxx>
39 #include <vcl/svapp.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::accessibility;
44 //===== internal ========================================================
46 ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
47 const uno::Reference<XAccessible>& rxParent,
48 ScPreviewShell* pViewShell,
49 const EditTextObject* pEditObj,
50 bool bHeader,
51 SvxAdjust eAdjust)
52 : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
53 mpEditObj(pEditObj->Clone()),
54 mpTextHelper(NULL),
55 mpViewShell(pViewShell),
56 mbHeader(bHeader),
57 meAdjust(eAdjust)
59 if (mpViewShell)
60 mpViewShell->AddAccessibilityObject(*this);
63 ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea(void)
65 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
67 // increment refcount to prevent double call off dtor
68 osl_atomic_increment( &m_refCount );
69 dispose();
73 void SAL_CALL ScAccessiblePageHeaderArea::disposing()
75 SolarMutexGuard aGuard;
76 if (mpViewShell)
78 mpViewShell->RemoveAccessibilityObject(*this);
79 mpViewShell = NULL;
81 if (mpTextHelper)
82 DELETEZ(mpTextHelper);
83 if (mpEditObj)
84 DELETEZ(mpEditObj);
86 ScAccessibleContextBase::disposing();
89 //===== SfxListener =====================================================
91 void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
93 if (rHint.ISA( SfxSimpleHint ) )
95 const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
96 // only notify if child exist, otherwise it is not necessary
97 if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
99 if (mpTextHelper)
100 mpTextHelper->UpdateChildren();
102 AccessibleEventObject aEvent;
103 aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
104 aEvent.Source = uno::Reference< XAccessibleContext >(this);
105 CommitChange(aEvent);
108 ScAccessibleContextBase::Notify(rBC, rHint);
110 //===== XAccessibleComponent ============================================
112 uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeaderArea::getAccessibleAtPoint(
113 const awt::Point& rPoint )
114 throw (uno::RuntimeException, std::exception)
116 uno::Reference<XAccessible> xRet;
117 if (containsPoint(rPoint))
119 SolarMutexGuard aGuard;
120 IsObjectValid();
122 if(!mpTextHelper)
123 CreateTextHelper();
125 xRet = mpTextHelper->GetAt(rPoint);
128 return xRet;
131 //===== XAccessibleContext ==============================================
133 sal_Int32 SAL_CALL
134 ScAccessiblePageHeaderArea::getAccessibleChildCount(void)
135 throw (uno::RuntimeException, std::exception)
137 SolarMutexGuard aGuard;
138 IsObjectValid();
139 if (!mpTextHelper)
140 CreateTextHelper();
141 return mpTextHelper->GetChildCount();
144 uno::Reference< XAccessible > SAL_CALL
145 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex)
146 throw (uno::RuntimeException,
147 lang::IndexOutOfBoundsException, std::exception)
149 SolarMutexGuard aGuard;
150 IsObjectValid();
151 if (!mpTextHelper)
152 CreateTextHelper();
153 return mpTextHelper->GetChild(nIndex);
156 uno::Reference<XAccessibleStateSet> SAL_CALL
157 ScAccessiblePageHeaderArea::getAccessibleStateSet(void)
158 throw (uno::RuntimeException, std::exception)
160 SolarMutexGuard aGuard;
161 uno::Reference<XAccessibleStateSet> xParentStates;
162 if (getAccessibleParent().is())
164 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
165 xParentStates = xParentContext->getAccessibleStateSet();
167 utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
168 if (IsDefunc())
169 pStateSet->AddState(AccessibleStateType::DEFUNC);
170 else
172 pStateSet->AddState(AccessibleStateType::ENABLED);
173 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
174 if (isShowing())
175 pStateSet->AddState(AccessibleStateType::SHOWING);
176 if (isVisible())
177 pStateSet->AddState(AccessibleStateType::VISIBLE);
179 return pStateSet;
182 //===== XServiceInfo ========================================================
184 OUString SAL_CALL
185 ScAccessiblePageHeaderArea::getImplementationName(void)
186 throw (uno::RuntimeException, std::exception)
188 return OUString("ScAccessiblePageHeaderArea");
191 uno::Sequence< OUString> SAL_CALL
192 ScAccessiblePageHeaderArea::getSupportedServiceNames(void)
193 throw (uno::RuntimeException, std::exception)
195 uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
196 sal_Int32 nOldSize(aSequence.getLength());
197 aSequence.realloc(nOldSize + 1);
199 aSequence[nOldSize] = "com.sun.star.sheet.AccessiblePageHeaderFooterAreasView";
201 return aSequence;
204 //===== XTypeProvider =======================================================
206 uno::Sequence<sal_Int8> SAL_CALL
207 ScAccessiblePageHeaderArea::getImplementationId(void)
208 throw (uno::RuntimeException, std::exception)
210 return css::uno::Sequence<sal_Int8>();
213 //===== internal ==============================================================
214 OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleDescription(void)
215 throw(uno::RuntimeException)
217 OUString sDesc;
218 switch (meAdjust)
220 case SVX_ADJUST_LEFT :
221 sDesc = OUString(ScResId(STR_ACC_LEFTAREA_DESCR));
222 break;
223 case SVX_ADJUST_RIGHT:
224 sDesc = OUString(ScResId(STR_ACC_RIGHTAREA_DESCR));
225 break;
226 case SVX_ADJUST_CENTER:
227 sDesc = OUString(ScResId(STR_ACC_CENTERAREA_DESCR));
228 break;
229 default:
230 OSL_FAIL("wrong adjustment found");
233 return sDesc;
236 OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleName(void)
237 throw (uno::RuntimeException, std::exception)
239 OUString sName;
240 switch (meAdjust)
242 case SVX_ADJUST_LEFT :
243 sName = OUString(ScResId(STR_ACC_LEFTAREA_NAME));
244 break;
245 case SVX_ADJUST_RIGHT:
246 sName = OUString(ScResId(STR_ACC_RIGHTAREA_NAME));
247 break;
248 case SVX_ADJUST_CENTER:
249 sName = OUString(ScResId(STR_ACC_CENTERAREA_NAME));
250 break;
251 default:
252 OSL_FAIL("wrong adjustment found");
255 return sName;
258 Rectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen(void) const
259 throw(::com::sun::star::uno::RuntimeException, std::exception)
261 Rectangle aRect;
262 if (mxParent.is())
264 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
265 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
266 if (xComp.is())
268 // has the same size and position on screen like the parent
269 aRect = Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
272 return aRect;
275 Rectangle ScAccessiblePageHeaderArea::GetBoundingBox(void) const
276 throw (::com::sun::star::uno::RuntimeException, std::exception)
278 Rectangle aRect;
279 if (mxParent.is())
281 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
282 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
283 if (xComp.is())
285 // has the same size and position on screen like the parent and so the pos is (0, 0)
286 Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
287 aRect = aNewRect;
291 return aRect;
294 void ScAccessiblePageHeaderArea::CreateTextHelper()
296 if (!mpTextHelper)
298 SAL_WNODEPRECATED_DECLARATIONS_PUSH
299 ::std::auto_ptr < ScAccessibleTextData > pAccessibleHeaderTextData
300 (new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust));
301 ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleHeaderTextData));
302 SAL_WNODEPRECATED_DECLARATIONS_POP
304 mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
305 mpTextHelper->SetEventSource(this);
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */