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