LibreOffice Module sw (master) 1
DocumentDrawModelManager.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
21
22#include <doc.hxx>
23#include <IDocumentUndoRedo.hxx>
28#include <docsh.hxx>
29#include <wrtsh.hxx>
30#include <swtypes.hxx>
31#include <svl/hint.hxx>
32#include <viewsh.hxx>
33#include <view.hxx>
34#include <drawdoc.hxx>
35#include <rootfrm.hxx>
36#include <fmtanchr.hxx>
37#include <editeng/eeitem.hxx>
38#include <editeng/fhgtitem.hxx>
39#include <svx/svdlayer.hxx>
40#include <svx/svdoutl.hxx>
41#include <svx/svdpage.hxx>
42#include <svx/svdpagv.hxx>
43#include <svx/svdotext.hxx>
44#include <svx/svdview.hxx>
45#include <svl/srchitem.hxx>
47#include <sal/log.hxx>
48#include <osl/diagnose.h>
49
50class SdrOutliner;
51
52namespace sw
53{
54
56 : m_rDoc(i_rSwdoc)
57 , mnHeaven(0)
58 , mnHell(0)
59 , mnControls(0)
60 , mnInvisibleHeaven(0)
61 , mnInvisibleHell(0)
62 , mnInvisibleControls(0)
63{
64}
65
66// Is also called by the Sw3 Reader, if there was an error when reading the
67// drawing layer. If it is called by the Sw3 Reader the layer is rebuilt
68// from scratch.
70{
71 // !! Attention: there is similar code in the Sw3 Reader (sw3imp.cxx) that
72 // also has to be maintained!!
73 if ( mpDrawModel )
75
76 // set FontHeight pool defaults without changing static SdrEngineDefaults
78
79 SAL_INFO( "sw.doc", "before create DrawDocument" );
80 // The document owns the SwDrawModel. We always have two layers and one page.
81 mpDrawModel.reset(new SwDrawModel(m_rDoc));
82
84
85 OUString sLayerNm;
86 sLayerNm = "Hell";
87 mnHell = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
88
89 sLayerNm = "Heaven";
90 mnHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
91
92 sLayerNm = "Controls";
93 mnControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
94 mpDrawModel->GetLayerAdmin().SetControlLayerName(sLayerNm);
95
96 // add invisible layers corresponding to the visible ones.
97 {
98 sLayerNm = "InvisibleHell";
99 mnInvisibleHell = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
100
101 sLayerNm = "InvisibleHeaven";
102 mnInvisibleHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
103
104 sLayerNm = "InvisibleControls";
105 mnInvisibleControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
106 }
107
108 rtl::Reference<SdrPage> pMasterPage = mpDrawModel->AllocPage( false );
109 mpDrawModel->InsertPage( pMasterPage.get() );
110 SAL_INFO( "sw.doc", "after create DrawDocument" );
111 SdrOutliner& rOutliner = mpDrawModel->GetDrawOutliner();
113 {
114 SAL_INFO( "sw.doc", "before create Spellchecker/Hyphenator" );
115 css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpell = ::GetSpellChecker();
116 rOutliner.SetSpeller( xSpell );
117 css::uno::Reference< css::linguistic2::XHyphenator > xHyphenator( ::GetHyphenator() );
118 rOutliner.SetHyphenator( xHyphenator );
119 SAL_INFO( "sw.doc", "after create Spellchecker/Hyphenator" );
120 }
121 m_rDoc.SetCalcFieldValueHdl(&rOutliner);
122 m_rDoc.SetCalcFieldValueHdl(&mpDrawModel->GetHitTestOutliner());
123
124 // Set the LinkManager in the model so that linked graphics can be inserted.
125 // The WinWord import needs it too.
128
130 if ( pRefDev )
131 mpDrawModel->SetRefDevice( pRefDev );
132
133 mpDrawModel->SetNotifyUndoActionHdl( std::bind( &SwDoc::AddDrawUndo, &m_rDoc, std::placeholders::_1 ));
135 if ( !pSh )
136 return;
137
138 for(const SwViewShell& rViewSh : pSh->GetRingContainer())
139 {
140 SwRootFrame* pRoot = rViewSh.GetLayout();
141 if( pRoot && !pRoot->GetDrawPage() )
142 {
143 // Disable "multiple layout" for the moment:
144 // use pMasterPage instead of a new created SdrPage
145 // mpDrawModel->AllocPage( FALSE );
146 // mpDrawModel->InsertPage( pDrawPage );
147 SdrPage* pDrawPage = pMasterPage.get();
148 pRoot->SetDrawPage( pDrawPage );
149 pDrawPage->SetSize( pRoot->getFrameArea().SSize() );
150 }
151 }
152}
153
154
156{
157 // !! Also maintain the code in the sw3io for inserting documents!!
158 mpDrawModel.reset();
159}
160
161
163{
164 return mpDrawModel.get();
165}
166
168{
169 return mpDrawModel.get();
170}
171
173{
174 OSL_ENSURE( !mpDrawModel, "MakeDrawModel_: Why?" );
177 if ( pSh )
178 {
179 for(SwViewShell& rViewSh : pSh->GetRingContainer())
180 rViewSh.MakeDrawView();
181
182 // Broadcast, so that the FormShell can be connected to the DrawView
183 if( m_rDoc.GetDocShell() )
184 {
185 SfxHint aHint( SfxHintId::SwDrawViewsCreated );
186 m_rDoc.GetDocShell()->Broadcast( aHint );
187 }
188 }
189 return mpDrawModel.get();
190}
191
193{
195}
196
198{
199 return mnHeaven;
200}
201
203{
204 return mnHell;
205}
206
208{
209 return mnControls;
210}
211
213{
214 return mnInvisibleHeaven;
215}
216
218{
219 return mnInvisibleHell;
220}
221
223{
224 return mnInvisibleControls;
225}
226
228{
229 OUString sLayerNm;
230 sLayerNm = "InvisibleHell";
231 _rSdrPageView.SetLayerVisible( sLayerNm, false );
232
233 sLayerNm = "InvisibleHeaven";
234 _rSdrPageView.SetLayerVisible( sLayerNm, false );
235
236 sLayerNm = "InvisibleControls";
237 _rSdrPageView.SetLayerVisible( sLayerNm, false );
238}
239
241{
242 bool bRetVal;
243
244 if ( _nLayerId == GetHeavenId() ||
245 _nLayerId == GetHellId() ||
246 _nLayerId == GetControlsId() )
247 {
248 bRetVal = true;
249 }
250 else if ( _nLayerId == GetInvisibleHeavenId() ||
251 _nLayerId == GetInvisibleHellId() ||
252 _nLayerId == GetInvisibleControlsId() )
253 {
254 bRetVal = false;
255 }
256 else
257 {
258 OSL_FAIL( "<SwDoc::IsVisibleLayerId(..)> - unknown layer ID." );
259 bRetVal = false;
260 }
261
262 return bRetVal;
263}
264
266{
267 SdrLayerID nInvisibleLayerId;
268
269 if ( _nVisibleLayerId == GetHeavenId() )
270 {
271 nInvisibleLayerId = GetInvisibleHeavenId();
272 }
273 else if ( _nVisibleLayerId == GetHellId() )
274 {
275 nInvisibleLayerId = GetInvisibleHellId();
276 }
277 else if ( _nVisibleLayerId == GetControlsId() )
278 {
279 nInvisibleLayerId = GetInvisibleControlsId();
280 }
281 else if ( _nVisibleLayerId == GetInvisibleHeavenId() ||
282 _nVisibleLayerId == GetInvisibleHellId() ||
283 _nVisibleLayerId == GetInvisibleControlsId() )
284 {
285 OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID already an invisible one." );
286 nInvisibleLayerId = _nVisibleLayerId;
287 }
288 else
289 {
290 OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID is unknown." );
291 nInvisibleLayerId = _nVisibleLayerId;
292 }
293
294 return nInvisibleLayerId;
295}
296
297bool DocumentDrawModelManager::Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem)
298{
299 SwPosFlyFrames aFrames = m_rDoc.GetAllFlyFormats(&rPaM, /*bDrawAlso=*/true);
300
301 for (const SwPosFlyFrame& rPosFlyFrame : aFrames)
302 {
303 // Filter for at-paragraph anchored draw frames.
304 const SwFrameFormat& rFrameFormat = rPosFlyFrame.GetFormat();
305 const SwFormatAnchor& rAnchor = rFrameFormat.GetAnchor();
306 if (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA || rFrameFormat.Which() != RES_DRAWFRMFMT)
307 continue;
308
309 // Does the shape have matching text?
310 SdrOutliner& rOutliner = GetDrawModel()->GetDrawOutliner();
311 SdrObject* pObject = const_cast<SdrObject*>(rFrameFormat.FindSdrObject());
312 SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>(pObject);
313 if (!pTextObj)
314 continue;
315 const OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
316 if (!pParaObj)
317 continue;
318 rOutliner.SetText(*pParaObj);
319 SwDocShell* pDocShell = m_rDoc.GetDocShell();
320 if (!pDocShell)
321 return false;
322 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
323 if (!pWrtShell)
324 return false;
325 if (!rOutliner.HasText(rSearchItem))
326 continue;
327
328 // If so, then select highlight the search result.
329 pWrtShell->SelectObj(Point(), 0, pObject);
330 SwView* pView = pDocShell->GetView();
331 if (!pView)
332 return false;
333 if (!pView->EnterShapeDrawTextMode(pObject))
334 continue;
335 SdrView* pSdrView = pWrtShell->GetDrawView();
336 if (!pSdrView)
337 return false;
338 OutlinerView* pOutlinerView = pSdrView->GetTextEditOutlinerView();
339 if (!rSearchItem.GetBackward())
340 pOutlinerView->SetSelection(ESelection(0, 0, 0, 0));
341 else
343 pOutlinerView->StartSearchAndReplace(rSearchItem);
344 return true;
345 }
346
347 return false;
348}
349
351{
352 mpDrawModel->SetNotifyUndoActionHdl( nullptr );
353}
354
355}
356
357/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OutputDevice * getReferenceDevice(bool bCreate) const =0
Returns the current reference device.
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual sfx2::LinkManager & GetLinkManager()=0
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
virtual bool DoesUndo() const =0
Is Undo enabled?
void SetSelection(const ESelection &)
sal_Int32 StartSearchAndReplace(const SvxSearchItem &rSearchItem)
SdrOutliner & GetDrawOutliner(const SdrTextObj *pObj=nullptr) const
const OutlinerView * GetTextEditOutlinerView() const
void SetLayerVisible(const OUString &rName, bool bShow)
virtual void SetSize(const Size &aSiz)
virtual OutlinerParaObject * GetOutlinerParaObject() const override
void SetPoolDefaultItem(const SfxPoolItem &)
bool GetBackward() const
const SwView * GetView() const
Definition: docsh.hxx:221
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:225
Definition: doc.hxx:192
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:239
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:261
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:145
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:406
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:177
SwPosFlyFrames GetAllFlyFormats(const SwPaM *, bool bDrawAlso, bool bAsCharAlso=false) const
Returns positions of all FlyFrames in the document.
Definition: doclay.cxx:499
void AddDrawUndo(std::unique_ptr< SdrUndoAction >)
Definition: undraw.cxx:55
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1322
SwDocShell * GetDocShell()
Definition: doc.hxx:1355
void SetCalcFieldValueHdl(Outliner *pOutliner)
In the Outliner, set a link to the method for field display in edit objects.
Definition: docdraw.cxx:540
bool SelectObj(const Point &rSelPt, sal_uInt8 nFlag=0, SdrObject *pObj=nullptr)
If an object has been given, exactly this object is selected (instead of searching over position).
Definition: feshview.cxx:177
FlyAnchors.
Definition: fmtanchr.hxx:37
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:83
const SwRect & getFrameArea() const
Definition: frame.hxx:179
Style of a layout element.
Definition: frmfmt.hxx:62
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:141
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
For querying current flys in document.
Definition: flypos.hxx:31
void SSize(const Size &rNew)
Definition: swrect.hxx:180
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
const SdrPage * GetDrawPage() const
Definition: rootfrm.hxx:226
void SetDrawPage(SdrPage *pNew)
Definition: rootfrm.hxx:228
void MakeDrawView()
Definition: vnew.cxx:363
SdrView * GetDrawView()
Definition: vnew.cxx:373
Definition: view.hxx:146
bool EnterShapeDrawTextMode(SdrObject *pObject)
Same as EnterDrawTextMode(), but takes an SdrObject instead of guessing it by document position.
Definition: viewdraw.cxx:498
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
virtual const SwDrawModel * GetDrawModel() const override
Draw Model and id accessors.
virtual void NotifyInvisibleLayers(SdrPageView &_rSdrPageView) override
method to notify drawing page view about the invisible layers
std::unique_ptr< SwDrawModel > mpDrawModel
virtual SdrLayerID GetHeavenId() const override
virtual bool IsVisibleLayerId(SdrLayerID _nLayerId) const override
method to determine, if a layer ID belongs to the visible ones.
virtual bool Search(const SwPaM &rPaM, const SvxSearchItem &rSearchItem) override
Searches text in shapes anchored inside rPaM.
virtual SdrLayerID GetInvisibleHellId() const override
virtual SdrLayerID GetControlsId() const override
virtual SwDrawModel * GetOrCreateDrawModel() override
SdrLayerID mnHeaven
Draw Model Layer IDs LayerIds, Heaven == above document Hell == below document Controls == at the ver...
virtual SwDrawModel * MakeDrawModel_() override
virtual SdrLayerID GetInvisibleLayerIdByVisibleOne(SdrLayerID _nVisibleLayerId) override
method to determine, if the corresponding invisible layer ID for a visible one.
virtual SdrLayerID GetInvisibleHeavenId() const override
virtual SdrLayerID GetInvisibleControlsId() const override
virtual SdrLayerID GetHellId() const override
ring_container GetRingContainer()
Definition: ring.hxx:240
static bool IsFuzzing()
SwDoc & m_rDoc
Definition: docbm.cxx:1201
#define EE_TEXTPOS_MAX_COUNT
#define EE_PARA_MAX_COUNT
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
EmbeddedObjectRef * pObject
std::set< SwPosFlyFrame, SwPosFlyFrameCmp > SwPosFlyFrames
Definition: flypos.hxx:45
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
#define SAL_INFO(area, stream)
Dialog to specify the properties of date form field.
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
Definition: swtypes.cxx:52
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
Definition: swtypes.cxx:57