Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
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>
39 :
40 0 : inline long Diff( const Point& rP1, const Point& rP2 )
41 : {
42 0 : long nX = rP1.X() - rP2.X();
43 0 : if (nX<0) nX = -nX;
44 0 : long nY = rP1.Y() - rP2.Y();
45 0 : if (nY<0) nY = -nY;
46 0 : return nX+nY;
47 : }
48 :
49 0 : bool FuSelection::TestDetective( SdrPageView* pPV, const Point& rPos )
50 : {
51 0 : if (!pPV)
52 0 : return false;
53 :
54 0 : bool bFound = false;
55 0 : SdrObjListIter aIter( *pPV->GetObjList(), IM_FLAT );
56 0 : SdrObject* pObject = aIter.Next();
57 0 : while (pObject && !bFound)
58 : {
59 0 : if (ScDetectiveFunc::IsNonAlienArrow( pObject ))
60 : {
61 : sal_uInt16 nHitLog = (sal_uInt16) pWindow->PixelToLogic(
62 0 : Size(pView->GetHitTolerancePixel(),0)).Width();
63 0 : if (SdrObjectPrimitiveHit(*pObject, rPos, nHitLog, *pPV, 0, false))
64 : {
65 0 : ScViewData* pViewData = pViewShell->GetViewData();
66 0 : ScSplitPos ePos = pViewShell->FindWindow( pWindow );
67 0 : Point aLineStart = pObject->GetPoint(0);
68 0 : Point aLineEnd = pObject->GetPoint(1);
69 0 : Point aPixel = pWindow->LogicToPixel( aLineStart );
70 : SCsCOL nStartCol;
71 : SCsROW nStartRow;
72 0 : pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nStartCol, nStartRow );
73 0 : aPixel = pWindow->LogicToPixel( aLineEnd );
74 : SCsCOL nEndCol;
75 : SCsROW nEndRow;
76 0 : pViewData->GetPosFromPixel( aPixel.X(), aPixel.Y(), ePos, nEndCol, nEndRow );
77 0 : SCsCOL nCurX = (SCsCOL) pViewData->GetCurX();
78 0 : SCsROW nCurY = (SCsROW) pViewData->GetCurY();
79 0 : sal_Bool bStart = ( Diff( rPos,aLineStart ) > Diff( rPos,aLineEnd ) );
80 0 : if ( nCurX == nStartCol && nCurY == nStartRow )
81 0 : bStart = false;
82 0 : else if ( nCurX == nEndCol && nCurY == nEndRow )
83 0 : bStart = sal_True;
84 :
85 : SCsCOL nDifX;
86 : SCsROW nDifY;
87 0 : if ( bStart )
88 : {
89 0 : nDifX = nStartCol - nCurX;
90 0 : nDifY = nStartRow - nCurY;
91 : }
92 : else
93 : {
94 0 : nDifX = nEndCol - nCurX;
95 0 : nDifY = nEndRow - nCurY;
96 : }
97 0 : pViewShell->MoveCursorRel( nDifX, nDifY, SC_FOLLOW_JUMP, false );
98 :
99 0 : bFound = true;
100 : }
101 : }
102 :
103 0 : pObject = aIter.Next();
104 : }
105 0 : return bFound;
106 : }
107 :
108 0 : bool FuSelection::IsNoteCaptionMarked() const
109 : {
110 0 : if( pView )
111 : {
112 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
113 0 : if( rMarkList.GetMarkCount() == 1 )
114 : {
115 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
116 0 : return ScDrawLayer::IsNoteCaption( pObj );
117 : }
118 : }
119 0 : return false;
120 : }
121 :
122 0 : bool FuSelection::IsNoteCaptionClicked( const Point& rPos ) const
123 : {
124 0 : SdrPageView* pPageView = pView ? pView->GetSdrPageView() : 0;
125 0 : if( pPageView )
126 : {
127 0 : const ScViewData& rViewData = *pViewShell->GetViewData();
128 0 : ScDocument& rDoc = *rViewData.GetDocument();
129 0 : SCTAB nTab = rViewData.GetTabNo();
130 0 : ScDocShell* pDocSh = rViewData.GetDocShell();
131 0 : bool bProtectDoc = rDoc.IsTabProtected( nTab ) || (pDocSh && pDocSh->IsReadOnly());
132 :
133 : // search the last object (on top) in the object list
134 0 : SdrObjListIter aIter( *pPageView->GetObjList(), IM_DEEPNOGROUPS, true );
135 0 : for( SdrObject* pObj = aIter.Next(); pObj; pObj = aIter.Next() )
136 : {
137 0 : if( pObj->GetLogicRect().IsInside( rPos ) )
138 : {
139 0 : if( const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab ) )
140 : {
141 0 : const ScAddress& rNotePos = pCaptData->maStart;
142 : // skip caption objects of notes in protected cells
143 0 : const ScProtectionAttr* pProtAttr = static_cast< const ScProtectionAttr* >( rDoc.GetAttr( rNotePos.Col(), rNotePos.Row(), nTab, ATTR_PROTECTION ) );
144 0 : bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell();
145 0 : if( !bProtectAttr || !bProtectDoc )
146 0 : return true;
147 : }
148 : }
149 0 : }
150 : }
151 0 : return false;
152 : }
153 :
154 0 : void FuSelection::ActivateNoteHandles(SdrObject* pObject)
155 : {
156 0 : if( pView && ScDrawLayer::IsNoteCaption( pObject ) )
157 : {
158 : // Leave the internal layer unlocked - relock in ScDrawView::MarkListHasChanged()
159 0 : pView->UnlockInternalLayer();
160 0 : pView->MarkObj( pObject, pView->GetSdrPageView() );
161 : }
162 0 : }
163 :
164 :
165 :
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|