fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / fusel2.cxx
blob82cb880c0ab980e75576c32dc30faafdf260bc64
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/svdocapt.hxx>
22 #include <svx/svdpagv.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <editeng/outliner.hxx>
26 #include "fusel.hxx"
27 #include "tabvwsh.hxx"
28 #include "document.hxx"
29 #include "detfunc.hxx"
30 #include "futext.hxx"
31 #include "sc.hrc"
32 #include "attrib.hxx"
33 #include "scitems.hxx"
34 #include "userdat.hxx"
35 #include "drwlayer.hxx"
36 #include "docsh.hxx"
37 #include "drawview.hxx"
38 #include <svx/sdrhittesthelper.hxx>
40 inline long Diff( const Point& rP1, const Point& rP2 )
42 long nX = rP1.X() - rP2.X();
43 if (nX<0) nX = -nX;
44 long nY = rP1.Y() - rP2.Y();
45 if (nY<0) nY = -nY;
46 return nX+nY;
49 bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
51 if (!pPV)
52 return false;
54 bool bFound = false;
55 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
56 SdrObject* pObject = aIter.Next();
57 while (pObject && !bFound)
59 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
61 sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
62 Size(pView->GetHitTolerancePixel(),0)).Width();
63 if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
65 ScViewData& rViewData = pViewShell->GetViewData();
66 ScSplitPos ePos = pViewShell->FindWindow( pWindow );
67 Point aLineStart = pObject->GetPoint(0);
68 Point aLineEnd = pObject->GetPoint(1);
69 Point aPixel = pWindow->LogicToPixel( aLineStart );
70 SCsCOL nStartCol;
71 SCsROW nStartRow;
72 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
73 aPixel = pWindow->LogicToPixel( aLineEnd );
74 SCsCOL nEndCol;
75 SCsROW nEndRow;
76 rViewData.GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
77 SCsCOL nCurX = (SCsCOL) rViewData.GetCurX();
78 SCsROW nCurY = (SCsROW) rViewData.GetCurY();
79 bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
80 if ( nCurX == nStartCol && nCurY == nStartRow )
81 bStart = false;
82 else if ( nCurX == nEndCol && nCurY == nEndRow )
83 bStart = true;
85 SCsCOL nDifX;
86 SCsROW nDifY;
87 if ( bStart )
89 nDifX = nStartCol - nCurX;
90 nDifY = nStartRow - nCurY;
92 else
94 nDifX = nEndCol - nCurX;
95 nDifY = nEndRow - nCurY;
97 pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
99 bFound = true;
103 pObject = aIter.Next();
105 return bFound;
108 bool FuSelection::IsNoteCaptionMarked() const
110 if( pView )
112 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
113 if( rMarkList.GetMarkCount() == 1 )
115 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
116 return ScDrawLayer::IsNoteCaption( pObj );
119 return false;
122 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
124 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
125 if( pPageView )
127 const ScViewData& rViewData = pViewShell->GetViewData();
128 ScDocument& rDoc = *rViewData.GetDocument();
129 SCTAB nTab = rViewData.GetTabNo();
130 ScDocShell* pDocSh = rViewData.GetDocShell();
131 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
133 // search the last object (on top) in the object list
134 SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, true );
135 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
137 if( pObj->GetLogicRect().IsInside( rPos ) )
139 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
141 const ScAddress& rNotePos = pCaptData->maStart;
142 // skip caption objects of notes in protected cells
143 const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
144 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
145 if( !bProtectAttr || !bProtectDoc )
146 return true;
151 return false;
154 void FuSelection::ActivateNoteHandles(SdrObject* pObject)
156 if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
158 // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
159 pView->UnlockInternalLayer();
160 pView->MarkObj( pObject, pView->GetSdrPageView() );
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */