1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePageHeaderArea.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include <tools/gen.hxx>
34 #include "AccessiblePageHeaderArea.hxx"
35 #include "AccessibleText.hxx"
36 #include "AccessibilityHints.hxx"
37 #include "unoguard.hxx"
38 #include "editsrc.hxx"
39 #include "prevwsh.hxx"
40 #include "prevloc.hxx"
41 #include "scresid.hxx"
46 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
47 #include <com/sun/star/accessibility/AccessibleRole.hpp>
49 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
50 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
52 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
53 #include <svx/editobj.hxx>
54 #include <svx/AccessibleTextHelper.hxx>
56 #include <unotools/accessiblestatesethelper.hxx>
57 #include <rtl/ustrbuf.hxx>
58 #include <toolkit/helper/convert.hxx>
60 using namespace ::com::sun::star
;
61 using namespace ::com::sun::star::accessibility
;
63 //===== internal ========================================================
65 ScAccessiblePageHeaderArea::ScAccessiblePageHeaderArea(
66 const uno::Reference
<XAccessible
>& rxParent
,
67 ScPreviewShell
* pViewShell
,
68 const EditTextObject
* pEditObj
,
71 : ScAccessibleContextBase(rxParent
, AccessibleRole::TEXT
),
72 mpEditObj(pEditObj
->Clone()),
74 mpViewShell(pViewShell
),
79 mpViewShell
->AddAccessibilityObject(*this);
82 ScAccessiblePageHeaderArea::~ScAccessiblePageHeaderArea(void)
84 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper
.bInDispose
)
86 // increment refcount to prevent double call off dtor
87 osl_incrementInterlockedCount( &m_refCount
);
92 void SAL_CALL
ScAccessiblePageHeaderArea::disposing()
97 mpViewShell
->RemoveAccessibilityObject(*this);
101 DELETEZ(mpTextHelper
);
105 ScAccessibleContextBase::disposing();
108 //===== SfxListener =====================================================
110 void ScAccessiblePageHeaderArea::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
112 if (rHint
.ISA( SfxSimpleHint
) )
114 const SfxSimpleHint
& rRef
= (const SfxSimpleHint
&)rHint
;
115 // only notify if child exist, otherwise it is not necessary
116 if (rRef
.GetId() == SC_HINT_ACC_VISAREACHANGED
)
119 mpTextHelper
->UpdateChildren();
121 AccessibleEventObject aEvent
;
122 aEvent
.EventId
= AccessibleEventId::VISIBLE_DATA_CHANGED
;
123 aEvent
.Source
= uno::Reference
< XAccessibleContext
>(this);
124 CommitChange(aEvent
);
127 ScAccessibleContextBase::Notify(rBC
, rHint
);
129 //===== XAccessibleComponent ============================================
131 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePageHeaderArea::getAccessibleAtPoint(
132 const awt::Point
& rPoint
)
133 throw (uno::RuntimeException
)
135 uno::Reference
<XAccessible
> xRet
;
136 if (containsPoint(rPoint
))
144 xRet
= mpTextHelper
->GetAt(rPoint
);
150 //===== XAccessibleContext ==============================================
153 ScAccessiblePageHeaderArea::getAccessibleChildCount(void)
154 throw (uno::RuntimeException
)
160 return mpTextHelper
->GetChildCount();
163 uno::Reference
< XAccessible
> SAL_CALL
164 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex
)
165 throw (uno::RuntimeException
,
166 lang::IndexOutOfBoundsException
)
172 return mpTextHelper
->GetChild(nIndex
);
175 uno::Reference
<XAccessibleStateSet
> SAL_CALL
176 ScAccessiblePageHeaderArea::getAccessibleStateSet(void)
177 throw (uno::RuntimeException
)
180 uno::Reference
<XAccessibleStateSet
> xParentStates
;
181 if (getAccessibleParent().is())
183 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
184 xParentStates
= xParentContext
->getAccessibleStateSet();
186 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
188 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
191 pStateSet
->AddState(AccessibleStateType::ENABLED
);
192 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
194 pStateSet
->AddState(AccessibleStateType::SHOWING
);
196 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
201 //===== XServiceInfo ========================================================
203 ::rtl::OUString SAL_CALL
204 ScAccessiblePageHeaderArea::getImplementationName(void)
205 throw (uno::RuntimeException
)
207 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessiblePageHeaderArea"));
210 uno::Sequence
< ::rtl::OUString
> SAL_CALL
211 ScAccessiblePageHeaderArea::getSupportedServiceNames(void)
212 throw (uno::RuntimeException
)
214 uno::Sequence
< ::rtl::OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
215 sal_Int32
nOldSize(aSequence
.getLength());
216 aSequence
.realloc(nOldSize
+ 1);
217 ::rtl::OUString
* pNames
= aSequence
.getArray();
219 pNames
[nOldSize
] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.AccessiblePageHeaderFooterAreasView"));
224 //===== XTypeProvider =======================================================
226 uno::Sequence
<sal_Int8
> SAL_CALL
227 ScAccessiblePageHeaderArea::getImplementationId(void)
228 throw (uno::RuntimeException
)
232 static uno::Sequence
<sal_Int8
> aId
;
233 if (aId
.getLength() == 0)
236 rtl_createUuid (reinterpret_cast<sal_uInt8
*>(aId
.getArray()), 0, sal_True
);
241 //===== internal ==============================================================
242 rtl::OUString SAL_CALL
ScAccessiblePageHeaderArea::createAccessibleDescription(void)
243 throw(uno::RuntimeException
)
248 case SVX_ADJUST_LEFT
:
249 sDesc
= String(ScResId(STR_ACC_LEFTAREA_DESCR
));
251 case SVX_ADJUST_RIGHT
:
252 sDesc
= String(ScResId(STR_ACC_RIGHTAREA_DESCR
));
254 case SVX_ADJUST_CENTER
:
255 sDesc
= String(ScResId(STR_ACC_CENTERAREA_DESCR
));
258 DBG_ERRORFILE("wrong adjustment found");
264 rtl::OUString SAL_CALL
ScAccessiblePageHeaderArea::createAccessibleName(void)
265 throw (uno::RuntimeException
)
270 case SVX_ADJUST_LEFT
:
271 sName
= String(ScResId(STR_ACC_LEFTAREA_NAME
));
273 case SVX_ADJUST_RIGHT
:
274 sName
= String(ScResId(STR_ACC_RIGHTAREA_NAME
));
276 case SVX_ADJUST_CENTER
:
277 sName
= String(ScResId(STR_ACC_CENTERAREA_NAME
));
280 DBG_ERRORFILE("wrong adjustment found");
286 Rectangle
ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen(void) const
287 throw(::com::sun::star::uno::RuntimeException
)
292 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
293 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
296 // has the same size and position on screen like the parent
297 aRect
= Rectangle(VCLPoint(xComp
->getLocationOnScreen()), VCLRectangle(xComp
->getBounds()).GetSize());
303 Rectangle
ScAccessiblePageHeaderArea::GetBoundingBox(void) const
304 throw (::com::sun::star::uno::RuntimeException
)
309 uno::Reference
<XAccessibleContext
> xContext
= mxParent
->getAccessibleContext();
310 uno::Reference
<XAccessibleComponent
> xComp(xContext
, uno::UNO_QUERY
);
313 // has the same size and position on screen like the parent and so the pos is (0, 0)
314 Rectangle
aNewRect(Point(0, 0), VCLRectangle(xComp
->getBounds()).GetSize());
322 void ScAccessiblePageHeaderArea::CreateTextHelper()
326 ::std::auto_ptr
< ScAccessibleTextData
> pAccessibleHeaderTextData
327 (new ScAccessibleHeaderTextData(mpViewShell
, mpEditObj
, mbHeader
, meAdjust
));
328 ::std::auto_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(pAccessibleHeaderTextData
));
330 mpTextHelper
= new ::accessibility::AccessibleTextHelper(pEditSource
);
331 mpTextHelper
->SetEventSource(this);