Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / fusel2.cxx
blobc65a068a16ce480c5609d7e15263c0f65beb7a5f
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/svditer.hxx>
21 #include <svx/svdocapt.hxx>
22 #include <svx/svdpagv.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <editeng/outliner.hxx>
26 #include "fusel.hxx"
27 #include "tabvwsh.hxx"
28 #include "document.hxx"
29 #include "detfunc.hxx"
30 #include "futext.hxx"
31 #include "sc.hrc"
32 #include "attrib.hxx"
33 #include "scitems.hxx"
34 #include "userdat.hxx"
35 #include "drwlayer.hxx"
36 #include "docsh.hxx"
37 #include "drawview.hxx"
38 #include <svx/sdrhittesthelper.hxx>
40 // -----------------------------------------------------------------------
42 inline long Diff( const Point& rP1, const Point& rP2 )
44 long nX = rP1.X() - rP2.X();
45 if (nX<0) nX = -nX;
46 long nY = rP1.Y() - rP2.Y();
47 if (nY<0) nY = -nY;
48 return nX+nY;
51 sal_Bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
53 if (!pPV)
54 return false;
56 sal_Bool bFound = false;
57 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
58 SdrObject* pObject = aIter.Next();
59 while (pObject && !bFound)
61 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
63 sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
64 Size(pView->GetHitTolerancePixel(),0)).Width();
65 if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
67 ScViewData* pViewData = pViewShell->GetViewData();
68 ScSplitPos ePos = pViewShell->FindWindow( pWindow );
69 Point aLineStart = pObject->GetPoint(0);
70 Point aLineEnd = pObject->GetPoint(1);
71 Point aPixel = pWindow->LogicToPixel( aLineStart );
72 SCsCOL nStartCol;
73 SCsROW nStartRow;
74 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
75 aPixel = pWindow->LogicToPixel( aLineEnd );
76 SCsCOL nEndCol;
77 SCsROW nEndRow;
78 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
79 SCsCOL nCurX = (SCsCOL) pViewData->GetCurX();
80 SCsROW nCurY = (SCsROW) pViewData->GetCurY();
81 sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
82 if ( nCurX == nStartCol && nCurY == nStartRow )
83 bStart = false;
84 else if ( nCurX == nEndCol && nCurY == nEndRow )
85 bStart = sal_True;
87 SCsCOL nDifX;
88 SCsROW nDifY;
89 if ( bStart )
91 nDifX = nStartCol - nCurX;
92 nDifY = nStartRow - nCurY;
94 else
96 nDifX = nEndCol - nCurX;
97 nDifY = nEndRow - nCurY;
99 pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
101 bFound = sal_True;
105 pObject = aIter.Next();
107 return bFound;
110 bool FuSelection::IsNoteCaptionMarked() const
112 if( pView )
114 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
115 if( rMarkList.GetMarkCount() == 1 )
117 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
118 return ScDrawLayer::IsNoteCaption( pObj );
121 return false;
124 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
126 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
127 if( pPageView )
129 const ScViewData& rViewData = *pViewShell->GetViewData();
130 ScDocument& rDoc = *rViewData.GetDocument();
131 SCTAB nTab = rViewData.GetTabNo();
132 ScDocShell* pDocSh = rViewData.GetDocShell();
133 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
135 // search the last object (on top) in the object list
136 SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, sal_True );
137 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
139 if( pObj->GetLogicRect().IsInside( rPos ) )
141 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
143 const ScAddress& rNotePos = pCaptData->maStart;
144 // skip caption objects of notes in protected cells
145 const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
146 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
147 if( !bProtectAttr || !bProtectDoc )
148 return true;
153 return false;
156 void FuSelection::ActivateNoteHandles(SdrObject* pObject)
158 if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
160 // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
161 pView->UnlockInternalLayer();
162 pView->MarkObj( pObject, pView->GetSdrPageView() );
166 //==================================================================
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */