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  rDoc( 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  return;
62 
63  const SdrMarkList* pMark = &GetMarkedObjectList();
64  const size_t nCount = pMark->GetMarkCount();
65 
66  BegUndo(ScResId(SCSTR_UNDO_PAGE_ANCHOR));
67  for( size_t i=0; i<nCount; ++i )
68  {
69  SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
70  AddUndo (std::make_unique<ScUndoAnchorData>( pObj, &rDoc, nTab ));
72  }
73  EndUndo();
74 
75  if ( pViewData )
77 
78  // Remove the anchor object.
79  maHdlList.RemoveAllByKind(SdrHdlKind::Anchor);
80  maHdlList.RemoveAllByKind(SdrHdlKind::Anchor_TR);
81 }
82 
83 void ScDrawView::SetCellAnchored(bool bResizeWithCell)
84 {
85  if( !AreObjectsMarked() )
86  return;
87 
88  const SdrMarkList* pMark = &GetMarkedObjectList();
89  const size_t nCount = pMark->GetMarkCount();
90 
91  BegUndo(ScResId(SCSTR_UNDO_CELL_ANCHOR));
92  for( size_t i=0; i<nCount; ++i )
93  {
94  SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
95  AddUndo (std::make_unique<ScUndoAnchorData>( pObj, &rDoc, nTab ));
96  ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, nTab, bResizeWithCell);
97  }
98  EndUndo();
99 
100  if ( pViewData )
101  {
103 
104  // Set the anchor object.
105  AddCustomHdl();
106  }
107 }
108 
110 {
111  bool bPage = false;
112  bool bCell = false;
113  bool bCellResize = false;
114  if( AreObjectsMarked() )
115  {
116  const SdrMarkList* pMark = &GetMarkedObjectList();
117  const size_t nCount = pMark->GetMarkCount();
118  for( size_t i=0; i<nCount; ++i )
119  {
120  const SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
121  const ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType( *pObj );
122  if( aAnchorType == SCA_CELL )
123  bCell =true;
124  else if (aAnchorType == SCA_CELL_RESIZE)
125  bCellResize = true;
126  else
127  bPage = true;
128  }
129  }
130  if( bPage && !bCell && !bCellResize )
131  return SCA_PAGE;
132  if( !bPage && bCell && !bCellResize )
133  return SCA_CELL;
134  if( !bPage && !bCell && bCellResize )
135  return SCA_CELL_RESIZE;
136  return SCA_DONTKNOW;
137 }
138 
139 namespace {
140 
145 void adjustAnchoredPosition(const SdrHint& rHint, const ScDocument& rDoc, SCTAB nTab)
146 {
147  if (rHint.GetKind() != SdrHintKind::ObjectChange && rHint.GetKind() != SdrHintKind::ObjectInserted)
148  return;
149 
150  SdrObject* pObj = const_cast<SdrObject*>(rHint.GetObject());
151  if (!pObj)
152  return;
153 
154  ScDrawObjData *pAnchor = ScDrawLayer::GetObjData(pObj);
155  if (!pAnchor)
156  return;
157 
158  if (pAnchor->meType == ScDrawObjData::CellNote)
159  return;
160 
161  if (pAnchor->getShapeRect() == pObj->GetSnapRect())
162  return;
163 
164  if (pAnchor->maStart.Tab() != nTab)
165  // The object is not anchored on the current sheet. Skip it.
166  // TODO: In the future, we may want to adjust objects that are
167  // anchored on all selected sheets.
168  return;
169 
170  ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, pAnchor->maStart.Tab(), pAnchor->mbResizeWithCell);
171 }
172 
173 }
174 
175 void ScDrawView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
176 {
177  if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
178  {
179  const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
180  adjustAnchoredPosition(*pSdrHint, rDoc, nTab);
181  FmFormView::Notify( rBC,rHint );
182  }
183  else if (auto pDeletedHint = dynamic_cast<const ScTabDeletedHint*>(&rHint)) // Sheet has been deleted
184  {
185  SCTAB nDelTab = pDeletedHint->GetTab();
186  if (ValidTab(nDelTab))
187  {
188  // used to be: HidePagePgNum(nDelTab) - hide only if the deleted sheet is shown here
189  if ( nDelTab == nTab )
190  HideSdrPage();
191  }
192  }
193  else if (auto pChangedHint = dynamic_cast<const ScTabSizeChangedHint*>(&rHint)) // Size has been changed
194  {
195  if ( nTab == pChangedHint->GetTab() )
196  UpdateWorkArea();
197  }
198  else
199  FmFormView::Notify( rBC,rHint );
200 }
201 
203 {
204  if ( !(pViewData &&
206  pObj && ( dynamic_cast<const SdrGrafObj*>( pObj) != nullptr || dynamic_cast<const SdrOle2Obj*>( pObj) != nullptr )) )
207  return;
208 
209  Graphic aGraphic;
210  TargetList aTargetList;
211  SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo( pObj );
212  const ImageMap* pImageMap = nullptr;
213  if ( pIMapInfo )
214  pImageMap = &pIMapInfo->GetImageMap();
215 
216  // handle target list
217  SfxViewFrame::GetTargetList( aTargetList );
218 
219  // handle graphics from object
220  if ( auto pGrafObj = dynamic_cast<SdrGrafObj*>( pObj) )
221  aGraphic = pGrafObj->GetGraphic();
222  else
223  {
224  const Graphic* pGraphic = static_cast<const SdrOle2Obj*>(pObj)->GetGraphic();
225  if ( pGraphic )
226  aGraphic = *pGraphic;
227  }
228 
229  ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj ); // from imapwrap
230 }
231 
232 /* 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:202
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:175
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
void SetPageAnchored()
Definition: drawvie3.cxx:58
const SvtOptionsDrawinglayer & getOptionsDrawinglayer() const
bool HasChildWindow(sal_uInt16)
ScAnchorType GetAnchorType() const
Definition: drawvie3.cxx:109
ScDocument & rDoc
needed ?
Definition: drawview.hxx:38
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