LibreOffice Module sc (master) 1
fusel2.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svx/svditer.hxx>
21#include <svx/svdpagv.hxx>
22
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>
34
35static tools::Long Diff( const Point& rP1, const Point& rP2 )
36{
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;
42}
43
44bool FuSelection::TestDetective( const SdrPageView* pPV, const Point& rPos )
45{
46 if (!pPV)
47 return false;
48
49 bool bFound = false;
50 SdrObjListIter aIter( pPV->GetObjList(), SdrIterMode::Flat );
51 SdrObject* pObject = aIter.Next();
52 while (pObject && !bFound)
53 {
55 {
56 double fHitLog = pWindow->PixelToLogic(Size(pView->GetHitTolerancePixel(),0)).Width();
57 if (SdrObjectPrimitiveHit(*pObject, rPos, {fHitLog, fHitLog}, *pPV, nullptr, false))
58 {
59 ScViewData& rViewData = rViewShell.GetViewData();
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;
78
79 SCCOL nDifX;
80 SCROW nDifY;
81 if ( bStart )
82 {
83 nDifX = nStartCol - nCurX;
84 nDifY = nStartRow - nCurY;
85 }
86 else
87 {
88 nDifX = nEndCol - nCurX;
89 nDifY = nEndRow - nCurY;
90 }
91 rViewShell.MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
92
93 bFound = true;
94 }
95 }
96
97 pObject = aIter.Next();
98 }
99 return bFound;
100}
101
103{
104 if( pView )
105 {
106 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
107 if( rMarkList.GetMarkCount() == 1 )
108 {
109 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
110 return ScDrawLayer::IsNoteCaption( pObj );
111 }
112 }
113 return false;
114}
115
117{
118 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : nullptr;
119 if( pPageView )
120 {
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());
126
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() )
130 {
131 if( pObj->GetLogicRect().Contains( rPos ) )
132 {
133 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
134 {
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;
141 }
142 }
143 }
144 }
145 return false;
146}
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::chart::ChartAxisLabelPosition ePos
ScDrawView * pView
Definition: fupoor.hxx:42
ScTabViewShell & rViewShell
Definition: fupoor.hxx:43
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:44
bool TestDetective(const SdrPageView *pPV, const Point &rPos)
Definition: fusel2.cxx:44
bool IsNoteCaptionClicked(const Point &rPos) const
Definition: fusel2.cxx:116
bool IsNoteCaptionMarked() const
Definition: fusel2.cxx:102
constexpr tools::Long Y() const
constexpr tools::Long X() const
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
static bool IsNonAlienArrow(const SdrObject *pObject)
Definition: detfunc.cxx:334
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1905
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4684
static bool IsNoteCaption(SdrObject *pObj)
Returns true, if the passed object is the caption of a cell note.
Definition: drwlayer.cxx:2901
static ScDrawObjData * GetNoteCaptionData(SdrObject *pObj, SCTAB nTab)
Returns the object data, if the passed object is a cell note caption.
Definition: drwlayer.cxx:2907
bool GetHideCell() const
Definition: attrib.hxx:152
bool GetProtection() const
Definition: attrib.hxx:148
ScSplitPos FindWindow(const vcl::Window *pWindow) const
Definition: tabview.cxx:899
void MoveCursorRel(SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift, bool bKeepSel=false)
Definition: tabview3.cxx:1268
ScViewData & GetViewData()
Definition: tabview.hxx:344
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
void GetPosFromPixel(tools::Long nClickX, tools::Long nClickY, ScSplitPos eWhich, SCCOL &rPosX, SCROW &rPosY, bool bTestMerge=true, bool bRepair=false, SCTAB nForTab=-1)
Definition: viewdata.cxx:2785
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOL GetCurX() const
Definition: viewdata.hxx:401
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
SdrObject * Next()
SdrObjList * GetObjList() const
sal_uInt16 GetHitTolerancePixel() const
SdrPageView * GetSdrPageView() const
bool IsReadOnly() const
EmbeddedObjectRef * pObject
static tools::Long Diff(const Point &rP1, const Point &rP2)
Definition: fusel2.cxx:35
long Long
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
SVXCORE_DLLPUBLIC SdrObject * SdrObjectPrimitiveHit(const SdrObject &rObject, const Point &rPnt, const basegfx::B2DVector &rHitTolerance, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer=nullptr)
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
ScSplitPos
Definition: viewdata.hxx:44
@ SC_FOLLOW_JUMP
Definition: viewdata.hxx:52