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