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