bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuzoom.cxx
blob254396ed4b0875118ddfd9342680062f56fe95be
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 sal_uInt16 SidArrayZoom[] = {
38 SID_ATTR_ZOOM,
39 SID_ZOOM_OUT,
40 SID_ZOOM_IN,
41 0 };
43 TYPEINIT1( FuZoom, FuPoor );
45 FuZoom::FuZoom(
46 ViewShell* pViewSh,
47 ::sd::Window* pWin,
48 ::sd::View* pView,
49 SdDrawDocument* pDoc,
50 SfxRequest& rReq)
51 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
52 bVisible(sal_False),
53 bStartDrag(sal_False)
57 FuZoom::~FuZoom()
59 if (bVisible)
61 // Hide ZoomRect
62 mpViewShell->DrawMarkRect(aZoomRect);
64 bVisible = sal_False;
65 bStartDrag = sal_False;
69 FunctionReference FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
71 FunctionReference xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
72 return xFunc;
75 sal_Bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
77 // remember button state for creation of own MouseEvents
78 SetMouseButtonCode(rMEvt.GetButtons());
80 mpWindow->CaptureMouse();
81 bStartDrag = sal_True;
83 aBeginPosPix = rMEvt.GetPosPixel();
84 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
86 return sal_True;
89 sal_Bool FuZoom::MouseMove(const MouseEvent& rMEvt)
91 if (bStartDrag)
93 if (bVisible)
95 mpViewShell->DrawMarkRect(aZoomRect);
98 Point aPosPix = rMEvt.GetPosPixel();
99 ForceScroll(aPosPix);
101 aEndPos = mpWindow->PixelToLogic(aPosPix);
102 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
104 if (nSlotId == SID_ZOOM_PANNING)
106 // Panning
108 Point aScroll = aBeginPos - aEndPos;
110 if (aScroll.X() != 0 || aScroll.Y() != 0)
112 Size aWorkSize = mpView->GetWorkArea().GetSize();
113 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
114 aScroll.X() /= aWorkSize.Width() / aPageSize.Width();
115 aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
116 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
117 aBeginPosPix = aPosPix;
120 else
122 Rectangle aRect(aBeginPos, aEndPos);
123 aZoomRect = aRect;
124 aZoomRect.Justify();
125 mpViewShell->DrawMarkRect(aZoomRect);
128 bVisible = sal_True;
131 return bStartDrag;
134 sal_Bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
136 // remember button state for creation of own MouseEvents
137 SetMouseButtonCode(rMEvt.GetButtons());
139 if (bVisible)
141 // Hide ZoomRect
142 mpViewShell->DrawMarkRect(aZoomRect);
143 bVisible = sal_False;
146 Point aPosPix = rMEvt.GetPosPixel();
148 if(SID_ZOOM_PANNING != nSlotId)
150 // Zoom
151 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
152 sal_uLong nTol = DRGPIX + DRGPIX;
154 if ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol )
156 // click at place: double zoom factor
157 Point aPos = mpWindow->PixelToLogic(aPosPix);
158 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
159 aSize.Width() /= 2;
160 aSize.Height() /= 2;
161 aPos.X() -= aSize.Width() / 2;
162 aPos.Y() -= aSize.Height() / 2;
163 aZoomRect.SetPos(aPos);
164 aZoomRect.SetSize(aSize);
167 mpViewShell->SetZoomRect(aZoomRect);
170 Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
171 mpWindow->GetOutputSizePixel()));
172 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
174 bStartDrag = sal_False;
175 mpWindow->ReleaseMouse();
176 mpViewShell->Cancel();
178 return sal_True;
181 void FuZoom::Activate()
183 aPtr = mpWindow->GetPointer();
185 if (nSlotId == SID_ZOOM_PANNING)
187 mpWindow->SetPointer(Pointer(POINTER_HAND));
189 else
191 mpWindow->SetPointer(Pointer(POINTER_MAGNIFY));
195 void FuZoom::Deactivate()
197 mpWindow->SetPointer( aPtr );
198 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
200 } // end of namespace sd
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */