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 { namespace sidebarwindows {
39 
40 // declaration and implementation of <SvxEditSource>
41 // for <::accessibility::AccessibleTextHelper> instance
43  public SfxBroadcaster
44 {
45  public:
46  explicit SidebarTextEditSource(SidebarTextControl& rSidebarTextControl);
47  virtual ~SidebarTextEditSource() override;
48 
49  virtual std::unique_ptr<SvxEditSource> Clone() const override;
50 
51  virtual SvxTextForwarder* GetTextForwarder() override;
52  virtual SvxViewForwarder* GetViewForwarder() override;
53  virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false ) override;
54 
55  virtual void UpdateData() override;
56 
57  virtual SfxBroadcaster& GetBroadcaster() const override;
58  DECL_LINK( NotifyHdl, EENotify&, void );
59 
60  private:
64 };
65 
67  : SvxEditSource()
68  , mrSidebarTextControl( rSidebarTextControl )
69  , mTextForwarder( *(rSidebarTextControl.GetTextView()->GetOutliner()), false )
70  , mViewForwarder( *(rSidebarTextControl.GetTextView()) )
71 {
73  {
75  }
76 }
77 
79 {
81  {
83  }
84 }
85 
86 std::unique_ptr<SvxEditSource> SidebarTextEditSource::Clone() const
87 {
88  return std::unique_ptr<SvxEditSource>(new SidebarTextEditSource( mrSidebarTextControl ));
89 }
90 
92 {
93  return &mTextForwarder;
94 }
95 
97 {
98  return &mViewForwarder;
99 }
100 
102 {
103  return &mViewForwarder;
104 }
105 
107 {
108  // nothing to do
109 }
110 
112 {
113  return * const_cast< SidebarTextEditSource* > (this);
114 }
115 
116 IMPL_LINK(SidebarTextEditSource, NotifyHdl, EENotify&, rNotify, void)
117 {
118  std::unique_ptr< SfxHint > aHint( SvxEditSourceHelper::EENotification2Hint( &rNotify ) );
119 
120  if (aHint)
121  {
122  Broadcast(*aHint);
123  }
124 }
125 
126 // declaration and implementation of accessible context for <SidebarTextControl> instance
128 {
129  public:
130  explicit SidebarTextControlAccessibleContext( SidebarTextControl& rSidebarTextControl );
131 
132  virtual sal_Int32 SAL_CALL
133  getAccessibleChildCount() override;
134  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
135  getAccessibleChild( sal_Int32 i ) override;
136 
137  virtual void SAL_CALL
139  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
140  virtual void SAL_CALL
142  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
143 
144  protected:
145  virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override;
146 
147  private:
148  std::unique_ptr<::accessibility::AccessibleTextHelper> mpAccessibleTextHelper;
149 
150  ::osl::Mutex maMutex;
151 
152  void defunc();
153 };
154 
156  : VCLXAccessibleComponent( rSidebarTextControl.GetWindowPeer() )
157  , maMutex()
158 {
159  mpAccessibleTextHelper.reset(new ::accessibility::AccessibleTextHelper( std::make_unique<SidebarTextEditSource>(rSidebarTextControl) ));
160  mpAccessibleTextHelper->SetEventSource( rSidebarTextControl.GetWindowPeer() );
161 }
162 
164 {
165  mpAccessibleTextHelper.reset();
166 }
167 
169 {
170  osl::MutexGuard aGuard( maMutex );
171 
172  sal_Int32 nChildCount( 0 );
173 
175  {
176  nChildCount = mpAccessibleTextHelper->GetChildCount();
177  }
178 
179  return nChildCount;
180 }
181 
182 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL SidebarTextControlAccessibleContext::getAccessibleChild( sal_Int32 i )
183 {
184  osl::MutexGuard aGuard( maMutex );
185 
186  css::uno::Reference< css::accessibility::XAccessible > xChild;
187 
189  {
190  xChild = mpAccessibleTextHelper->GetChild( i );
191  }
192 
193  return xChild;
194 }
195 
197  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
198 {
199  osl::MutexGuard aGuard( maMutex );
200 
202  {
203  mpAccessibleTextHelper->AddEventListener(xListener);
204  }
205 }
206 
208  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener)
209 {
210  osl::MutexGuard aGuard( maMutex );
211 
213  {
214  mpAccessibleTextHelper->RemoveEventListener(xListener);
215  }
216 }
217 
219 {
221  {
222  switch ( rVclWindowEvent.GetId() )
223  {
224  case VclEventId::ObjectDying:
225  {
226  defunc();
227  }
228  break;
229  case VclEventId::WindowGetFocus:
230  case VclEventId::ControlGetFocus:
231  {
232  mpAccessibleTextHelper->SetFocus();
233  }
234  break;
235  case VclEventId::WindowLoseFocus:
236  case VclEventId::ControlLoseFocus:
237  {
238  mpAccessibleTextHelper->SetFocus( false );
239  }
240  break;
241  default: break;
242  }
243  }
244 
246 }
247 
248 // implementation of accessible for <SidebarTextControl> instance
250  : VCLXWindow()
251  , mrSidebarTextControl( rSidebarTextControl )
252 {
254 }
255 
257 {
258 }
259 
260 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarTextControlAccessible::CreateAccessibleContext()
261 {
264  css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext );
265  return xAcc;
266 }
267 
268 } } // end of namespace sw::sidebarwindows
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SidebarTextControlAccessible(SidebarTextControl &rSidebarTextControl)
::osl::Mutex maMutex
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
VclEventId GetId() const
static::std::unique_ptr< SfxHint > EENotification2Hint(EENotify const *aNotify)
IMPL_LINK(SidebarTextControl, OnlineSpellCallback, SpellCallbackInfo &, rInfo, void)
virtual std::unique_ptr< SvxEditSource > Clone() const override
virtual SvxTextForwarder * GetTextForwarder() override
Dialog to specify the properties of date form field.
virtual SvxViewForwarder * GetViewForwarder() override
virtual SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
void SetNotifyHdl(const Link< EENotify &, void > &rLink)
int i
virtual SfxBroadcaster & GetBroadcaster() const override
Outliner * GetOutliner() const
SidebarTextControlAccessibleContext(SidebarTextControl &rSidebarTextControl)
virtual css::uno::Reference< css::accessibility::XAccessibleContext > CreateAccessibleContext() override
std::unique_ptr<::accessibility::AccessibleTextHelper > mpAccessibleTextHelper
virtual void SetWindow(const VclPtr< vcl::Window > &pWindow)
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
SidebarTextEditSource(SidebarTextControl &rSidebarTextControl)
DECL_LINK(NotifyHdl, EENotify &, void)
VCLXWindow * GetWindowPeer() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override