bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuzoom.cxx
blob782c32e5ab448ae5926f9eadf361640ba07fd438
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(false),
53 bStartDrag(false)
57 FuZoom::~FuZoom()
59 if (bVisible)
61 // Hide ZoomRect
62 mpViewShell->DrawMarkRect(aZoomRect);
64 bVisible = false;
65 bStartDrag = false;
69 rtl::Reference<FuPoor> FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
71 rtl::Reference<FuPoor> xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
72 return xFunc;
75 bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
77 // remember button state for creation of own MouseEvents
78 SetMouseButtonCode(rMEvt.GetButtons());
80 mpWindow->CaptureMouse();
81 bStartDrag = true;
83 aBeginPosPix = rMEvt.GetPosPixel();
84 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
85 aZoomRect.SetSize( Size( 0, 0 ) );
86 aZoomRect.SetPos( aBeginPos );
88 return true;
91 bool FuZoom::MouseMove(const MouseEvent& rMEvt)
93 if (rMEvt.IsShift())
94 mpWindow->SetPointer(Pointer(PointerStyle::Hand));
95 else if (nSlotId != SID_ZOOM_PANNING)
96 mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
98 if (bStartDrag)
100 if (bVisible)
102 mpViewShell->DrawMarkRect(aZoomRect);
105 Point aPosPix = rMEvt.GetPosPixel();
106 ForceScroll(aPosPix);
108 aEndPos = mpWindow->PixelToLogic(aPosPix);
109 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
111 if (nSlotId == SID_ZOOM_PANNING || (rMEvt.IsShift() && !bVisible) )
113 // Panning
115 Point aScroll = aBeginPos - aEndPos;
117 if (aScroll.X() != 0 || aScroll.Y() != 0)
119 Size aWorkSize = mpView->GetWorkArea().GetSize();
120 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
121 aScroll.X() /= aWorkSize.Width() / aPageSize.Width();
122 aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
123 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
124 aBeginPosPix = aPosPix;
127 else
129 Rectangle aRect(aBeginPos, aEndPos);
130 aZoomRect = aRect;
131 aZoomRect.Justify();
132 mpViewShell->DrawMarkRect(aZoomRect);
133 bVisible = true;
137 return bStartDrag;
140 bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
142 // remember button state for creation of own MouseEvents
143 SetMouseButtonCode(rMEvt.GetButtons());
145 if (bVisible)
147 // Hide ZoomRect
148 mpViewShell->DrawMarkRect(aZoomRect);
149 bVisible = false;
152 Point aPosPix = rMEvt.GetPosPixel();
154 if(SID_ZOOM_PANNING != nSlotId && !rMEvt.IsShift())
156 // Zoom
157 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
158 sal_uLong nTol = DRGPIX + DRGPIX;
160 if ( ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol ) || rMEvt.IsMod1() )
162 // click at place: double zoom factor
163 Point aPos = mpWindow->PixelToLogic(aPosPix);
164 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
165 if ( rMEvt.IsMod1() )
167 aSize.Width() *= 2;
168 aSize.Height() *= 2;
170 else
172 aSize.Width() /= 2;
173 aSize.Height() /= 2;
175 aPos.X() -= aSize.Width() / 2;
176 aPos.Y() -= aSize.Height() / 2;
177 aZoomRect.SetPos(aPos);
178 aZoomRect.SetSize(aSize);
181 mpViewShell->SetZoomRect(aZoomRect);
182 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
185 Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
186 mpWindow->GetOutputSizePixel()));
187 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
189 bStartDrag = false;
190 mpWindow->ReleaseMouse();
192 return true;
195 void FuZoom::Activate()
197 aPtr = mpWindow->GetPointer();
199 if (nSlotId == SID_ZOOM_PANNING)
201 mpWindow->SetPointer(Pointer(PointerStyle::Hand));
203 else
205 mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
209 void FuZoom::Deactivate()
211 mpWindow->SetPointer( aPtr );
212 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
214 } // end of namespace sd
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */