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>
33 #include <svx/sdrhittesthelper.hxx>
34 
35 static 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 
44 bool 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  {
54  if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
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 
117 bool 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().IsInside( 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 {
151  if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
152  {
153  // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
155  pView->MarkObj( pObject, pView->GetSdrPageView() );
156  }
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
size_t GetMarkCount() const
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1890
SCROW Row() const
Definition: address.hxx:262
ScSplitPos FindWindow(const vcl::Window *pWindow) const
Definition: tabview.cxx:904
bool IsNoteCaptionClicked(const Point &rPos) const
Definition: fusel2.cxx:117
long Long
SCROW GetCurY() const
Definition: viewdata.hxx:402
static bool IsNonAlienArrow(const SdrObject *pObject)
Definition: detfunc.cxx:430
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
SdrMark * GetMark(size_t nNum) const
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
EmbeddedObjectRef * pObject
static tools::Long Diff(const Point &rP1, const Point &rP2)
Definition: fusel2.cxx:35
css::chart::ChartAxisLabelPosition ePos
ScSplitPos
Definition: viewdata.hxx:45
SdrObject * SdrObjectPrimitiveHit(const SdrObject &rObject, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
ScViewData & GetViewData()
Definition: tabview.hxx:332
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4714
bool GetHideCell() const
Definition: attrib.hxx:148
SdrObjList * GetObjList() const
SdrObject * GetMarkedSdrObj() const
void ActivateNoteHandles(SdrObject *pObj)
Definition: fusel2.cxx:149
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:2694
sal_Int16 SCCOL
Definition: types.hxx:22
static ScDrawObjData * GetNoteCaptionData(SdrObject *pObj, SCTAB nTab)
Returns the object data, if the passed object is a cell note caption.
Definition: drwlayer.cxx:2315
const SdrMarkList & GetMarkedObjectList() const
bool TestDetective(const SdrPageView *pPV, const Point &rPos)
Definition: fusel2.cxx:44
bool IsNoteCaptionMarked() const
Definition: fusel2.cxx:103
SCCOL Col() const
Definition: address.hxx:267
bool IsReadOnly() const
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
void UnlockInternalLayer()
Unlocks the internal layer that contains caption objects of cell notes.
Definition: drawview.hxx:138
sal_Int32 SCROW
Definition: types.hxx:18
bool GetProtection() const
Definition: attrib.hxx:144
void MoveCursorRel(SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift, bool bKeepSel=false)
Definition: tabview3.cxx:1260
ScDrawView * pView
Definition: fupoor.hxx:43
sal_uInt16 GetHitTolerancePixel() const
SdrPageView * GetSdrPageView() const
static bool IsNoteCaption(SdrObject *pObj)
Returns true, if the passed object is the caption of a cell note.
Definition: drwlayer.cxx:2309
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:45
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401