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_sw.hxx"
26
27
28 #include <vos/mutex.hxx>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <rtl/uuid.h>
33 #include <vcl/svapp.hxx>
34 #include <hffrm.hxx>
35 #include "accheaderfooter.hxx"
36 #ifndef _ACCESS_HRC
37 #include "access.hrc"
38 #endif
39
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::accessibility;
44 using ::rtl::OUString;
45
46 const sal_Char sServiceNameHeader[] = "com.sun.star.text.AccessibleHeaderView";
47 const sal_Char sServiceNameFooter[] = "com.sun.star.text.AccessibleFooterView";
48 const sal_Char sImplementationNameHeader[] = "com.sun.star.comp.Writer.SwAccessibleHeaderView";
49 const sal_Char sImplementationNameFooter[] = "com.sun.star.comp.Writer.SwAccessibleFooterView";
50
SwAccessibleHeaderFooter(SwAccessibleMap * pInitMap,const SwHeaderFrm * pHdFrm)51 SwAccessibleHeaderFooter::SwAccessibleHeaderFooter(
52 SwAccessibleMap* pInitMap,
53 const SwHeaderFrm* pHdFrm ) :
54 SwAccessibleContext( pInitMap, AccessibleRole::HEADER, pHdFrm )
55 {
56 vos::OGuard aGuard(Application::GetSolarMutex());
57
58 OUString sArg( OUString::valueOf( (sal_Int32)pHdFrm->GetPhyPageNum() ) );
59 SetName( GetResource( STR_ACCESS_HEADER_NAME, &sArg ) );
60 }
61
SwAccessibleHeaderFooter(SwAccessibleMap * pInitMap,const SwFooterFrm * pFtFrm)62 SwAccessibleHeaderFooter::SwAccessibleHeaderFooter(
63 SwAccessibleMap* pInitMap,
64 const SwFooterFrm* pFtFrm ) :
65 SwAccessibleContext( pInitMap, AccessibleRole::FOOTER, pFtFrm )
66 {
67 vos::OGuard aGuard(Application::GetSolarMutex());
68
69 OUString sArg( OUString::valueOf( (sal_Int32)pFtFrm->GetPhyPageNum() ) );
70 SetName( GetResource( STR_ACCESS_FOOTER_NAME, &sArg ) );
71 }
72
~SwAccessibleHeaderFooter()73 SwAccessibleHeaderFooter::~SwAccessibleHeaderFooter()
74 {
75 }
76
getAccessibleDescription(void)77 OUString SAL_CALL SwAccessibleHeaderFooter::getAccessibleDescription (void)
78 throw (uno::RuntimeException)
79 {
80 vos::OGuard aGuard(Application::GetSolarMutex());
81
82 CHECK_FOR_DEFUNC( XAccessibleContext )
83
84 sal_uInt16 nResId = AccessibleRole::HEADER == GetRole()
85 ? STR_ACCESS_HEADER_DESC
86 : STR_ACCESS_FOOTER_DESC ;
87
88 OUString sArg( GetFormattedPageNumber() );
89
90 return GetResource( nResId, &sArg );
91 }
92
getImplementationName()93 OUString SAL_CALL SwAccessibleHeaderFooter::getImplementationName()
94 throw( RuntimeException )
95 {
96 if( AccessibleRole::HEADER == GetRole() )
97 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameHeader));
98 else
99 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFooter));
100 }
101
supportsService(const::rtl::OUString & sTestServiceName)102 sal_Bool SAL_CALL SwAccessibleHeaderFooter::supportsService(
103 const ::rtl::OUString& sTestServiceName)
104 throw (uno::RuntimeException)
105 {
106 if( sTestServiceName.equalsAsciiL( sAccessibleServiceName,
107 sizeof(sAccessibleServiceName)-1 ) )
108 return sal_True;
109 else if( AccessibleRole::HEADER == GetRole() )
110 return sTestServiceName.equalsAsciiL( sServiceNameHeader, sizeof(sServiceNameHeader)-1 );
111 else
112 return sTestServiceName.equalsAsciiL( sServiceNameFooter, sizeof(sServiceNameFooter)-1 );
113
114 }
115
getSupportedServiceNames()116 Sequence< OUString > SAL_CALL SwAccessibleHeaderFooter::getSupportedServiceNames()
117 throw( uno::RuntimeException )
118 {
119 Sequence< OUString > aRet(2);
120 OUString* pArray = aRet.getArray();
121 if( AccessibleRole::HEADER == GetRole() )
122 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameHeader) );
123 else
124 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFooter) );
125 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
126 return aRet;
127 }
128
getImplementationId()129 Sequence< sal_Int8 > SAL_CALL SwAccessibleHeaderFooter::getImplementationId()
130 throw(RuntimeException)
131 {
132 vos::OGuard aGuard(Application::GetSolarMutex());
133 static Sequence< sal_Int8 > aId( 16 );
134 static sal_Bool bInit = sal_False;
135 if(!bInit)
136 {
137 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
138 bInit = sal_True;
139 }
140 return aId;
141 }
142
getBackground()143 sal_Int32 SAL_CALL SwAccessibleHeaderFooter::getBackground()
144 throw (::com::sun::star::uno::RuntimeException)
145 {
146 Reference< XAccessible > xParent = getAccessibleParent();
147 if (xParent.is())
148 {
149 Reference< XAccessibleComponent > xAccContext (xParent,UNO_QUERY);
150 if(xAccContext.is())
151 {
152 return xAccContext->getBackground();
153 }
154 }
155 return SwAccessibleContext::getBackground();
156 }
157