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 <dlgedview.hxx>
21 #include <dlged.hxx>
22 #include <dlgedpage.hxx>
23 
24 #include <vcl/canvastools.hxx>
25 #include <vcl/scrbar.hxx>
26 
27 #include <dlgedobj.hxx>
28 
29 namespace basctl
30 {
31 
DlgEdView(SdrModel & rSdrModel,OutputDevice & rOut,DlgEditor & rEditor)32 DlgEdView::DlgEdView(
33     SdrModel& rSdrModel,
34     OutputDevice& rOut,
35     DlgEditor& rEditor)
36 :   SdrView(rSdrModel, &rOut),
37     rDlgEditor(rEditor)
38 {
39     SetBufferedOutputAllowed(true);
40     SetBufferedOverlayAllowed(true);
41 }
42 
~DlgEdView()43 DlgEdView::~DlgEdView()
44 {
45 }
46 
MarkListHasChanged()47 void DlgEdView::MarkListHasChanged()
48 {
49     SdrView::MarkListHasChanged();
50 
51     DlgEdHint aHint( DlgEdHint::SELECTIONCHANGED );
52     rDlgEditor.Broadcast( aHint );
53     rDlgEditor.UpdatePropertyBrowserDelayed();
54 }
55 
MakeVisible(const tools::Rectangle & rRect,vcl::Window & rWin)56 void DlgEdView::MakeVisible( const tools::Rectangle& rRect, vcl::Window& rWin )
57 {
58     // visible area
59     MapMode aMap( rWin.GetMapMode() );
60     Point aOrg( aMap.GetOrigin() );
61     Size aVisSize( rWin.GetOutDev()->GetOutputSize() );
62     tools::Rectangle RectTmp( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
63     tools::Rectangle aVisRect( RectTmp );
64 
65     // check, if rectangle is inside visible area
66     if ( aVisRect.IsInside( rRect ) )
67         return;
68 
69     // calculate scroll distance; the rectangle must be inside the visible area
70     sal_Int32 nScrollX = 0, nScrollY = 0;
71 
72     sal_Int32 nVisLeft   = aVisRect.Left();
73     sal_Int32 nVisRight  = aVisRect.Right();
74     sal_Int32 nVisTop    = aVisRect.Top();
75     sal_Int32 nVisBottom = aVisRect.Bottom();
76 
77     sal_Int32 nDeltaX = rDlgEditor.GetHScroll()->GetLineSize();
78     sal_Int32 nDeltaY = rDlgEditor.GetVScroll()->GetLineSize();
79 
80     while ( rRect.Right() > nVisRight + nScrollX )
81         nScrollX += nDeltaX;
82 
83     while ( rRect.Left() < nVisLeft + nScrollX )
84         nScrollX -= nDeltaX;
85 
86     while ( rRect.Bottom() > nVisBottom + nScrollY )
87         nScrollY += nDeltaY;
88 
89     while ( rRect.Top() < nVisTop + nScrollY )
90         nScrollY -= nDeltaY;
91 
92     // don't scroll beyond the page size
93     Size aPageSize = rDlgEditor.GetPage().GetSize();
94     sal_Int32 nPageWidth  = aPageSize.Width();
95     sal_Int32 nPageHeight = aPageSize.Height();
96 
97     if ( nVisRight + nScrollX > nPageWidth )
98         nScrollX = nPageWidth - nVisRight;
99 
100     if ( nVisLeft + nScrollX < 0 )
101         nScrollX = -nVisLeft;
102 
103     if ( nVisBottom + nScrollY > nPageHeight )
104         nScrollY = nPageHeight - nVisBottom;
105 
106     if ( nVisTop + nScrollY < 0 )
107         nScrollY = -nVisTop;
108 
109     // scroll window
110     rWin.PaintImmediately();
111     rWin.Scroll( -nScrollX, -nScrollY );
112     aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
113     rWin.SetMapMode( aMap );
114     rWin.Invalidate();
115 
116     // update scroll bars
117     rDlgEditor.UpdateScrollBars();
118 
119     DlgEdHint aHint( DlgEdHint::WINDOWSCROLLED );
120     rDlgEditor.Broadcast( aHint );
121 }
122 
impLocalHitCorrection(SdrObject * pRetval,const Point & rPnt,sal_uInt16 nTol)123 static SdrObject* impLocalHitCorrection(SdrObject* pRetval, const Point& rPnt, sal_uInt16 nTol)
124 {
125     DlgEdObj* pDlgEdObj = dynamic_cast< DlgEdObj* >(pRetval);
126 
127     if(pDlgEdObj)
128     {
129         bool bExcludeInner(false);
130 
131         if(dynamic_cast< DlgEdForm* >(pRetval) != nullptr)
132         {
133             // from DlgEdForm::CheckHit; exclude inner for DlgEdForm
134             bExcludeInner = true;
135         }
136         else if(pDlgEdObj->supportsService("com.sun.star.awt.UnoControlGroupBoxModel"))
137         {
138             // from DlgEdObj::CheckHit; exclude inner for group shapes
139             bExcludeInner = true;
140         }
141 
142         if(bExcludeInner)
143         {
144             // use direct model data; it's a DlgEdObj, so GetLastBoundRect()
145             // will access aOutRect directly
146             const tools::Rectangle aOuterRectangle(pDlgEdObj->GetLastBoundRect());
147 
148             if(!aOuterRectangle.IsEmpty())
149             {
150                 basegfx::B2DRange aOuterRange = vcl::unotools::b2DRectangleFromRectangle(aOuterRectangle);
151 
152                 if(nTol)
153                 {
154                     aOuterRange.grow(-1.0 * nTol);
155                 }
156 
157                 if(aOuterRange.isInside(basegfx::B2DPoint(rPnt.X(), rPnt.Y())))
158                 {
159                     pRetval = nullptr;
160                 }
161             }
162         }
163     }
164 
165     return pRetval;
166 }
167 
CheckSingleSdrObjectHit(const Point & rPnt,sal_uInt16 nTol,SdrObject * pObj,SdrPageView * pPV,SdrSearchOptions nOptions,const SdrLayerIDSet * pMVisLay) const168 SdrObject* DlgEdView::CheckSingleSdrObjectHit(const Point& rPnt, sal_uInt16 nTol, SdrObject* pObj, SdrPageView* pPV, SdrSearchOptions nOptions, const SdrLayerIDSet* pMVisLay) const
169 {
170     // call parent
171     SdrObject* pRetval = SdrView::CheckSingleSdrObjectHit(rPnt, nTol, pObj, pPV, nOptions, pMVisLay);
172 
173     if(pRetval)
174     {
175         // check hit object locally
176         pRetval = impLocalHitCorrection(pRetval, rPnt, nTol);
177     }
178 
179     return pRetval;
180 }
181 
182 } // namespace basctl
183 
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
185