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