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 sal_uInt16 nHitLog = static_cast<sal_uInt16>(pWindow->PixelToLogic(
57 Size(pView->GetHitTolerancePixel(),0)).Width());
58 if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, nullptr, false))
59 {
60 ScViewData& rViewData = rViewShell.GetViewData();
62 Point aLineStart = pObject->GetPoint(0);
63 Point aLineEnd = pObject->GetPoint(1);
64 Point aPixel = pWindow->LogicToPixel( aLineStart );
65 SCCOL nStartCol;
66 SCROW nStartRow;
67 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
68 aPixel = pWindow->LogicToPixel( aLineEnd );
69 SCCOL nEndCol;
70 SCROW nEndRow;
71 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
72 SCCOL nCurX = rViewData.GetCurX();
73 SCROW nCurY = rViewData.GetCurY();
74 bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
75 if ( nCurX == nStartCol && nCurY == nStartRow )
76 bStart = false;
77 else if ( nCurX == nEndCol && nCurY == nEndRow )
78 bStart = true;
79
80 SCCOL nDifX;
81 SCROW nDifY;
82 if ( bStart )
83 {
84 nDifX = nStartCol - nCurX;
85 nDifY = nStartRow - nCurY;
86 }
87 else
88 {
89 nDifX = nEndCol - nCurX;
90 nDifY = nEndRow - nCurY;
91 }
92 rViewShell.MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
93
94 bFound = true;
95 }
96 }
97
98 pObject = aIter.Next();
99 }
100 return bFound;
101}
102
104{
105 if( pView )
106 {
107 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
108 if( rMarkList.GetMarkCount() == 1 )
109 {
110 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
111 return ScDrawLayer::IsNoteCaption( pObj );
112 }
113 }
114 return false;
115}
116
117bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
118{
119 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : nullptr;
120 if( pPageView )
121 {
122 const ScViewData& rViewData = rViewShell.GetViewData();
123 ScDocument& rDoc = rViewData.GetDocument();
124 SCTAB nTab = rViewData.GetTabNo();
125 ScDocShell* pDocSh = rViewData.GetDocShell();
126 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
127
128 // search the last object (on top) in the object list
129 SdrObjListIter aIter( pPageView->GetObjList(), SdrIterMode::DeepNoGroups, true );
130 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
131 {
132 if( pObj->GetLogicRect().Contains( rPos ) )
133 {
134 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
135 {
136 const ScAddress& rNotePos = pCaptData->maStart;
137 // skip caption objects of notes in protected cells
138 const ScProtectionAttr* pProtAttr = rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION );
139 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
140 if( !bProtectAttr || !bProtectDoc )
141 return true;
142 }
143 }
144 }
145 }
146 return false;
147}
148
150{
152 {
153 // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
156 }
157}
158
159/* 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
void ActivateNoteHandles(SdrObject *pObj)
Definition: fusel2.cxx:149
bool TestDetective(const SdrPageView *pPV, const Point &rPos)
Definition: fusel2.cxx:44
bool IsNoteCaptionClicked(const Point &rPos) const
Definition: fusel2.cxx:117
bool IsNoteCaptionMarked() const
Definition: fusel2.cxx:103
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:1919
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4778
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
void UnlockInternalLayer()
Unlocks the internal layer that contains caption objects of cell notes.
Definition: drawview.hxx:137
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:343
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:2780
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
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
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, sal_uInt16 nTol, 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