fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / drawvie3.cxx
blob74ad8e683f192defba98d64b4501e601e768a247
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svdograf.hxx>
21 #include <svx/svdoole2.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/viewfrm.hxx>
25 #include "sc.hrc"
26 #include "scresid.hxx"
27 #include "drawview.hxx"
28 #include "drwlayer.hxx"
29 #include "imapwrap.hxx"
30 #include "viewdata.hxx"
31 #include "dbfunc.hxx"
32 #include "document.hxx"
33 #include "userdat.hxx"
34 #include "tabvwsh.hxx"
35 #include "docsh.hxx"
37 ScDrawView::ScDrawView( OutputDevice* pOut, ScViewData* pData ) :
38 FmFormView( pData->GetDocument()->GetDrawLayer(), pOut ),
39 pViewData( pData ),
40 pDev( pOut ),
41 pDoc( pData->GetDocument() ),
42 nTab( pData->GetTabNo() ),
43 pDropMarker( NULL ),
44 pDropMarkObj( NULL ),
45 bInConstruct( true )
47 // #i73602# Use default from the configuration
48 SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Calc());
50 // #i74769#, #i75172# Use default from the configuration
51 SetBufferedOutputAllowed(getOptionsDrawinglayer().IsPaintBuffer_Calc());
53 Construct();
56 // Verankerung setzen
58 void ScDrawView::SetPageAnchored()
60 if( AreObjectsMarked() )
62 const SdrMarkList* pMark = &GetMarkedObjectList();
63 const size_t nCount = pMark->GetMarkCount();
65 BegUndo( OUString(ScResId( SCSTR_UNDO_PAGE_ANCHOR )) );
66 for( size_t i=0; i<nCount; ++i )
68 SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
69 AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab ));
70 ScDrawLayer::SetPageAnchored( *pObj );
72 EndUndo();
74 if ( pViewData )
75 pViewData->GetDocShell()->SetDrawModified();
77 // Remove the anchor object.
78 maHdlList.RemoveAllByKind(HDL_ANCHOR);
79 maHdlList.RemoveAllByKind(HDL_ANCHOR_TR);
83 void ScDrawView::SetCellAnchored()
85 if (!pDoc)
86 return;
88 if( AreObjectsMarked() )
90 const SdrMarkList* pMark = &GetMarkedObjectList();
91 const size_t nCount = pMark->GetMarkCount();
93 BegUndo( OUString(ScResId( SCSTR_UNDO_CELL_ANCHOR )) );
94 for( size_t i=0; i<nCount; ++i )
96 SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
97 AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab ));
98 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab);
100 EndUndo();
102 if ( pViewData )
103 pViewData->GetDocShell()->SetDrawModified();
105 // Set the anchor object.
106 AddCustomHdl();
110 ScAnchorType ScDrawView::GetAnchorType() const
112 bool bPage = false;
113 bool bCell = false;
114 if( AreObjectsMarked() )
116 const SdrMarkList* pMark = &GetMarkedObjectList();
117 const size_t nCount = pMark->GetMarkCount();
118 for( size_t i=0; i<nCount; ++i )
120 const SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj();
121 if( ScDrawLayer::GetAnchorType( *pObj ) == SCA_CELL )
122 bCell =true;
123 else
124 bPage = true;
127 if( bPage && !bCell )
128 return SCA_PAGE;
129 if( !bPage && bCell )
130 return SCA_CELL;
131 return SCA_DONTKNOW;
134 namespace {
137 * Updated the anchors of any non-note object that is cell anchored which
138 * has been moved since the last anchors for its position was calculated.
140 void adjustAnchoredPosition(const SdrHint& rHint, const ScDocument& rDoc, SCTAB nTab)
142 if (rHint.GetKind() != HINT_OBJCHG && rHint.GetKind() != HINT_OBJINSERTED)
143 return;
145 SdrObject* pObj = const_cast<SdrObject*>(rHint.GetObject());
146 if (!pObj)
147 return;
149 ScDrawObjData *pAnchor = ScDrawLayer::GetObjData(pObj);
150 if (!pAnchor)
151 return;
153 if (pAnchor->meType == ScDrawObjData::CellNote)
154 return;
156 if (pAnchor->maLastRect == pObj->GetSnapRect())
157 return;
159 if (pAnchor->maStart.Tab() != nTab)
160 // The object is not anchored on the current sheet. Skip it.
161 // TODO: In the future, we may want to adjust objects that are
162 // anchored on all selected sheets.
163 return;
165 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, pAnchor->maStart.Tab());
170 void ScDrawView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
172 if (dynamic_cast<const ScTabDeletedHint*>(&rHint)) // Tabelle geloescht
174 SCTAB nDelTab = static_cast<const ScTabDeletedHint&>(rHint).GetTab();
175 if (ValidTab(nDelTab))
177 // used to be: HidePagePgNum(nDelTab) - hide only if the deleted sheet is shown here
178 if ( nDelTab == nTab )
179 HideSdrPage();
182 else if (dynamic_cast<const ScTabSizeChangedHint*>(&rHint)) // Groesse geaendert
184 if ( nTab == static_cast<const ScTabSizeChangedHint&>(rHint).GetTab() )
185 UpdateWorkArea();
187 else if ( const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>( &rHint ) )
189 adjustAnchoredPosition(*pSdrHint, *pDoc, nTab);
190 FmFormView::Notify( rBC,rHint );
192 else
193 FmFormView::Notify( rBC,rHint );
196 void ScDrawView::UpdateIMap( SdrObject* pObj )
198 if ( pViewData &&
199 pViewData->GetViewShell()->GetViewFrame()->HasChildWindow( ScIMapChildWindowId() ) &&
200 pObj && ( pObj->ISA(SdrGrafObj) || pObj->ISA(SdrOle2Obj) ) )
202 Graphic aGraphic;
203 TargetList aTargetList;
204 ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo( pObj );
205 const ImageMap* pImageMap = NULL;
206 if ( pIMapInfo )
207 pImageMap = &pIMapInfo->GetImageMap();
209 // Target-Liste besorgen
210 pViewData->GetViewShell()->GetViewFrame()->GetTargetList( aTargetList );
212 // Grafik vom Objekt besorgen
213 if ( pObj->ISA( SdrGrafObj ) )
214 aGraphic = static_cast<SdrGrafObj*>(pObj)->GetGraphic();
215 else
217 const Graphic* pGraphic = static_cast<const SdrOle2Obj*>(pObj)->GetGraphic();
218 if ( pGraphic )
219 aGraphic = *pGraphic;
222 ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj ); // aus imapwrap
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */