LibreOffice Module sw (master)  1
SidebarTxtControlAcc.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 <sal/config.h>
21 
22 #include <memory>
23 
24 #include "SidebarTxtControlAcc.hxx"
25 
26 #include "SidebarTxtControl.hxx"
27 
28 #include <svl/SfxBroadcaster.hxx>
30 #include <editeng/unoedsrc.hxx>
31 #include <editeng/unoforou.hxx>
32 #include <editeng/unoviwou.hxx>
33 #include <editeng/unoedhlp.hxx>
35 #include <editeng/outliner.hxx>
36 #include <vcl/vclevent.hxx>
37 
38 namespace sw::sidebarwindows {
39 
40 namespace {
41 
42 // declaration and implementation of <SvxEditSource>
43 // for <::accessibility::AccessibleTextHelper> instance
44 class SidebarTextEditSource : public SvxEditSource,
45  public SfxBroadcaster
46 {
47  public:
48  explicit SidebarTextEditSource(SidebarTextControl& rSidebarTextControl);
49  virtual ~SidebarTextEditSource() override;
50 
51  virtual std::unique_ptr<SvxEditSource> Clone() const override;
52 
53  virtual SvxTextForwarder* GetTextForwarder() override;
54  virtual SvxViewForwarder* GetViewForwarder() override;
55  virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false ) override;
56 
57  virtual void UpdateData() override;
58 
59  virtual SfxBroadcaster& GetBroadcaster() const override;
60  DECL_LINK( NotifyHdl, EENotify&, void );
61 
62  private:
63  SidebarTextControl& mrSidebarTextControl;
66 };
67 
68 }
69 
70 SidebarTextEditSource::SidebarTextEditSource( SidebarTextControl& rSidebarTextControl )
71  : SvxEditSource()
72  , mrSidebarTextControl( rSidebarTextControl )
73  , mTextForwarder( *(rSidebarTextControl.GetTextView()->GetOutliner()), false )
74  , mViewForwarder( *(rSidebarTextControl.GetTextView()) )
75 {
76  if ( mrSidebarTextControl.GetTextView() )
77  {
78  mrSidebarTextControl.GetTextView()->GetOutliner()->SetNotifyHdl( LINK(this, SidebarTextEditSource, NotifyHdl) );
79  }
80 }
81 
82 SidebarTextEditSource::~SidebarTextEditSource()
83 {
84  if ( mrSidebarTextControl.GetTextView() )
85  {
86  mrSidebarTextControl.GetTextView()->GetOutliner()->SetNotifyHdl( Link<EENotify&,void>() );
87  }
88 }
89 
90 std::unique_ptr<SvxEditSource> SidebarTextEditSource::Clone() const
91 {
92  return std::unique_ptr<SvxEditSource>(new SidebarTextEditSource( mrSidebarTextControl ));
93 }
94 
95 SvxTextForwarder* SidebarTextEditSource::GetTextForwarder()
96 {
97  return &mTextForwarder;
98 }
99 
100 SvxViewForwarder* SidebarTextEditSource::GetViewForwarder()
101 {
102  return &mViewForwarder;
103 }
104 
105 SvxEditViewForwarder* SidebarTextEditSource::GetEditViewForwarder( bool /*bCreate*/ )
106 {
107  return &mViewForwarder;
108 }
109 
110 void SidebarTextEditSource::UpdateData()
111 {
112  // nothing to do
113 }
114 
115 SfxBroadcaster& SidebarTextEditSource::GetBroadcaster() const
116 {
117  return * const_cast< SidebarTextEditSource* > (this);
118 }
119 
120 IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify&, rNotify, void)
121 {
122  std::unique_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( &rNotify ) );
123 
124  if (aHint)
125  {
126  Broadcast(*aHint);
127  }
128 }
129 
130 namespace {
131 
132 // declaration and implementation of accessible context for <SidebarTextControl> instance
133 class SidebarTextControlAccessibleContext : public VCLXAccessibleComponent
134 {
135  public:
136  explicit SidebarTextControlAccessibleContext( SidebarTextControl& rSidebarTextControl );
137 
138  virtual sal_Int32 SAL_CALL
139  getAccessibleChildCount() override;
140  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
141  getAccessibleChild( sal_Int32 i ) override;
142 
143  virtual void SAL_CALL
144  addAccessibleEventListener (
145  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
146  virtual void SAL_CALL
147  removeAccessibleEventListener (
148  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
149 
150  protected:
151  virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override;
152 
153  private:
154  std::unique_ptr<::accessibility::AccessibleTextHelper> mpAccessibleTextHelper;
155 
156  ::osl::Mutex maMutex;
157 };
158 
159 }
160 
161 SidebarTextControlAccessibleContext::SidebarTextControlAccessibleContext( SidebarTextControl& rSidebarTextControl )
162  : VCLXAccessibleComponent( rSidebarTextControl.GetWindowPeer() )
163  , maMutex()
164 {
165  mpAccessibleTextHelper.reset(new ::accessibility::AccessibleTextHelper( std::make_unique<SidebarTextEditSource>(rSidebarTextControl) ));
166  mpAccessibleTextHelper->SetEventSource( rSidebarTextControl.GetWindowPeer() );
167 }
168 
169 sal_Int32 SAL_CALL SidebarTextControlAccessibleContext::getAccessibleChildCount()
170 {
171  osl::MutexGuard aGuard( maMutex );
172 
173  sal_Int32 nChildCount( 0 );
174 
176  {
177  nChildCount = mpAccessibleTextHelper->GetChildCount();
178  }
179 
180  return nChildCount;
181 }
182 
183 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTextControlAccessibleContext::getAccessibleChild( sal_Int32 i )
184 {
185  osl::MutexGuard aGuard( maMutex );
186 
187  css::uno::Reference< css::accessibility::XAccessible > xChild;
188 
190  {
191  xChild = mpAccessibleTextHelper->GetChild( i );
192  }
193 
194  return xChild;
195 }
196 
197 void SAL_CALL SidebarTextControlAccessibleContext::addAccessibleEventListener (
198  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
199 {
200  osl::MutexGuard aGuard( maMutex );
201 
203  {
204  mpAccessibleTextHelper->AddEventListener(xListener);
205  }
206 }
207 
208 void SAL_CALL SidebarTextControlAccessibleContext::removeAccessibleEventListener (
209  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
210 {
211  osl::MutexGuard aGuard( maMutex );
212 
214  {
215  mpAccessibleTextHelper->RemoveEventListener(xListener);
216  }
217 }
218 
219 void SidebarTextControlAccessibleContext::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
220 {
222  {
223  switch ( rVclWindowEvent.GetId() )
224  {
225  case VclEventId::ObjectDying:
226  {
227  mpAccessibleTextHelper.reset();
228  }
229  break;
230  case VclEventId::WindowGetFocus:
231  case VclEventId::ControlGetFocus:
232  {
233  mpAccessibleTextHelper->SetFocus();
234  }
235  break;
236  case VclEventId::WindowLoseFocus:
237  case VclEventId::ControlLoseFocus:
238  {
239  mpAccessibleTextHelper->SetFocus( false );
240  }
241  break;
242  default: break;
243  }
244  }
245 
247 }
248 
249 // implementation of accessible for <SidebarTextControl> instance
250 SidebarTextControlAccessible::SidebarTextControlAccessible( SidebarTextControl& rSidebarTextControl )
251  : VCLXWindow()
252  , mrSidebarTextControl( rSidebarTextControl )
253 {
255 }
256 
258 {
259 }
260 
261 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTextControlAccessible::CreateAccessibleContext()
262 {
263  SidebarTextControlAccessibleContext* pAccContext(
264  new SidebarTextControlAccessibleContext( mrSidebarTextControl ) );
265  css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
266  return xAcc;
267 }
268 
269 } // end of namespace sw::sidebarwindows
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify &, rNotify, void)
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
VclEventId GetId() const
static::std::unique_ptr< SfxHint > EENotification2Hint(EENotify const *aNotify)
SvxDrawOutlinerViewForwarder mViewForwarder
SvxOutlinerForwarder mTextForwarder
sal_Int32 SAL_CALL getAccessibleChildCount() override
std::unique_ptr<::accessibility::AccessibleTextHelper > mpAccessibleTextHelper
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
::osl::Mutex maMutex
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
SidebarTextControl & mrSidebarTextControl
virtual css::uno::Reference< css::accessibility::XAccessibleContext > CreateAccessibleContext() override
virtual void SetWindow(const VclPtr< vcl::Window > &pWindow)