1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <svx/svditer.hxx>
32cdf0e10cSrcweir #include <svx/svdocapt.hxx>
33cdf0e10cSrcweir #include <svx/svdpagv.hxx>
34cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35cdf0e10cSrcweir #include <editeng/outliner.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "fusel.hxx"
38cdf0e10cSrcweir #include "tabvwsh.hxx"
39cdf0e10cSrcweir #include "document.hxx"
40cdf0e10cSrcweir #include "detfunc.hxx"
41cdf0e10cSrcweir #include "futext.hxx"
42cdf0e10cSrcweir #include "sc.hrc"
43cdf0e10cSrcweir #include "attrib.hxx"
44cdf0e10cSrcweir #include "scitems.hxx"
45cdf0e10cSrcweir #include "userdat.hxx"
46cdf0e10cSrcweir #include "drwlayer.hxx"
47cdf0e10cSrcweir #include "docsh.hxx"
48cdf0e10cSrcweir #include "drawview.hxx"
49cdf0e10cSrcweir #include <svx/sdrhittesthelper.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir // -----------------------------------------------------------------------
52cdf0e10cSrcweir
Diff(const Point & rP1,const Point & rP2)53cdf0e10cSrcweir inline long Diff( const Point& rP1, const Point& rP2 )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir long nX = rP1.X() - rP2.X();
56cdf0e10cSrcweir if (nX<0) nX = -nX;
57cdf0e10cSrcweir long nY = rP1.Y() - rP2.Y();
58cdf0e10cSrcweir if (nY<0) nY = -nY;
59cdf0e10cSrcweir return nX+nY;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
TestDetective(SdrPageView * pPV,const Point & rPos)62cdf0e10cSrcweir sal_Bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir if (!pPV)
65cdf0e10cSrcweir return sal_False;
66cdf0e10cSrcweir
67cdf0e10cSrcweir sal_Bool bFound = sal_False;
68cdf0e10cSrcweir SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
69cdf0e10cSrcweir SdrObject* pObject = aIter.Next();
70cdf0e10cSrcweir while (pObject && !bFound)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
73cdf0e10cSrcweir {
74cdf0e10cSrcweir sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
75cdf0e10cSrcweir Size(pView->GetHitTolerancePixel(),0)).Width();
76cdf0e10cSrcweir if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
77cdf0e10cSrcweir {
78cdf0e10cSrcweir ScViewData* pViewData = pViewShell->GetViewData();
79cdf0e10cSrcweir ScSplitPos ePos = pViewShell->FindWindow( pWindow );
80cdf0e10cSrcweir Point aLineStart = pObject->GetPoint(0);
81cdf0e10cSrcweir Point aLineEnd = pObject->GetPoint(1);
82cdf0e10cSrcweir Point aPixel = pWindow->LogicToPixel( aLineStart );
83cdf0e10cSrcweir SCsCOL nStartCol;
84cdf0e10cSrcweir SCsROW nStartRow;
85cdf0e10cSrcweir pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
86cdf0e10cSrcweir aPixel = pWindow->LogicToPixel( aLineEnd );
87cdf0e10cSrcweir SCsCOL nEndCol;
88cdf0e10cSrcweir SCsROW nEndRow;
89cdf0e10cSrcweir pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
90cdf0e10cSrcweir SCsCOL nCurX = (SCsCOL) pViewData->GetCurX();
91cdf0e10cSrcweir SCsROW nCurY = (SCsROW) pViewData->GetCurY();
92cdf0e10cSrcweir sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
93cdf0e10cSrcweir if ( nCurX == nStartCol && nCurY == nStartRow )
94cdf0e10cSrcweir bStart = sal_False;
95cdf0e10cSrcweir else if ( nCurX == nEndCol && nCurY == nEndRow )
96cdf0e10cSrcweir bStart = sal_True;
97cdf0e10cSrcweir
98cdf0e10cSrcweir SCsCOL nDifX;
99cdf0e10cSrcweir SCsROW nDifY;
100cdf0e10cSrcweir if ( bStart )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir nDifX = nStartCol - nCurX;
103cdf0e10cSrcweir nDifY = nStartRow - nCurY;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir else
106cdf0e10cSrcweir {
107cdf0e10cSrcweir nDifX = nEndCol - nCurX;
108cdf0e10cSrcweir nDifY = nEndRow - nCurY;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, sal_False );
111cdf0e10cSrcweir
112cdf0e10cSrcweir bFound = sal_True;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir pObject = aIter.Next();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir return bFound;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
IsNoteCaptionMarked() const121cdf0e10cSrcweir bool FuSelection::IsNoteCaptionMarked() const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir if( pView )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
126cdf0e10cSrcweir if( rMarkList.GetMarkCount() == 1 )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
129cdf0e10cSrcweir return ScDrawLayer::IsNoteCaption( pObj );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir return false;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
IsNoteCaptionClicked(const Point & rPos) const135cdf0e10cSrcweir bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
138cdf0e10cSrcweir if( pPageView )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir const ScViewData& rViewData = *pViewShell->GetViewData();
141cdf0e10cSrcweir ScDocument& rDoc = *rViewData.GetDocument();
142cdf0e10cSrcweir SCTAB nTab = rViewData.GetTabNo();
143cdf0e10cSrcweir ScDocShell* pDocSh = rViewData.GetDocShell();
144cdf0e10cSrcweir bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
145cdf0e10cSrcweir
146cdf0e10cSrcweir // search the last object (on top) in the object list
147cdf0e10cSrcweir SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, sal_True );
148cdf0e10cSrcweir for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir if( pObj->GetLogicRect().IsInside( rPos ) )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir const ScAddress& rNotePos = pCaptData->maStart;
155cdf0e10cSrcweir // skip caption objects of notes in protected cells
156cdf0e10cSrcweir const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
157cdf0e10cSrcweir bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
158cdf0e10cSrcweir if( !bProtectAttr || !bProtectDoc )
159cdf0e10cSrcweir return true;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir return false;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
ActivateNoteHandles(SdrObject * pObject)167cdf0e10cSrcweir void FuSelection::ActivateNoteHandles(SdrObject* pObject)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
172cdf0e10cSrcweir pView->UnlockInternalLayer();
173cdf0e10cSrcweir pView->MarkObj( pObject, pView->GetSdrPageView() );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir //==================================================================
178cdf0e10cSrcweir
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181cdf0e10cSrcweir
182