1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <svx/svxids.hrc>
23 #include <sfx2/bindings.hxx>
24 #include <sfx2/viewfrm.hxx>
26 #include <svx/svdpagv.hxx>
28 #include "FrameView.hxx"
29 #include "ViewShell.hxx"
32 #include "drawdoc.hxx"
33 #include "zoomlist.hxx"
37 sal_uInt16 SidArrayZoom
[] = {
43 TYPEINIT1( FuZoom
, FuPoor
);
51 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
62 mpViewShell
->DrawMarkRect(aZoomRect
);
69 rtl::Reference
<FuPoor
> FuZoom::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
71 rtl::Reference
<FuPoor
> xFunc( new FuZoom( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
75 bool FuZoom::MouseButtonDown(const MouseEvent
& rMEvt
)
77 // remember button state for creation of own MouseEvents
78 SetMouseButtonCode(rMEvt
.GetButtons());
80 mpWindow
->CaptureMouse();
83 aBeginPosPix
= rMEvt
.GetPosPixel();
84 aBeginPos
= mpWindow
->PixelToLogic(aBeginPosPix
);
85 aZoomRect
.SetSize( Size( 0, 0 ) );
86 aZoomRect
.SetPos( aBeginPos
);
91 bool FuZoom::MouseMove(const MouseEvent
& rMEvt
)
94 mpWindow
->SetPointer(Pointer(PointerStyle::Hand
));
95 else if (nSlotId
!= SID_ZOOM_PANNING
)
96 mpWindow
->SetPointer(Pointer(PointerStyle::Magnify
));
102 mpViewShell
->DrawMarkRect(aZoomRect
);
105 Point aPosPix
= rMEvt
.GetPosPixel();
106 ForceScroll(aPosPix
);
108 aEndPos
= mpWindow
->PixelToLogic(aPosPix
);
109 aBeginPos
= mpWindow
->PixelToLogic(aBeginPosPix
);
111 if (nSlotId
== SID_ZOOM_PANNING
|| (rMEvt
.IsShift() && !bVisible
) )
115 Point aScroll
= aBeginPos
- aEndPos
;
117 if (aScroll
.X() != 0 || aScroll
.Y() != 0)
119 Size aWorkSize
= mpView
->GetWorkArea().GetSize();
120 Size aPageSize
= mpView
->GetSdrPageView()->GetPage()->GetSize();
121 aScroll
.X() /= aWorkSize
.Width() / aPageSize
.Width();
122 aScroll
.Y() /= aWorkSize
.Height() / aPageSize
.Height();
123 mpViewShell
->Scroll(aScroll
.X(), aScroll
.Y());
124 aBeginPosPix
= aPosPix
;
129 Rectangle
aRect(aBeginPos
, aEndPos
);
132 mpViewShell
->DrawMarkRect(aZoomRect
);
140 bool FuZoom::MouseButtonUp(const MouseEvent
& rMEvt
)
142 // remember button state for creation of own MouseEvents
143 SetMouseButtonCode(rMEvt
.GetButtons());
148 mpViewShell
->DrawMarkRect(aZoomRect
);
152 Point aPosPix
= rMEvt
.GetPosPixel();
154 if(SID_ZOOM_PANNING
!= nSlotId
&& !rMEvt
.IsShift())
157 Size aZoomSizePixel
= mpWindow
->LogicToPixel(aZoomRect
).GetSize();
158 sal_uLong nTol
= DRGPIX
+ DRGPIX
;
160 if ( ( aZoomSizePixel
.Width() < (long) nTol
&& aZoomSizePixel
.Height() < (long) nTol
) || rMEvt
.IsMod1() )
162 // click at place: double zoom factor
163 Point aPos
= mpWindow
->PixelToLogic(aPosPix
);
164 Size aSize
= mpWindow
->PixelToLogic(mpWindow
->GetOutputSizePixel());
165 if ( rMEvt
.IsMod1() )
175 aPos
.X() -= aSize
.Width() / 2;
176 aPos
.Y() -= aSize
.Height() / 2;
177 aZoomRect
.SetPos(aPos
);
178 aZoomRect
.SetSize(aSize
);
181 mpViewShell
->SetZoomRect(aZoomRect
);
182 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
185 Rectangle aVisAreaWin
= mpWindow
->PixelToLogic(Rectangle(Point(0,0),
186 mpWindow
->GetOutputSizePixel()));
187 mpViewShell
->GetZoomList()->InsertZoomRect(aVisAreaWin
);
190 mpWindow
->ReleaseMouse();
195 void FuZoom::Activate()
197 aPtr
= mpWindow
->GetPointer();
199 if (nSlotId
== SID_ZOOM_PANNING
)
201 mpWindow
->SetPointer(Pointer(PointerStyle::Hand
));
205 mpWindow
->SetPointer(Pointer(PointerStyle::Magnify
));
209 void FuZoom::Deactivate()
211 mpWindow
->SetPointer( aPtr
);
212 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
214 } // end of namespace sd
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */