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