Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / drawvie3.cxx
blobb05c82864a609a9164de939b94ac8c6b1faeb5d9
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 "drawview.hxx"
26 #include "drwlayer.hxx"
27 #include "viewdata.hxx"
28 #include "dbfunc.hxx"
29 #include "document.hxx"
30 #include "userdat.hxx"
31 #include "tabvwsh.hxx"
32 #include "docsh.hxx"
34 void ScIMapDlgSet( const Graphic& rGraphic, const ImageMap* pImageMap,
35 const TargetList* pTargetList, void* pEditingObj ); // imapwrap
36 sal_uInt16 ScIMapChildWindowId();
38 // STATIC DATA -----------------------------------------------------------
40 ScDrawView::ScDrawView( OutputDevice* pOut, ScViewData* pData ) :
41 FmFormView( pData->GetDocument()->GetDrawLayer(), pOut ),
42 pViewData( pData ),
43 pDev( pOut ),
44 pDoc( pData->GetDocument() ),
45 nTab( pData->GetTabNo() ),
46 pDropMarker( NULL ),
47 pDropMarkObj( NULL ),
48 bInConstruct( true )
50 // #i73602# Use default from the configuration
51 SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Calc());
53 // #i74769#, #i75172# Use default from the configuration
54 SetBufferedOutputAllowed(getOptionsDrawinglayer().IsPaintBuffer_Calc());
56 Construct();
59 // Verankerung setzen
61 void ScDrawView::SetPageAnchored()
63 SdrObject* pObj = NULL;
64 if( AreObjectsMarked() )
66 const SdrMarkList* pMark = &GetMarkedObjectList();
67 sal_uLong nCount = pMark->GetMarkCount();
68 for( sal_uLong i=0; i<nCount; i++ )
70 pObj = pMark->GetMark(i)->GetMarkedSdrObj();
71 ScDrawLayer::SetPageAnchored( *pObj );
74 if ( pViewData )
75 pViewData->GetDocShell()->SetDrawModified();
77 // Remove the anchor object.
78 aHdl.RemoveAllByKind(HDL_ANCHOR);
79 aHdl.RemoveAllByKind(HDL_ANCHOR_TR);
83 void ScDrawView::SetCellAnchored()
85 if (!pDoc)
86 return;
88 SdrObject* pObj = NULL;
89 if( AreObjectsMarked() )
91 const SdrMarkList* pMark = &GetMarkedObjectList();
92 sal_uLong nCount = pMark->GetMarkCount();
93 for( sal_uLong i=0; i<nCount; i++ )
95 pObj = pMark->GetMark(i)->GetMarkedSdrObj();
96 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab);
99 if ( pViewData )
100 pViewData->GetDocShell()->SetDrawModified();
102 // Set the anchor object.
103 AddCustomHdl();
107 ScAnchorType ScDrawView::GetAnchorType() const
109 sal_Bool bPage = false;
110 sal_Bool bCell = false;
111 const SdrObject* pObj = NULL;
112 if( AreObjectsMarked() )
114 const SdrMarkList* pMark = &GetMarkedObjectList();
115 sal_uLong nCount = pMark->GetMarkCount();
116 Point p0;
117 for( sal_uLong i=0; i<nCount; i++ )
119 pObj = pMark->GetMark(i)->GetMarkedSdrObj();
120 if( ScDrawLayer::GetAnchorType( *pObj ) == SCA_CELL )
121 bCell =true;
122 else
123 bPage = sal_True;
126 if( bPage && !bCell )
127 return SCA_PAGE;
128 if( !bPage && bCell )
129 return SCA_CELL;
130 return SCA_DONTKNOW;
133 namespace {
136 * Updated the anchors of any non-note object that is cell anchored which
137 * has been moved since the last anchors for its position was calculated.
139 void adjustAnchoredPosition(const SdrHint& rHint, const ScDocument& rDoc, SCTAB nTab)
141 if (rHint.GetKind() != HINT_OBJCHG && rHint.GetKind() != HINT_OBJINSERTED)
142 return;
144 SdrObject* pObj = const_cast<SdrObject*>(rHint.GetObject());
145 if (!pObj)
146 return;
148 ScDrawObjData *pAnchor = ScDrawLayer::GetObjData(pObj);
149 if (!pAnchor)
150 return;
152 if (pAnchor->meType == ScDrawObjData::CellNote)
153 return;
155 if (pAnchor->maLastRect == pObj->GetLogicRect())
156 return;
158 if (pAnchor->maStart.Tab() != nTab)
159 // The object is not anchored on the current sheet. Skip it.
160 // TODO: In the future, we may want to adjust objects that are
161 // anchored on all selected sheets.
162 return;
164 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, pAnchor->maStart.Tab());
169 void ScDrawView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
171 if (rHint.ISA(ScTabDeletedHint)) // Tabelle geloescht
173 SCTAB nDelTab = ((ScTabDeletedHint&)rHint).GetTab();
174 if (ValidTab(nDelTab))
176 // used to be: HidePagePgNum(nDelTab) - hide only if the deleted sheet is shown here
177 if ( nDelTab == nTab )
178 HideSdrPage();
181 else if (rHint.ISA(ScTabSizeChangedHint)) // Groesse geaendert
183 if ( nTab == ((ScTabSizeChangedHint&)rHint).GetTab() )
184 UpdateWorkArea();
186 else if ( rHint.ISA( SdrHint ) )
188 if (const SdrHint* pSdrHint = PTR_CAST( 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 = ( (SdrGrafObj*) pObj )->GetGraphic();
215 else
217 Graphic* pGraphic = ((const SdrOle2Obj*) pObj )->GetGraphic();
218 if ( pGraphic )
219 aGraphic = *pGraphic;
222 ScIMapDlgSet( aGraphic, pImageMap, &aTargetList, pObj ); // aus imapwrap
224 // TargetListe kann von uns wieder geloescht werden
225 for ( size_t i = 0, n = aTargetList.size(); i < n; ++i )
226 delete aTargetList[ i ];
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */