Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/gen.hxx>
30 : : #include "AccessiblePageHeaderArea.hxx"
31 : : #include "AccessibleText.hxx"
32 : : #include "AccessibilityHints.hxx"
33 : : #include "editsrc.hxx"
34 : : #include "prevwsh.hxx"
35 : : #include "prevloc.hxx"
36 : : #include "scresid.hxx"
37 : : #include "sc.hrc"
38 : :
39 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 : : #include <editeng/editobj.hxx>
43 : : #include <svx/AccessibleTextHelper.hxx>
44 : : #include <comphelper/servicehelper.hxx>
45 : : #include <unotools/accessiblestatesethelper.hxx>
46 : : #include <rtl/ustrbuf.hxx>
47 : : #include <toolkit/helper/convert.hxx>
48 : : #include <vcl/svapp.hxx>
49 : :
50 : : using namespace ::com::sun::star;
51 : : using namespace ::com::sun::star::accessibility;
52 : :
53 : : //===== internal ========================================================
54 : :
55 : 24 : ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
56 : : const uno::Reference<XAccessible>& rxParent,
57 : : ScPreviewShell* pViewShell,
58 : : const EditTextObject* pEditObj,
59 : : sal_Bool bHeader,
60 : : SvxAdjust eAdjust)
61 : : : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
62 [ + - ]: 24 : mpEditObj(pEditObj->Clone()),
63 : : mpTextHelper(NULL),
64 : : mpViewShell(pViewShell),
65 : : mbHeader(bHeader),
66 : 24 : meAdjust(eAdjust)
67 : : {
68 [ + - ]: 24 : if (mpViewShell)
69 [ + - ]: 24 : mpViewShell->AddAccessibilityObject(*this);
70 : 24 : }
71 : :
72 : 24 : ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea(void)
73 : : {
74 [ - + ][ # # ]: 24 : if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
[ - + ]
75 : : {
76 : : // increment refcount to prevent double call off dtor
77 [ # # ]: 0 : osl_incrementInterlockedCount( &m_refCount );
78 [ # # ]: 0 : dispose();
79 : : }
80 [ - + ]: 48 : }
81 : :
82 : 24 : void SAL_CALL ScAccessiblePageHeaderArea::disposing()
83 : : {
84 [ + - ]: 24 : SolarMutexGuard aGuard;
85 [ + - ]: 24 : if (mpViewShell)
86 : : {
87 [ + - ]: 24 : mpViewShell->RemoveAccessibilityObject(*this);
88 : 24 : mpViewShell = NULL;
89 : : }
90 [ + + ]: 24 : if (mpTextHelper)
91 [ + - ][ + - ]: 18 : DELETEZ(mpTextHelper);
92 [ + - ]: 24 : if (mpEditObj)
93 [ + - ][ + - ]: 24 : DELETEZ(mpEditObj);
94 : :
95 [ + - ][ + - ]: 24 : ScAccessibleContextBase::disposing();
96 : 24 : }
97 : :
98 : : //===== SfxListener =====================================================
99 : :
100 : 68 : void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
101 : : {
102 [ + + ]: 68 : if (rHint.ISA( SfxSimpleHint ) )
103 : : {
104 : 44 : const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
105 : : // only notify if child exist, otherwise it is not necessary
106 [ + + ]: 44 : if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
107 : : {
108 [ + - ]: 10 : if (mpTextHelper)
109 [ + - ]: 10 : mpTextHelper->UpdateChildren();
110 : :
111 [ + - ]: 10 : AccessibleEventObject aEvent;
112 : 10 : aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
113 [ + - ][ + - ]: 10 : aEvent.Source = uno::Reference< XAccessibleContext >(this);
114 [ + - ][ + - ]: 10 : CommitChange(aEvent);
115 : : }
116 : : }
117 : 68 : ScAccessibleContextBase::Notify(rBC, rHint);
118 : 68 : }
119 : : //===== XAccessibleComponent ============================================
120 : :
121 : 2 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeaderArea::getAccessibleAtPoint(
122 : : const awt::Point& rPoint )
123 : : throw (uno::RuntimeException)
124 : : {
125 : 2 : uno::Reference<XAccessible> xRet;
126 [ + + ][ + - ]: 2 : if (containsPoint(rPoint))
127 : : {
128 [ + - ]: 1 : SolarMutexGuard aGuard;
129 [ + - ]: 1 : IsObjectValid();
130 : :
131 [ - + ]: 1 : if(!mpTextHelper)
132 [ # # ]: 0 : CreateTextHelper();
133 : :
134 [ + - ][ + - ]: 1 : xRet = mpTextHelper->GetAt(rPoint);
[ + - ]
135 : : }
136 : :
137 : 2 : return xRet;
138 : : }
139 : :
140 : : //===== XAccessibleContext ==============================================
141 : :
142 : : sal_Int32 SAL_CALL
143 : 52 : ScAccessiblePageHeaderArea::getAccessibleChildCount(void)
144 : : throw (uno::RuntimeException)
145 : : {
146 [ + - ]: 52 : SolarMutexGuard aGuard;
147 [ + - ]: 52 : IsObjectValid();
148 [ + + ]: 52 : if (!mpTextHelper)
149 [ + - ]: 18 : CreateTextHelper();
150 [ + - ][ + - ]: 52 : return mpTextHelper->GetChildCount();
151 : : }
152 : :
153 : : uno::Reference< XAccessible > SAL_CALL
154 : 24 : ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex)
155 : : throw (uno::RuntimeException,
156 : : lang::IndexOutOfBoundsException)
157 : : {
158 [ + - ]: 24 : SolarMutexGuard aGuard;
159 [ + - ]: 24 : IsObjectValid();
160 [ - + ]: 24 : if (!mpTextHelper)
161 [ # # ]: 0 : CreateTextHelper();
162 [ + - ][ + - ]: 24 : return mpTextHelper->GetChild(nIndex);
163 : : }
164 : :
165 : : uno::Reference<XAccessibleStateSet> SAL_CALL
166 : 19 : ScAccessiblePageHeaderArea::getAccessibleStateSet(void)
167 : : throw (uno::RuntimeException)
168 : : {
169 [ + - ]: 19 : SolarMutexGuard aGuard;
170 : 19 : uno::Reference<XAccessibleStateSet> xParentStates;
171 [ + - ][ + - ]: 19 : if (getAccessibleParent().is())
172 : : {
173 [ + - ][ + - ]: 19 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
[ + - ]
174 [ + - ][ + - ]: 19 : xParentStates = xParentContext->getAccessibleStateSet();
[ + - ]
175 : : }
176 [ + - ]: 19 : utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
177 [ - + ]: 19 : if (IsDefunc())
178 [ # # ]: 0 : pStateSet->AddState(AccessibleStateType::DEFUNC);
179 : : else
180 : : {
181 [ + - ]: 19 : pStateSet->AddState(AccessibleStateType::ENABLED);
182 [ + - ]: 19 : pStateSet->AddState(AccessibleStateType::MULTI_LINE);
183 [ + - ][ - + ]: 19 : if (isShowing())
184 [ # # ]: 0 : pStateSet->AddState(AccessibleStateType::SHOWING);
185 [ + - ][ + - ]: 19 : if (isVisible())
186 [ + - ]: 19 : pStateSet->AddState(AccessibleStateType::VISIBLE);
187 : : }
188 [ + - ][ + - ]: 19 : return pStateSet;
[ + - ]
189 : : }
190 : :
191 : : //===== XServiceInfo ========================================================
192 : :
193 : : ::rtl::OUString SAL_CALL
194 : 7 : ScAccessiblePageHeaderArea::getImplementationName(void)
195 : : throw (uno::RuntimeException)
196 : : {
197 : 7 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessiblePageHeaderArea"));
198 : : }
199 : :
200 : : uno::Sequence< ::rtl::OUString> SAL_CALL
201 : 0 : ScAccessiblePageHeaderArea::getSupportedServiceNames(void)
202 : : throw (uno::RuntimeException)
203 : : {
204 : 0 : uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
205 : 0 : sal_Int32 nOldSize(aSequence.getLength());
206 [ # # ]: 0 : aSequence.realloc(nOldSize + 1);
207 [ # # ]: 0 : ::rtl::OUString* pNames = aSequence.getArray();
208 : :
209 [ # # ]: 0 : pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.AccessiblePageHeaderFooterAreasView"));
210 : :
211 : 0 : return aSequence;
212 : : }
213 : :
214 : : //===== XTypeProvider =======================================================
215 : :
216 : : namespace
217 : : {
218 : : class theScAccessiblePageHeaderAreaImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePageHeaderAreaImplementationId > {};
219 : : }
220 : :
221 : : uno::Sequence<sal_Int8> SAL_CALL
222 : 0 : ScAccessiblePageHeaderArea::getImplementationId(void)
223 : : throw (uno::RuntimeException)
224 : : {
225 : 0 : return theScAccessiblePageHeaderAreaImplementationId::get().getSeq();
226 : : }
227 : :
228 : : //===== internal ==============================================================
229 : 19 : rtl::OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleDescription(void)
230 : : throw(uno::RuntimeException)
231 : : {
232 : 19 : rtl::OUString sDesc;
233 [ + - + - ]: 19 : switch (meAdjust)
234 : : {
235 : : case SVX_ADJUST_LEFT :
236 [ + - ][ + - ]: 12 : sDesc = String(ScResId(STR_ACC_LEFTAREA_DESCR));
[ + - ][ + - ]
237 : 12 : break;
238 : : case SVX_ADJUST_RIGHT:
239 [ # # ][ # # ]: 0 : sDesc = String(ScResId(STR_ACC_RIGHTAREA_DESCR));
[ # # ][ # # ]
240 : 0 : break;
241 : : case SVX_ADJUST_CENTER:
242 [ + - ][ + - ]: 7 : sDesc = String(ScResId(STR_ACC_CENTERAREA_DESCR));
[ + - ][ + - ]
243 : 7 : break;
244 : : default:
245 : : OSL_FAIL("wrong adjustment found");
246 : : }
247 : :
248 : 19 : return sDesc;
249 : : }
250 : :
251 : 3 : rtl::OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleName(void)
252 : : throw (uno::RuntimeException)
253 : : {
254 : 3 : rtl::OUString sName;
255 [ + - + - ]: 3 : switch (meAdjust)
256 : : {
257 : : case SVX_ADJUST_LEFT :
258 [ + - ][ + - ]: 2 : sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
[ + - ][ + - ]
259 : 2 : break;
260 : : case SVX_ADJUST_RIGHT:
261 [ # # ][ # # ]: 0 : sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
[ # # ][ # # ]
262 : 0 : break;
263 : : case SVX_ADJUST_CENTER:
264 [ + - ][ + - ]: 1 : sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
[ + - ][ + - ]
265 : 1 : break;
266 : : default:
267 : : OSL_FAIL("wrong adjustment found");
268 : : }
269 : :
270 : 3 : return sName;
271 : : }
272 : :
273 : 1 : Rectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen(void) const
274 : : throw(::com::sun::star::uno::RuntimeException)
275 : : {
276 : 1 : Rectangle aRect;
277 [ + - ]: 1 : if (mxParent.is())
278 : : {
279 [ + - ][ + - ]: 1 : uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
280 [ + - ]: 1 : uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
281 [ + - ]: 1 : if (xComp.is())
282 : : {
283 : : // has the same size and position on screen like the parent
284 [ + - ][ + - ]: 1 : aRect = Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
285 : 1 : }
286 : : }
287 : 1 : return aRect;
288 : : }
289 : :
290 : 604 : Rectangle ScAccessiblePageHeaderArea::GetBoundingBox(void) const
291 : : throw (::com::sun::star::uno::RuntimeException)
292 : : {
293 : 604 : Rectangle aRect;
294 [ + - ]: 604 : if (mxParent.is())
295 : : {
296 [ + - ][ + - ]: 604 : uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
297 [ + - ]: 604 : uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
298 [ + - ]: 604 : if (xComp.is())
299 : : {
300 : : // has the same size and position on screen like the parent and so the pos is (0, 0)
301 [ + - ][ + - ]: 604 : Rectangle aNewRect(Point(0, 0), VCLRectangle(xComp->getBounds()).GetSize());
[ + - ][ + - ]
[ + - ]
302 : 604 : aRect = aNewRect;
303 : 604 : }
304 : : }
305 : :
306 : 604 : return aRect;
307 : : }
308 : :
309 : 18 : void ScAccessiblePageHeaderArea::CreateTextHelper()
310 : : {
311 [ + - ]: 18 : if (!mpTextHelper)
312 : : {
313 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
314 : : ::std::auto_ptr < ScAccessibleTextData > pAccessibleHeaderTextData
315 [ + - ][ + - ]: 18 : (new ScAccessibleHeaderTextData(mpViewShell, mpEditObj, mbHeader, meAdjust));
316 [ + - ][ + - ]: 18 : ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleHeaderTextData));
[ + - ]
317 : : SAL_WNODEPRECATED_DECLARATIONS_POP
318 : :
319 [ + - ][ + - ]: 18 : mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
[ + - ]
320 [ + - ][ + - ]: 18 : mpTextHelper->SetEventSource(this);
[ + - ][ + - ]
321 : : }
322 : 18 : }
323 : :
324 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|