LibreOffice Module sd (master) 1
fuzoom.cxx
Go to the documentation of this file.
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 <fuzoom.hxx>
21
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>
28
29#include <ViewShell.hxx>
30#include <View.hxx>
31#include <Window.hxx>
32#include <zoomlist.hxx>
33
34namespace sd {
35
36const sal_uInt16 SidArrayZoom[] = {
37 SID_ATTR_ZOOM,
38 SID_ZOOM_OUT,
39 SID_ZOOM_IN,
40 0 };
41
42
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)
53{
54}
55
57{
58 if (bVisible)
59 {
60 // Hide ZoomRect
62
63 bVisible = false;
64 bStartDrag = false;
65 }
66}
67
69{
70 rtl::Reference<FuPoor> xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
71 return xFunc;
72}
73
75{
76 // remember button state for creation of own MouseEvents
78
79 mpWindow->CaptureMouse();
80 bStartDrag = true;
81
82 aBeginPosPix = rMEvt.GetPosPixel();
83 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
84 aZoomRect.SetSize( Size( 0, 0 ) );
86
87 return true;
88}
89
90bool FuZoom::MouseMove(const MouseEvent& rMEvt)
91{
92 if (rMEvt.IsShift())
93 mpWindow->SetPointer(PointerStyle::Hand);
94 else if (nSlotId != SID_ZOOM_PANNING)
95 mpWindow->SetPointer(PointerStyle::Magnify);
96
97 if (bStartDrag)
98 {
99 if (bVisible)
100 {
102 }
103
104 Point aPosPix = rMEvt.GetPosPixel();
105 ForceScroll(aPosPix);
106
107 aEndPos = mpWindow->PixelToLogic(aPosPix);
108 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
109
110 if (nSlotId == SID_ZOOM_PANNING || (rMEvt.IsShift() && !bVisible) )
111 {
112 // Panning
113
114 Point aScroll = aBeginPos - aEndPos;
115
116 if (aScroll.X() != 0 || aScroll.Y() != 0)
117 {
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)
122 {
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;
127 }
128 }
129 }
130 else
131 {
133 aZoomRect = aRect;
136 bVisible = true;
137 }
138 }
139
140 return bStartDrag;
141}
142
144{
145 // remember button state for creation of own MouseEvents
147
148 if (bVisible)
149 {
150 // Hide ZoomRect
152 bVisible = false;
153 }
154
155 Point aPosPix = rMEvt.GetPosPixel();
156
157 if(SID_ZOOM_PANNING != nSlotId && !rMEvt.IsShift())
158 {
159 // Zoom
160 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
162
163 if ( ( aZoomSizePixel.Width() < static_cast<::tools::Long>(nTol) && aZoomSizePixel.Height() < static_cast<::tools::Long>(nTol) ) || rMEvt.IsMod1() )
164 {
165 // click at place: double zoom factor
166 Point aPos = mpWindow->PixelToLogic(aPosPix);
167 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
168 if ( rMEvt.IsMod1() )
169 {
170 aSize.setWidth( aSize.Width() * 2 );
171 aSize.setHeight( aSize.Height() * 2 );
172 }
173 else
174 {
175 aSize.setWidth( aSize.Width() / 2 );
176 aSize.setHeight( aSize.Height() / 2 );
177 }
178 aPos.AdjustX( -(aSize.Width() / 2) );
179 aPos.AdjustY( -(aSize.Height() / 2) );
180 aZoomRect.SetPos(aPos);
181 aZoomRect.SetSize(aSize);
182 }
183
186 }
187
188 ::tools::Rectangle aVisAreaWin = mpWindow->PixelToLogic(::tools::Rectangle(Point(0,0),
189 mpWindow->GetOutputSizePixel()));
190 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
191
192 bStartDrag = false;
193 mpWindow->ReleaseMouse();
194
195 return true;
196}
197
199{
200 aPtr = mpWindow->GetPointer();
201
202 if (nSlotId == SID_ZOOM_PANNING)
203 {
204 mpWindow->SetPointer(PointerStyle::Hand);
205 }
206 else
207 {
208 mpWindow->SetPointer(PointerStyle::Magnify);
209 }
210}
211
213{
214 mpWindow->SetPointer( aPtr );
216}
217} // end of namespace sd
218
219/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsMod1() const
sal_uInt16 GetButtons() const
const Point & GetPosPixel() const
bool IsShift() const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
const tools::Rectangle & GetWorkArea() const
sal_Int32 GetDragThresholdPixels() const
SdrPage * GetPage() const
Size GetSize() const
SdrPageView * GetSdrPageView() const
void Invalidate(sal_uInt16 nId)
SfxBindings & GetBindings()
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
Base class for all functions.
Definition: fupoor.hxx:48
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
ViewShell * mpViewShell
Definition: fupoor.hxx:145
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:57
sal_uInt16 nSlotId
Definition: fupoor.hxx:150
void ForceScroll(const Point &aPixPos)
scroll when approached the border of the window; is called by MouseMove
Definition: fupoor.cxx:121
::sd::View * mpView
Definition: fupoor.hxx:144
PointerStyle aPtr
Definition: fuzoom.hxx:52
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuzoom.cxx:74
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuzoom.cxx:68
Point aBeginPos
Definition: fuzoom.hxx:47
virtual void Deactivate() override
deactivates the function
Definition: fuzoom.cxx:212
virtual void Activate() override
activates the function
Definition: fuzoom.cxx:198
Point aEndPos
Definition: fuzoom.hxx:48
bool bVisible
Definition: fuzoom.hxx:50
FuZoom(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuzoom.cxx:43
bool bStartDrag
Definition: fuzoom.hxx:51
::tools::Rectangle aZoomRect
Definition: fuzoom.hxx:49
Point aBeginPosPix
Definition: fuzoom.hxx:46
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuzoom.cxx:90
virtual ~FuZoom() override
Definition: fuzoom.cxx:56
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuzoom.cxx:143
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
void DrawMarkRect(const ::tools::Rectangle &rRect) const
Draw a selection rectangle with the ?provided pen on all split windows.
Definition: viewshe2.cxx:442
void Scroll(::tools::Long nX, ::tools::Long nY)
Definition: viewshe2.cxx:265
virtual void SetZoomRect(const ::tools::Rectangle &rZoomRect)
Set zoom rectangle for active window.
Definition: viewshe2.cxx:358
ZoomList * GetZoomList()
Definition: ViewShell.hxx:219
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
void InsertZoomRect(const ::tools::Rectangle &rRect)
Definition: zoomlist.cxx:38
void SetSize(const Size &)
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
const sal_uInt16 SidArrayZoom[]
Definition: fuzoom.cxx:36
long Long
PointerStyle
sal_uIntPtr sal_uLong
bool bVisible