LibreOffice Module sc (master)  1
drawvie3.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 #include <svx/svdograf.hxx>
21 #include <svx/svdoole2.hxx>
22 #include <svx/ImageMapInfo.hxx>
23 #include <sfx2/viewfrm.hxx>
24 
25 #include <strings.hrc>
26 #include <scresid.hxx>
27 #include <drawview.hxx>
28 #include <drwlayer.hxx>
29 #include "imapwrap.hxx"
30 #include <viewdata.hxx>
31 #include <document.hxx>
32 #include <userdat.hxx>
33 #include <tabvwsh.hxx>
34 #include <docsh.hxx>
35 
37  OutputDevice* pOut,
38  ScViewData* pData )
39 : FmFormView(*pData->GetDocument()->GetDrawLayer(), pOut),
40  pViewData( pData ),
41  pDev( pOut ),
42  pDoc( pData->GetDocument() ),
43  nTab( pData->GetTabNo() ),
44  pDropMarkObj( nullptr ),
45  bInConstruct( true )
46 {
47  // #i73602# Use default from the configuration
48  SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Calc());
49 
50  // #i74769#, #i75172# Use default from the configuration
51  SetBufferedOutputAllowed(getOptionsDrawinglayer().IsPaintBuffer_Calc());
52 
53  Construct();
54 }
55 
56 // set anchor
57 
59 {
60  if( AreObjectsMarked() )
61  {
62  const SdrMarkList* pMark = &GetMarkedObjectList();
63  const size_t nCount = pMark->GetMarkCount();
64 
65  BegUndo(ScResId(SCSTR_UNDO_PAGE_ANCHOR));
66  for( size_t i=0; i<nCount; ++i )
67  {
68  SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
69  AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
71  }
72  EndUndo();
73 
74  if ( pViewData )
76 
77  // Remove the anchor object.
78  maHdlList.RemoveAllByKind(SdrHdlKind::Anchor);
79  maHdlList.RemoveAllByKind(SdrHdlKind::Anchor_TR);
80  }
81 }
82 
83 void ScDrawView::SetCellAnchored(bool bResizeWithCell)
84 {
85  if (!pDoc)
86  return;
87 
88  if( AreObjectsMarked() )
89  {
90  const SdrMarkList* pMark = &GetMarkedObjectList();
91  const size_t nCount = pMark->GetMarkCount();
92 
93  BegUndo(ScResId(SCSTR_UNDO_CELL_ANCHOR));
94  for( size_t i=0; i<nCount; ++i )
95  {
96  SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
97  AddUndo (std::make_unique<ScUndoAnchorData>( pObj, pDoc, nTab ));
98  ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab, bResizeWithCell);
99  }
100  EndUndo();
101 
102  if ( pViewData )
103  {
105 
106  // Set the anchor object.
107  AddCustomHdl();
108  }
109  }
110 }
111 
113 {
114  bool bPage = false;
115  bool bCell = false;
116  bool bCellResize = false;
117  if( AreObjectsMarked() )
118  {
119  const SdrMarkList* pMark = &GetMarkedObjectList();
120  const size_t nCount = pMark->GetMarkCount();
121  for( size_t i=0; i<nCount; ++i )
122  {
123  const SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
124  const ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType( *pObj );
125  if( aAnchorType == SCA_CELL )
126  bCell =true;
127  else if (aAnchorType == SCA_CELL_RESIZE)
128  bCellResize = true;
129  else
130  bPage = true;
131  }
132  }
133  if( bPage && !bCell && !bCellResize )
134  return SCA_PAGE;
135  if( !bPage && bCell && !bCellResize )
136  return SCA_CELL;
137  if( !bPage && !bCell && bCellResize )
138  return SCA_CELL_RESIZE;
139  return SCA_DONTKNOW;
140 }
141 
142 namespace {
143 
148 void adjustAnchoredPosition(const SdrHint& rHint, const ScDocument& rDoc, SCTAB nTab)
149 {
150  if (rHint.GetKind() != SdrHintKind::ObjectChange && rHint.GetKind() != SdrHintKind::ObjectInserted)
151  return;
152 
153  SdrObject* pObj = const_cast<SdrObject*>(rHint.GetObject());
154  if (!pObj)
155  return;
156 
157  ScDrawObjData *pAnchor = ScDrawLayer::GetObjData(pObj);
158  if (!pAnchor)
159  return;
160 
161  if (pAnchor->meType == ScDrawObjData::CellNote)
162  return;
163 
164  if (pAnchor->getShapeRect() == pObj->GetSnapRect())
165  return;
166 
167  if (pAnchor->maStart.Tab() != nTab)
168  // The object is not anchored on the current sheet. Skip it.
169  // TODO: In the future, we may want to adjust objects that are
170  // anchored on all selected sheets.
171  return;
172 
173  ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, pAnchor->maStart.Tab(), pAnchor->mbResizeWithCell);
174 }
175 
176 }
177 
178 void ScDrawView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
179 {
180  if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
181  {
182  const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
183  adjustAnchoredPosition(*pSdrHint, *pDoc, nTab);
184  FmFormView::Notify( rBC,rHint );
185  }
186  else if (dynamic_cast<const ScTabDeletedHint*>(&rHint)) // Sheet has been deleted
187  {
188  SCTAB nDelTab = static_cast<const ScTabDeletedHint&>(rHint).GetTab();
189  if (ValidTab(nDelTab))
190  {
191  // used to be: HidePagePgNum(nDelTab) - hide only if the deleted sheet is shown here
192  if ( nDelTab == nTab )
193  HideSdrPage();
194  }
195  }
196  else if (dynamic_cast<const ScTabSizeChangedHint*>(&rHint)) // Size has been changed
197  {
198  if ( nTab == static_cast<const ScTabSizeChangedHint&>(rHint).GetTab() )
199  UpdateWorkArea();
200  }
201  else
202  FmFormView::Notify( rBC,rHint );
203 }
204 
206 {
207  if ( pViewData &&
209  pObj && ( dynamic_cast<const SdrGrafObj*>( pObj) != nullptr || dynamic_cast<const SdrOle2Obj*>( pObj) != nullptr ) )
210  {
211  Graphic aGraphic;
212  TargetList aTargetList;
213  SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo( pObj );
214  const ImageMap* pImageMap = nullptr;
215  if ( pIMapInfo )
216  pImageMap = &pIMapInfo->GetImageMap();
217 
218  // handle target list
219  SfxViewFrame::GetTargetList( aTargetList );
220 
221  // handle graphics from object
222  if ( dynamic_cast<const SdrGrafObj*>( pObj) != nullptr )
223  aGraphic = static_cast<SdrGrafObj*>(pObj)->GetGraphic();
224  else
225  {
226  const Graphic* pGraphic = static_cast<const SdrOle2Obj*>(pObj)->GetGraphic();
227  if ( pGraphic )
228  aGraphic = *pGraphic;
229  }
230 
231  ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj ); // from imapwrap
232  }
233 }
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
SdrHintKind GetKind() const
size_t GetMarkCount() const
void UpdateIMap(SdrObject *pObj)
Definition: drawvie3.cxx:205
static void SetPageAnchored(SdrObject &)
Definition: drwlayer.cxx:2144
bool AreObjectsMarked() const
static void GetTargetList(TargetList &rList)
static ScDrawObjData * GetObjData(SdrObject *pObj, bool bCreate=false)
Definition: drwlayer.cxx:2282
void BegUndo()
SdrMark * GetMark(size_t nNum) const
virtual void AddCustomHdl() override
Definition: drawview.cxx:136
ScViewData * pViewData
Definition: drawview.hxx:36
ScAddress maStart
Definition: userdat.hxx:38
SfxHintId GetId() const
virtual const tools::Rectangle & GetSnapRect() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: drawvie3.cxx:178
void SetBufferedOutputAllowed(bool bNew)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
int nCount
SCTAB Tab() const
Definition: address.hxx:271
void EndUndo()
void UpdateWorkArea()
Definition: drawview.cxx:261
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
SdrObject * GetMarkedSdrObj() const
bool mbResizeWithCell
Definition: userdat.hxx:43
const tools::Rectangle & getShapeRect() const
Definition: userdat.hxx:48
ScAnchorType
Definition: global.hxx:382
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
void Construct()
Definition: drawview.cxx:69
void SetBufferedOverlayAllowed(bool bNew)
int i
void SetCellAnchored(bool bResizeWithCell)
Definition: drawvie3.cxx:83
static ScAnchorType GetAnchorType(const SdrObject &)
Definition: drwlayer.cxx:2150
static void SetCellAnchoredFromPosition(SdrObject &rObj, const ScDocument &rDoc, SCTAB nTab, bool bResizeWithCell)
Definition: drwlayer.cxx:2040
const SdrMarkList & GetMarkedObjectList() const
void RemoveAllByKind(SdrHdlKind eKind)
void ScIMapDlgSet(const Graphic &rGraphic, const ImageMap *pImageMap, const TargetList *pTargetList, void *pEditingObj)
Definition: imapwrap.cxx:29
ScDrawView(OutputDevice *pOut, ScViewData *pData)
Definition: drawvie3.cxx:36
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
SCTAB GetTab() const
Definition: drawview.hxx:101
void SetPageAnchored()
Definition: drawvie3.cxx:58
ScDocument * pDoc
needed ?
Definition: drawview.hxx:38
const SvtOptionsDrawinglayer & getOptionsDrawinglayer() const
bool HasChildWindow(sal_uInt16)
ScAnchorType GetAnchorType() const
Definition: drawvie3.cxx:112
const ImageMap & GetImageMap() const
virtual void HideSdrPage() override
SdrHdlList maHdlList
void SetDrawModified()
SetDrawModified - without Formula update.
Definition: docsh.cxx:2883
::std::vector< OUString > TargetList
bool ValidTab(SCTAB nTab)
Definition: address.hxx:105
sal_Int16 SCTAB
Definition: types.hxx:23
SCTAB nTab
Definition: drawview.hxx:39
static SvxIMapInfo * GetIMapInfo(const SdrObject *pObject)
const SdrObject * GetObject() const
sal_uInt16 ScIMapChildWindowId()
Definition: imapwrap.cxx:24