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 
31*cdf0e10cSrcweir #include "AccessiblePageHeader.hxx"
32*cdf0e10cSrcweir #include "AccessiblePageHeaderArea.hxx"
33*cdf0e10cSrcweir #include "AccessibilityHints.hxx"
34*cdf0e10cSrcweir #include "prevwsh.hxx"
35*cdf0e10cSrcweir #include "unoguard.hxx"
36*cdf0e10cSrcweir #include "miscuno.hxx"
37*cdf0e10cSrcweir #include "prevloc.hxx"
38*cdf0e10cSrcweir #include "document.hxx"
39*cdf0e10cSrcweir #include "stlpool.hxx"
40*cdf0e10cSrcweir #include "scitems.hxx"
41*cdf0e10cSrcweir #include "attrib.hxx"
42*cdf0e10cSrcweir #include "scresid.hxx"
43*cdf0e10cSrcweir #ifndef SC_SC_HRC
44*cdf0e10cSrcweir #include "sc.hrc"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <vcl/window.hxx>
52*cdf0e10cSrcweir #include <svl/smplhint.hxx>
53*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
54*cdf0e10cSrcweir #include <svl/style.hxx>
55*cdf0e10cSrcweir #include <svl/itempool.hxx>
56*cdf0e10cSrcweir #include <editeng/editobj.hxx>
57*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <algorithm>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using namespace	::com::sun::star;
62*cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir const sal_uInt8     MAX_AREAS = 3;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir //=====  internal  ============================================================
67*cdf0e10cSrcweir struct Acquire
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	void operator() (ScAccessiblePageHeaderArea* pArea)
70*cdf0e10cSrcweir 	{
71*cdf0e10cSrcweir         if (pArea)
72*cdf0e10cSrcweir             pArea->acquire();
73*cdf0e10cSrcweir 	}
74*cdf0e10cSrcweir };
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir struct Release
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	void operator() (ScAccessiblePageHeaderArea*& pArea)
79*cdf0e10cSrcweir 	{
80*cdf0e10cSrcweir         if (pArea)
81*cdf0e10cSrcweir             pArea->release();
82*cdf0e10cSrcweir 	}
83*cdf0e10cSrcweir };
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir struct Dispose
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	void operator() (ScAccessiblePageHeaderArea*& pArea)
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir         if (pArea)
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir             pArea->dispose();
92*cdf0e10cSrcweir             pArea->release();
93*cdf0e10cSrcweir         }
94*cdf0e10cSrcweir         pArea = NULL;
95*cdf0e10cSrcweir 	}
96*cdf0e10cSrcweir };
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir ScAccessiblePageHeader::ScAccessiblePageHeader( const ::com::sun::star::uno::Reference<
99*cdf0e10cSrcweir 						        ::com::sun::star::accessibility::XAccessible>& rxParent,
100*cdf0e10cSrcweir 							ScPreviewShell* pViewShell, sal_Bool bHeader, sal_Int32 nIndex ) :
101*cdf0e10cSrcweir ScAccessibleContextBase( rxParent, bHeader ? AccessibleRole::HEADER : AccessibleRole::FOOTER ),
102*cdf0e10cSrcweir 	mpViewShell( pViewShell ),
103*cdf0e10cSrcweir 	mnIndex( nIndex ),
104*cdf0e10cSrcweir 	mbHeader( bHeader ),
105*cdf0e10cSrcweir     maAreas(MAX_AREAS, NULL),
106*cdf0e10cSrcweir     mnChildCount(-1)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	if (mpViewShell)
109*cdf0e10cSrcweir 		mpViewShell->AddAccessibilityObject(*this);
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir ScAccessiblePageHeader::~ScAccessiblePageHeader()
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
115*cdf0e10cSrcweir 	{
116*cdf0e10cSrcweir 		// increment refcount to prevent double call off dtor
117*cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
118*cdf0e10cSrcweir 		dispose();
119*cdf0e10cSrcweir 	}
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir void SAL_CALL ScAccessiblePageHeader::disposing()
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     ScUnoGuard aGuard;
125*cdf0e10cSrcweir 	if (mpViewShell)
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		mpViewShell->RemoveAccessibilityObject(*this);
128*cdf0e10cSrcweir 		mpViewShell = NULL;
129*cdf0e10cSrcweir 	}
130*cdf0e10cSrcweir     std::for_each(maAreas.begin(), maAreas.end(), Dispose());
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	ScAccessibleContextBase::disposing();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //=====  SfxListener  =====================================================
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir void ScAccessiblePageHeader::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir 	if (rHint.ISA( SfxSimpleHint ) )
140*cdf0e10cSrcweir 	{
141*cdf0e10cSrcweir 		const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
142*cdf0e10cSrcweir 		// only notify if child exist, otherwise it is not necessary
143*cdf0e10cSrcweir 		if ((rRef.GetId() == SC_HINT_DATACHANGED))
144*cdf0e10cSrcweir         {
145*cdf0e10cSrcweir             ScHFAreas aOldAreas(maAreas);
146*cdf0e10cSrcweir             std::for_each(aOldAreas.begin(), aOldAreas.end(), Acquire());
147*cdf0e10cSrcweir             mnChildCount = -1;
148*cdf0e10cSrcweir             getAccessibleChildCount();
149*cdf0e10cSrcweir             for (sal_uInt8 i = 0; i < MAX_AREAS; ++i)
150*cdf0e10cSrcweir             {
151*cdf0e10cSrcweir                 if ((aOldAreas[i] && maAreas[i] && !ScGlobal::EETextObjEqual(aOldAreas[i]->GetEditTextObject(), maAreas[i]->GetEditTextObject())) ||
152*cdf0e10cSrcweir                     (aOldAreas[i] && !maAreas[i]) || (!aOldAreas[i] && maAreas[i]))
153*cdf0e10cSrcweir                 {
154*cdf0e10cSrcweir                     if (aOldAreas[i] && aOldAreas[i]->GetEditTextObject())
155*cdf0e10cSrcweir                     {
156*cdf0e10cSrcweir 			            AccessibleEventObject aEvent;
157*cdf0e10cSrcweir 			            aEvent.EventId = AccessibleEventId::CHILD;
158*cdf0e10cSrcweir 			            aEvent.Source = uno::Reference< XAccessibleContext >(this);
159*cdf0e10cSrcweir                         aEvent.OldValue = uno::makeAny(uno::Reference<XAccessible>(aOldAreas[i]));
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 			            CommitChange(aEvent); // child gone - event
162*cdf0e10cSrcweir                         aOldAreas[i]->dispose();
163*cdf0e10cSrcweir                     }
164*cdf0e10cSrcweir                     if (maAreas[i] && maAreas[i]->GetEditTextObject())
165*cdf0e10cSrcweir                     {
166*cdf0e10cSrcweir 			            AccessibleEventObject aEvent;
167*cdf0e10cSrcweir 			            aEvent.EventId = AccessibleEventId::CHILD;
168*cdf0e10cSrcweir 			            aEvent.Source = uno::Reference< XAccessibleContext >(this);
169*cdf0e10cSrcweir                         aEvent.NewValue = uno::makeAny(uno::Reference<XAccessible>(maAreas[i]));
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 			            CommitChange(aEvent); // new child - event
172*cdf0e10cSrcweir                     }
173*cdf0e10cSrcweir                 }
174*cdf0e10cSrcweir             }
175*cdf0e10cSrcweir             std::for_each(aOldAreas.begin(), aOldAreas.end(), Release());
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir         else if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             AccessibleEventObject aEvent;
180*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
181*cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(this);
182*cdf0e10cSrcweir             CommitChange(aEvent);
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	ScAccessibleContextBase::Notify(rBC, rHint);
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir //=====  XAccessibleComponent  ============================================
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleAtPoint( const awt::Point& aPoint )
192*cdf0e10cSrcweir     							throw (uno::RuntimeException)
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir 	uno::Reference<XAccessible> xRet;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     if (containsPoint(aPoint))
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir     	ScUnoGuard aGuard;
199*cdf0e10cSrcweir         IsObjectValid();
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         sal_Int32 nCount(getAccessibleChildCount()); // fill the areas
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         if (nCount)
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             // return the first with content, because they have all the same Bounding Box
206*cdf0e10cSrcweir 	        sal_uInt8 i(0);
207*cdf0e10cSrcweir             while(!xRet.is() && i < MAX_AREAS)
208*cdf0e10cSrcweir             {
209*cdf0e10cSrcweir                 if (maAreas[i])
210*cdf0e10cSrcweir                     xRet = maAreas[i];
211*cdf0e10cSrcweir                 else
212*cdf0e10cSrcweir                     ++i;
213*cdf0e10cSrcweir             }
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	return xRet;
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void SAL_CALL ScAccessiblePageHeader::grabFocus() throw (uno::RuntimeException)
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir  	ScUnoGuard aGuard;
223*cdf0e10cSrcweir     IsObjectValid();
224*cdf0e10cSrcweir 	if (getAccessibleParent().is())
225*cdf0e10cSrcweir 	{
226*cdf0e10cSrcweir 		uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
227*cdf0e10cSrcweir 		if (xAccessibleComponent.is())
228*cdf0e10cSrcweir 			xAccessibleComponent->grabFocus();
229*cdf0e10cSrcweir 	}
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir //=====  XAccessibleContext  ==============================================
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessiblePageHeader::getAccessibleChildCount() throw (uno::RuntimeException)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	ScUnoGuard aGuard;
237*cdf0e10cSrcweir     IsObjectValid();
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     if((mnChildCount < 0) && mpViewShell)
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         mnChildCount = 0;
242*cdf0e10cSrcweir         ScDocument* pDoc = mpViewShell->GetDocument();
243*cdf0e10cSrcweir         if (pDoc)
244*cdf0e10cSrcweir         {
245*cdf0e10cSrcweir         	// find out how many regions (left,center, right) are with content
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir             SfxStyleSheetBase* pStyle = pDoc->GetStyleSheetPool()->Find(pDoc->GetPageStyle(mpViewShell->GetLocationData().GetPrintTab()), SFX_STYLE_FAMILY_PAGE);
248*cdf0e10cSrcweir             if (pStyle)
249*cdf0e10cSrcweir             {
250*cdf0e10cSrcweir                 sal_uInt16 nPageWhichId(0);
251*cdf0e10cSrcweir                 if (mbHeader)
252*cdf0e10cSrcweir                     nPageWhichId = mpViewShell->GetLocationData().IsHeaderLeft() ? ATTR_PAGE_HEADERLEFT : ATTR_PAGE_HEADERRIGHT;
253*cdf0e10cSrcweir                 else
254*cdf0e10cSrcweir                     nPageWhichId = mpViewShell->GetLocationData().IsFooterLeft() ? ATTR_PAGE_FOOTERLEFT : ATTR_PAGE_FOOTERRIGHT;
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 			    const ScPageHFItem& rPageItem = static_cast<const ScPageHFItem&>(pStyle->GetItemSet().Get(nPageWhichId));
257*cdf0e10cSrcweir 				AddChild(rPageItem.GetLeftArea(), 0, SVX_ADJUST_LEFT);
258*cdf0e10cSrcweir 				AddChild(rPageItem.GetCenterArea(), 1, SVX_ADJUST_CENTER);
259*cdf0e10cSrcweir 				AddChild(rPageItem.GetRightArea(), 2, SVX_ADJUST_RIGHT);
260*cdf0e10cSrcweir             }
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	return mnChildCount;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessiblePageHeader::getAccessibleChild( sal_Int32 nIndex )
268*cdf0e10cSrcweir     							throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	ScUnoGuard aGuard;
271*cdf0e10cSrcweir     IsObjectValid();
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	uno::Reference<XAccessible> xRet;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     if(mnChildCount < 0)
276*cdf0e10cSrcweir         getAccessibleChildCount();
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     ScHFAreas::iterator aItr = maAreas.begin();
279*cdf0e10cSrcweir     ScHFAreas::iterator aEndItr = maAreas.end();
280*cdf0e10cSrcweir     while (!xRet.is() && (nIndex >= 0) && (aItr != aEndItr))
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir         if (*aItr)
283*cdf0e10cSrcweir         {
284*cdf0e10cSrcweir             if (nIndex == 0)
285*cdf0e10cSrcweir                 xRet = *aItr;
286*cdf0e10cSrcweir             else
287*cdf0e10cSrcweir                 --nIndex;
288*cdf0e10cSrcweir         }
289*cdf0e10cSrcweir         else
290*cdf0e10cSrcweir             ++aItr;
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	if ( !xRet.is() )
294*cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	return xRet;
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessiblePageHeader::getAccessibleIndexInParent() throw (uno::RuntimeException)
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir 	return mnIndex;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir uno::Reference< XAccessibleStateSet > SAL_CALL ScAccessiblePageHeader::getAccessibleStateSet()
305*cdf0e10cSrcweir 								throw (uno::RuntimeException)
306*cdf0e10cSrcweir {
307*cdf0e10cSrcweir 	ScUnoGuard aGuard;
308*cdf0e10cSrcweir 	uno::Reference<XAccessibleStateSet> xParentStates;
309*cdf0e10cSrcweir 	if (getAccessibleParent().is())
310*cdf0e10cSrcweir 	{
311*cdf0e10cSrcweir 		uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
312*cdf0e10cSrcweir 		xParentStates = xParentContext->getAccessibleStateSet();
313*cdf0e10cSrcweir 	}
314*cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
315*cdf0e10cSrcweir 	if (IsDefunc(xParentStates))
316*cdf0e10cSrcweir 		pStateSet->AddState(AccessibleStateType::DEFUNC);
317*cdf0e10cSrcweir     else
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::ENABLED);
320*cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::OPAQUE);
321*cdf0e10cSrcweir 	    if (isShowing())
322*cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SHOWING);
323*cdf0e10cSrcweir 	    if (isVisible())
324*cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::VISIBLE);
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 	return pStateSet;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir //=====  XServiceInfo  ====================================================
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir rtl::OUString SAL_CALL ScAccessiblePageHeader::getImplementationName() throw(uno::RuntimeException)
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir 	return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePageHeader"));
334*cdf0e10cSrcweir }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePageHeader::getSupportedServiceNames()
337*cdf0e10cSrcweir 													throw(uno::RuntimeException)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
340*cdf0e10cSrcweir     sal_Int32 nOldSize(aSequence.getLength());
341*cdf0e10cSrcweir     aSequence.realloc(nOldSize + 1);
342*cdf0e10cSrcweir     ::rtl::OUString* pNames = aSequence.getArray();
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 	pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AccessibleHeaderFooterView"));
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 	return aSequence;
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir //====  internal  =========================================================
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessiblePageHeader::createAccessibleDescription(void)
352*cdf0e10cSrcweir 				    throw (uno::RuntimeException)
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir     String sDesc(ScResId(mbHeader ? STR_ACC_HEADER_DESCR : STR_ACC_FOOTER_DESCR));
355*cdf0e10cSrcweir     sDesc.SearchAndReplaceAscii("%1", String(ScResId(SCSTR_UNKNOWN)));
356*cdf0e10cSrcweir 	return rtl::OUString( sDesc );
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessiblePageHeader::createAccessibleName(void)
360*cdf0e10cSrcweir 				    throw (uno::RuntimeException)
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     String sName(ScResId(mbHeader ? STR_ACC_HEADER_NAME : STR_ACC_FOOTER_NAME));
363*cdf0e10cSrcweir     sName.SearchAndReplaceAscii("%1", String(ScResId(SCSTR_UNKNOWN)));
364*cdf0e10cSrcweir 	return rtl::OUString( sName );
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir Rectangle ScAccessiblePageHeader::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	Rectangle aCellRect(GetBoundingBox());
370*cdf0e10cSrcweir 	if (mpViewShell)
371*cdf0e10cSrcweir 	{
372*cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindow();
373*cdf0e10cSrcweir 		if (pWindow)
374*cdf0e10cSrcweir 		{
375*cdf0e10cSrcweir 			Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
376*cdf0e10cSrcweir 			aCellRect.setX(aCellRect.getX() + aRect.getX());
377*cdf0e10cSrcweir 			aCellRect.setY(aCellRect.getY() + aRect.getY());
378*cdf0e10cSrcweir 		}
379*cdf0e10cSrcweir 	}
380*cdf0e10cSrcweir 	return aCellRect;
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir Rectangle ScAccessiblePageHeader::GetBoundingBox() const throw (uno::RuntimeException)
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir 	Rectangle aRect;
386*cdf0e10cSrcweir 	if (mpViewShell)
387*cdf0e10cSrcweir 	{
388*cdf0e10cSrcweir 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
389*cdf0e10cSrcweir 		if ( mbHeader )
390*cdf0e10cSrcweir 			rData.GetHeaderPosition( aRect );
391*cdf0e10cSrcweir 		else
392*cdf0e10cSrcweir 			rData.GetFooterPosition( aRect );
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir         // the Rectangle could contain negative coordinates so it should be cliped
395*cdf0e10cSrcweir         Rectangle aClipRect(Point(0, 0), aRect.GetSize());
396*cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindow();
397*cdf0e10cSrcweir 		if (pWindow)
398*cdf0e10cSrcweir 			aClipRect = pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow());
399*cdf0e10cSrcweir         aRect = aClipRect.GetIntersection(aRect);
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     if (aRect.IsEmpty())
402*cdf0e10cSrcweir         aRect.SetSize(Size(-1, -1));
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	return aRect;
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir sal_Bool ScAccessiblePageHeader::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir 	return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
410*cdf0e10cSrcweir 		(rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir void ScAccessiblePageHeader::AddChild(const EditTextObject* pArea, sal_uInt32 nIndex, SvxAdjust eAdjust)
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     if (pArea && (pArea->GetText(0).Len() || (pArea->GetParagraphCount() > 1)))
416*cdf0e10cSrcweir     {
417*cdf0e10cSrcweir         if (maAreas[nIndex])
418*cdf0e10cSrcweir         {
419*cdf0e10cSrcweir             if (!ScGlobal::EETextObjEqual(maAreas[nIndex]->GetEditTextObject(), pArea))
420*cdf0e10cSrcweir             {
421*cdf0e10cSrcweir                 maAreas[nIndex]->release();
422*cdf0e10cSrcweir                 maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, mbHeader, eAdjust);
423*cdf0e10cSrcweir                 maAreas[nIndex]->acquire();
424*cdf0e10cSrcweir             }
425*cdf0e10cSrcweir         }
426*cdf0e10cSrcweir         else
427*cdf0e10cSrcweir         {
428*cdf0e10cSrcweir             maAreas[nIndex] = new ScAccessiblePageHeaderArea(this, mpViewShell, pArea, mbHeader, eAdjust);
429*cdf0e10cSrcweir             maAreas[nIndex]->acquire();
430*cdf0e10cSrcweir         }
431*cdf0e10cSrcweir         ++mnChildCount;
432*cdf0e10cSrcweir     }
433*cdf0e10cSrcweir     else
434*cdf0e10cSrcweir     {
435*cdf0e10cSrcweir         if (maAreas[nIndex])
436*cdf0e10cSrcweir         {
437*cdf0e10cSrcweir             maAreas[nIndex]->release();
438*cdf0e10cSrcweir             maAreas[nIndex] = NULL;
439*cdf0e10cSrcweir         }
440*cdf0e10cSrcweir     }
441*cdf0e10cSrcweir }
442