merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / access / accpage.cxx
blob7bc480f5117ced6051e2e33335d590660c479ba9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accpage.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <rtl/uuid.h>
36 #include <vcl/window.hxx>
37 #include <vcl/svapp.hxx>
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include "accpage.hxx"
43 #ifndef _ACCESS_HRC
44 #include "access.hrc"
45 #endif
46 #include <pagefrm.hxx>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::accessibility;
51 using uno::Reference;
52 using uno::RuntimeException;
53 using uno::Sequence;
54 using ::rtl::OUString;
57 const sal_Char sServiceName[] = "com.sun.star.text.AccessiblePageView";
58 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessiblePageView";
60 sal_Bool SwAccessiblePage::IsSelected()
62 return GetMap()->IsPageSelected( static_cast < const SwPageFrm * >( GetFrm() ) );
65 void SwAccessiblePage::GetStates(
66 ::utl::AccessibleStateSetHelper& rStateSet )
68 SwAccessibleContext::GetStates( rStateSet );
70 // FOCUSABLE
71 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
73 // FOCUSED
74 if( IsSelected() )
76 ASSERT( bIsSelected, "bSelected out of sync" );
77 ::vos::ORef < SwAccessibleContext > xThis( this );
78 GetMap()->SetCursorContext( xThis );
80 Window *pWin = GetWindow();
81 if( pWin && pWin->HasFocus() )
82 rStateSet.AddState( AccessibleStateType::FOCUSED );
86 void SwAccessiblePage::_InvalidateCursorPos()
88 sal_Bool bNewSelected = IsSelected();
89 sal_Bool bOldSelected;
92 vos::OGuard aGuard( aMutex );
93 bOldSelected = bIsSelected;
94 bIsSelected = bNewSelected;
97 if( bNewSelected )
99 // remember that object as the one that has the caret. This is
100 // neccessary to notify that object if the cursor leaves it.
101 ::vos::ORef < SwAccessibleContext > xThis( this );
102 GetMap()->SetCursorContext( xThis );
105 if( bOldSelected != bNewSelected )
107 Window *pWin = GetWindow();
108 if( pWin && pWin->HasFocus() )
109 FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
113 void SwAccessiblePage::_InvalidateFocus()
115 Window *pWin = GetWindow();
116 if( pWin )
118 sal_Bool bSelected;
121 vos::OGuard aGuard( aMutex );
122 bSelected = bIsSelected;
124 ASSERT( bSelected, "focus object should be selected" );
126 FireStateChangedEvent( AccessibleStateType::FOCUSED,
127 pWin->HasFocus() && bSelected );
131 SwAccessiblePage::SwAccessiblePage( SwAccessibleMap* pInitMap,
132 const SwFrm* pFrame ) :
133 SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame )
135 DBG_ASSERT( pFrame != NULL, "need frame" );
136 DBG_ASSERT( pInitMap != NULL, "need map" );
137 DBG_ASSERT( pFrame->IsPageFrm(), "need page frame" );
139 vos::OGuard aGuard(Application::GetSolarMutex());
141 OUString sPage = OUString::valueOf(
142 static_cast<sal_Int32>(
143 static_cast<const SwPageFrm*>( GetFrm() )->GetPhyPageNum() ) );
144 SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) );
147 SwAccessiblePage::~SwAccessiblePage()
151 sal_Bool SwAccessiblePage::HasCursor()
153 vos::OGuard aGuard( aMutex );
154 return bIsSelected;
157 OUString SwAccessiblePage::getImplementationName( )
158 throw( RuntimeException )
160 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
163 sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName)
164 throw( RuntimeException )
166 return rServiceName.equalsAsciiL( sServiceName, sizeof(sServiceName)-1 ) ||
167 rServiceName.equalsAsciiL( sAccessibleServiceName,
168 sizeof(sAccessibleServiceName)-1 );
171 Sequence<OUString> SwAccessiblePage::getSupportedServiceNames( )
172 throw( RuntimeException )
174 Sequence< OUString > aRet(2);
175 OUString* pArray = aRet.getArray();
176 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
177 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
178 return aRet;
181 Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId()
182 throw(RuntimeException)
184 vos::OGuard aGuard(Application::GetSolarMutex());
185 static Sequence< sal_Int8 > aId( 16 );
186 static sal_Bool bInit = sal_False;
187 if(!bInit)
189 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
190 bInit = sal_True;
192 return aId;
195 OUString SwAccessiblePage::getAccessibleDescription( )
196 throw( RuntimeException )
198 CHECK_FOR_DEFUNC( ::com::sun::star::accessibility::XAccessibleContext );
200 OUString sArg( GetFormattedPageNumber() );
201 return GetResource( STR_ACCESS_PAGE_DESC, &sArg );