xref: /aoo41x/main/sc/source/ui/drawfunc/fusel2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #include <svx/svditer.hxx>
36 #include <svx/svdocapt.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <editeng/outliner.hxx>
40 
41 #include "fusel.hxx"
42 #include "tabvwsh.hxx"
43 #include "document.hxx"
44 #include "detfunc.hxx"
45 #include "futext.hxx"
46 #include "sc.hrc"
47 #include "attrib.hxx"
48 #include "scitems.hxx"
49 #include "userdat.hxx"
50 #include "drwlayer.hxx"
51 #include "docsh.hxx"
52 #include "drawview.hxx"
53 #include <svx/sdrhittesthelper.hxx>
54 
55 // -----------------------------------------------------------------------
56 
57 inline long Diff( const Point& rP1, const Point& rP2 )
58 {
59 	long nX = rP1.X() - rP2.X();
60 	if (nX<0) nX = -nX;
61 	long nY = rP1.Y() - rP2.Y();
62 	if (nY<0) nY = -nY;
63 	return nX+nY;
64 }
65 
66 sal_Bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
67 {
68 	if (!pPV)
69 		return sal_False;
70 
71 	sal_Bool bFound = sal_False;
72 	SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
73 	SdrObject* pObject = aIter.Next();
74 	while (pObject && !bFound)
75 	{
76 		if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
77 		{
78 			sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
79 								Size(pView->GetHitTolerancePixel(),0)).Width();
80 			if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
81 			{
82 				ScViewData* pViewData = pViewShell->GetViewData();
83 				ScSplitPos ePos = pViewShell->FindWindow( pWindow );
84 				Point aLineStart = pObject->GetPoint(0);
85 				Point aLineEnd   = pObject->GetPoint(1);
86 				Point aPixel = pWindow->LogicToPixel( aLineStart );
87 				SCsCOL nStartCol;
88 				SCsROW nStartRow;
89 				pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
90 				aPixel = pWindow->LogicToPixel( aLineEnd );
91 				SCsCOL nEndCol;
92 				SCsROW nEndRow;
93 				pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
94 				SCsCOL nCurX = (SCsCOL) pViewData->GetCurX();
95 				SCsROW nCurY = (SCsROW) pViewData->GetCurY();
96 				sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
97 				if ( nCurX == nStartCol && nCurY == nStartRow )
98 					bStart = sal_False;
99 				else if ( nCurX == nEndCol && nCurY == nEndRow )
100 					bStart = sal_True;
101 
102 				SCsCOL nDifX;
103 				SCsROW nDifY;
104 				if ( bStart )
105 				{
106 					nDifX = nStartCol - nCurX;
107 					nDifY = nStartRow - nCurY;
108 				}
109 				else
110 				{
111 					nDifX = nEndCol - nCurX;
112 					nDifY = nEndRow - nCurY;
113 				}
114 				pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, sal_False );
115 
116 				bFound = sal_True;
117 			}
118 		}
119 
120 		pObject = aIter.Next();
121 	}
122 	return bFound;
123 }
124 
125 bool FuSelection::IsNoteCaptionMarked() const
126 {
127     if( pView )
128     {
129         const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
130         if( rMarkList.GetMarkCount() == 1 )
131         {
132             SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
133             return ScDrawLayer::IsNoteCaption( pObj );
134         }
135     }
136     return false;
137 }
138 
139 bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
140 {
141     SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
142     if( pPageView )
143     {
144         const ScViewData& rViewData = *pViewShell->GetViewData();
145         ScDocument& rDoc = *rViewData.GetDocument();
146         SCTAB nTab = rViewData.GetTabNo();
147         ScDocShell* pDocSh = rViewData.GetDocShell();
148         bool bProtectDoc =  rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
149 
150         // search the last object (on top) in the object list
151         SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, sal_True );
152         for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
153         {
154             if( pObj->GetLogicRect().IsInside( rPos ) )
155             {
156                 if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
157                 {
158                     const ScAddress& rNotePos = pCaptData->maStart;
159                     // skip caption objects of notes in protected cells
160                     const ScProtectionAttr* pProtAttr =  static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
161                     bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
162                     if( !bProtectAttr || !bProtectDoc )
163                         return true;
164                 }
165             }
166         }
167     }
168     return false;
169 }
170 
171 void FuSelection::ActivateNoteHandles(SdrObject* pObject)
172 {
173     if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
174     {
175         // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
176         pView->UnlockInternalLayer();
177         pView->MarkObj( pObject, pView->GetSdrPageView() );
178     }
179 }
180 
181 //==================================================================
182 
183 
184 
185 
186