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 const sal_uInt16 SidArrayZoom
[] = {
50 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
61 mpViewShell
->DrawMarkRect(aZoomRect
);
68 rtl::Reference
<FuPoor
> FuZoom::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
70 rtl::Reference
<FuPoor
> xFunc( new FuZoom( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
74 bool FuZoom::MouseButtonDown(const MouseEvent
& rMEvt
)
76 // remember button state for creation of own MouseEvents
77 SetMouseButtonCode(rMEvt
.GetButtons());
79 mpWindow
->CaptureMouse();
82 aBeginPosPix
= rMEvt
.GetPosPixel();
83 aBeginPos
= mpWindow
->PixelToLogic(aBeginPosPix
);
84 aZoomRect
.SetSize( Size( 0, 0 ) );
85 aZoomRect
.SetPos( aBeginPos
);
90 bool FuZoom::MouseMove(const MouseEvent
& rMEvt
)
93 mpWindow
->SetPointer(Pointer(PointerStyle::Hand
));
94 else if (nSlotId
!= SID_ZOOM_PANNING
)
95 mpWindow
->SetPointer(Pointer(PointerStyle::Magnify
));
101 mpViewShell
->DrawMarkRect(aZoomRect
);
104 Point aPosPix
= rMEvt
.GetPosPixel();
105 ForceScroll(aPosPix
);
107 aEndPos
= mpWindow
->PixelToLogic(aPosPix
);
108 aBeginPos
= mpWindow
->PixelToLogic(aBeginPosPix
);
110 if (nSlotId
== SID_ZOOM_PANNING
|| (rMEvt
.IsShift() && !bVisible
) )
114 Point aScroll
= aBeginPos
- aEndPos
;
116 if (aScroll
.X() != 0 || aScroll
.Y() != 0)
118 Size aWorkSize
= mpView
->GetWorkArea().GetSize();
119 Size aPageSize
= mpView
->GetSdrPageView()->GetPage()->GetSize();
120 aScroll
.setX( aScroll
.X() / ( aWorkSize
.Width() / aPageSize
.Width()) );
121 aScroll
.setY( aScroll
.Y() / ( aWorkSize
.Height() / aPageSize
.Height()) );
122 mpViewShell
->Scroll(aScroll
.X(), aScroll
.Y());
123 aBeginPosPix
= aPosPix
;
128 ::tools::Rectangle
aRect(aBeginPos
, aEndPos
);
131 mpViewShell
->DrawMarkRect(aZoomRect
);
139 bool FuZoom::MouseButtonUp(const MouseEvent
& rMEvt
)
141 // remember button state for creation of own MouseEvents
142 SetMouseButtonCode(rMEvt
.GetButtons());
147 mpViewShell
->DrawMarkRect(aZoomRect
);
151 Point aPosPix
= rMEvt
.GetPosPixel();
153 if(SID_ZOOM_PANNING
!= nSlotId
&& !rMEvt
.IsShift())
156 Size aZoomSizePixel
= mpWindow
->LogicToPixel(aZoomRect
).GetSize();
157 sal_uLong nTol
= DRGPIX
+ DRGPIX
;
159 if ( ( aZoomSizePixel
.Width() < static_cast<long>(nTol
) && aZoomSizePixel
.Height() < static_cast<long>(nTol
) ) || rMEvt
.IsMod1() )
161 // click at place: double zoom factor
162 Point aPos
= mpWindow
->PixelToLogic(aPosPix
);
163 Size aSize
= mpWindow
->PixelToLogic(mpWindow
->GetOutputSizePixel());
164 if ( rMEvt
.IsMod1() )
166 aSize
.setWidth( aSize
.Width() * 2 );
167 aSize
.setHeight( aSize
.Height() * 2 );
171 aSize
.setWidth( aSize
.Width() / 2 );
172 aSize
.setHeight( aSize
.Height() / 2 );
174 aPos
.AdjustX( -(aSize
.Width() / 2) );
175 aPos
.AdjustY( -(aSize
.Height() / 2) );
176 aZoomRect
.SetPos(aPos
);
177 aZoomRect
.SetSize(aSize
);
180 mpViewShell
->SetZoomRect(aZoomRect
);
181 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
184 ::tools::Rectangle aVisAreaWin
= mpWindow
->PixelToLogic(::tools::Rectangle(Point(0,0),
185 mpWindow
->GetOutputSizePixel()));
186 mpViewShell
->GetZoomList()->InsertZoomRect(aVisAreaWin
);
189 mpWindow
->ReleaseMouse();
194 void FuZoom::Activate()
196 aPtr
= mpWindow
->GetPointer();
198 if (nSlotId
== SID_ZOOM_PANNING
)
200 mpWindow
->SetPointer(Pointer(PointerStyle::Hand
));
204 mpWindow
->SetPointer(Pointer(PointerStyle::Magnify
));
208 void FuZoom::Deactivate()
210 mpWindow
->SetPointer( aPtr
);
211 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom
);
213 } // end of namespace sd
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */