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 <ndtxt.hxx>
32 #include <svl/hint.hxx>
33 #include <svx/svdundo.hxx>
34 #include <viewsh.hxx>
35 #include <view.hxx>
36 #include <drawdoc.hxx>
37 #include <rootfrm.hxx>
38 #include <fmtanchr.hxx>
39 #include <editeng/eeitem.hxx>
40 #include <editeng/fhgtitem.hxx>
41 #include <svx/svdmodel.hxx>
42 #include <svx/svdlayer.hxx>
43 #include <svx/svdoutl.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdpagv.hxx>
46 #include <svx/svdotext.hxx>
47 #include <svx/svdview.hxx>
48 #include <svl/srchitem.hxx>
49 #include <tools/link.hxx>
50 #include <unotools/configmgr.hxx>
51 #include <sal/log.hxx>
52 
53 class SdrOutliner;
54 
55 namespace sw
56 {
57 
59  : m_rDoc(i_rSwdoc)
60  , mnHeaven(0)
61  , mnHell(0)
62  , mnControls(0)
63  , mnInvisibleHeaven(0)
64  , mnInvisibleHell(0)
65  , mnInvisibleControls(0)
66 {
67 }
68 
69 // Is also called by the Sw3 Reader, if there was an error when reading the
70 // drawing layer. If it is called by the Sw3 Reader the layer is rebuilt
71 // from scratch.
73 {
74  // !! Attention: there is similar code in the Sw3 Reader (sw3imp.cxx) that
75  // also has to be maintained!!
76  if ( mpDrawModel )
78 
79  // set FontHeight pool defaults without changing static SdrEngineDefaults
81 
82  SAL_INFO( "sw.doc", "before create DrawDocument" );
83  // The document owns the SwDrawModel. We always have two layers and one page.
84  mpDrawModel.reset( new SwDrawModel( &m_rDoc ) );
85 
87 
88  OUString sLayerNm;
89  sLayerNm = "Hell";
90  mnHell = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
91 
92  sLayerNm = "Heaven";
93  mnHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
94 
95  sLayerNm = "Controls";
96  mnControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
97  mpDrawModel->GetLayerAdmin().SetControlLayerName(sLayerNm);
98 
99  // add invisible layers corresponding to the visible ones.
100  {
101  sLayerNm = "InvisibleHell";
102  mnInvisibleHell = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
103 
104  sLayerNm = "InvisibleHeaven";
105  mnInvisibleHeaven = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
106 
107  sLayerNm = "InvisibleControls";
108  mnInvisibleControls = mpDrawModel->GetLayerAdmin().NewLayer( sLayerNm )->GetID();
109  }
110 
111  SdrPage* pMasterPage = mpDrawModel->AllocPage( false );
112  mpDrawModel->InsertPage( pMasterPage );
113  SAL_INFO( "sw.doc", "after create DrawDocument" );
114  SdrOutliner& rOutliner = mpDrawModel->GetDrawOutliner();
116  {
117  SAL_INFO( "sw.doc", "before create Spellchecker/Hyphenator" );
118  css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpell = ::GetSpellChecker();
119  rOutliner.SetSpeller( xSpell );
120  css::uno::Reference< css::linguistic2::XHyphenator > xHyphenator( ::GetHyphenator() );
121  rOutliner.SetHyphenator( xHyphenator );
122  SAL_INFO( "sw.doc", "after create Spellchecker/Hyphenator" );
123  }
124  m_rDoc.SetCalcFieldValueHdl(&rOutliner);
125  m_rDoc.SetCalcFieldValueHdl(&mpDrawModel->GetHitTestOutliner());
126 
127  // Set the LinkManager in the model so that linked graphics can be inserted.
128  // The WinWord import needs it too.
131 
133  if ( pRefDev )
134  mpDrawModel->SetRefDevice( pRefDev );
135 
136  mpDrawModel->SetNotifyUndoActionHdl( std::bind( &SwDoc::AddDrawUndo, &m_rDoc, std::placeholders::_1 ));
138  if ( pSh )
139  {
140  for(const SwViewShell& rViewSh : pSh->GetRingContainer())
141  {
142  SwRootFrame* pRoot = rViewSh.GetLayout();
143  if( pRoot && !pRoot->GetDrawPage() )
144  {
145  // Disable "multiple layout" for the moment:
146  // use pMasterPage instead of a new created SdrPage
147  // mpDrawModel->AllocPage( FALSE );
148  // mpDrawModel->InsertPage( pDrawPage );
149  SdrPage* pDrawPage = pMasterPage;
150  pRoot->SetDrawPage( pDrawPage );
151  pDrawPage->SetSize( pRoot->getFrameArea().SSize() );
152  }
153  }
154  }
155 }
156 
157 
159 {
160  // !! Also maintain the code in the sw3io for inserting documents!!
161  mpDrawModel.reset();
162 }
163 
164 
166 {
167  return mpDrawModel.get();
168 }
169 
171 {
172  return mpDrawModel.get();
173 }
174 
176 {
177  OSL_ENSURE( !mpDrawModel, "MakeDrawModel_: Why?" );
178  InitDrawModel();
180  if ( pSh )
181  {
182  for(SwViewShell& rViewSh : pSh->GetRingContainer())
183  rViewSh.MakeDrawView();
184 
185  // Broadcast, so that the FormShell can be connected to the DrawView
186  if( m_rDoc.GetDocShell() )
187  {
188  SfxHint aHint( SfxHintId::SwDrawViewsCreated );
189  m_rDoc.GetDocShell()->Broadcast( aHint );
190  }
191  }
192  return mpDrawModel.get();
193 }
194 
196 {
197  return GetDrawModel() ? GetDrawModel() : MakeDrawModel_();
198 }
199 
201 {
202  return mnHeaven;
203 }
204 
206 {
207  return mnHell;
208 }
209 
211 {
212  return mnControls;
213 }
214 
216 {
217  return mnInvisibleHeaven;
218 }
219 
221 {
222  return mnInvisibleHell;
223 }
224 
226 {
227  return mnInvisibleControls;
228 }
229 
231 {
232  OUString sLayerNm;
233  sLayerNm = "InvisibleHell";
234  _rSdrPageView.SetLayerVisible( sLayerNm, false );
235 
236  sLayerNm = "InvisibleHeaven";
237  _rSdrPageView.SetLayerVisible( sLayerNm, false );
238 
239  sLayerNm = "InvisibleControls";
240  _rSdrPageView.SetLayerVisible( sLayerNm, false );
241 }
242 
244 {
245  bool bRetVal;
246 
247  if ( _nLayerId == GetHeavenId() ||
248  _nLayerId == GetHellId() ||
249  _nLayerId == GetControlsId() )
250  {
251  bRetVal = true;
252  }
253  else if ( _nLayerId == GetInvisibleHeavenId() ||
254  _nLayerId == GetInvisibleHellId() ||
255  _nLayerId == GetInvisibleControlsId() )
256  {
257  bRetVal = false;
258  }
259  else
260  {
261  OSL_FAIL( "<SwDoc::IsVisibleLayerId(..)> - unknown layer ID." );
262  bRetVal = false;
263  }
264 
265  return bRetVal;
266 }
267 
269 {
270  SdrLayerID nInvisibleLayerId;
271 
272  if ( _nVisibleLayerId == GetHeavenId() )
273  {
274  nInvisibleLayerId = GetInvisibleHeavenId();
275  }
276  else if ( _nVisibleLayerId == GetHellId() )
277  {
278  nInvisibleLayerId = GetInvisibleHellId();
279  }
280  else if ( _nVisibleLayerId == GetControlsId() )
281  {
282  nInvisibleLayerId = GetInvisibleControlsId();
283  }
284  else if ( _nVisibleLayerId == GetInvisibleHeavenId() ||
285  _nVisibleLayerId == GetInvisibleHellId() ||
286  _nVisibleLayerId == GetInvisibleControlsId() )
287  {
288  OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID already an invisible one." );
289  nInvisibleLayerId = _nVisibleLayerId;
290  }
291  else
292  {
293  OSL_FAIL( "<SwDoc::GetInvisibleLayerIdByVisibleOne(..)> - given layer ID is unknown." );
294  nInvisibleLayerId = _nVisibleLayerId;
295  }
296 
297  return nInvisibleLayerId;
298 }
299 
300 bool DocumentDrawModelManager::Search(const SwPaM& rPaM, const SvxSearchItem& rSearchItem)
301 {
302  SwPosFlyFrames aFrames = m_rDoc.GetAllFlyFormats(&rPaM, /*bDrawAlso=*/true);
303 
304  for (const SwPosFlyFramePtr& pPosFlyFrame : aFrames)
305  {
306  // Filter for at-paragraph anchored draw frames.
307  const SwFrameFormat& rFrameFormat = pPosFlyFrame->GetFormat();
308  const SwFormatAnchor& rAnchor = rFrameFormat.GetAnchor();
309  if (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA || rFrameFormat.Which() != RES_DRAWFRMFMT)
310  continue;
311 
312  // Does the shape have matching text?
313  SdrOutliner& rOutliner = GetDrawModel()->GetDrawOutliner();
314  SdrObject* pObject = const_cast<SdrObject*>(rFrameFormat.FindSdrObject());
315  SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>(pObject);
316  if (!pTextObj)
317  continue;
318  const OutlinerParaObject* pParaObj = pTextObj->GetOutlinerParaObject();
319  if (!pParaObj)
320  continue;
321  rOutliner.SetText(*pParaObj);
322  SwDocShell* pDocShell = m_rDoc.GetDocShell();
323  if (!pDocShell)
324  return false;
325  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
326  if (!pWrtShell)
327  return false;
328  if (!rOutliner.HasText(rSearchItem))
329  continue;
330 
331  // If so, then select highlight the search result.
332  pWrtShell->SelectObj(Point(), 0, pObject);
333  SwView* pView = pDocShell->GetView();
334  if (!pView)
335  return false;
336  if (!pView->EnterShapeDrawTextMode(pObject))
337  continue;
338  SdrView* pSdrView = pWrtShell->GetDrawView();
339  if (!pSdrView)
340  return false;
341  OutlinerView* pOutlinerView = pSdrView->GetTextEditOutlinerView();
342  if (!rSearchItem.GetBackward())
343  pOutlinerView->SetSelection(ESelection(0, 0, 0, 0));
344  else
346  pOutlinerView->StartSearchAndReplace(rSearchItem);
347  return true;
348  }
349 
350  return false;
351 }
352 
354 {
355  mpDrawModel->SetNotifyUndoActionHdl( nullptr );
356 }
357 
358 }
359 
360 /* 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:376
SwDocShell * GetDocShell()
Definition: doc.hxx:1341
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:270
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:292
void SetCalcFieldValueHdl(Outliner *pOutliner)
In the Outliner, set a link to the method for field display in edit objects.
Definition: docdraw.cxx:491
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.
Definition: accfrmobj.cxx:38
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
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:516
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
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:437
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:366
virtual SwDrawModel * MakeDrawModel_() override
#define RES_DRAWFRMFMT
Definition: hintids.hxx:277
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:208
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:185
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:1308
virtual SdrLayerID GetInvisibleControlsId() const override
void SetPoolDefaultItem(const SfxPoolItem &)
void SetLayerVisible(const OUString &rName, bool bShow)