1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <tabvwsh.hxx>
25 #include <document.hxx>
26 #include <detfunc.hxx>
28 #include <scitems.hxx>
29 #include <userdat.hxx>
30 #include <drwlayer.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();
39 tools::Long nY
= rP1
.Y() - rP2
.Y();
44 bool FuSelection::TestDetective( const SdrPageView
* pPV
, const Point
& rPos
)
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
);
66 rViewData
.GetPosFromPixel( aPixel
.X(), aPixel
.Y(), ePos
, nStartCol
, nStartRow
);
67 aPixel
= pWindow
->LogicToPixel( aLineEnd
);
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
)
76 else if ( nCurX
== nEndCol
&& nCurY
== nEndRow
)
83 nDifX
= nStartCol
- nCurX
;
84 nDifY
= nStartRow
- nCurY
;
88 nDifX
= nEndCol
- nCurX
;
89 nDifY
= nEndRow
- nCurY
;
91 rViewShell
.MoveCursorRel( nDifX
, nDifY
, SC_FOLLOW_JUMP
, false );
97 pObject
= aIter
.Next();
102 bool FuSelection::IsNoteCaptionMarked() const
106 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
107 if( rMarkList
.GetMarkCount() == 1 )
109 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
110 return ScDrawLayer::IsNoteCaption( pObj
);
116 bool FuSelection::IsNoteCaptionClicked( const Point
& rPos
) const
118 SdrPageView
* pPageView
= pView
? pView
->GetSdrPageView() : nullptr;
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
)
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */