1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir // INCLUDE --------------------------------------------------------------- 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <svx/svditer.hxx> 36*cdf0e10cSrcweir #include <svx/svdocapt.hxx> 37*cdf0e10cSrcweir #include <svx/svdpagv.hxx> 38*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 39*cdf0e10cSrcweir #include <editeng/outliner.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "fusel.hxx" 42*cdf0e10cSrcweir #include "tabvwsh.hxx" 43*cdf0e10cSrcweir #include "document.hxx" 44*cdf0e10cSrcweir #include "detfunc.hxx" 45*cdf0e10cSrcweir #include "futext.hxx" 46*cdf0e10cSrcweir #include "sc.hrc" 47*cdf0e10cSrcweir #include "attrib.hxx" 48*cdf0e10cSrcweir #include "scitems.hxx" 49*cdf0e10cSrcweir #include "userdat.hxx" 50*cdf0e10cSrcweir #include "drwlayer.hxx" 51*cdf0e10cSrcweir #include "docsh.hxx" 52*cdf0e10cSrcweir #include "drawview.hxx" 53*cdf0e10cSrcweir #include <svx/sdrhittesthelper.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // ----------------------------------------------------------------------- 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir inline long Diff( const Point& rP1, const Point& rP2 ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir long nX = rP1.X() - rP2.X(); 60*cdf0e10cSrcweir if (nX<0) nX = -nX; 61*cdf0e10cSrcweir long nY = rP1.Y() - rP2.Y(); 62*cdf0e10cSrcweir if (nY<0) nY = -nY; 63*cdf0e10cSrcweir return nX+nY; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir sal_Bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir if (!pPV) 69*cdf0e10cSrcweir return sal_False; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir sal_Bool bFound = sal_False; 72*cdf0e10cSrcweir SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT ); 73*cdf0e10cSrcweir SdrObject* pObject = aIter.Next(); 74*cdf0e10cSrcweir while (pObject && !bFound) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if (ScDetectiveFunc::IsNonAlienArrow( pObject )) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic( 79*cdf0e10cSrcweir Size(pView->GetHitTolerancePixel(),0)).Width(); 80*cdf0e10cSrcweir if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false)) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir ScViewData* pViewData = pViewShell->GetViewData(); 83*cdf0e10cSrcweir ScSplitPos ePos = pViewShell->FindWindow( pWindow ); 84*cdf0e10cSrcweir Point aLineStart = pObject->GetPoint(0); 85*cdf0e10cSrcweir Point aLineEnd = pObject->GetPoint(1); 86*cdf0e10cSrcweir Point aPixel = pWindow->LogicToPixel( aLineStart ); 87*cdf0e10cSrcweir SCsCOL nStartCol; 88*cdf0e10cSrcweir SCsROW nStartRow; 89*cdf0e10cSrcweir pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow ); 90*cdf0e10cSrcweir aPixel = pWindow->LogicToPixel( aLineEnd ); 91*cdf0e10cSrcweir SCsCOL nEndCol; 92*cdf0e10cSrcweir SCsROW nEndRow; 93*cdf0e10cSrcweir pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow ); 94*cdf0e10cSrcweir SCsCOL nCurX = (SCsCOL) pViewData->GetCurX(); 95*cdf0e10cSrcweir SCsROW nCurY = (SCsROW) pViewData->GetCurY(); 96*cdf0e10cSrcweir sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) ); 97*cdf0e10cSrcweir if ( nCurX == nStartCol && nCurY == nStartRow ) 98*cdf0e10cSrcweir bStart = sal_False; 99*cdf0e10cSrcweir else if ( nCurX == nEndCol && nCurY == nEndRow ) 100*cdf0e10cSrcweir bStart = sal_True; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir SCsCOL nDifX; 103*cdf0e10cSrcweir SCsROW nDifY; 104*cdf0e10cSrcweir if ( bStart ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir nDifX = nStartCol - nCurX; 107*cdf0e10cSrcweir nDifY = nStartRow - nCurY; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir else 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir nDifX = nEndCol - nCurX; 112*cdf0e10cSrcweir nDifY = nEndRow - nCurY; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, sal_False ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir bFound = sal_True; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir pObject = aIter.Next(); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir return bFound; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir bool FuSelection::IsNoteCaptionMarked() const 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir if( pView ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); 130*cdf0e10cSrcweir if( rMarkList.GetMarkCount() == 1 ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj(); 133*cdf0e10cSrcweir return ScDrawLayer::IsNoteCaption( pObj ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir return false; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0; 142*cdf0e10cSrcweir if( pPageView ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir const ScViewData& rViewData = *pViewShell->GetViewData(); 145*cdf0e10cSrcweir ScDocument& rDoc = *rViewData.GetDocument(); 146*cdf0e10cSrcweir SCTAB nTab = rViewData.GetTabNo(); 147*cdf0e10cSrcweir ScDocShell* pDocSh = rViewData.GetDocShell(); 148*cdf0e10cSrcweir bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly()); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // search the last object (on top) in the object list 151*cdf0e10cSrcweir SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, sal_True ); 152*cdf0e10cSrcweir for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir if( pObj->GetLogicRect().IsInside( rPos ) ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir const ScAddress& rNotePos = pCaptData->maStart; 159*cdf0e10cSrcweir // skip caption objects of notes in protected cells 160*cdf0e10cSrcweir const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) ); 161*cdf0e10cSrcweir bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell(); 162*cdf0e10cSrcweir if( !bProtectAttr || !bProtectDoc ) 163*cdf0e10cSrcweir return true; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir return false; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir void FuSelection::ActivateNoteHandles(SdrObject* pObject) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if( pView && ScDrawLayer::IsNoteCaption( pObject ) ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged() 176*cdf0e10cSrcweir pView->UnlockInternalLayer(); 177*cdf0e10cSrcweir pView->MarkObj( pObject, pView->GetSdrPageView() ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //================================================================== 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir 186