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