tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / func / fuzoom.cxx
blob2c966daa2e326c855b2dd8fdf02947fd52b9b794
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>
27 #include <vcl/ptrstyle.hxx>
29 #include <ViewShell.hxx>
30 #include <View.hxx>
31 #include <Window.hxx>
32 #include <zoomlist.hxx>
34 namespace sd {
36 const sal_uInt16 SidArrayZoom[] = {
37 SID_ATTR_ZOOM,
38 SID_ZOOM_OUT,
39 SID_ZOOM_IN,
40 0 };
43 FuZoom::FuZoom(
44 ViewShell* pViewSh,
45 ::sd::Window* pWin,
46 ::sd::View* pView,
47 SdDrawDocument* pDoc,
48 SfxRequest& rReq)
49 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
50 bVisible(false),
51 bStartDrag(false),
52 aPtr(PointerStyle::Arrow)
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(PointerStyle::Hand);
94 else if (nSlotId != SID_ZOOM_PANNING)
95 mpWindow->SetPointer(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 if (aWorkSize.Width() != 0 && aWorkSize.Height() != 0 &&
121 aPageSize.Width() != 0 && aPageSize.Height() != 0)
123 aScroll.setX( aScroll.X() / ( aWorkSize.Width() / aPageSize.Width()) );
124 aScroll.setY( aScroll.Y() / ( aWorkSize.Height() / aPageSize.Height()) );
125 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
126 aBeginPosPix = aPosPix;
130 else
132 ::tools::Rectangle aRect(aBeginPos, aEndPos);
133 aZoomRect = aRect;
134 aZoomRect.Normalize();
135 mpViewShell->DrawMarkRect(aZoomRect);
136 bVisible = true;
140 return bStartDrag;
143 bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
145 // remember button state for creation of own MouseEvents
146 SetMouseButtonCode(rMEvt.GetButtons());
148 if (bVisible)
150 // Hide ZoomRect
151 mpViewShell->DrawMarkRect(aZoomRect);
152 bVisible = false;
155 Point aPosPix = rMEvt.GetPosPixel();
157 if(SID_ZOOM_PANNING != nSlotId && !rMEvt.IsShift())
159 // Zoom
160 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
161 sal_uLong nTol = 2 * mpView->GetDragThresholdPixels();
163 if ( ( aZoomSizePixel.Width() < static_cast<::tools::Long>(nTol) && aZoomSizePixel.Height() < static_cast<::tools::Long>(nTol) ) || rMEvt.IsMod1() )
165 // click at place: double zoom factor
166 Point aPos = mpWindow->PixelToLogic(aPosPix);
167 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
168 if ( rMEvt.IsMod1() )
170 aSize.setWidth( aSize.Width() * 2 );
171 aSize.setHeight( aSize.Height() * 2 );
173 else
175 aSize.setWidth( aSize.Width() / 2 );
176 aSize.setHeight( aSize.Height() / 2 );
178 aPos.AdjustX( -(aSize.Width() / 2) );
179 aPos.AdjustY( -(aSize.Height() / 2) );
180 aZoomRect.SetPos(aPos);
181 aZoomRect.SetSize(aSize);
184 mpViewShell->SetZoomRect(aZoomRect);
185 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
188 ::tools::Rectangle aVisAreaWin = mpWindow->PixelToLogic(::tools::Rectangle(Point(0,0),
189 mpWindow->GetOutputSizePixel()));
190 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
192 bStartDrag = false;
193 mpWindow->ReleaseMouse();
195 return true;
198 void FuZoom::Activate()
200 aPtr = mpWindow->GetPointer();
202 if (nSlotId == SID_ZOOM_PANNING)
204 mpWindow->SetPointer(PointerStyle::Hand);
206 else
208 mpWindow->SetPointer(PointerStyle::Magnify);
212 void FuZoom::Deactivate()
214 mpWindow->SetPointer( aPtr );
215 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
217 } // end of namespace sd
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */