tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / drawfunc / fusel2.cxx
blobcc9a1478ceb4e84090132ef13d7918c5d5f0ad70
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/svdpagv.hxx>
23 #include <fusel.hxx>
24 #include <tabvwsh.hxx>
25 #include <document.hxx>
26 #include <detfunc.hxx>
27 #include <attrib.hxx>
28 #include <scitems.hxx>
29 #include <userdat.hxx>
30 #include <drwlayer.hxx>
31 #include <docsh.hxx>
32 #include <drawview.hxx>
33 #include <svx/sdrhittesthelper.hxx>
35 static tools::Long Diff( const Point& rP1, const Point& rP2 )
37 tools::Long nX = rP1.X() - rP2.X();
38 if (nX<0) nX = -nX;
39 tools::Long nY = rP1.Y() - rP2.Y();
40 if (nY<0) nY = -nY;
41 return nX+nY;
44 bool FuSelection::TestDetective( const SdrPageView* pPV, const Point& rPos )
46 if (!pPV)
47 return false;
49 bool bFound = false;
50 SdrObjListIter aIter( pPV->GetObjList(), SdrIterMode::Flat );
51 SdrObject* pObject = aIter.Next();
52 while (pObject && !bFound)
54 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
56 double fHitLog = pWindow->PixelToLogic(Size(pView->GetHitTolerancePixel(),0)).Width();
57 if (SdrObjectPrimitiveHit(*pObject, rPos, {fHitLog, fHitLog}, *pPV, nullptr, false))
59 ScViewData& rViewData = rViewShell.GetViewData();
60 ScSplitPos ePos = rViewShell.FindWindow( pWindow );
61 Point aLineStart = pObject->GetPoint(0);
62 Point aLineEnd = pObject->GetPoint(1);
63 Point aPixel = pWindow->LogicToPixel( aLineStart );
64 SCCOL nStartCol;
65 SCROW nStartRow;
66 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
67 aPixel = pWindow->LogicToPixel( aLineEnd );
68 SCCOL nEndCol;
69 SCROW nEndRow;
70 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
71 SCCOL nCurX = rViewData.GetCurX();
72 SCROW nCurY = rViewData.GetCurY();
73 bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
74 if ( nCurX == nStartCol && nCurY == nStartRow )
75 bStart = false;
76 else if ( nCurX == nEndCol && nCurY == nEndRow )
77 bStart = true;
79 SCCOL nDifX;
80 SCROW nDifY;
81 if ( bStart )
83 nDifX = nStartCol - nCurX;
84 nDifY = nStartRow - nCurY;
86 else
88 nDifX = nEndCol - nCurX;
89 nDifY = nEndRow - nCurY;
91 rViewShell.MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
93 bFound = true;
97 pObject = aIter.Next();
99 return bFound;
102 bool FuSelection::IsNoteCaptionMarked() const
104 if( pView )
106 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
107 if( rMarkList.GetMarkCount() == 1 )
109 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
110 return ScDrawLayer::IsNoteCaption( pObj );
113 return false;
116 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
118 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : nullptr;
119 if( pPageView )
121 const ScViewData& rViewData = rViewShell.GetViewData();
122 ScDocument& rDoc = rViewData.GetDocument();
123 SCTAB nTab = rViewData.GetTabNo();
124 ScDocShell* pDocSh = rViewData.GetDocShell();
125 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
127 // search the last object (on top) in the object list
128 SdrObjListIter aIter( pPageView->GetObjList(), SdrIterMode::DeepNoGroups, true );
129 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
131 if( pObj->GetLogicRect().Contains( rPos ) )
133 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
135 const ScAddress& rNotePos = pCaptData->maStart;
136 // skip caption objects of notes in protected cells
137 const ScProtectionAttr* pProtAttr = rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION );
138 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
139 if( !bProtectAttr || !bProtectDoc )
140 return true;
145 return false;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */