merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / Accessibility / AccessiblePageHeaderArea.cxx
blob0aa42aabcc318d028d1d6199dcf3135ccd47f9c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePageHeaderArea.cxx,v $
10 * $Revision: 1.19 $
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"
42 #ifndef SC_SC_HRC
43 #include "sc.hrc"
44 #endif
46 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
47 #include <com/sun/star/accessibility/AccessibleRole.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
50 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
51 #endif
52 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
53 #include <svx/editobj.hxx>
54 #include <svx/AccessibleTextHelper.hxx>
55 #include <rtl/uuid.h>
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,
69 sal_Bool bHeader,
70 SvxAdjust eAdjust)
71 : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT),
72 mpEditObj(pEditObj->Clone()),
73 mpTextHelper(NULL),
74 mpViewShell(pViewShell),
75 mbHeader(bHeader),
76 meAdjust(eAdjust)
78 if (mpViewShell)
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 );
88 dispose();
92 void SAL_CALL ScAccessiblePageHeaderArea::disposing()
94 ScUnoGuard aGuard;
95 if (mpViewShell)
97 mpViewShell->RemoveAccessibilityObject(*this);
98 mpViewShell = NULL;
100 if (mpTextHelper)
101 DELETEZ(mpTextHelper);
102 if (mpEditObj)
103 DELETEZ(mpEditObj);
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)
118 if (mpTextHelper)
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))
138 ScUnoGuard aGuard;
139 IsObjectValid();
141 if(!mpTextHelper)
142 CreateTextHelper();
144 xRet = mpTextHelper->GetAt(rPoint);
147 return xRet;
150 //===== XAccessibleContext ==============================================
152 sal_Int32 SAL_CALL
153 ScAccessiblePageHeaderArea::getAccessibleChildCount(void)
154 throw (uno::RuntimeException)
156 ScUnoGuard aGuard;
157 IsObjectValid();
158 if (!mpTextHelper)
159 CreateTextHelper();
160 return mpTextHelper->GetChildCount();
163 uno::Reference< XAccessible > SAL_CALL
164 ScAccessiblePageHeaderArea::getAccessibleChild(sal_Int32 nIndex)
165 throw (uno::RuntimeException,
166 lang::IndexOutOfBoundsException)
168 ScUnoGuard aGuard;
169 IsObjectValid();
170 if (!mpTextHelper)
171 CreateTextHelper();
172 return mpTextHelper->GetChild(nIndex);
175 uno::Reference<XAccessibleStateSet> SAL_CALL
176 ScAccessiblePageHeaderArea::getAccessibleStateSet(void)
177 throw (uno::RuntimeException)
179 ScUnoGuard aGuard;
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();
187 if (IsDefunc())
188 pStateSet->AddState(AccessibleStateType::DEFUNC);
189 else
191 pStateSet->AddState(AccessibleStateType::ENABLED);
192 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
193 if (isShowing())
194 pStateSet->AddState(AccessibleStateType::SHOWING);
195 if (isVisible())
196 pStateSet->AddState(AccessibleStateType::VISIBLE);
198 return pStateSet;
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"));
221 return aSequence;
224 //===== XTypeProvider =======================================================
226 uno::Sequence<sal_Int8> SAL_CALL
227 ScAccessiblePageHeaderArea::getImplementationId(void)
228 throw (uno::RuntimeException)
230 ScUnoGuard aGuard;
231 IsObjectValid();
232 static uno::Sequence<sal_Int8> aId;
233 if (aId.getLength() == 0)
235 aId.realloc (16);
236 rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
238 return aId;
241 //===== internal ==============================================================
242 rtl::OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleDescription(void)
243 throw(uno::RuntimeException)
245 rtl::OUString sDesc;
246 switch (meAdjust)
248 case SVX_ADJUST_LEFT :
249 sDesc = String(ScResId(STR_ACC_LEFTAREA_DESCR));
250 break;
251 case SVX_ADJUST_RIGHT:
252 sDesc = String(ScResId(STR_ACC_RIGHTAREA_DESCR));
253 break;
254 case SVX_ADJUST_CENTER:
255 sDesc = String(ScResId(STR_ACC_CENTERAREA_DESCR));
256 break;
257 default:
258 DBG_ERRORFILE("wrong adjustment found");
261 return sDesc;
264 rtl::OUString SAL_CALL ScAccessiblePageHeaderArea::createAccessibleName(void)
265 throw (uno::RuntimeException)
267 rtl::OUString sName;
268 switch (meAdjust)
270 case SVX_ADJUST_LEFT :
271 sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
272 break;
273 case SVX_ADJUST_RIGHT:
274 sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
275 break;
276 case SVX_ADJUST_CENTER:
277 sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
278 break;
279 default:
280 DBG_ERRORFILE("wrong adjustment found");
283 return sName;
286 Rectangle ScAccessiblePageHeaderArea::GetBoundingBoxOnScreen(void) const
287 throw(::com::sun::star::uno::RuntimeException)
289 Rectangle aRect;
290 if (mxParent.is())
292 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
293 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
294 if (xComp.is())
296 // has the same size and position on screen like the parent
297 aRect = Rectangle(VCLPoint(xComp->getLocationOnScreen()), VCLRectangle(xComp->getBounds()).GetSize());
300 return aRect;
303 Rectangle ScAccessiblePageHeaderArea::GetBoundingBox(void) const
304 throw (::com::sun::star::uno::RuntimeException)
306 Rectangle aRect;
307 if (mxParent.is())
309 uno::Reference<XAccessibleContext> xContext = mxParent->getAccessibleContext();
310 uno::Reference<XAccessibleComponent> xComp(xContext, uno::UNO_QUERY);
311 if (xComp.is())
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());
315 aRect = aNewRect;
319 return aRect;
322 void ScAccessiblePageHeaderArea::CreateTextHelper()
324 if (!mpTextHelper)
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);