merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / func / fuzoom.cxx
blobf2dea7cef2da2c1b4fa1324995f537df182526c0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuzoom.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
35 #include "fuzoom.hxx"
37 #include <svx/svxids.hrc>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include "app.hrc"
41 #include <svx/svdpagv.hxx>
43 #ifndef SD_FRAMW_VIEW_HXX
44 #include "FrameView.hxx"
45 #endif
46 #include "ViewShell.hxx"
47 #include "View.hxx"
48 #ifndef SD_WINDOW_SHELL_HXX
49 #include "Window.hxx"
50 #endif
51 #include "drawdoc.hxx"
52 #include "zoomlist.hxx"
54 namespace sd {
56 USHORT SidArrayZoom[] = {
57 SID_ATTR_ZOOM,
58 SID_ZOOM_OUT,
59 SID_ZOOM_IN,
60 0 };
62 TYPEINIT1( FuZoom, FuPoor );
64 /*************************************************************************
66 |* Konstruktor
68 \************************************************************************/
70 FuZoom::FuZoom(
71 ViewShell* pViewSh,
72 ::sd::Window* pWin,
73 ::sd::View* pView,
74 SdDrawDocument* pDoc,
75 SfxRequest& rReq)
76 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
77 bVisible(FALSE),
78 bStartDrag(FALSE)
82 /*************************************************************************
84 |* Destruktor
86 \************************************************************************/
88 FuZoom::~FuZoom()
90 if (bVisible)
92 // Hide ZoomRect
93 mpViewShell->DrawMarkRect(aZoomRect);
95 bVisible = FALSE;
96 bStartDrag = FALSE;
100 FunctionReference FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
102 FunctionReference xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
103 return xFunc;
106 /*************************************************************************
108 |* MouseButtonDown-event
110 \************************************************************************/
112 BOOL FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
114 // #95491# remember button state for creation of own MouseEvents
115 SetMouseButtonCode(rMEvt.GetButtons());
117 mpWindow->CaptureMouse();
118 bStartDrag = TRUE;
120 aBeginPosPix = rMEvt.GetPosPixel();
121 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
123 return TRUE;
126 /*************************************************************************
128 |* MouseMove-event
130 \************************************************************************/
132 BOOL FuZoom::MouseMove(const MouseEvent& rMEvt)
134 if (bStartDrag)
136 if (bVisible)
138 mpViewShell->DrawMarkRect(aZoomRect);
141 Point aPosPix = rMEvt.GetPosPixel();
142 ForceScroll(aPosPix);
144 aEndPos = mpWindow->PixelToLogic(aPosPix);
145 aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
147 if (nSlotId == SID_ZOOM_PANNING)
149 // Panning
151 Point aScroll = aBeginPos - aEndPos;
153 // #i2237#
154 // removed old stuff here which still forced zoom to be
155 // %BRUSH_SIZE which is outdated now
157 if (aScroll.X() != 0 || aScroll.Y() != 0)
159 Size aWorkSize = mpView->GetWorkArea().GetSize();
160 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
161 aScroll.X() /= aWorkSize.Width() / aPageSize.Width();
162 aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
163 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
164 aBeginPosPix = aPosPix;
167 else
169 Rectangle aRect(aBeginPos, aEndPos);
170 aZoomRect = aRect;
171 aZoomRect.Justify();
172 mpViewShell->DrawMarkRect(aZoomRect);
175 bVisible = TRUE;
178 return bStartDrag;
181 /*************************************************************************
183 |* MouseButtonUp-event
185 \************************************************************************/
187 BOOL FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
189 // #95491# remember button state for creation of own MouseEvents
190 SetMouseButtonCode(rMEvt.GetButtons());
192 if (bVisible)
194 // Hide ZoomRect
195 mpViewShell->DrawMarkRect(aZoomRect);
196 bVisible = FALSE;
199 Point aPosPix = rMEvt.GetPosPixel();
201 if(SID_ZOOM_PANNING != nSlotId)
203 // Zoom
204 Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
205 ULONG nTol = DRGPIX + DRGPIX;
207 if ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol )
209 // Klick auf der Stelle: Zoomfaktor verdoppeln
210 Point aPos = mpWindow->PixelToLogic(aPosPix);
211 Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
212 aSize.Width() /= 2;
213 aSize.Height() /= 2;
214 aPos.X() -= aSize.Width() / 2;
215 aPos.Y() -= aSize.Height() / 2;
216 aZoomRect.SetPos(aPos);
217 aZoomRect.SetSize(aSize);
220 mpViewShell->SetZoomRect(aZoomRect);
223 Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
224 mpWindow->GetOutputSizePixel()));
225 mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
227 bStartDrag = FALSE;
228 mpWindow->ReleaseMouse();
229 mpViewShell->Cancel();
231 return TRUE;
234 /*************************************************************************
236 |* Function aktivieren
238 \************************************************************************/
240 void FuZoom::Activate()
242 aPtr = mpWindow->GetPointer();
244 if (nSlotId == SID_ZOOM_PANNING)
246 mpWindow->SetPointer(Pointer(POINTER_HAND));
248 else
250 mpWindow->SetPointer(Pointer(POINTER_MAGNIFY));
254 /*************************************************************************
256 |* Function deaktivieren
258 \************************************************************************/
260 void FuZoom::Deactivate()
262 mpWindow->SetPointer( aPtr );
263 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
265 } // end of namespace sd