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 SfxItemState GetItemState( const ESelection& /*rSel*/, sal_uInt16 /*nWhich*/ ) const override { return SfxItemState::UNKNOWN; }
107 SfxItemState GetItemState( sal_Int32 /*nPara*/, sal_uInt16 /*nWhich*/ ) const override { return SfxItemState::UNKNOWN; }
108
109 SfxItemPool* GetPool() const override { return nullptr; }
110
111 void QuickInsertText( const OUString& /*rText*/, const ESelection& /*rSel*/ ) override {}
112 void QuickInsertField( const SvxFieldItem& /*rFld*/, const ESelection& /*rSel*/ ) override {}
113 void QuickSetAttribs( const SfxItemSet& /*rSet*/, const ESelection& /*rSel*/ ) override {}
114 void QuickInsertLineBreak( const ESelection& /*rSel*/ ) override {}
115
116 const SfxItemSet * GetEmptyItemSetPtr() override { return nullptr; }
117
118 void AppendParagraph() override {}
119 sal_Int32 AppendTextPortion( sal_Int32 /*nPara*/, const OUString & /*rText*/, const SfxItemSet & /*rSet*/ ) override { return 0; }
120
121 //XTextCopy
122 void CopyText(const SvxTextForwarder& ) override {}
123
124 OUString CalcFieldValue( const SvxFieldItem& /*rField*/, sal_Int32 /*nPara*/, sal_Int32 /*nPos*/, std::optional<Color>& /*rpTxtColor*/, std::optional<Color>& /*rpFldColor*/ ) override
125 {
126 return OUString();
127 }
128 void FieldClicked( const SvxFieldItem& ) override {}
129
130 bool IsValid() const override { return true; }
131
132 LanguageType GetLanguage( sal_Int32, sal_Int32 ) const override { return LANGUAGE_DONTKNOW; }
133 sal_Int32 GetFieldCount( sal_Int32 ) const override { return 0; }
134 EFieldInfo GetFieldInfo( sal_Int32, sal_uInt16 ) const override { return EFieldInfo(); }
135 EBulletInfo GetBulletInfo( sal_Int32 ) const override { return EBulletInfo(); }
136 tools::Rectangle GetCharBounds( sal_Int32, sal_Int32 ) const override { return tools::Rectangle(); }
137 tools::Rectangle GetParaBounds( sal_Int32 ) const override { return tools::Rectangle(); }
138 MapMode GetMapMode() const override { return MapMode(); }
139 OutputDevice* GetRefDevice() const override { return nullptr; }
140 bool GetIndexAtPoint( const Point&, sal_Int32&, sal_Int32& ) const override { return false; }
141 bool GetWordIndices( sal_Int32, sal_Int32, sal_Int32&, sal_Int32& ) const override { return false; }
142 bool GetAttributeRun( sal_Int32&, sal_Int32&, sal_Int32, sal_Int32, bool ) const override { return false; }
143 sal_Int32 GetLineCount( sal_Int32 nPara ) const override { return nPara == 0 ? 1 : 0; }
144 sal_Int32 GetLineLen( sal_Int32, sal_Int32 ) const override { return 0; }
145 void GetLineBoundaries( /*out*/sal_Int32 & rStart, /*out*/sal_Int32 & rEnd, sal_Int32 /*nParagraph*/, sal_Int32 /*nLine*/ ) const override { rStart = rEnd = 0; }
146 sal_Int32 GetLineNumberAtIndex( sal_Int32 /*nPara*/, sal_Int32 /*nIndex*/ ) const override { return 0; }
147
148 // the following two methods would, strictly speaking, require
149 // a switch to a real EditSource, too. Fortunately, the
150 // AccessibleEditableTextPara implementation currently always
151 // calls GetEditViewForwarder(true) before doing
152 // changes. Thus, we rely on this behaviour here (problem
153 // when that changes: via accessibility API, it would no
154 // longer be possible to enter text in previously empty
155 // shapes).
156 bool Delete( const ESelection& ) override { return false; }
157 bool InsertText( const OUString&, const ESelection& ) override { return false; }
158 bool QuickFormatDoc( bool ) override { return true; }
159 sal_Int16 GetDepth( sal_Int32 ) const override { return -1; }
160 bool SetDepth( sal_Int32, sal_Int16 ) override { return true; }
161
162 Point LogicToPixel( const Point& rPoint, const MapMode& /*rMapMode*/ ) const override { return rPoint; }
163 Point PixelToLogic( const Point& rPoint, const MapMode& /*rMapMode*/ ) const override { return rPoint; }
164
165 };
166
167 }
168
169 // Implementing AccessibleProxyEditSource_Impl
170
171
172 AccessibleProxyEditSource_Impl::AccessibleProxyEditSource_Impl( SdrObject& rObj,
173 SdrView& rView,
174 const OutputDevice& rViewWindow ) :
175 maEditSource( rObj, nullptr, rView, rViewWindow )
176 {
177 }
178
179 SvxTextForwarder* AccessibleProxyEditSource_Impl::GetTextForwarder()
180 {
182 }
183
184 SvxViewForwarder* AccessibleProxyEditSource_Impl::GetViewForwarder()
185 {
187 }
188
189 SvxEditViewForwarder* AccessibleProxyEditSource_Impl::GetEditViewForwarder( bool bCreate )
190 {
191 return maEditSource.GetEditViewForwarder( bCreate );
192 }
193
194 std::unique_ptr<SvxEditSource> AccessibleProxyEditSource_Impl::Clone() const
195 {
196 return maEditSource.Clone();
197 }
198
199 void AccessibleProxyEditSource_Impl::UpdateData()
200 {
202 }
203
204 SfxBroadcaster& AccessibleProxyEditSource_Impl::GetBroadcaster() const
205 {
207 }
208
209
210 // Implementing AccessibleEmptyEditSource
211
212
213 AccessibleEmptyEditSource::AccessibleEmptyEditSource( SdrObject& rObj,
214 SdrView& rView,
215 const OutputDevice& rViewWindow ) :
216 mpEditSource( new AccessibleEmptyEditSource_Impl() ),
217 mrObj(rObj),
218 mrView(rView),
219 mrViewWindow(rViewWindow),
220 mbEditSourceEmpty( true )
221 {
223 }
224
226 {
227 if( !mbEditSourceEmpty )
228 {
229 // deregister as listener
230 if (mpEditSource)
231 EndListening( mpEditSource->GetBroadcaster() );
232 }
233 else
234 {
236 }
237 }
238
240 {
241 if (!mpEditSource)
242 return nullptr;
243
244 return mpEditSource->GetTextForwarder();
245 }
246
248 {
249 if (!mpEditSource)
250 return nullptr;
251
252 return mpEditSource->GetViewForwarder();
253 }
254
256 {
257 // deregister EmptyEditSource model listener
259
260 ::std::unique_ptr< SvxEditSource > pProxySource( new AccessibleProxyEditSource_Impl(mrObj, mrView, mrViewWindow) );
261 mpEditSource.swap(pProxySource);
262
263 // register as listener
264 StartListening( mpEditSource->GetBroadcaster() );
265
266 // we've irrevocably a full EditSource now.
267 mbEditSourceEmpty = false;
268 }
269
271 {
272 if (!mpEditSource)
273 return nullptr;
274
275 // switch edit source, if not yet done
276 if( mbEditSourceEmpty && bCreate )
278
279 return mpEditSource->GetEditViewForwarder( bCreate );
280 }
281
282 std::unique_ptr<SvxEditSource> AccessibleEmptyEditSource::Clone() const
283 {
284 if (!mpEditSource)
285 return nullptr;
286
287 return mpEditSource->Clone();
288 }
289
291 {
292 if (mpEditSource)
293 mpEditSource->UpdateData();
294 }
295
297 {
298 return *const_cast<AccessibleEmptyEditSource*>(this);
299 }
300
302 {
303 const SdrHint* pSdrHint = ( rHint.GetId() == SfxHintId::ThisIsAnSdrHint ? static_cast<const SdrHint*>(&rHint) : nullptr );
304
305 if( pSdrHint && pSdrHint->GetKind() == SdrHintKind::BeginEdit &&
306 &mrObj == pSdrHint->GetObject() && mpEditSource )
307 {
308 // switch edit source, if not yet done. This is necessary
309 // to become a full-fledged EditSource the first time a
310 // user start entering text in a previously empty object.
313 }
314 else if (pSdrHint && pSdrHint->GetObject()!=nullptr)
315 {
316 // When the SdrObject just got a para outliner object then
317 // switch the edit source.
318 if (pSdrHint->GetObject()->GetOutlinerParaObject() != nullptr)
320 }
321
322 // forward messages
323 Broadcast( rHint );
324 }
325
326} // end of namespace accessibility
327
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxTextEditSource maEditSource
SlideSorterView & mrView
SdrHintKind GetKind() const
Definition: svdmodel.hxx:132
const SdrObject * GetObject() const
Definition: svdmodel.hxx:131
Abstract DrawObject.
Definition: svdobj.hxx:261
static SdrItemPool & GetGlobalDrawObjectItemPool()
Definition: svdobj.cxx:576
virtual OutlinerParaObject * GetOutlinerParaObject() const
Definition: svdobj.cxx:1867
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:284
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:937
virtual SvxViewForwarder * GetViewForwarder() override
Definition: unoshtxt.cxx:949
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: unoshtxt.cxx:931
virtual SfxBroadcaster & GetBroadcaster() const override
Definition: unoshtxt.cxx:960
virtual void UpdateData() override
Definition: unoshtxt.cxx:955
virtual SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
Definition: unoshtxt.cxx:943
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