Line data Source code
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 :
28 : #include "FrameView.hxx"
29 : #include "ViewShell.hxx"
30 : #include "View.hxx"
31 : #include "Window.hxx"
32 : #include "drawdoc.hxx"
33 : #include "zoomlist.hxx"
34 :
35 : namespace sd {
36 :
37 : sal_uInt16 SidArrayZoom[] = {
38 : SID_ATTR_ZOOM,
39 : SID_ZOOM_OUT,
40 : SID_ZOOM_IN,
41 : 0 };
42 :
43 0 : TYPEINIT1( FuZoom, FuPoor );
44 :
45 : /*************************************************************************
46 : |*
47 : |* Konstruktor
48 : |*
49 : \************************************************************************/
50 :
51 0 : FuZoom::FuZoom(
52 : ViewShell* pViewSh,
53 : ::sd::Window* pWin,
54 : ::sd::View* pView,
55 : SdDrawDocument* pDoc,
56 : SfxRequest& rReq)
57 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
58 : bVisible(sal_False),
59 0 : bStartDrag(sal_False)
60 : {
61 0 : }
62 :
63 : /*************************************************************************
64 : |*
65 : |* Destruktor
66 : |*
67 : \************************************************************************/
68 :
69 0 : FuZoom::~FuZoom()
70 : {
71 0 : if (bVisible)
72 : {
73 : // Hide ZoomRect
74 0 : mpViewShell->DrawMarkRect(aZoomRect);
75 :
76 0 : bVisible = sal_False;
77 0 : bStartDrag = sal_False;
78 : }
79 0 : }
80 :
81 0 : FunctionReference FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
82 : {
83 0 : FunctionReference xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
84 0 : return xFunc;
85 : }
86 :
87 : /*************************************************************************
88 : |*
89 : |* MouseButtonDown-event
90 : |*
91 : \************************************************************************/
92 :
93 0 : sal_Bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
94 : {
95 : // remember button state for creation of own MouseEvents
96 0 : SetMouseButtonCode(rMEvt.GetButtons());
97 :
98 0 : mpWindow->CaptureMouse();
99 0 : bStartDrag = sal_True;
100 :
101 0 : aBeginPosPix = rMEvt.GetPosPixel();
102 0 : aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
103 :
104 0 : return sal_True;
105 : }
106 :
107 : /*************************************************************************
108 : |*
109 : |* MouseMove-event
110 : |*
111 : \************************************************************************/
112 :
113 0 : sal_Bool FuZoom::MouseMove(const MouseEvent& rMEvt)
114 : {
115 0 : if (bStartDrag)
116 : {
117 0 : if (bVisible)
118 : {
119 0 : mpViewShell->DrawMarkRect(aZoomRect);
120 : }
121 :
122 0 : Point aPosPix = rMEvt.GetPosPixel();
123 0 : ForceScroll(aPosPix);
124 :
125 0 : aEndPos = mpWindow->PixelToLogic(aPosPix);
126 0 : aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
127 :
128 0 : if (nSlotId == SID_ZOOM_PANNING)
129 : {
130 : // Panning
131 :
132 0 : Point aScroll = aBeginPos - aEndPos;
133 :
134 0 : if (aScroll.X() != 0 || aScroll.Y() != 0)
135 : {
136 0 : Size aWorkSize = mpView->GetWorkArea().GetSize();
137 0 : Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
138 0 : aScroll.X() /= aWorkSize.Width() / aPageSize.Width();
139 0 : aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
140 0 : mpViewShell->Scroll(aScroll.X(), aScroll.Y());
141 0 : aBeginPosPix = aPosPix;
142 : }
143 : }
144 : else
145 : {
146 0 : Rectangle aRect(aBeginPos, aEndPos);
147 0 : aZoomRect = aRect;
148 0 : aZoomRect.Justify();
149 0 : mpViewShell->DrawMarkRect(aZoomRect);
150 : }
151 :
152 0 : bVisible = sal_True;
153 : }
154 :
155 0 : return bStartDrag;
156 : }
157 :
158 : /*************************************************************************
159 : |*
160 : |* MouseButtonUp-event
161 : |*
162 : \************************************************************************/
163 :
164 0 : sal_Bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
165 : {
166 : // remember button state for creation of own MouseEvents
167 0 : SetMouseButtonCode(rMEvt.GetButtons());
168 :
169 0 : if (bVisible)
170 : {
171 : // Hide ZoomRect
172 0 : mpViewShell->DrawMarkRect(aZoomRect);
173 0 : bVisible = sal_False;
174 : }
175 :
176 0 : Point aPosPix = rMEvt.GetPosPixel();
177 :
178 0 : if(SID_ZOOM_PANNING != nSlotId)
179 : {
180 : // Zoom
181 0 : Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
182 0 : sal_uLong nTol = DRGPIX + DRGPIX;
183 :
184 0 : if ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol )
185 : {
186 : // Klick auf der Stelle: Zoomfaktor verdoppeln
187 0 : Point aPos = mpWindow->PixelToLogic(aPosPix);
188 0 : Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
189 0 : aSize.Width() /= 2;
190 0 : aSize.Height() /= 2;
191 0 : aPos.X() -= aSize.Width() / 2;
192 0 : aPos.Y() -= aSize.Height() / 2;
193 0 : aZoomRect.SetPos(aPos);
194 0 : aZoomRect.SetSize(aSize);
195 : }
196 :
197 0 : mpViewShell->SetZoomRect(aZoomRect);
198 : }
199 :
200 : Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
201 0 : mpWindow->GetOutputSizePixel()));
202 0 : mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
203 :
204 0 : bStartDrag = sal_False;
205 0 : mpWindow->ReleaseMouse();
206 0 : mpViewShell->Cancel();
207 :
208 0 : return sal_True;
209 : }
210 :
211 : /*************************************************************************
212 : |*
213 : |* Function aktivieren
214 : |*
215 : \************************************************************************/
216 :
217 0 : void FuZoom::Activate()
218 : {
219 0 : aPtr = mpWindow->GetPointer();
220 :
221 0 : if (nSlotId == SID_ZOOM_PANNING)
222 : {
223 0 : mpWindow->SetPointer(Pointer(POINTER_HAND));
224 : }
225 : else
226 : {
227 0 : mpWindow->SetPointer(Pointer(POINTER_MAGNIFY));
228 : }
229 0 : }
230 :
231 : /*************************************************************************
232 : |*
233 : |* Function deaktivieren
234 : |*
235 : \************************************************************************/
236 :
237 0 : void FuZoom::Deactivate()
238 : {
239 0 : mpWindow->SetPointer( aPtr );
240 0 : mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
241 0 : }
242 : } // end of namespace sd
243 :
244 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|