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>
45 #include "tabvwsh.hxx"
46 #include "document.hxx"
47 #include "detfunc.hxx"
51 #include "scitems.hxx"
52 #include "userdat.hxx"
53 #include "drwlayer.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();
64 long nY
= rP1
.Y() - rP2
.Y();
69 BOOL
FuSelection::TestDetective( SdrPageView
* pPV
, const Point
& rPos
)
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
);
92 pViewData
->GetPosFromPixel( aPixel
.X(), aPixel
.Y(), ePos
, nStartCol
, nStartRow
);
93 aPixel
= pWindow
->LogicToPixel( aLineEnd
);
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
)
102 else if ( nCurX
== nEndCol
&& nCurY
== nEndRow
)
109 nDifX
= nStartCol
- nCurX
;
110 nDifY
= nStartRow
- nCurY
;
114 nDifX
= nEndCol
- nCurX
;
115 nDifY
= nEndRow
- nCurY
;
117 pViewShell
->MoveCursorRel( nDifX
, nDifY
, SC_FOLLOW_JUMP
, FALSE
);
123 pObject
= aIter
.Next();
128 bool FuSelection::IsNoteCaptionMarked() const
132 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
133 if( rMarkList
.GetMarkCount() == 1 )
135 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
136 return ScDrawLayer::IsNoteCaption( pObj
);
142 bool FuSelection::IsNoteCaptionClicked( const Point
& rPos
) const
144 SdrPageView
* pPageView
= pView
? pView
->GetSdrPageView() : 0;
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
)
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 //==================================================================