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