Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuzoom.cxx
blobe71452847a9d2df4f0a56f8005e9ba7fd65f73f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <fuzoom.hxx>
22 #include <svx/svxids.hrc>
23 #include <sfx2/bindings.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <app.hrc>
26 #include <svx/svdpagv.hxx>
28 #include <FrameView.hxx>
29 #include <ViewShell.hxx>
30 #include <View.hxx>
31 #include <Window.hxx>
32 #include <drawdoc.hxx>
33 #include <zoomlist.hxx>
35 namespace sd {
37 const sal_uInt16 SidArrayZoom[] = {
38 SID_ATTR_ZOOM,
39 SID_ZOOM_OUT,
40 SID_ZOOM_IN,
41 0 };
44 FuZoom::FuZoom(
45 ViewShell* pViewSh,
46 ::sd::Window* pWin,
47 ::sd::View* pView,
48 SdDrawDocument* pDoc,
49 SfxRequest& rReq)
50 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
51 bVisible(false),
52 bStartDrag(false)
56 FuZoom::~FuZoom()
58 if (bVisible)
60 // Hide ZoomRect
61 mpViewShell->DrawMarkRect(aZoomRect);
63 bVisible = false;
64 bStartDrag = false;
68 rtl::Reference<FuPoor> FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
70 rtl::Reference<FuPoor> xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
71 return xFunc;
74 bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
76 // remember button state for creation of own MouseEvents
77 SetMouseButtonCode(rMEvt.GetButtons());
79 mpWindow->CaptureMouse();
80 bStartDrag = true;
82 aBeginPosPix = rMEvt.GetPosPixel();
83 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
84 aZoomRect.SetSize( Size( 0, 0 ) );
85 aZoomRect.SetPos( aBeginPos );
87 return true;
90 bool FuZoom::MouseMove(const MouseEvent& rMEvt)
92 if (rMEvt.IsShift())
93 mpWindow->SetPointer(Pointer(PointerStyle::Hand));
94 else if (nSlotId != SID_ZOOM_PANNING)
95 mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
97 if (bStartDrag)
99 if (bVisible)
101 mpViewShell->DrawMarkRect(aZoomRect);
104 Point aPosPix = rMEvt.GetPosPixel();
105 ForceScroll(aPosPix);
107 aEndPos = mpWindow->PixelToLogic(aPosPix);
108 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
110 if (nSlotId == SID_ZOOM_PANNING || (rMEvt.IsShift() && !bVisible) )
112 // Panning
114 Point aScroll = aBeginPos - aEndPos;
116 if (aScroll.X() != 0 || aScroll.Y() != 0)
118 Size aWorkSize = mpView->GetWorkArea().GetSize();
119 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
120 aScroll.setX( aScroll.X() / ( aWorkSize.Width() / aPageSize.Width()) );
121 aScroll.setY( aScroll.Y() / ( aWorkSize.Height() / aPageSize.Height()) );
122 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
123 aBeginPosPix = aPosPix;
126 else
128 ::tools::Rectangle aRect(aBeginPos, aEndPos);
129 aZoomRect = aRect;
130 aZoomRect.Justify();
131 mpViewShell->DrawMarkRect(aZoomRect);
132 bVisible = true;
136 return bStartDrag;
139 bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
141 // remember button state for creation of own MouseEvents
142 SetMouseButtonCode(rMEvt.GetButtons());
144 if (bVisible)
146 // Hide ZoomRect
147 mpViewShell->DrawMarkRect(aZoomRect);
148 bVisible = false;
151 Point aPosPix = rMEvt.GetPosPixel();
153 if(SID_ZOOM_PANNING != nSlotId && !rMEvt.IsShift())
155 // Zoom
156 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
157 sal_uLong nTol = DRGPIX + DRGPIX;
159 if ( ( aZoomSizePixel.Width() < static_cast<long>(nTol) && aZoomSizePixel.Height() < static_cast<long>(nTol) ) || rMEvt.IsMod1() )
161 // click at place: double zoom factor
162 Point aPos = mpWindow->PixelToLogic(aPosPix);
163 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
164 if ( rMEvt.IsMod1() )
166 aSize.setWidth( aSize.Width() * 2 );
167 aSize.setHeight( aSize.Height() * 2 );
169 else
171 aSize.setWidth( aSize.Width() / 2 );
172 aSize.setHeight( aSize.Height() / 2 );
174 aPos.AdjustX( -(aSize.Width() / 2) );
175 aPos.AdjustY( -(aSize.Height() / 2) );
176 aZoomRect.SetPos(aPos);
177 aZoomRect.SetSize(aSize);
180 mpViewShell->SetZoomRect(aZoomRect);
181 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
184 ::tools::Rectangle aVisAreaWin = mpWindow->PixelToLogic(::tools::Rectangle(Point(0,0),
185 mpWindow->GetOutputSizePixel()));
186 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
188 bStartDrag = false;
189 mpWindow->ReleaseMouse();
191 return true;
194 void FuZoom::Activate()
196 aPtr = mpWindow->GetPointer();
198 if (nSlotId == SID_ZOOM_PANNING)
200 mpWindow->SetPointer(Pointer(PointerStyle::Hand));
202 else
204 mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
208 void FuZoom::Deactivate()
210 mpWindow->SetPointer( aPtr );
211 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
213 } // end of namespace sd
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */