LibreOffice Module sw (master) 1
accpage.cxx
Go to the documentation of this file.
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 <com/sun/star/accessibility/AccessibleStateType.hpp>
22#include <com/sun/star/accessibility/AccessibleRole.hpp>
24#include "accpage.hxx"
25
26#include <strings.hrc>
27#include <pagefrm.hxx>
28
29using namespace ::com::sun::star;
30using namespace ::com::sun::star::accessibility;
31
32using uno::Sequence;
33
34constexpr OUStringLiteral sImplementationName = u"com.sun.star.comp.Writer.SwAccessiblePageView";
35
37{
38 return GetMap()->IsPageSelected( static_cast < const SwPageFrame * >( GetFrame() ) );
39}
40
41void SwAccessiblePage::GetStates( sal_Int64& rStateSet )
42{
44
45 // FOCUSABLE
46 rStateSet |= AccessibleStateType::FOCUSABLE;
47
48 // FOCUSED
49 if( IsSelected() )
50 {
51 OSL_ENSURE( m_bIsSelected, "bSelected out of sync" );
53 GetMap()->SetCursorContext( xThis );
54
55 vcl::Window *pWin = GetWindow();
56 if( pWin && pWin->HasFocus() )
57 rStateSet |= AccessibleStateType::FOCUSED;
58 }
59}
60
62{
63 bool bNewSelected = IsSelected();
64 bool bOldSelected;
65
66 {
67 std::scoped_lock aGuard( m_Mutex );
68 bOldSelected = m_bIsSelected;
69 m_bIsSelected = bNewSelected;
70 }
71
72 if( bNewSelected )
73 {
74 // remember that object as the one that has the caret. This is
75 // necessary to notify that object if the cursor leaves it.
77 GetMap()->SetCursorContext( xThis );
78 }
79
80 if( bOldSelected != bNewSelected )
81 {
82 vcl::Window *pWin = GetWindow();
83 if( pWin && pWin->HasFocus() )
84 FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
85 }
86}
87
89{
90 vcl::Window *pWin = GetWindow();
91 if( !pWin )
92 return;
93
94 bool bSelected;
95
96 {
97 std::scoped_lock aGuard( m_Mutex );
98 bSelected = m_bIsSelected;
99 }
100 OSL_ENSURE( bSelected, "focus object should be selected" );
101
102 FireStateChangedEvent( AccessibleStateType::FOCUSED,
103 pWin->HasFocus() && bSelected );
104}
105
106SwAccessiblePage::SwAccessiblePage(std::shared_ptr<SwAccessibleMap> const& pInitMap,
107 const SwFrame* pFrame )
108 : SwAccessibleContext( pInitMap, AccessibleRole::PANEL, pFrame )
109 , m_bIsSelected( false )
110{
111 assert(pFrame != nullptr);
112 assert(pInitMap != nullptr);
113 assert(pFrame->IsPageFrame());
114
115 OUString sPage = OUString::number(
116 static_cast<const SwPageFrame*>( GetFrame() )->GetPhyPageNum() );
117 SetName( GetResource( STR_ACCESS_PAGE_NAME, &sPage ) );
118}
119
121{
122}
123
125{
126 std::scoped_lock aGuard( m_Mutex );
127 return m_bIsSelected;
128}
129
131{
132 return sImplementationName;
133}
134
135sal_Bool SwAccessiblePage::supportsService( const OUString& rServiceName)
136{
137 return cppu::supportsService(this, rServiceName);
138}
139
141{
142 return { "com.sun.star.text.AccessiblePageView", sAccessibleServiceName };
143}
144
145Sequence< sal_Int8 > SAL_CALL SwAccessiblePage::getImplementationId()
146{
147 return css::uno::Sequence<sal_Int8>();
148}
149
151{
153
154 OUString sArg( GetFormattedPageNumber() );
155 return GetResource( STR_ACCESS_PAGE_DESC, &sArg );
156}
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:42
constexpr OUStringLiteral sImplementationName
Definition: accpage.cxx:34
void FireStateChangedEvent(sal_Int64 nState, bool bNewState)
Definition: acccontext.cxx:467
void SetName(const OUString &rName)
Definition: acccontext.hxx:99
virtual void GetStates(sal_Int64 &rStateSet)
Definition: acccontext.cxx:481
vcl::Window * GetWindow()
Definition: acccontext.cxx:80
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
std::mutex m_Mutex
Definition: acccontext.hxx:64
static OUString GetResource(TranslateId pResId, const OUString *pArg1=nullptr, const OUString *pArg2=nullptr)
const SwFrame * GetFrame() const
Definition: accframe.hxx:102
OUString GetFormattedPageNumber() const
Definition: accframe.cxx:427
void SetCursorContext(const ::rtl::Reference< SwAccessibleContext > &rCursorContext)
Definition: accmap.cxx:2732
bool IsPageSelected(const SwPageFrame *pPageFrame) const
Definition: accmap.cxx:2965
virtual ~SwAccessiblePage() override
Definition: accpage.cxx:120
virtual OUString SAL_CALL getImplementationName() override
Definition: accpage.cxx:130
SwAccessiblePage(std::shared_ptr< SwAccessibleMap > const &pInitMap, const SwFrame *pFrame)
Definition: accpage.cxx:106
virtual void InvalidateFocus_() override
Definition: accpage.cxx:88
virtual void InvalidateCursorPos_() override
Definition: accpage.cxx:61
virtual bool HasCursor() override
Definition: accpage.cxx:124
bool m_bIsSelected
Definition: accpage.hxx:34
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: accpage.cxx:145
virtual void GetStates(sal_Int64 &rStateSet) override
Definition: accpage.cxx:41
virtual OUString SAL_CALL getAccessibleDescription() override
Definition: accpage.cxx:150
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
Definition: accpage.cxx:135
bool IsSelected()
Definition: accpage.cxx:36
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: accpage.cxx:140
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsPageFrame() const
Definition: frame.hxx:1184
A page of the document layout.
Definition: pagefrm.hxx:60
bool HasFocus() const
float u
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool