1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 28 29 // INCLUDE --------------------------------------------------------------- 30 31 #include <svx/svditer.hxx> 32 #include <svx/svdocapt.hxx> 33 #include <svx/svdpagv.hxx> 34 #include <sfx2/dispatch.hxx> 35 #include <editeng/outliner.hxx> 36 37 #include "fusel.hxx" 38 #include "tabvwsh.hxx" 39 #include "document.hxx" 40 #include "detfunc.hxx" 41 #include "futext.hxx" 42 #include "sc.hrc" 43 #include "attrib.hxx" 44 #include "scitems.hxx" 45 #include "userdat.hxx" 46 #include "drwlayer.hxx" 47 #include "docsh.hxx" 48 #include "drawview.hxx" 49 #include <svx/sdrhittesthelper.hxx> 50 51 // ----------------------------------------------------------------------- 52 53 inline long Diff( const Point& rP1, const Point& rP2 ) 54 { 55 long nX = rP1.X() - rP2.X(); 56 if (nX<0) nX = -nX; 57 long nY = rP1.Y() - rP2.Y(); 58 if (nY<0) nY = -nY; 59 return nX+nY; 60 } 61 62 sal_Bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos ) 63 { 64 if (!pPV) 65 return sal_False; 66 67 sal_Bool bFound = sal_False; 68 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT ); 69 SdrObject* pObject = aIter.Next(); 70 while (pObject && !bFound) 71 { 72 if (ScDetectiveFunc::IsNonAlienArrow( pObject )) 73 { 74 sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic( 75 Size(pView->GetHitTolerancePixel(),0)).Width(); 76 if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false)) 77 { 78 ScViewData* pViewData = pViewShell->GetViewData(); 79 ScSplitPos ePos = pViewShell->FindWindow( pWindow ); 80 Point aLineStart = pObject->GetPoint(0); 81 Point aLineEnd = pObject->GetPoint(1); 82 Point aPixel = pWindow->LogicToPixel( aLineStart ); 83 SCsCOL nStartCol; 84 SCsROW nStartRow; 85 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow ); 86 aPixel = pWindow->LogicToPixel( aLineEnd ); 87 SCsCOL nEndCol; 88 SCsROW nEndRow; 89 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow ); 90 SCsCOL nCurX = (SCsCOL) pViewData->GetCurX(); 91 SCsROW nCurY = (SCsROW) pViewData->GetCurY(); 92 sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) ); 93 if ( nCurX == nStartCol && nCurY == nStartRow ) 94 bStart = sal_False; 95 else if ( nCurX == nEndCol && nCurY == nEndRow ) 96 bStart = sal_True; 97 98 SCsCOL nDifX; 99 SCsROW nDifY; 100 if ( bStart ) 101 { 102 nDifX = nStartCol - nCurX; 103 nDifY = nStartRow - nCurY; 104 } 105 else 106 { 107 nDifX = nEndCol - nCurX; 108 nDifY = nEndRow - nCurY; 109 } 110 pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, sal_False ); 111 112 bFound = sal_True; 113 } 114 } 115 116 pObject = aIter.Next(); 117 } 118 return bFound; 119 } 120 121 bool FuSelection::IsNoteCaptionMarked() const 122 { 123 if( pView ) 124 { 125 const SdrMarkList& rMarkList = pView->GetMarkedObjectList(); 126 if( rMarkList.GetMarkCount() == 1 ) 127 { 128 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj(); 129 return ScDrawLayer::IsNoteCaption( pObj ); 130 } 131 } 132 return false; 133 } 134 135 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const 136 { 137 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0; 138 if( pPageView ) 139 { 140 const ScViewData& rViewData = *pViewShell->GetViewData(); 141 ScDocument& rDoc = *rViewData.GetDocument(); 142 SCTAB nTab = rViewData.GetTabNo(); 143 ScDocShell* pDocSh = rViewData.GetDocShell(); 144 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly()); 145 146 // search the last object (on top) in the object list 147 SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, sal_True ); 148 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() ) 149 { 150 if( pObj->GetLogicRect().IsInside( rPos ) ) 151 { 152 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) ) 153 { 154 const ScAddress& rNotePos = pCaptData->maStart; 155 // skip caption objects of notes in protected cells 156 const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) ); 157 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell(); 158 if( !bProtectAttr || !bProtectDoc ) 159 return true; 160 } 161 } 162 } 163 } 164 return false; 165 } 166 167 void FuSelection::ActivateNoteHandles(SdrObject* pObject) 168 { 169 if( pView && ScDrawLayer::IsNoteCaption( pObject ) ) 170 { 171 // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged() 172 pView->UnlockInternalLayer(); 173 pView->MarkObj( pObject, pView->GetSdrPageView() ); 174 } 175 } 176 177 //================================================================== 178 179 180 181 182