xref: /aoo41x/main/sd/source/ui/func/fuzoom.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "fuzoom.hxx"
33 
34 #include <svx/svxids.hrc>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include "app.hrc"
38 #include <svx/svdpagv.hxx>
39 
40 #ifndef SD_FRAMW_VIEW_HXX
41 #include "FrameView.hxx"
42 #endif
43 #include "ViewShell.hxx"
44 #include "View.hxx"
45 #ifndef SD_WINDOW_SHELL_HXX
46 #include "Window.hxx"
47 #endif
48 #include "drawdoc.hxx"
49 #include "zoomlist.hxx"
50 
51 namespace sd {
52 
53 sal_uInt16 SidArrayZoom[] = {
54 					SID_ATTR_ZOOM,
55 					SID_ZOOM_OUT,
56 					SID_ZOOM_IN,
57 					0 };
58 
59 TYPEINIT1( FuZoom, FuPoor );
60 
61 /*************************************************************************
62 |*
63 |* Konstruktor
64 |*
65 \************************************************************************/
66 
67 FuZoom::FuZoom(
68     ViewShell* pViewSh,
69     ::sd::Window* pWin,
70     ::sd::View* pView,
71     SdDrawDocument*	pDoc,
72     SfxRequest& rReq)
73     : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
74       bVisible(sal_False),
75       bStartDrag(sal_False)
76 {
77 }
78 
79 /*************************************************************************
80 |*
81 |* Destruktor
82 |*
83 \************************************************************************/
84 
85 FuZoom::~FuZoom()
86 {
87 	if (bVisible)
88 	{
89 		// Hide ZoomRect
90 		mpViewShell->DrawMarkRect(aZoomRect);
91 
92 		bVisible = sal_False;
93 		bStartDrag = sal_False;
94 	}
95 }
96 
97 FunctionReference FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
98 {
99 	FunctionReference xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
100 	return xFunc;
101 }
102 
103 /*************************************************************************
104 |*
105 |* MouseButtonDown-event
106 |*
107 \************************************************************************/
108 
109 sal_Bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
110 {
111 	// #95491# remember button state for creation of own MouseEvents
112 	SetMouseButtonCode(rMEvt.GetButtons());
113 
114 	mpWindow->CaptureMouse();
115 	bStartDrag = sal_True;
116 
117 	aBeginPosPix = rMEvt.GetPosPixel();
118 	aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
119 
120 	return sal_True;
121 }
122 
123 /*************************************************************************
124 |*
125 |* MouseMove-event
126 |*
127 \************************************************************************/
128 
129 sal_Bool FuZoom::MouseMove(const MouseEvent& rMEvt)
130 {
131 	if (bStartDrag)
132 	{
133 		if (bVisible)
134 		{
135 			mpViewShell->DrawMarkRect(aZoomRect);
136 		}
137 
138 		Point aPosPix = rMEvt.GetPosPixel();
139 		ForceScroll(aPosPix);
140 
141 		aEndPos = mpWindow->PixelToLogic(aPosPix);
142 		aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
143 
144 		if (nSlotId == SID_ZOOM_PANNING)
145 		{
146 			// Panning
147 
148 			Point aScroll = aBeginPos - aEndPos;
149 
150 			// #i2237#
151 			// removed old stuff here which still forced zoom to be
152 			// %BRUSH_SIZE which is outdated now
153 
154 			if (aScroll.X() != 0 || aScroll.Y() != 0)
155 			{
156 				Size aWorkSize = mpView->GetWorkArea().GetSize();
157 				Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
158 				aScroll.X() /= aWorkSize.Width()  / aPageSize.Width();
159 				aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
160 				mpViewShell->Scroll(aScroll.X(), aScroll.Y());
161 				aBeginPosPix = aPosPix;
162 			}
163 		}
164 		else
165 		{
166 			Rectangle aRect(aBeginPos, aEndPos);
167 			aZoomRect = aRect;
168 			aZoomRect.Justify();
169 			mpViewShell->DrawMarkRect(aZoomRect);
170 		}
171 
172 		bVisible = sal_True;
173 	}
174 
175 	return bStartDrag;
176 }
177 
178 /*************************************************************************
179 |*
180 |* MouseButtonUp-event
181 |*
182 \************************************************************************/
183 
184 sal_Bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
185 {
186 	// #95491# remember button state for creation of own MouseEvents
187 	SetMouseButtonCode(rMEvt.GetButtons());
188 
189 	if (bVisible)
190 	{
191 		// Hide ZoomRect
192 		mpViewShell->DrawMarkRect(aZoomRect);
193 		bVisible = sal_False;
194 	}
195 
196 	Point aPosPix = rMEvt.GetPosPixel();
197 
198 	if(SID_ZOOM_PANNING != nSlotId)
199 	{
200 		// Zoom
201 		Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
202 		sal_uLong nTol = DRGPIX + DRGPIX;
203 
204 		if ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol )
205 		{
206 			// Klick auf der Stelle: Zoomfaktor verdoppeln
207 			Point aPos = mpWindow->PixelToLogic(aPosPix);
208 			Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
209 			aSize.Width() /= 2;
210 			aSize.Height() /= 2;
211 			aPos.X() -= aSize.Width() / 2;
212 			aPos.Y() -= aSize.Height() / 2;
213 			aZoomRect.SetPos(aPos);
214 			aZoomRect.SetSize(aSize);
215 		}
216 
217 		mpViewShell->SetZoomRect(aZoomRect);
218 	}
219 
220 	Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
221 										   mpWindow->GetOutputSizePixel()));
222 	mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
223 
224 	bStartDrag = sal_False;
225 	mpWindow->ReleaseMouse();
226 	mpViewShell->Cancel();
227 
228 	return sal_True;
229 }
230 
231 /*************************************************************************
232 |*
233 |* Function aktivieren
234 |*
235 \************************************************************************/
236 
237 void FuZoom::Activate()
238 {
239 	aPtr = mpWindow->GetPointer();
240 
241 	if (nSlotId == SID_ZOOM_PANNING)
242 	{
243 		mpWindow->SetPointer(Pointer(POINTER_HAND));
244 	}
245 	else
246 	{
247 		mpWindow->SetPointer(Pointer(POINTER_MAGNIFY));
248 	}
249 }
250 
251 /*************************************************************************
252 |*
253 |* Function deaktivieren
254 |*
255 \************************************************************************/
256 
257 void FuZoom::Deactivate()
258 {
259 	mpWindow->SetPointer( aPtr );
260 	mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
261 }
262 } // end of namespace sd
263