Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vcl/window.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <unotools/accessiblestatesethelper.hxx>
23 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 : #include <comphelper/servicehelper.hxx>
26 : #include "accpage.hxx"
27 :
28 : #include "access.hrc"
29 : #include <pagefrm.hxx>
30 :
31 : using namespace ::com::sun::star;
32 : using namespace ::com::sun::star::accessibility;
33 :
34 : using uno::Reference;
35 : using uno::RuntimeException;
36 : using uno::Sequence;
37 :
38 :
39 : const sal_Char sServiceName[] = "com.sun.star.text.AccessiblePageView";
40 : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessiblePageView";
41 :
42 0 : sal_Bool SwAccessiblePage::IsSelected()
43 : {
44 0 : return GetMap()->IsPageSelected( static_cast < const SwPageFrm * >( GetFrm() ) );
45 : }
46 :
47 0 : void SwAccessiblePage::GetStates(
48 : ::utl::AccessibleStateSetHelper& rStateSet )
49 : {
50 0 : SwAccessibleContext::GetStates( rStateSet );
51 :
52 : // FOCUSABLE
53 0 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
54 :
55 : // FOCUSED
56 0 : if( IsSelected() )
57 : {
58 : OSL_ENSURE( bIsSelected, "bSelected out of sync" );
59 0 : ::rtl::Reference < SwAccessibleContext > xThis( this );
60 0 : GetMap()->SetCursorContext( xThis );
61 :
62 0 : Window *pWin = GetWindow();
63 0 : if( pWin && pWin->HasFocus() )
64 0 : rStateSet.AddState( AccessibleStateType::FOCUSED );
65 : }
66 0 : }
67 :
68 0 : void SwAccessiblePage::_InvalidateCursorPos()
69 : {
70 0 : sal_Bool bNewSelected = IsSelected();
71 : sal_Bool bOldSelected;
72 :
73 : {
74 0 : osl::MutexGuard aGuard( aMutex );
75 0 : bOldSelected = bIsSelected;
76 0 : bIsSelected = bNewSelected;
77 : }
78 :
79 0 : if( bNewSelected )
80 : {
81 : // remember that object as the one that has the caret. This is
82 : // necessary to notify that object if the cursor leaves it.
83 0 : ::rtl::Reference < SwAccessibleContext > xThis( this );
84 0 : GetMap()->SetCursorContext( xThis );
85 : }
86 :
87 0 : if( bOldSelected != bNewSelected )
88 : {
89 0 : Window *pWin = GetWindow();
90 0 : if( pWin && pWin->HasFocus() )
91 0 : FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
92 : }
93 0 : }
94 :
95 0 : void SwAccessiblePage::_InvalidateFocus()
96 : {
97 0 : Window *pWin = GetWindow();
98 0 : if( pWin )
99 : {
100 : sal_Bool bSelected;
101 :
102 : {
103 0 : osl::MutexGuard aGuard( aMutex );
104 0 : bSelected = bIsSelected;
105 : }
106 : OSL_ENSURE( bSelected, "focus object should be selected" );
107 :
108 : FireStateChangedEvent( AccessibleStateType::FOCUSED,
109 0 : pWin->HasFocus() && bSelected );
110 : }
111 0 : }
112 :
113 0 : SwAccessiblePage::SwAccessiblePage( SwAccessibleMap* pInitMap,
114 : const SwFrm* pFrame )
115 : : SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame )
116 0 : , bIsSelected( sal_False )
117 : {
118 : OSL_ENSURE( pFrame != NULL, "need frame" );
119 : OSL_ENSURE( pInitMap != NULL, "need map" );
120 : OSL_ENSURE( pFrame->IsPageFrm(), "need page frame" );
121 :
122 0 : SolarMutexGuard aGuard;
123 :
124 : OUString sPage = OUString::valueOf(
125 : static_cast<sal_Int32>(
126 0 : static_cast<const SwPageFrm*>( GetFrm() )->GetPhyPageNum() ) );
127 0 : SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) );
128 0 : }
129 :
130 0 : SwAccessiblePage::~SwAccessiblePage()
131 : {
132 0 : }
133 :
134 0 : sal_Bool SwAccessiblePage::HasCursor()
135 : {
136 0 : osl::MutexGuard aGuard( aMutex );
137 0 : return bIsSelected;
138 : }
139 :
140 0 : OUString SwAccessiblePage::getImplementationName( )
141 : throw( RuntimeException )
142 : {
143 0 : return OUString(sImplementationName);
144 : }
145 :
146 0 : sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName)
147 : throw( RuntimeException )
148 : {
149 0 : return rServiceName.equalsAsciiL( sServiceName, sizeof(sServiceName)-1 ) ||
150 : rServiceName.equalsAsciiL( sAccessibleServiceName,
151 0 : sizeof(sAccessibleServiceName)-1 );
152 : }
153 :
154 0 : Sequence<OUString> SwAccessiblePage::getSupportedServiceNames( )
155 : throw( RuntimeException )
156 : {
157 0 : Sequence< OUString > aRet(2);
158 0 : OUString* pArray = aRet.getArray();
159 0 : pArray[0] = OUString( sServiceName );
160 0 : pArray[1] = OUString( sAccessibleServiceName );
161 0 : return aRet;
162 : }
163 :
164 : namespace
165 : {
166 : class theSwAccessiblePageImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessiblePageImplementationId > {};
167 : }
168 :
169 0 : Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId()
170 : throw(RuntimeException)
171 : {
172 0 : return theSwAccessiblePageImplementationId::get().getSeq();
173 : }
174 :
175 0 : OUString SwAccessiblePage::getAccessibleDescription( )
176 : throw( RuntimeException )
177 : {
178 0 : CHECK_FOR_DEFUNC( ::com::sun::star::accessibility::XAccessibleContext );
179 :
180 0 : OUString sArg( GetFormattedPageNumber() );
181 0 : return GetResource( STR_ACCESS_PAGE_DESC, &sArg );
182 99 : }
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|