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