Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
29 :
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>
40 :
41 : using namespace ::com::sun::star;
42 : using namespace ::com::sun::star::accessibility;
43 :
44 : //===== internal ========================================================
45 :
46 13 : ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
47 : const uno::Reference<XAccessible>& rxParent,
48 : ScPreviewShell* pViewShell,
49 : const EditTextObject* pEditObj,
50 : sal_Bool bHeader,
51 : SvxAdjust eAdjust)
52 : : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
53 13 : mpEditObj(pEditObj->Clone()),
54 : mpTextHelper(NULL),
55 : mpViewShell(pViewShell),
56 : mbHeader(bHeader),
57 26 : meAdjust(eAdjust)
58 : {
59 13 : if (mpViewShell)
60 13 : mpViewShell->AddAccessibilityObject(*this);
61 13 : }
62 :
63 39 : ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea(void)
64 : {
65 13 : if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
66 : {
67 : // increment refcount to prevent double call off dtor
68 0 : osl_atomic_increment( &m_refCount );
69 0 : dispose();
70 : }
71 26 : }
72 :
73 13 : void SAL_CALL ScAccessiblePageHeaderArea::disposing()
74 : {
75 13 : SolarMutexGuard aGuard;
76 13 : if (mpViewShell)
77 : {
78 13 : mpViewShell->RemoveAccessibilityObject(*this);
79 13 : mpViewShell = NULL;
80 : }
81 13 : if (mpTextHelper)
82 10 : DELETEZ(mpTextHelper);
83 13 : if (mpEditObj)
84 13 : DELETEZ(mpEditObj);
85 :
86 13 : ScAccessibleContextBase::disposing();
87 13 : }
88 :
89 : //===== SfxListener =====================================================
90 :
91 41 : void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
92 : {
93 41 : if (rHint.ISA( SfxSimpleHint ) )
94 : {
95 28 : const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
96 : // only notify if child exist, otherwise it is not necessary
97 28 : if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
98 : {
99 10 : if (mpTextHelper)
100 10 : mpTextHelper->UpdateChildren();
101 :
102 10 : AccessibleEventObject aEvent;
103 10 : aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
104 10 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
105 10 : CommitChange(aEvent);
106 : }
107 : }
108 41 : ScAccessibleContextBase::Notify(rBC, rHint);
109 41 : }
110 : //===== XAccessibleComponent ============================================
111 :
112 0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeaderArea::getAccessibleAtPoint(
113 : const awt::Point& rPoint )
114 : throw (uno::RuntimeException)
115 : {
116 0 : uno::Reference<XAccessible> xRet;
117 0 : if (containsPoint(rPoint))
118 : {
119 0 : SolarMutexGuard aGuard;
120 0 : IsObjectValid();
121 :
122 0 : if(!mpTextHelper)
123 0 : CreateTextHelper();
124 :
125 0 : xRet = mpTextHelper->GetAt(rPoint);
126 : }
127 :
128 0 : return xRet;
129 : }
130 :
131 : //===== XAccessibleContext ==============================================
132 :
133 : sal_Int32 SAL_CALL
134 26 : ScAccessiblePageHeaderArea::getAccessibleChildCount(void)
135 : throw (uno::RuntimeException)
136 : {
137 26 : SolarMutexGuard aGuard;
138 26 : IsObjectValid();
139 26 : if (!mpTextHelper)
140 10 : CreateTextHelper();
141 26 : return mpTextHelper->GetChildCount();
142 : }
143 :
144 : uno::Reference< XAccessible > SAL_CALL
145 13 : ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex)
146 : throw (uno::RuntimeException,
147 : lang::IndexOutOfBoundsException)
148 : {
149 13 : SolarMutexGuard aGuard;
150 13 : IsObjectValid();
151 13 : if (!mpTextHelper)
152 0 : CreateTextHelper();
153 13 : return mpTextHelper->GetChild(nIndex);
154 : }
155 :
156 : uno::Reference<XAccessibleStateSet> SAL_CALL
157 10 : ScAccessiblePageHeaderArea::getAccessibleStateSet(void)
158 : throw (uno::RuntimeException)
159 : {
160 10 : SolarMutexGuard aGuard;
161 20 : uno::Reference<XAccessibleStateSet> xParentStates;
162 10 : if (getAccessibleParent().is())
163 : {
164 10 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
165 10 : xParentStates = xParentContext->getAccessibleStateSet();
166 : }
167 10 : utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
168 10 : if (IsDefunc())
169 0 : pStateSet->AddState(AccessibleStateType::DEFUNC);
170 : else
171 : {
172 10 : pStateSet->AddState(AccessibleStateType::ENABLED);
173 10 : pStateSet->AddState(AccessibleStateType::MULTI_LINE);
174 10 : if (isShowing())
175 0 : pStateSet->AddState(AccessibleStateType::SHOWING);
176 10 : if (isVisible())
177 10 : pStateSet->AddState(AccessibleStateType::VISIBLE);
178 : }
179 20 : return pStateSet;
180 : }
181 :
182 : //===== XServiceInfo ========================================================
183 :
184 : OUString SAL_CALL
185 3 : ScAccessiblePageHeaderArea::getImplementationName(void)
186 : throw (uno::RuntimeException)
187 : {
188 3 : return OUString("ScAccessiblePageHeaderArea");
189 : }
190 :
191 : uno::Sequence< OUString> SAL_CALL
192 0 : ScAccessiblePageHeaderArea::getSupportedServiceNames(void)
193 : throw (uno::RuntimeException)
194 : {
195 0 : uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
196 0 : sal_Int32 nOldSize(aSequence.getLength());
197 0 : aSequence.realloc(nOldSize + 1);
198 0 : OUString* pNames = aSequence.getArray();
199 :
200 0 : pNames[nOldSize] = OUString("com.sun.star.sheet.AccessiblePageHeaderFooterAreasView");
201 :
202 0 : return aSequence;
203 : }
204 :
205 : //===== XTypeProvider =======================================================
206 :
207 : namespace
208 : {
209 : class theScAccessiblePageHeaderAreaImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePageHeaderAreaImplementationId > {};
210 : }
211 :
212 : uno::Sequence<sal_Int8> SAL_CALL
213 0 : ScAccessiblePageHeaderArea::getImplementationId(void)
214 : throw (uno::RuntimeException)
215 : {
216 0 : return theScAccessiblePageHeaderAreaImplementationId::get().getSeq();
217 : }
218 :
219 : //===== internal ==============================================================
220 6 : OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleDescription(void)
221 : throw(uno::RuntimeException)
222 : {
223 6 : OUString sDesc;
224 6 : switch (meAdjust)
225 : {
226 : case SVX_ADJUST_LEFT :
227 6 : sDesc = String(ScResId(STR_ACC_LEFTAREA_DESCR));
228 6 : break;
229 : case SVX_ADJUST_RIGHT:
230 0 : sDesc = String(ScResId(STR_ACC_RIGHTAREA_DESCR));
231 0 : break;
232 : case SVX_ADJUST_CENTER:
233 0 : sDesc = String(ScResId(STR_ACC_CENTERAREA_DESCR));
234 0 : break;
235 : default:
236 : OSL_FAIL("wrong adjustment found");
237 : }
238 :
239 6 : return sDesc;
240 : }
241 :
242 1 : OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleName(void)
243 : throw (uno::RuntimeException)
244 : {
245 1 : OUString sName;
246 1 : switch (meAdjust)
247 : {
248 : case SVX_ADJUST_LEFT :
249 1 : sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
250 1 : break;
251 : case SVX_ADJUST_RIGHT:
252 0 : sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
253 0 : break;
254 : case SVX_ADJUST_CENTER:
255 0 : sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
256 0 : break;
257 : default:
258 : OSL_FAIL("wrong adjustment found");
259 : }
260 :
261 1 : return sName;
262 : }
263 :
264 0 : Rectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen(void) const
265 : throw(::com::sun::star::uno::RuntimeException)
266 : {
267 0 : Rectangle aRect;
268 0 : if (mxParent.is())
269 : {
270 0 : uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
271 0 : uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
272 0 : if (xComp.is())
273 : {
274 : // has the same size and position on screen like the parent
275 0 : aRect = Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
276 0 : }
277 : }
278 0 : return aRect;
279 : }
280 :
281 13 : Rectangle ScAccessiblePageHeaderArea::GetBoundingBox(void) const
282 : throw (::com::sun::star::uno::RuntimeException)
283 : {
284 13 : Rectangle aRect;
285 13 : if (mxParent.is())
286 : {
287 13 : uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
288 26 : uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
289 13 : if (xComp.is())
290 : {
291 : // has the same size and position on screen like the parent and so the pos is (0, 0)
292 13 : Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
293 13 : aRect = aNewRect;
294 13 : }
295 : }
296 :
297 13 : return aRect;
298 : }
299 :
300 10 : void ScAccessiblePageHeaderArea::CreateTextHelper()
301 : {
302 10 : if (!mpTextHelper)
303 : {
304 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
305 : ::std::auto_ptr < ScAccessibleTextData > pAccessibleHeaderTextData
306 10 : (new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust));
307 20 : ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleHeaderTextData));
308 : SAL_WNODEPRECATED_DECLARATIONS_POP
309 :
310 10 : mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
311 20 : mpTextHelper->SetEventSource(this);
312 : }
313 103 : }
314 :
315 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|