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