merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / drawfunc / fusel2.cxx
blob7c096fd51d7109eaec38354b7c5d139a6ba2e32e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fusel2.cxx,v $
10 * $Revision: 1.12.128.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <svx/svditer.hxx>
39 #include <svx/svdocapt.hxx>
40 #include <svx/svdpagv.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <svx/outliner.hxx>
44 #include "fusel.hxx"
45 #include "tabvwsh.hxx"
46 #include "document.hxx"
47 #include "detfunc.hxx"
48 #include "futext.hxx"
49 #include "sc.hrc"
50 #include "attrib.hxx"
51 #include "scitems.hxx"
52 #include "userdat.hxx"
53 #include "drwlayer.hxx"
54 #include "docsh.hxx"
55 #include "drawview.hxx"
56 #include <svx/sdrhittesthelper.hxx>
58 // -----------------------------------------------------------------------
60 inline long Diff( const Point& rP1, const Point& rP2 )
62 long nX = rP1.X() - rP2.X();
63 if (nX<0) nX = -nX;
64 long nY = rP1.Y() - rP2.Y();
65 if (nY<0) nY = -nY;
66 return nX+nY;
69 BOOL FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
71 if (!pPV)
72 return FALSE;
74 BOOL bFound = FALSE;
75 SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
76 SdrObject* pObject = aIter.Next();
77 while (pObject && !bFound)
79 if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
81 USHORT nHitLog = (USHORT) pWindow->PixelToLogic(
82 Size(pView->GetHitTolerancePixel(),0)).Width();
83 if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
85 ScViewData* pViewData = pViewShell->GetViewData();
86 ScSplitPos ePos = pViewShell->FindWindow( pWindow );
87 Point aLineStart = pObject->GetPoint(0);
88 Point aLineEnd = pObject->GetPoint(1);
89 Point aPixel = pWindow->LogicToPixel( aLineStart );
90 SCsCOL nStartCol;
91 SCsROW nStartRow;
92 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
93 aPixel = pWindow->LogicToPixel( aLineEnd );
94 SCsCOL nEndCol;
95 SCsROW nEndRow;
96 pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
97 SCsCOL nCurX = (SCsCOL) pViewData->GetCurX();
98 SCsROW nCurY = (SCsROW) pViewData->GetCurY();
99 BOOL bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
100 if ( nCurX == nStartCol && nCurY == nStartRow )
101 bStart = FALSE;
102 else if ( nCurX == nEndCol && nCurY == nEndRow )
103 bStart = TRUE;
105 SCsCOL nDifX;
106 SCsROW nDifY;
107 if ( bStart )
109 nDifX = nStartCol - nCurX;
110 nDifY = nStartRow - nCurY;
112 else
114 nDifX = nEndCol - nCurX;
115 nDifY = nEndRow - nCurY;
117 pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, FALSE );
119 bFound = TRUE;
123 pObject = aIter.Next();
125 return bFound;
128 bool FuSelection::IsNoteCaptionMarked() const
130 if( pView )
132 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
133 if( rMarkList.GetMarkCount() == 1 )
135 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
136 return ScDrawLayer::IsNoteCaption( pObj );
139 return false;
142 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
144 SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
145 if( pPageView )
147 const ScViewData& rViewData = *pViewShell->GetViewData();
148 ScDocument& rDoc = *rViewData.GetDocument();
149 SCTAB nTab = rViewData.GetTabNo();
150 ScDocShell* pDocSh = rViewData.GetDocShell();
151 bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
153 // search the last object (on top) in the object list
154 SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, TRUE );
155 for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
157 if( pObj->GetLogicRect().IsInside( rPos ) )
159 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
161 const ScAddress& rNotePos = pCaptData->maStart;
162 // skip caption objects of notes in protected cells
163 const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
164 bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
165 if( !bProtectAttr || !bProtectDoc )
166 return true;
171 return false;
174 void FuSelection::ActivateNoteHandles(SdrObject* pObject)
176 if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
178 // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
179 pView->UnlockInternalLayer();
180 pView->MarkObj( pObject, pView->GetSdrPageView() );
184 //==================================================================