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 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 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 73 SwAccessibleHeaderFooter::~SwAccessibleHeaderFooter() 74 { 75 } 76 77 OUString SAL_CALL SwAccessibleHeaderFooter::getAccessibleDescription (void) 78 { 79 vos::OGuard aGuard(Application::GetSolarMutex()); 80 81 CHECK_FOR_DEFUNC( XAccessibleContext ) 82 83 sal_uInt16 nResId = AccessibleRole::HEADER == GetRole() 84 ? STR_ACCESS_HEADER_DESC 85 : STR_ACCESS_FOOTER_DESC ; 86 87 OUString sArg( GetFormattedPageNumber() ); 88 89 return GetResource( nResId, &sArg ); 90 } 91 92 OUString SAL_CALL SwAccessibleHeaderFooter::getImplementationName() 93 { 94 if( AccessibleRole::HEADER == GetRole() ) 95 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameHeader)); 96 else 97 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFooter)); 98 } 99 100 sal_Bool SAL_CALL SwAccessibleHeaderFooter::supportsService( 101 const ::rtl::OUString& sTestServiceName) 102 { 103 if( sTestServiceName.equalsAsciiL( sAccessibleServiceName, 104 sizeof(sAccessibleServiceName)-1 ) ) 105 return sal_True; 106 else if( AccessibleRole::HEADER == GetRole() ) 107 return sTestServiceName.equalsAsciiL( sServiceNameHeader, sizeof(sServiceNameHeader)-1 ); 108 else 109 return sTestServiceName.equalsAsciiL( sServiceNameFooter, sizeof(sServiceNameFooter)-1 ); 110 111 } 112 113 Sequence< OUString > SAL_CALL SwAccessibleHeaderFooter::getSupportedServiceNames() 114 { 115 Sequence< OUString > aRet(2); 116 OUString* pArray = aRet.getArray(); 117 if( AccessibleRole::HEADER == GetRole() ) 118 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameHeader) ); 119 else 120 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFooter) ); 121 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) ); 122 return aRet; 123 } 124 125 Sequence< sal_Int8 > SAL_CALL SwAccessibleHeaderFooter::getImplementationId() 126 { 127 vos::OGuard aGuard(Application::GetSolarMutex()); 128 static Sequence< sal_Int8 > aId( 16 ); 129 static sal_Bool bInit = sal_False; 130 if(!bInit) 131 { 132 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True ); 133 bInit = sal_True; 134 } 135 return aId; 136 } 137 138 sal_Int32 SAL_CALL SwAccessibleHeaderFooter::getBackground() 139 { 140 Reference< XAccessible > xParent = getAccessibleParent(); 141 if (xParent.is()) 142 { 143 Reference< XAccessibleComponent > xAccContext (xParent,UNO_QUERY); 144 if(xAccContext.is()) 145 { 146 return xAccContext->getBackground(); 147 } 148 } 149 return SwAccessibleContext::getBackground(); 150 } 151