xref: /aoo41x/main/sw/source/core/access/accpage.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <rtl/uuid.h>
29cdf0e10cSrcweir #include <vcl/window.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
32cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
34cdf0e10cSrcweir #include "accpage.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _ACCESS_HRC
37cdf0e10cSrcweir #include "access.hrc"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <pagefrm.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using uno::Reference;
45cdf0e10cSrcweir using uno::RuntimeException;
46cdf0e10cSrcweir using uno::Sequence;
47cdf0e10cSrcweir using ::rtl::OUString;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir const sal_Char sServiceName[] = "com.sun.star.text.AccessiblePageView";
51cdf0e10cSrcweir const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessiblePageView";
52cdf0e10cSrcweir 
IsSelected()53cdf0e10cSrcweir sal_Bool SwAccessiblePage::IsSelected()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	return GetMap()->IsPageSelected( static_cast < const SwPageFrm * >( GetFrm() ) );
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
GetStates(::utl::AccessibleStateSetHelper & rStateSet)58cdf0e10cSrcweir void SwAccessiblePage::GetStates(
59cdf0e10cSrcweir 		::utl::AccessibleStateSetHelper& rStateSet )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	SwAccessibleContext::GetStates( rStateSet );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	// FOCUSABLE
64cdf0e10cSrcweir 	rStateSet.AddState( AccessibleStateType::FOCUSABLE );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	// FOCUSED
67cdf0e10cSrcweir 	if( IsSelected() )
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		ASSERT( bIsSelected, "bSelected out of sync" );
70cdf0e10cSrcweir 		::vos::ORef < SwAccessibleContext > xThis( this );
71cdf0e10cSrcweir 		GetMap()->SetCursorContext( xThis );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		Window *pWin = GetWindow();
74cdf0e10cSrcweir 		if( pWin && pWin->HasFocus() )
75cdf0e10cSrcweir 			rStateSet.AddState( AccessibleStateType::FOCUSED );
76cdf0e10cSrcweir 	}
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
_InvalidateCursorPos()79cdf0e10cSrcweir void SwAccessiblePage::_InvalidateCursorPos()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	sal_Bool bNewSelected = IsSelected();
82cdf0e10cSrcweir 	sal_Bool bOldSelected;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		vos::OGuard aGuard( aMutex );
86cdf0e10cSrcweir 		bOldSelected = bIsSelected;
87cdf0e10cSrcweir 		bIsSelected = bNewSelected;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	if( bNewSelected )
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		// remember that object as the one that has the caret. This is
93cdf0e10cSrcweir 		// neccessary to notify that object if the cursor leaves it.
94cdf0e10cSrcweir 		::vos::ORef < SwAccessibleContext > xThis( this );
95cdf0e10cSrcweir 		GetMap()->SetCursorContext( xThis );
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if( bOldSelected != bNewSelected )
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		Window *pWin = GetWindow();
101cdf0e10cSrcweir 		if( pWin && pWin->HasFocus() )
102cdf0e10cSrcweir 			FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
_InvalidateFocus()106cdf0e10cSrcweir void SwAccessiblePage::_InvalidateFocus()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	Window *pWin = GetWindow();
109cdf0e10cSrcweir 	if( pWin )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		sal_Bool bSelected;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		{
114cdf0e10cSrcweir 			vos::OGuard aGuard( aMutex );
115cdf0e10cSrcweir 			bSelected = bIsSelected;
116cdf0e10cSrcweir 		}
117cdf0e10cSrcweir 		ASSERT( bSelected, "focus object should be selected" );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		FireStateChangedEvent( AccessibleStateType::FOCUSED,
120cdf0e10cSrcweir 							   pWin->HasFocus() && bSelected );
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
SwAccessiblePage(SwAccessibleMap * pInitMap,const SwFrm * pFrame)124cdf0e10cSrcweir SwAccessiblePage::SwAccessiblePage( SwAccessibleMap* pInitMap,
125cdf0e10cSrcweir                                     const SwFrm* pFrame )
126cdf0e10cSrcweir     : SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame )
127cdf0e10cSrcweir     , bIsSelected( sal_False )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     DBG_ASSERT( pFrame != NULL, "need frame" );
130cdf0e10cSrcweir     DBG_ASSERT( pInitMap != NULL, "need map" );
131cdf0e10cSrcweir     DBG_ASSERT( pFrame->IsPageFrm(), "need page frame" );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     OUString sPage = OUString::valueOf(
136cdf0e10cSrcweir         static_cast<sal_Int32>(
137cdf0e10cSrcweir             static_cast<const SwPageFrm*>( GetFrm() )->GetPhyPageNum() ) );
138cdf0e10cSrcweir     SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
~SwAccessiblePage()141cdf0e10cSrcweir SwAccessiblePage::~SwAccessiblePage()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
HasCursor()145cdf0e10cSrcweir sal_Bool SwAccessiblePage::HasCursor()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	vos::OGuard aGuard( aMutex );
148cdf0e10cSrcweir 	return bIsSelected;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
getImplementationName()151cdf0e10cSrcweir OUString SwAccessiblePage::getImplementationName( )
152cdf0e10cSrcweir     throw( RuntimeException )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)157cdf0e10cSrcweir sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName)
158cdf0e10cSrcweir     throw( RuntimeException )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	return rServiceName.equalsAsciiL( sServiceName, sizeof(sServiceName)-1 ) ||
161cdf0e10cSrcweir 	   	rServiceName.equalsAsciiL( sAccessibleServiceName,
162cdf0e10cSrcweir 								   sizeof(sAccessibleServiceName)-1 );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
getSupportedServiceNames()165cdf0e10cSrcweir Sequence<OUString> SwAccessiblePage::getSupportedServiceNames( )
166cdf0e10cSrcweir     throw( RuntimeException )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	Sequence< OUString > aRet(2);
169cdf0e10cSrcweir 	OUString* pArray = aRet.getArray();
170cdf0e10cSrcweir 	pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
171cdf0e10cSrcweir 	pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
172cdf0e10cSrcweir 	return aRet;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
getImplementationId()175cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId()
176cdf0e10cSrcweir 		throw(RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
179cdf0e10cSrcweir     static Sequence< sal_Int8 > aId( 16 );
180cdf0e10cSrcweir     static sal_Bool bInit = sal_False;
181cdf0e10cSrcweir     if(!bInit)
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
184cdf0e10cSrcweir         bInit = sal_True;
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir     return aId;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
getAccessibleDescription()189cdf0e10cSrcweir OUString SwAccessiblePage::getAccessibleDescription( )
190cdf0e10cSrcweir     throw( RuntimeException )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     CHECK_FOR_DEFUNC( ::com::sun::star::accessibility::XAccessibleContext );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	OUString sArg( GetFormattedPageNumber() );
195cdf0e10cSrcweir     return GetResource( STR_ACCESS_PAGE_DESC, &sArg );
196cdf0e10cSrcweir }
197