LibreOffice Module svx (master) 1
AccessibleEmptyEditSource.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
21// Global header
22
23
24#include <memory>
25#include <svl/itemset.hxx>
26#include <editeng/editdata.hxx>
27#include <editeng/outliner.hxx>
28#include <svx/svdmodel.hxx>
29#include <svx/svdobj.hxx>
30#include <svx/svdpool.hxx>
31
32
33// Project-local header
34
35
37#include <svx/unoshtxt.hxx>
38
39namespace accessibility
40{
41 namespace {
42
46 class AccessibleProxyEditSource_Impl : public SvxEditSource
47 {
48 public:
55 AccessibleProxyEditSource_Impl( SdrObject& rObj,
56 SdrView& rView,
57 const OutputDevice& rViewWindow );
58
59 // from the SvxEditSource interface
60 SvxTextForwarder* GetTextForwarder() override;
61 SvxViewForwarder* GetViewForwarder() override;
62 SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false ) override;
63
64 std::unique_ptr<SvxEditSource> Clone() const override;
65
66 void UpdateData() override;
67
68 SfxBroadcaster& GetBroadcaster() const override;
69
70 private:
72
73 };
74
77 class AccessibleEmptyEditSource_Impl : public SvxEditSource, public SvxViewForwarder, public SvxTextForwarder, public SfxBroadcaster
78 {
79 public:
80
81 AccessibleEmptyEditSource_Impl() {}
82
83 // SvxEditSource
84 SvxTextForwarder* GetTextForwarder() override { return this; }
85 SvxViewForwarder* GetViewForwarder() override { return this; }
86 std::unique_ptr<SvxEditSource> Clone() const override { return nullptr; }
87 void UpdateData() override {}
88 SfxBroadcaster& GetBroadcaster() const override { return *const_cast<AccessibleEmptyEditSource_Impl*>(this); }
89
90 // SvxTextForwarder
91 sal_Int32 GetParagraphCount() const override { return 1; }
92 sal_Int32 GetTextLen( sal_Int32 /*nParagraph*/ ) const override { return 0; }
93 OUString GetText( const ESelection& /*rSel*/ ) const override { return OUString(); }
94 SfxItemSet GetAttribs( const ESelection& /*rSel*/, EditEngineAttribs /*nOnlyHardAttrib*/ = EditEngineAttribs::All ) const override
95 {
96 // AW: Very dangerous: The former implementation used a SfxItemPool created on the
97 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
98 // a deleted Pool by design.
100 }
101 SfxItemSet GetParaAttribs( sal_Int32 /*nPara*/ ) const override { return GetAttribs(ESelection()); }
102 void SetParaAttribs( sal_Int32 /*nPara*/, const SfxItemSet& /*rSet*/ ) override {}
103 void RemoveAttribs( const ESelection& /*rSelection*/ ) override {}
104 void GetPortions( sal_Int32 /*nPara*/, std::vector<sal_Int32>& /*rList*/ ) const override {}
105
106 OUString GetStyleSheet(sal_Int32 /*nPara*/) const override { return OUString(); }
107 void SetStyleSheet(sal_Int32 /*nPara*/, const OUString& /*rStyleName*/) override {}
108
109 SfxItemState GetItemState( const ESelection& /*rSel*/, sal_uInt16 /*nWhich*/ ) const override { return SfxItemState::UNKNOWN; }
110 SfxItemState GetItemState( sal_Int32 /*nPara*/, sal_uInt16 /*nWhich*/ ) const override { return SfxItemState::UNKNOWN; }
111
112 SfxItemPool* GetPool() const override { return nullptr; }
113
114 void QuickInsertText( const OUString& /*rText*/, const ESelection& /*rSel*/ ) override {}
115 void QuickInsertField( const SvxFieldItem& /*rFld*/, const ESelection& /*rSel*/ ) override {}
116 void QuickSetAttribs( const SfxItemSet& /*rSet*/, const ESelection& /*rSel*/ ) override {}
117 void QuickInsertLineBreak( const ESelection& /*rSel*/ ) override {}
118
119 const SfxItemSet * GetEmptyItemSetPtr() override { return nullptr; }
120
121 void AppendParagraph() override {}
122 sal_Int32 AppendTextPortion( sal_Int32 /*nPara*/, const OUString & /*rText*/, const SfxItemSet & /*rSet*/ ) override { return 0; }
123
124 //XTextCopy
125 void CopyText(const SvxTextForwarder& ) override {}
126
127 OUString CalcFieldValue( const SvxFieldItem& /*rField*/, sal_Int32 /*nPara*/, sal_Int32 /*nPos*/, std::optional<Color>& /*rpTxtColor*/, std::optional<Color>& /*rpFldColor*/, std::optional<FontLineStyle>& /*rpFldLineStyle*/ ) override
128 {
129 return OUString();
130 }
131 void FieldClicked( const SvxFieldItem& ) override {}
132
133 bool IsValid() const override { return true; }
134
135 LanguageType GetLanguage( sal_Int32, sal_Int32 ) const override { return LANGUAGE_DONTKNOW; }
136 sal_Int32 GetFieldCount( sal_Int32 ) const override { return 0; }
137 EFieldInfo GetFieldInfo( sal_Int32, sal_uInt16 ) const override { return EFieldInfo(); }
138 EBulletInfo GetBulletInfo( sal_Int32 ) const override { return EBulletInfo(); }
139 tools::Rectangle GetCharBounds( sal_Int32, sal_Int32 ) const override { return tools::Rectangle(); }
140 tools::Rectangle GetParaBounds( sal_Int32 ) const override { return tools::Rectangle(); }
141 MapMode GetMapMode() const override { return MapMode(); }
142 OutputDevice* GetRefDevice() const override { return nullptr; }
143 bool GetIndexAtPoint( const Point&, sal_Int32&, sal_Int32& ) const override { return false; }
144 bool GetWordIndices( sal_Int32, sal_Int32, sal_Int32&, sal_Int32& ) const override { return false; }
145 bool GetAttributeRun( sal_Int32&, sal_Int32&, sal_Int32, sal_Int32, bool ) const override { return false; }
146 sal_Int32 GetLineCount( sal_Int32 nPara ) const override { return nPara == 0 ? 1 : 0; }
147 sal_Int32 GetLineLen( sal_Int32, sal_Int32 ) const override { return 0; }
148 void GetLineBoundaries( /*out*/sal_Int32 & rStart, /*out*/sal_Int32 & rEnd, sal_Int32 /*nParagraph*/, sal_Int32 /*nLine*/ ) const override { rStart = rEnd = 0; }
149 sal_Int32 GetLineNumberAtIndex( sal_Int32 /*nPara*/, sal_Int32 /*nIndex*/ ) const override { return 0; }
150
151 // the following two methods would, strictly speaking, require
152 // a switch to a real EditSource, too. Fortunately, the
153 // AccessibleEditableTextPara implementation currently always
154 // calls GetEditViewForwarder(true) before doing
155 // changes. Thus, we rely on this behaviour here (problem
156 // when that changes: via accessibility API, it would no
157 // longer be possible to enter text in previously empty
158 // shapes).
159 bool Delete( const ESelection& ) override { return false; }
160 bool InsertText( const OUString&, const ESelection& ) override { return false; }
161 bool QuickFormatDoc( bool ) override { return true; }
162 sal_Int16 GetDepth( sal_Int32 ) const override { return -1; }
163 bool SetDepth( sal_Int32, sal_Int16 ) override { return true; }
164
165 Point LogicToPixel( const Point& rPoint, const MapMode& /*rMapMode*/ ) const override { return rPoint; }
166 Point PixelToLogic( const Point& rPoint, const MapMode& /*rMapMode*/ ) const override { return rPoint; }
167
168 };
169
170 }
171
172 // Implementing AccessibleProxyEditSource_Impl
173
174
175 AccessibleProxyEditSource_Impl::AccessibleProxyEditSource_Impl( SdrObject& rObj,
176 SdrView& rView,
177 const OutputDevice& rViewWindow ) :
178 maEditSource( rObj, nullptr, rView, rViewWindow )
179 {
180 }
181
182 SvxTextForwarder* AccessibleProxyEditSource_Impl::GetTextForwarder()
183 {
185 }
186
187 SvxViewForwarder* AccessibleProxyEditSource_Impl::GetViewForwarder()
188 {
190 }
191
192 SvxEditViewForwarder* AccessibleProxyEditSource_Impl::GetEditViewForwarder( bool bCreate )
193 {
194 return maEditSource.GetEditViewForwarder( bCreate );
195 }
196
197 std::unique_ptr<SvxEditSource> AccessibleProxyEditSource_Impl::Clone() const
198 {
199 return maEditSource.Clone();
200 }
201
202 void AccessibleProxyEditSource_Impl::UpdateData()
203 {
205 }
206
207 SfxBroadcaster& AccessibleProxyEditSource_Impl::GetBroadcaster() const
208 {
210 }
211
212
213 // Implementing AccessibleEmptyEditSource
214
215
216 AccessibleEmptyEditSource::AccessibleEmptyEditSource( SdrObject& rObj,
217 SdrView& rView,
218 const OutputDevice& rViewWindow ) :
219 mpEditSource( new AccessibleEmptyEditSource_Impl() ),
220 mrObj(rObj),
221 mrView(rView),
222 mrViewWindow(rViewWindow),
223 mbEditSourceEmpty( true )
224 {
226 }
227
229 {
230 if( !mbEditSourceEmpty )
231 {
232 // deregister as listener
233 if (mpEditSource)
234 EndListening( mpEditSource->GetBroadcaster() );
235 }
236 else
237 {
239 }
240 }
241
243 {
244 if (!mpEditSource)
245 return nullptr;
246
247 return mpEditSource->GetTextForwarder();
248 }
249
251 {
252 if (!mpEditSource)
253 return nullptr;
254
255 return mpEditSource->GetViewForwarder();
256 }
257
259 {
260 // deregister EmptyEditSource model listener
262
263 ::std::unique_ptr< SvxEditSource > pProxySource( new AccessibleProxyEditSource_Impl(mrObj, mrView, mrViewWindow) );
264 mpEditSource.swap(pProxySource);
265
266 // register as listener
267 StartListening( mpEditSource->GetBroadcaster() );
268
269 // we've irrevocably a full EditSource now.
270 mbEditSourceEmpty = false;
271 }
272
274 {
275 if (!mpEditSource)
276 return nullptr;
277
278 // switch edit source, if not yet done
279 if( mbEditSourceEmpty && bCreate )
281
282 return mpEditSource->GetEditViewForwarder( bCreate );
283 }
284
285 std::unique_ptr<SvxEditSource> AccessibleEmptyEditSource::Clone() const
286 {
287 if (!mpEditSource)
288 return nullptr;
289
290 return mpEditSource->Clone();
291 }
292
294 {
295 if (mpEditSource)
296 mpEditSource->UpdateData();
297 }
298
300 {
301 return *const_cast<AccessibleEmptyEditSource*>(this);
302 }
303
305 {
306 const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr );
307
308 if( pSdrHint && pSdrHint->GetKind() == SdrHintKind::BeginEdit &&
309 &mrObj == pSdrHint->GetObject() && mpEditSource )
310 {
311 // switch edit source, if not yet done. This is necessary
312 // to become a full-fledged EditSource the first time a
313 // user start entering text in a previously empty object.
316 }
317 else if (pSdrHint && pSdrHint->GetObject()!=nullptr)
318 {
319 // When the SdrObject just got a para outliner object then
320 // switch the edit source.
321 if (pSdrHint->GetObject()->GetOutlinerParaObject() != nullptr)
323 }
324
325 // forward messages
326 Broadcast( rHint );
327 }
328
329} // end of namespace accessibility
330
331
332/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxTextEditSource maEditSource
SlideSorterView & mrView
SdrHintKind GetKind() const
Definition: svdmodel.hxx:133
const SdrObject * GetObject() const
Definition: svdmodel.hxx:132
Abstract DrawObject.
Definition: svdobj.hxx:260
static SdrItemPool & GetGlobalDrawObjectItemPool()
Definition: svdobj.cxx:548
virtual OutlinerParaObject * GetOutlinerParaObject() const
Definition: svdobj.cxx:1833
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:289
void Broadcast(const SfxHint &rHint)
SfxHintId GetId() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
virtual SvxTextForwarder * GetTextForwarder() override
Definition: unoshtxt.cxx:936
virtual SvxViewForwarder * GetViewForwarder() override
Definition: unoshtxt.cxx:948
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: unoshtxt.cxx:930
virtual SfxBroadcaster & GetBroadcaster() const override
Definition: unoshtxt.cxx:959
virtual void UpdateData() override
Definition: unoshtxt.cxx:954
virtual SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
Definition: unoshtxt.cxx:942
Proxy edit source for shapes without text.
std::unique_ptr< SvxEditSource > mpEditSource
Pointer to edit source implementation.
void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
SfxBroadcaster & GetBroadcaster() const override
std::unique_ptr< SvxEditSource > Clone() const override
SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
EditEngineAttribs
#define LANGUAGE_DONTKNOW
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
SfxItemState