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