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_sw.hxx" 30 31 32 #include <rtl/uuid.h> 33 #include <vcl/window.hxx> 34 #include <vcl/svapp.hxx> 35 #include <unotools/accessiblestatesethelper.hxx> 36 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 37 #include <com/sun/star/accessibility/AccessibleRole.hpp> 38 #include "accpage.hxx" 39 40 #ifndef _ACCESS_HRC 41 #include "access.hrc" 42 #endif 43 #include <pagefrm.hxx> 44 45 using namespace ::com::sun::star; 46 using namespace ::com::sun::star::accessibility; 47 48 using uno::Reference; 49 using uno::RuntimeException; 50 using uno::Sequence; 51 using ::rtl::OUString; 52 53 54 const sal_Char sServiceName[] = "com.sun.star.text.AccessiblePageView"; 55 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessiblePageView"; 56 57 sal_Bool SwAccessiblePage::IsSelected() 58 { 59 return GetMap()->IsPageSelected( static_cast < const SwPageFrm * >( GetFrm() ) ); 60 } 61 62 void SwAccessiblePage::GetStates( 63 ::utl::AccessibleStateSetHelper& rStateSet ) 64 { 65 SwAccessibleContext::GetStates( rStateSet ); 66 67 // FOCUSABLE 68 rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 69 70 // FOCUSED 71 if( IsSelected() ) 72 { 73 ASSERT( bIsSelected, "bSelected out of sync" ); 74 ::vos::ORef < SwAccessibleContext > xThis( this ); 75 GetMap()->SetCursorContext( xThis ); 76 77 Window *pWin = GetWindow(); 78 if( pWin && pWin->HasFocus() ) 79 rStateSet.AddState( AccessibleStateType::FOCUSED ); 80 } 81 } 82 83 void SwAccessiblePage::_InvalidateCursorPos() 84 { 85 sal_Bool bNewSelected = IsSelected(); 86 sal_Bool bOldSelected; 87 88 { 89 vos::OGuard aGuard( aMutex ); 90 bOldSelected = bIsSelected; 91 bIsSelected = bNewSelected; 92 } 93 94 if( bNewSelected ) 95 { 96 // remember that object as the one that has the caret. This is 97 // neccessary to notify that object if the cursor leaves it. 98 ::vos::ORef < SwAccessibleContext > xThis( this ); 99 GetMap()->SetCursorContext( xThis ); 100 } 101 102 if( bOldSelected != bNewSelected ) 103 { 104 Window *pWin = GetWindow(); 105 if( pWin && pWin->HasFocus() ) 106 FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected ); 107 } 108 } 109 110 void SwAccessiblePage::_InvalidateFocus() 111 { 112 Window *pWin = GetWindow(); 113 if( pWin ) 114 { 115 sal_Bool bSelected; 116 117 { 118 vos::OGuard aGuard( aMutex ); 119 bSelected = bIsSelected; 120 } 121 ASSERT( bSelected, "focus object should be selected" ); 122 123 FireStateChangedEvent( AccessibleStateType::FOCUSED, 124 pWin->HasFocus() && bSelected ); 125 } 126 } 127 128 SwAccessiblePage::SwAccessiblePage( SwAccessibleMap* pInitMap, 129 const SwFrm* pFrame ) 130 : SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame ) 131 , bIsSelected( sal_False ) 132 { 133 DBG_ASSERT( pFrame != NULL, "need frame" ); 134 DBG_ASSERT( pInitMap != NULL, "need map" ); 135 DBG_ASSERT( pFrame->IsPageFrm(), "need page frame" ); 136 137 vos::OGuard aGuard(Application::GetSolarMutex()); 138 139 OUString sPage = OUString::valueOf( 140 static_cast<sal_Int32>( 141 static_cast<const SwPageFrm*>( GetFrm() )->GetPhyPageNum() ) ); 142 SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) ); 143 } 144 145 SwAccessiblePage::~SwAccessiblePage() 146 { 147 } 148 149 sal_Bool SwAccessiblePage::HasCursor() 150 { 151 vos::OGuard aGuard( aMutex ); 152 return bIsSelected; 153 } 154 155 OUString SwAccessiblePage::getImplementationName( ) 156 throw( RuntimeException ) 157 { 158 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName)); 159 } 160 161 sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName) 162 throw( RuntimeException ) 163 { 164 return rServiceName.equalsAsciiL( sServiceName, sizeof(sServiceName)-1 ) || 165 rServiceName.equalsAsciiL( sAccessibleServiceName, 166 sizeof(sAccessibleServiceName)-1 ); 167 } 168 169 Sequence<OUString> SwAccessiblePage::getSupportedServiceNames( ) 170 throw( RuntimeException ) 171 { 172 Sequence< OUString > aRet(2); 173 OUString* pArray = aRet.getArray(); 174 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) ); 175 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) ); 176 return aRet; 177 } 178 179 Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId() 180 throw(RuntimeException) 181 { 182 vos::OGuard aGuard(Application::GetSolarMutex()); 183 static Sequence< sal_Int8 > aId( 16 ); 184 static sal_Bool bInit = sal_False; 185 if(!bInit) 186 { 187 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True ); 188 bInit = sal_True; 189 } 190 return aId; 191 } 192 193 OUString SwAccessiblePage::getAccessibleDescription( ) 194 throw( RuntimeException ) 195 { 196 CHECK_FOR_DEFUNC( ::com::sun::star::accessibility::XAccessibleContext ); 197 198 OUString sArg( GetFormattedPageNumber() ); 199 return GetResource( STR_ACCESS_PAGE_DESC, &sArg ); 200 } 201