LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuzoom.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 89 1.1 %
Date: 2015-06-13 12:38:46 Functions: 2 16 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "fuzoom.hxx"
      21             : 
      22             : #include <svx/svxids.hrc>
      23             : #include <sfx2/bindings.hxx>
      24             : #include <sfx2/viewfrm.hxx>
      25             : #include "app.hrc"
      26             : #include <svx/svdpagv.hxx>
      27             : 
      28             : #include "FrameView.hxx"
      29             : #include "ViewShell.hxx"
      30             : #include "View.hxx"
      31             : #include "Window.hxx"
      32             : #include "drawdoc.hxx"
      33             : #include "zoomlist.hxx"
      34             : 
      35             : namespace sd {
      36             : 
      37             : sal_uInt16 SidArrayZoom[] = {
      38             :                     SID_ATTR_ZOOM,
      39             :                     SID_ZOOM_OUT,
      40             :                     SID_ZOOM_IN,
      41             :                     0 };
      42             : 
      43           0 : TYPEINIT1( FuZoom, FuPoor );
      44             : 
      45           0 : FuZoom::FuZoom(
      46             :     ViewShell* pViewSh,
      47             :     ::sd::Window* pWin,
      48             :     ::sd::View* pView,
      49             :     SdDrawDocument* pDoc,
      50             :     SfxRequest& rReq)
      51             :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
      52             :       bVisible(false),
      53           0 :       bStartDrag(false)
      54             : {
      55           0 : }
      56             : 
      57           0 : FuZoom::~FuZoom()
      58             : {
      59           0 :     if (bVisible)
      60             :     {
      61             :         // Hide ZoomRect
      62           0 :         mpViewShell->DrawMarkRect(aZoomRect);
      63             : 
      64           0 :         bVisible = false;
      65           0 :         bStartDrag = false;
      66             :     }
      67           0 : }
      68             : 
      69           0 : rtl::Reference<FuPoor> FuZoom::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      70             : {
      71           0 :     rtl::Reference<FuPoor> xFunc( new FuZoom( pViewSh, pWin, pView, pDoc, rReq ) );
      72           0 :     return xFunc;
      73             : }
      74             : 
      75           0 : bool FuZoom::MouseButtonDown(const MouseEvent& rMEvt)
      76             : {
      77             :     // remember button state for creation of own MouseEvents
      78           0 :     SetMouseButtonCode(rMEvt.GetButtons());
      79             : 
      80           0 :     mpWindow->CaptureMouse();
      81           0 :     bStartDrag = true;
      82             : 
      83           0 :     aBeginPosPix = rMEvt.GetPosPixel();
      84           0 :     aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
      85           0 :     aZoomRect.SetSize( Size( 0, 0 ) );
      86           0 :     aZoomRect.SetPos( aBeginPos );
      87             : 
      88           0 :     return true;
      89             : }
      90             : 
      91           0 : bool FuZoom::MouseMove(const MouseEvent& rMEvt)
      92             : {
      93           0 :     if (rMEvt.IsShift())
      94           0 :         mpWindow->SetPointer(Pointer(PointerStyle::Hand));
      95           0 :     else if (nSlotId != SID_ZOOM_PANNING)
      96           0 :         mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
      97             : 
      98           0 :     if (bStartDrag)
      99             :     {
     100           0 :         if (bVisible)
     101             :         {
     102           0 :             mpViewShell->DrawMarkRect(aZoomRect);
     103             :         }
     104             : 
     105           0 :         Point aPosPix = rMEvt.GetPosPixel();
     106           0 :         ForceScroll(aPosPix);
     107             : 
     108           0 :         aEndPos = mpWindow->PixelToLogic(aPosPix);
     109           0 :         aBeginPos = mpWindow->PixelToLogic(aBeginPosPix);
     110             : 
     111           0 :         if (nSlotId == SID_ZOOM_PANNING || (rMEvt.IsShift() && !bVisible) )
     112             :         {
     113             :             // Panning
     114             : 
     115           0 :             Point aScroll = aBeginPos - aEndPos;
     116             : 
     117           0 :             if (aScroll.X() != 0 || aScroll.Y() != 0)
     118             :             {
     119           0 :                 Size aWorkSize = mpView->GetWorkArea().GetSize();
     120           0 :                 Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
     121           0 :                 aScroll.X() /= aWorkSize.Width()  / aPageSize.Width();
     122           0 :                 aScroll.Y() /= aWorkSize.Height() / aPageSize.Height();
     123           0 :                 mpViewShell->Scroll(aScroll.X(), aScroll.Y());
     124           0 :                 aBeginPosPix = aPosPix;
     125             :             }
     126             :         }
     127             :         else
     128             :         {
     129           0 :             Rectangle aRect(aBeginPos, aEndPos);
     130           0 :             aZoomRect = aRect;
     131           0 :             aZoomRect.Justify();
     132           0 :             mpViewShell->DrawMarkRect(aZoomRect);
     133           0 :             bVisible = true;
     134             :         }
     135             :     }
     136             : 
     137           0 :     return bStartDrag;
     138             : }
     139             : 
     140           0 : bool FuZoom::MouseButtonUp(const MouseEvent& rMEvt)
     141             : {
     142             :     // remember button state for creation of own MouseEvents
     143           0 :     SetMouseButtonCode(rMEvt.GetButtons());
     144             : 
     145           0 :     if (bVisible)
     146             :     {
     147             :         // Hide ZoomRect
     148           0 :         mpViewShell->DrawMarkRect(aZoomRect);
     149           0 :         bVisible = false;
     150             :     }
     151             : 
     152           0 :     Point aPosPix = rMEvt.GetPosPixel();
     153             : 
     154           0 :     if(SID_ZOOM_PANNING != nSlotId && !rMEvt.IsShift())
     155             :     {
     156             :         // Zoom
     157           0 :         Size aZoomSizePixel = mpWindow->LogicToPixel(aZoomRect).GetSize();
     158           0 :         sal_uLong nTol = DRGPIX + DRGPIX;
     159             : 
     160           0 :         if ( ( aZoomSizePixel.Width() < (long) nTol && aZoomSizePixel.Height() < (long) nTol ) || rMEvt.IsMod1() )
     161             :         {
     162             :             // click at place: double zoom factor
     163           0 :             Point aPos = mpWindow->PixelToLogic(aPosPix);
     164           0 :             Size aSize = mpWindow->PixelToLogic(mpWindow->GetOutputSizePixel());
     165           0 :             if ( rMEvt.IsMod1() )
     166             :             {
     167           0 :                 aSize.Width() *= 2;
     168           0 :                 aSize.Height() *= 2;
     169             :             }
     170             :             else
     171             :             {
     172           0 :                 aSize.Width() /= 2;
     173           0 :                 aSize.Height() /= 2;
     174             :             }
     175           0 :             aPos.X() -= aSize.Width() / 2;
     176           0 :             aPos.Y() -= aSize.Height() / 2;
     177           0 :             aZoomRect.SetPos(aPos);
     178           0 :             aZoomRect.SetSize(aSize);
     179             :         }
     180             : 
     181           0 :         mpViewShell->SetZoomRect(aZoomRect);
     182           0 :         mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
     183             :     }
     184             : 
     185           0 :     Rectangle aVisAreaWin = mpWindow->PixelToLogic(Rectangle(Point(0,0),
     186           0 :                                            mpWindow->GetOutputSizePixel()));
     187           0 :     mpViewShell->GetZoomList()->InsertZoomRect(aVisAreaWin);
     188             : 
     189           0 :     bStartDrag = false;
     190           0 :     mpWindow->ReleaseMouse();
     191             : 
     192           0 :     return true;
     193             : }
     194             : 
     195           0 : void FuZoom::Activate()
     196             : {
     197           0 :     aPtr = mpWindow->GetPointer();
     198             : 
     199           0 :     if (nSlotId == SID_ZOOM_PANNING)
     200             :     {
     201           0 :         mpWindow->SetPointer(Pointer(PointerStyle::Hand));
     202             :     }
     203             :     else
     204             :     {
     205           0 :         mpWindow->SetPointer(Pointer(PointerStyle::Magnify));
     206             :     }
     207           0 : }
     208             : 
     209           0 : void FuZoom::Deactivate()
     210             : {
     211           0 :     mpWindow->SetPointer( aPtr );
     212           0 :     mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
     213           0 : }
     214          66 : } // end of namespace sd
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11