LCOV - code coverage report
Current view: top level - sd/source/ui/view - sdwindow.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 270 413 65.4 %
Date: 2014-11-03 Functions: 34 51 66.7 %
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 "Window.hxx"
      21             : #include <sfx2/dispatch.hxx>
      22             : #include <sfx2/request.hxx>
      23             : 
      24             : #include <sfx2/viewfrm.hxx>
      25             : #include <svx/svxids.hrc>
      26             : 
      27             : #include <editeng/outliner.hxx>
      28             : #include <editeng/editview.hxx>
      29             : 
      30             : #include "app.hrc"
      31             : #include "helpids.h"
      32             : #include "ViewShell.hxx"
      33             : #include "DrawViewShell.hxx"
      34             : #include "View.hxx"
      35             : #include "FrameView.hxx"
      36             : #include "OutlineViewShell.hxx"
      37             : #include "drawdoc.hxx"
      38             : #include "AccessibleDrawDocumentView.hxx"
      39             : #include "WindowUpdater.hxx"
      40             : 
      41             : #include <vcl/svapp.hxx>
      42             : #include <vcl/settings.hxx>
      43             : 
      44             : namespace sd {
      45             : 
      46             : #define SCROLL_LINE_FACT   0.05     ///< factor for line scrolling
      47             : #define SCROLL_PAGE_FACT   0.5      ///< factor for page scrolling
      48             : #define SCROLL_SENSITIVE   20       ///< sensitive area in pixel
      49             : #define ZOOM_MULTIPLICATOR 10000    ///< multiplier to avoid rounding errors
      50             : #define MIN_ZOOM           5        ///< minimal zoom factor
      51             : #define MAX_ZOOM           3000     ///< maximal zoom factor
      52             : 
      53         338 : Window::Window(vcl::Window* pParent)
      54             :     : vcl::Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
      55             :       DropTargetHelper( this ),
      56             :       mpShareWin(NULL),
      57             :       maWinPos(0, 0),           // precautionary; but the values should be set
      58             :       maViewOrigin(0, 0),       // again from the owner of the window
      59             :       maViewSize(1000, 1000),
      60             :       maPrevSize(-1,-1),
      61             :       mnMinZoom(MIN_ZOOM),
      62             :       mnMaxZoom(MAX_ZOOM),
      63             :       mbMinZoomAutoCalc(false),
      64             :       mbCalcMinZoomByMinSide(true),
      65             :       mbCenterAllowed(true),
      66             :       mnTicks (0),
      67             :       mbDraggedFrom(false),
      68             :       mpViewShell(NULL),
      69         338 :       mbUseDropScroll (true)
      70             : {
      71         338 :     SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
      72             : 
      73         338 :     MapMode aMap(GetMapMode());
      74         338 :     aMap.SetMapUnit(MAP_100TH_MM);
      75         338 :     SetMapMode(aMap);
      76             : 
      77             :     // whit it, the vcl::WindowColor is used in the slide mode
      78         338 :     SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
      79             : 
      80             :     // adjust contrast mode initially
      81         338 :     bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
      82             :     SetDrawMode( bUseContrast
      83             :         ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
      84         338 :         : ViewShell::OUTPUT_DRAWMODE_COLOR );
      85             : 
      86             :     // set Help ID
      87             :     // SetHelpId(HID_SD_WIN_DOCUMENT);
      88         338 :     SetUniqueId(HID_SD_WIN_DOCUMENT);
      89             : 
      90             :     // #i78183# Added after discussed with AF
      91         338 :     EnableRTL(false);
      92         338 : }
      93             : 
      94        1014 : Window::~Window (void)
      95             : {
      96         338 :     if (mpViewShell != NULL)
      97             :     {
      98           0 :         WindowUpdater* pWindowUpdater = mpViewShell->GetWindowUpdater();
      99           0 :         if (pWindowUpdater != NULL)
     100           0 :             pWindowUpdater->UnregisterWindow (this);
     101             :     }
     102         676 : }
     103             : 
     104         802 : void Window::SetViewShell (ViewShell* pViewSh)
     105             : {
     106         802 :     WindowUpdater* pWindowUpdater = NULL;
     107             :     // Unregister at device updater of old view shell.
     108         802 :     if (mpViewShell != NULL)
     109             :     {
     110         464 :         pWindowUpdater = mpViewShell->GetWindowUpdater();
     111         464 :         if (pWindowUpdater != NULL)
     112         464 :             pWindowUpdater->UnregisterWindow (this);
     113             :     }
     114             : 
     115         802 :     mpViewShell = pViewSh;
     116             : 
     117             :     // Register at device updater of new view shell
     118         802 :     if (mpViewShell != NULL)
     119             :     {
     120         464 :         pWindowUpdater = mpViewShell->GetWindowUpdater();
     121         464 :         if (pWindowUpdater != NULL)
     122         464 :             pWindowUpdater->RegisterWindow (this);
     123             :     }
     124         802 : }
     125             : 
     126        2251 : void Window::CalcMinZoom()
     127             : {
     128             :     // Are we entitled to change the minimal zoom factor?
     129        2251 :     if ( mbMinZoomAutoCalc )
     130             :     {
     131             :         // Get current zoom factor.
     132           0 :         long nZoom = GetZoom();
     133             : 
     134           0 :         if ( mpShareWin )
     135             :         {
     136           0 :             mpShareWin->CalcMinZoom();
     137           0 :             mnMinZoom = mpShareWin->mnMinZoom;
     138             :         }
     139             :         else
     140             :         {
     141             :             // Get the rectangle of the output area in logical coordinates
     142             :             // and calculate the scaling factors that would lead to the view
     143             :             // area (also called application area) to completely fill the
     144             :             // window.
     145           0 :             Size aWinSize = PixelToLogic(GetOutputSizePixel());
     146           0 :             sal_uLong nX = (sal_uLong) ((double) aWinSize.Width()
     147           0 :                 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Width());
     148           0 :             sal_uLong nY = (sal_uLong) ((double) aWinSize.Height()
     149           0 :                 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Height());
     150             : 
     151             :             // Decide whether to take the larger or the smaller factor.
     152             :             sal_uLong nFact;
     153           0 :             if (mbCalcMinZoomByMinSide)
     154           0 :                 nFact = std::min(nX, nY);
     155             :             else
     156           0 :                 nFact = std::max(nX, nY);
     157             : 
     158             :             // The factor is tansfomed according to the current zoom factor.
     159           0 :             nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
     160           0 :             mnMinZoom = std::max((sal_uInt16) MIN_ZOOM, (sal_uInt16) nFact);
     161             :         }
     162             :         // If the current zoom factor is smaller than the calculated minimal
     163             :         // zoom factor then set the new minimal factor as the current zoom
     164             :         // factor.
     165           0 :         if ( nZoom < (long) mnMinZoom )
     166           0 :             SetZoomFactor(mnMinZoom);
     167             :     }
     168        2251 : }
     169             : 
     170           0 : void Window::SetMinZoom (long int nMin)
     171             : {
     172           0 :     mnMinZoom = (sal_uInt16) nMin;
     173           0 : }
     174             : 
     175           0 : void Window::SetMaxZoom (long int nMax)
     176             : {
     177           0 :     mnMaxZoom = (sal_uInt16) nMax;
     178           0 : }
     179             : 
     180        2995 : long Window::GetZoom (void) const
     181             : {
     182        2995 :     if( GetMapMode().GetScaleX().GetDenominator() )
     183             :     {
     184        2995 :         return GetMapMode().GetScaleX().GetNumerator() * 100L
     185        2995 :             / GetMapMode().GetScaleX().GetDenominator();
     186             :     }
     187             :     else
     188             :     {
     189           0 :         return 0;
     190             :     }
     191             : }
     192             : 
     193        1327 : void Window::Resize()
     194             : {
     195        1327 :     vcl::Window::Resize();
     196        1327 :     CalcMinZoom();
     197             : 
     198        1327 :     if( mpViewShell && mpViewShell->GetViewFrame() )
     199        1327 :         mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
     200        1327 : }
     201             : 
     202        1351 : void Window::PrePaint()
     203             : {
     204        1351 :     if ( mpViewShell )
     205        1351 :         mpViewShell->PrePaint();
     206        1351 : }
     207             : 
     208         908 : void Window::Paint(const Rectangle& rRect)
     209             : {
     210         908 :     if ( mpViewShell )
     211         908 :         mpViewShell->Paint(rRect, this);
     212         908 : }
     213             : 
     214           0 : void Window::KeyInput(const KeyEvent& rKEvt)
     215             : {
     216           0 :     if (!(mpViewShell && mpViewShell->KeyInput(rKEvt, this)))
     217             :     {
     218           0 :         if (mpViewShell && rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
     219             :         {
     220           0 :             mpViewShell->GetViewShell()->Escape();
     221             :         }
     222             :         else
     223             :         {
     224           0 :             vcl::Window::KeyInput(rKEvt);
     225             :         }
     226             :     }
     227           0 : }
     228             : 
     229           0 : void Window::MouseButtonDown(const MouseEvent& rMEvt)
     230             : {
     231           0 :     if ( mpViewShell )
     232           0 :         mpViewShell->MouseButtonDown(rMEvt, this);
     233           0 : }
     234             : 
     235           0 : void Window::MouseMove(const MouseEvent& rMEvt)
     236             : {
     237           0 :     if ( mpViewShell )
     238           0 :         mpViewShell->MouseMove(rMEvt, this);
     239           0 : }
     240             : 
     241           0 : void Window::MouseButtonUp(const MouseEvent& rMEvt)
     242             : {
     243           0 :     mnTicks = 0;
     244             : 
     245           0 :     if ( mpViewShell )
     246           0 :         mpViewShell->MouseButtonUp(rMEvt, this);
     247           0 : }
     248             : 
     249           0 : void Window::Command(const CommandEvent& rCEvt)
     250             : {
     251           0 :     if ( mpViewShell )
     252           0 :         mpViewShell->Command(rCEvt, this);
     253           0 : }
     254             : 
     255          16 : bool Window::Notify( NotifyEvent& rNEvt )
     256             : {
     257          16 :     bool nResult = false;
     258          16 :     if ( mpViewShell )
     259             :     {
     260          16 :         nResult = mpViewShell->Notify(rNEvt, this);
     261             :     }
     262          16 :     if( !nResult )
     263          16 :         nResult = vcl::Window::Notify( rNEvt );
     264             : 
     265          16 :     return nResult;
     266             : }
     267             : 
     268           0 : void Window::RequestHelp(const HelpEvent& rEvt)
     269             : {
     270           0 :     if ( mpViewShell )
     271             :     {
     272           0 :         if( !mpViewShell->RequestHelp( rEvt, this) )
     273           0 :             vcl::Window::RequestHelp( rEvt );
     274             :     }
     275             :     else
     276           0 :         vcl::Window::RequestHelp( rEvt );
     277           0 : }
     278             : 
     279             : /**
     280             :  * Set the position of the upper left corner from the visible area of the
     281             :  * window.
     282             :  */
     283        1094 : void Window::SetWinViewPos(const Point& rPnt)
     284             : {
     285        1094 :     maWinPos = rPnt;
     286        1094 : }
     287             : 
     288             : /**
     289             :  * Set origin of the representation in respect to the whole working area.
     290             :  */
     291         924 : void Window::SetViewOrigin(const Point& rPnt)
     292             : {
     293         924 :     maViewOrigin = rPnt;
     294         924 : }
     295             : 
     296             : /**
     297             :  * Set size of the whole working area which can be seen with the window.
     298             :  */
     299         924 : void Window::SetViewSize(const Size& rSize)
     300             : {
     301         924 :     maViewSize = rSize;
     302         924 :     CalcMinZoom();
     303         924 : }
     304             : 
     305         464 : void Window::SetCenterAllowed (bool bIsAllowed)
     306             : {
     307         464 :     mbCenterAllowed = bIsAllowed;
     308         464 : }
     309             : 
     310        1448 : long Window::SetZoomFactor(long nZoom)
     311             : {
     312             :     // Clip the zoom factor to the valid range marked by nMinZoom as
     313             :     // calculated by CalcMinZoom() and the constant MAX_ZOOM.
     314        1448 :     if ( nZoom > MAX_ZOOM )
     315           0 :         nZoom = MAX_ZOOM;
     316        1448 :     if ( nZoom < (long) mnMinZoom )
     317           0 :         nZoom = mnMinZoom;
     318             : 
     319             :     // Set the zoom factor at the window's map mode.
     320        1448 :     MapMode aMap(GetMapMode());
     321        1448 :     aMap.SetScaleX(Fraction(nZoom, 100));
     322        1448 :     aMap.SetScaleY(Fraction(nZoom, 100));
     323        1448 :     SetMapMode(aMap);
     324             : 
     325             :     // invalidate previous size - it was relative to the old scaling
     326        1448 :     maPrevSize = Size(-1,-1);
     327             : 
     328             :     // Update the map mode's origin (to what effect?).
     329        1448 :     UpdateMapOrigin();
     330             : 
     331             :     // Update the view's snapping to the new zoom factor.
     332        1448 :     if ( mpViewShell && mpViewShell->ISA(DrawViewShell) )
     333        1448 :         ((DrawViewShell*) mpViewShell)->GetView()->
     334        2896 :                                         RecalcLogicSnapMagnetic(*this);
     335             : 
     336             :     // Return the zoom factor just in case it has been changed above to lie
     337             :     // inside the valid range.
     338        1448 :     return nZoom;
     339             : }
     340             : 
     341         726 : void Window::SetZoomIntegral(long nZoom)
     342             : {
     343             :     // Clip the zoom factor to the valid range marked by nMinZoom as
     344             :     // previously calculated by <member>CalcMinZoom()</member> and the
     345             :     // MAX_ZOOM constant.
     346         726 :     if ( nZoom > MAX_ZOOM )
     347           0 :         nZoom = MAX_ZOOM;
     348         726 :     if ( nZoom < (long) mnMinZoom )
     349           0 :         nZoom = mnMinZoom;
     350             : 
     351             :     // Calculate the window's new origin.
     352         726 :     Size aSize = PixelToLogic(GetOutputSizePixel());
     353         726 :     long nW = aSize.Width()  * GetZoom() / nZoom;
     354         726 :     long nH = aSize.Height() * GetZoom() / nZoom;
     355         726 :     maWinPos.X() += (aSize.Width()  - nW) / 2;
     356         726 :     maWinPos.Y() += (aSize.Height() - nH) / 2;
     357         726 :     if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
     358         726 :     if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
     359             : 
     360             :     // Finally update this window's map mode to the given zoom factor that
     361             :     // has been clipped to the valid range.
     362         726 :     SetZoomFactor(nZoom);
     363         726 : }
     364             : 
     365         207 : long Window::GetZoomForRect( const Rectangle& rZoomRect )
     366             : {
     367         207 :     long nRetZoom = 100;
     368             : 
     369         207 :     if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
     370             :     {
     371             :         // Calculate the scale factors which will lead to the given
     372             :         // rectangle being fully visible (when translated accordingly) as
     373             :         // large as possible in the output area independently in both
     374             :         // coordinate directions .
     375         207 :         sal_uLong nX(0L);
     376         207 :         sal_uLong nY(0L);
     377             : 
     378         207 :         const Size aWinSize( PixelToLogic(GetOutputSizePixel()) );
     379         207 :         if(rZoomRect.GetHeight())
     380             :         {
     381         207 :             nX = (sal_uLong) ((double) aWinSize.Height()
     382         207 :                * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
     383             :         }
     384             : 
     385         207 :         if(rZoomRect.GetWidth())
     386             :         {
     387         207 :             nY = (sal_uLong) ((double) aWinSize.Width()
     388         207 :                 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
     389             :         }
     390             : 
     391             :         // Use the smaller one of both so that the zoom rectangle will be
     392             :         // fully visible with respect to both coordinate directions.
     393         207 :         sal_uLong nFact = std::min(nX, nY);
     394             : 
     395             :         // Transform the current zoom factor so that it leads to the desired
     396             :         // scaling.
     397         207 :         nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
     398             : 
     399             :         // Calculate the new origin.
     400         207 :         if ( nFact == 0 )
     401             :         {
     402             :             // Don't change anything if the scale factor is degenrate.
     403         192 :             nRetZoom = GetZoom();
     404             :         }
     405             :         else
     406             :         {
     407             :             // Clip the zoom factor to the valid range marked by nMinZoom as
     408             :             // previously calculated by <member>CalcMinZoom()</member> and the
     409             :             // MAX_ZOOM constant.
     410          15 :             if ( nRetZoom > MAX_ZOOM )
     411           0 :                 nRetZoom = MAX_ZOOM;
     412          15 :             if ( nRetZoom < (long) mnMinZoom )
     413           0 :                 nRetZoom = mnMinZoom;
     414             :        }
     415             :     }
     416             : 
     417         207 :     return nRetZoom;
     418             : }
     419             : 
     420             : /** Recalculate the zoom factor and translation so that the given rectangle
     421             :     is displayed centered and as large as possible while still being fully
     422             :     visible in the window.
     423             : */
     424         726 : long Window::SetZoomRect (const Rectangle& rZoomRect)
     425             : {
     426         726 :     long nNewZoom = 100;
     427             : 
     428         726 :     if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
     429             :     {
     430             :         // The given rectangle is degenerate.  Use the default zoom factor
     431             :         // (above) of 100%.
     432           0 :         SetZoomIntegral(nNewZoom);
     433             :     }
     434             :     else
     435             :     {
     436         726 :         Point aPos = rZoomRect.TopLeft();
     437             :         // Transform the output area from pixel coordinates into logical
     438             :         // coordinates.
     439         726 :         Size aWinSize = PixelToLogic(GetOutputSizePixel());
     440             :         // Paranoia!  The degenerate case of zero width or height has been
     441             :         // taken care of above.
     442             :         DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Width = 0!");
     443             :         DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Height = 0!");
     444             : 
     445             :         // Calculate the scale factors which will lead to the given
     446             :         // rectangle being fully visible (when translated accordingly) as
     447             :         // large as possible in the output area independently in both
     448             :         // coordinate directions .
     449         726 :         sal_uLong nX(0L);
     450         726 :         sal_uLong nY(0L);
     451             : 
     452         726 :         if(rZoomRect.GetHeight())
     453             :         {
     454         726 :             nX = (sal_uLong) ((double) aWinSize.Height()
     455         726 :                * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
     456             :         }
     457             : 
     458         726 :         if(rZoomRect.GetWidth())
     459             :         {
     460         726 :             nY = (sal_uLong) ((double) aWinSize.Width()
     461         726 :                 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
     462             :         }
     463             : 
     464             :         // Use the smaller one of both so that the zoom rectangle will be
     465             :         // fully visible with respect to both coordinate directions.
     466         726 :         sal_uLong nFact = std::min(nX, nY);
     467             : 
     468             :         // Transform the current zoom factor so that it leads to the desired
     469             :         // scaling.
     470         726 :         long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
     471             : 
     472             :         // Calculate the new origin.
     473         726 :         if ( nFact == 0 )
     474             :         {
     475             :             // Don't change anything if the scale factor is degenrate.
     476           4 :             nNewZoom = GetZoom();
     477             :         }
     478             :         else
     479             :         {
     480             :             // Calculate the new window position that centers the given
     481             :             // rectangle on the screen.
     482         722 :             if ( nZoom > MAX_ZOOM )
     483           0 :                 nFact = nFact * MAX_ZOOM / nZoom;
     484             : 
     485         722 :             maWinPos = maViewOrigin + aPos;
     486             : 
     487         722 :             aWinSize.Width() = (long) ((double) aWinSize.Width() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
     488         722 :             maWinPos.X() += (rZoomRect.GetWidth() - aWinSize.Width()) / 2;
     489         722 :             aWinSize.Height() = (long) ((double) aWinSize.Height() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
     490         722 :             maWinPos.Y() += (rZoomRect.GetHeight() - aWinSize.Height()) / 2;
     491             : 
     492         722 :             if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
     493         722 :             if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
     494             : 
     495             :             // Adapt the window's map mode to the new zoom factor.
     496         722 :             nNewZoom = SetZoomFactor(nZoom);
     497             :         }
     498             :     }
     499             : 
     500         726 :     return(nNewZoom);
     501             : }
     502             : 
     503           0 : void Window::SetMinZoomAutoCalc (bool bAuto)
     504             : {
     505           0 :     mbMinZoomAutoCalc = bAuto;
     506           0 : }
     507             : 
     508             : /**
     509             :  * Calculate and set new MapMode origin.
     510             :  * If aWinPos.X()/Y() == -1, then we center the corresponding position (e.g. for
     511             :  * initialization).
     512             :  */
     513        3060 : void Window::UpdateMapOrigin(bool bInvalidate)
     514             : {
     515        3060 :     bool       bChanged = false;
     516        3060 :     const Size aWinSize = PixelToLogic(GetOutputSizePixel());
     517             : 
     518        3060 :     if ( mbCenterAllowed )
     519             :     {
     520        3060 :         if( maPrevSize != Size(-1,-1) )
     521             :         {
     522             :             // keep view centered around current pos, when window
     523             :             // resizes
     524        1400 :             maWinPos.X() -= (aWinSize.Width() - maPrevSize.Width()) / 2;
     525        1400 :             maWinPos.Y() -= (aWinSize.Height() - maPrevSize.Height()) / 2;
     526        1400 :             bChanged = true;
     527             :         }
     528             : 
     529        3060 :         if ( maWinPos.X() > maViewSize.Width() - aWinSize.Width() )
     530             :         {
     531           8 :             maWinPos.X() = maViewSize.Width() - aWinSize.Width();
     532           8 :             bChanged = true;
     533             :         }
     534        3060 :         if ( maWinPos.Y() > maViewSize.Height() - aWinSize.Height() )
     535             :         {
     536         178 :             maWinPos.Y() = maViewSize.Height() - aWinSize.Height();
     537         178 :             bChanged = true;
     538             :         }
     539        3060 :         if ( aWinSize.Width() > maViewSize.Width() || maWinPos.X() < 0 )
     540             :         {
     541         368 :             maWinPos.X() = maViewSize.Width()  / 2 - aWinSize.Width()  / 2;
     542         368 :             bChanged = true;
     543             :         }
     544        3060 :         if ( aWinSize.Height() > maViewSize.Height() || maWinPos.Y() < 0 )
     545             :         {
     546         544 :             maWinPos.Y() = maViewSize.Height() / 2 - aWinSize.Height() / 2;
     547         544 :             bChanged = true;
     548             :         }
     549             :     }
     550             : 
     551        3060 :     UpdateMapMode ();
     552             : 
     553        3060 :     maPrevSize = aWinSize;
     554             : 
     555        3060 :     if (bChanged && bInvalidate)
     556        1710 :         Invalidate();
     557        3060 : }
     558             : 
     559        3060 : void Window::UpdateMapMode (void)
     560             : {
     561        3060 :     maWinPos -= maViewOrigin;
     562        3060 :     Size aPix(maWinPos.X(), maWinPos.Y());
     563        3060 :     aPix = LogicToPixel(aPix);
     564             :     // Size has to be a multiple of BRUSH_SIZE due to the correct depiction of
     565             :     // pattern
     566             :     // #i2237#
     567             :     // removed old stuff here which still forced zoom to be
     568             :     // %BRUSH_SIZE which is outdated now
     569             : 
     570        3060 :     if (mpViewShell && mpViewShell->ISA(DrawViewShell))
     571             :     {
     572             :         // page should not "stick" to the window border
     573        3060 :         if (aPix.Width() == 0)
     574             :         {
     575             :             // #i2237#
     576             :             // Since BRUSH_SIZE alignment is outdated now, i use the
     577             :             // former constant here directly
     578           4 :             aPix.Width() -= 8;
     579             :         }
     580        3060 :         if (aPix.Height() == 0)
     581             :         {
     582             :             // #i2237#
     583             :             // Since BRUSH_SIZE alignment is outdated now, i use the
     584             :             // former constant here directly
     585           0 :             aPix.Height() -= 8;
     586             :         }
     587             :     }
     588             : 
     589        3060 :     aPix = PixelToLogic(aPix);
     590        3060 :     maWinPos.X() = aPix.Width();
     591        3060 :     maWinPos.Y() = aPix.Height();
     592        3060 :     Point aNewOrigin (-maWinPos.X(), -maWinPos.Y());
     593        3060 :     maWinPos += maViewOrigin;
     594             : 
     595        3060 :     MapMode aMap(GetMapMode());
     596        3060 :     aMap.SetOrigin(aNewOrigin);
     597        3060 :     SetMapMode(aMap);
     598        3060 : }
     599             : 
     600             : /**
     601             :  * @returns X position of the visible area as fraction (< 1) of the whole
     602             :  * working area.
     603             :  */
     604        1877 : double Window::GetVisibleX()
     605             : {
     606        1877 :     return ((double) maWinPos.X() / maViewSize.Width());
     607             : }
     608             : 
     609             : /**
     610             :  * @returns Y position of the visible area as fraction (< 1) of the whole
     611             :  * working area.
     612             :  */
     613        1877 : double Window::GetVisibleY()
     614             : {
     615        1877 :     return ((double) maWinPos.Y() / maViewSize.Height());
     616             : }
     617             : 
     618             : /**
     619             :  * Set x and y position of the visible area as fraction (< 1) of the whole
     620             :  * working area. Negative values are ignored.
     621             :  */
     622           4 : void Window::SetVisibleXY(double fX, double fY)
     623             : {
     624           4 :     long nOldX = maWinPos.X();
     625           4 :     long nOldY = maWinPos.Y();
     626             : 
     627           4 :     if ( fX >= 0 )
     628           4 :         maWinPos.X() = (long) (fX * maViewSize.Width());
     629           4 :     if ( fY >= 0 )
     630           0 :         maWinPos.Y() = (long) (fY * maViewSize.Height());
     631           4 :     UpdateMapOrigin(false);
     632           4 :     Scroll(nOldX - maWinPos.X(), nOldY - maWinPos.Y(), SCROLL_CHILDREN);
     633           4 :     Update();
     634           4 : }
     635             : 
     636             : /**
     637             :  * @returns width of the visible area in proportion to the width of the whole
     638             :  * working area.
     639             :  */
     640        4824 : double Window::GetVisibleWidth()
     641             : {
     642        4824 :     Size aWinSize = PixelToLogic(GetOutputSizePixel());
     643        4824 :     if ( aWinSize.Width() > maViewSize.Width() )
     644          24 :         aWinSize.Width() = maViewSize.Width();
     645        4824 :     return ((double) aWinSize.Width() / maViewSize.Width());
     646             : }
     647             : 
     648             : /**
     649             :  * @returns height of the visible area in proportion to the height of the whole
     650             :  * working area.
     651             :  */
     652        6280 : double Window::GetVisibleHeight()
     653             : {
     654        6280 :     Size aWinSize = PixelToLogic(GetOutputSizePixel());
     655        6280 :     if ( aWinSize.Height() > maViewSize.Height() )
     656         152 :         aWinSize.Height() = maViewSize.Height();
     657        6280 :     return ((double) aWinSize.Height() / maViewSize.Height());
     658             : }
     659             : 
     660             : /**
     661             :  * @returns width of a scroll column in proportion to the width of the whole
     662             :  * working area.
     663             :  */
     664        1608 : double Window::GetScrlLineWidth()
     665             : {
     666        1608 :     return (GetVisibleWidth() * SCROLL_LINE_FACT);
     667             : }
     668             : 
     669             : /**
     670             :  * @returns height of a scroll column in proportion to the height of the whole
     671             :  * working area.
     672             :  */
     673        1532 : double Window::GetScrlLineHeight()
     674             : {
     675        1532 :     return (GetVisibleHeight() * SCROLL_LINE_FACT);
     676             : }
     677             : 
     678             : /**
     679             :  * @returns width of a scroll page in proportion to the width of the whole
     680             :  * working area.
     681             :  */
     682        1608 : double Window::GetScrlPageWidth()
     683             : {
     684        1608 :     return (GetVisibleWidth() * SCROLL_PAGE_FACT);
     685             : }
     686             : 
     687             : /**
     688             :  * @returns height of a scroll page in proportion to the height of the whole
     689             :  * working area.
     690             :  */
     691        1532 : double Window::GetScrlPageHeight()
     692             : {
     693        1532 :     return (GetVisibleHeight() * SCROLL_PAGE_FACT);
     694             : }
     695             : 
     696             : /**
     697             :  * Deactivate window.
     698             :  */
     699           0 : void Window::LoseFocus()
     700             : {
     701           0 :     mnTicks = 0;
     702           0 :     vcl::Window::LoseFocus ();
     703           0 : }
     704             : 
     705             : /**
     706             :  * Activate window.
     707             :  */
     708           0 : void Window::GrabFocus()
     709             : {
     710           0 :     mnTicks      = 0;
     711           0 :     vcl::Window::GrabFocus ();
     712           0 : }
     713             : 
     714           4 : void Window::DataChanged( const DataChangedEvent& rDCEvt )
     715             : {
     716           4 :     vcl::Window::DataChanged( rDCEvt );
     717             : 
     718             :     /* Omit PRINTER by all documents which are not using a printer.
     719             :        Omit FONTS and FONTSUBSTITUTION if no text output is available or if the
     720             :        document does not allow text.  */
     721             : 
     722          12 :     if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
     723           8 :          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
     724           8 :          (rDCEvt.GetType() == DATACHANGED_FONTS) ||
     725          16 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
     726           8 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     727           4 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
     728             :     {
     729           8 :         if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     730           4 :              (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     731             :         {
     732             :             // When the screen zoom factor has changed then reset the zoom
     733             :             // factor of the frame to always display the whole page.
     734           4 :             const AllSettings* pOldSettings = rDCEvt.GetOldSettings ();
     735           4 :             const AllSettings& rNewSettings = GetSettings ();
     736           4 :             if (pOldSettings)
     737           8 :                 if (pOldSettings->GetStyleSettings().GetScreenZoom()
     738           4 :                     != rNewSettings.GetStyleSettings().GetScreenZoom())
     739             :                     mpViewShell->GetViewFrame()->GetDispatcher()->
     740           0 :                         Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     741             : 
     742             :             /* Rearrange or initiate Resize for scroll bars since the size of
     743             :                the scroll bars my have changed. Within this, inside the resize-
     744             :                handler, the size of the scroll bars will be asked from the
     745             :                Settings. */
     746           4 :             Resize();
     747             : 
     748             :             /* Re-set data, which are from system control or from Settings. May
     749             :                have to re-set more data since the resolution may also has
     750             :                changed. */
     751           4 :             if( mpViewShell )
     752             :             {
     753           4 :                 const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
     754           4 :                 SvtAccessibilityOptions aAccOptions;
     755             :                 sal_uLong                   nOutputMode;
     756             :                 sal_uInt16                  nPreviewSlot;
     757             : 
     758           4 :                 if( rStyleSettings.GetHighContrastMode() )
     759           0 :                     nOutputMode = ViewShell::OUTPUT_DRAWMODE_CONTRAST;
     760             :                 else
     761           4 :                     nOutputMode = ViewShell::OUTPUT_DRAWMODE_COLOR;
     762             : 
     763           4 :                 if( rStyleSettings.GetHighContrastMode() && aAccOptions.GetIsForPagePreviews() )
     764           0 :                     nPreviewSlot = SID_PREVIEW_QUALITY_CONTRAST;
     765             :                 else
     766           4 :                     nPreviewSlot = SID_PREVIEW_QUALITY_COLOR;
     767             : 
     768           4 :                 if( mpViewShell->ISA( DrawViewShell ) )
     769             :                 {
     770           4 :                     SetDrawMode( nOutputMode );
     771           4 :                     mpViewShell->GetFrameView()->SetDrawMode( nOutputMode );
     772           4 :                     Invalidate();
     773             :                 }
     774             : 
     775             :                 // Overwrite window color for OutlineView
     776           4 :                 if( mpViewShell->ISA(OutlineViewShell ) )
     777             :                 {
     778           0 :                     svtools::ColorConfig aColorConfig;
     779           0 :                     const Color aDocColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
     780           0 :                     SetBackground( Wallpaper( aDocColor ) );
     781             :                 }
     782             : 
     783           8 :                 SfxRequest aReq( nPreviewSlot, SfxCallMode::SLOT, mpViewShell->GetDocSh()->GetDoc()->GetItemPool() );
     784           4 :                 mpViewShell->ExecReq( aReq );
     785           4 :                 mpViewShell->Invalidate();
     786           4 :                 mpViewShell->ArrangeGUIElements();
     787             : 
     788             :                 // re-create handles to show new outfit
     789           4 :                 if(mpViewShell->ISA(DrawViewShell))
     790             :                 {
     791           4 :                     mpViewShell->GetView()->AdjustMarkHdl();
     792           4 :                 }
     793             :             }
     794             :         }
     795             : 
     796          12 :         if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
     797           8 :              ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     798           4 :               (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
     799             :         {
     800             :             /* Virtual devices, which also depends on the resolution or the
     801             :                system control, should be updated. Otherwise, we should update
     802             :                the virtual devices at least at DATACHANGED_DISPLAY since some
     803             :                systems allow to change the resolution and color depth during
     804             :                runtime. Or the virtual devices have to be updated when the color
     805             :                palette has changed since a different color matching can be used
     806             :                when outputting. */
     807             :         }
     808             : 
     809           4 :         if ( rDCEvt.GetType() == DATACHANGED_FONTS )
     810             :         {
     811             :             /* If the document provides font choose boxes, we have to update
     812             :                them. I don't know how this looks like (also not really me, I
     813             :                only translated the comment ;). We may can handle it global. We
     814             :                have to discuss it with PB, but he is ill at the moment.
     815             :                Before we handle it here, discuss it with PB and me. */
     816             :         }
     817             : 
     818           8 :         if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
     819           4 :              (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) )
     820             :         {
     821             :             /* Do reformating since the fonts of the document may no longer
     822             :                exist, or exist now, or are replaced with others. */
     823           0 :             if( mpViewShell )
     824             :             {
     825           0 :                 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
     826           0 :                 if( pDocSh )
     827           0 :                     pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
     828             :             }
     829             :         }
     830             : 
     831           4 :         if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
     832             :         {
     833             :             /* I don't know how the handling should look like. Maybe we delete a
     834             :                printer and look what we have to do. Maybe I have to add
     835             :                something to the VCL, in case the used printer is deleted.
     836             :                Otherwise I may recalculate the formatting here if the current
     837             :                printer is destroyed. */
     838           0 :             if( mpViewShell )
     839             :             {
     840           0 :                 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
     841           0 :                 if( pDocSh )
     842           0 :                     pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
     843             :             }
     844             :         }
     845             : 
     846             :         // Update everything
     847           4 :         Invalidate();
     848             :     }
     849           4 : }
     850             : 
     851           0 : sal_Int8 Window::AcceptDrop( const AcceptDropEvent& rEvt )
     852             : {
     853           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     854             : 
     855           0 :     if( mpViewShell && !mpViewShell->GetDocSh()->IsReadOnly() )
     856             :     {
     857           0 :         if( mpViewShell )
     858           0 :             nRet = mpViewShell->AcceptDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
     859             : 
     860           0 :         if (mbUseDropScroll && ! mpViewShell->ISA(OutlineViewShell))
     861           0 :             DropScroll( rEvt.maPosPixel );
     862             :     }
     863             : 
     864           0 :     return nRet;
     865             : }
     866             : 
     867           0 : sal_Int8 Window::ExecuteDrop( const ExecuteDropEvent& rEvt )
     868             : {
     869           0 :     sal_Int8 nRet = DND_ACTION_NONE;
     870             : 
     871           0 :     if( mpViewShell )
     872             :     {
     873           0 :         nRet = mpViewShell->ExecuteDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
     874             :     }
     875             : 
     876           0 :     return nRet;
     877             : }
     878             : 
     879         126 : void Window::SetUseDropScroll (bool bUseDropScroll)
     880             : {
     881         126 :     mbUseDropScroll = bUseDropScroll;
     882         126 : }
     883             : 
     884           0 : void Window::DropScroll(const Point& rMousePos)
     885             : {
     886           0 :     short nDx = 0;
     887           0 :     short nDy = 0;
     888             : 
     889           0 :     Size aSize = GetOutputSizePixel();
     890             : 
     891           0 :     if (aSize.Width() > SCROLL_SENSITIVE * 3)
     892             :     {
     893           0 :         if ( rMousePos.X() < SCROLL_SENSITIVE )
     894             :         {
     895           0 :             nDx = -1;
     896             :         }
     897             : 
     898           0 :         if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE )
     899             :         {
     900           0 :             nDx = 1;
     901             :         }
     902             :     }
     903             : 
     904           0 :     if (aSize.Height() > SCROLL_SENSITIVE * 3)
     905             :     {
     906           0 :         if ( rMousePos.Y() < SCROLL_SENSITIVE )
     907             :         {
     908           0 :             nDy = -1;
     909             :         }
     910             : 
     911           0 :         if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE )
     912             :         {
     913           0 :             nDy = 1;
     914             :         }
     915             :     }
     916             : 
     917           0 :     if ( (nDx || nDy) && (rMousePos.X()!=0 || rMousePos.Y()!=0 ) )
     918             :     {
     919           0 :         if (mnTicks > 20)
     920           0 :             mpViewShell->ScrollLines(nDx, nDy);
     921             :         else
     922           0 :             mnTicks ++;
     923             :     }
     924           0 : }
     925             : 
     926             : ::com::sun::star::uno::Reference<
     927             :     ::com::sun::star::accessibility::XAccessible>
     928           6 :     Window::CreateAccessible (void)
     929             : {
     930             :     // If current viewshell is PresentationViewShell, just return empty because the correct ShowWin will be created later.
     931           6 :     if (mpViewShell && mpViewShell->ISA(PresentationViewShell))
     932             :     {
     933           0 :         return vcl::Window::CreateAccessible ();
     934             :     }
     935           6 :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc = GetAccessible(false);
     936           6 :     if (xAcc.get())
     937             :     {
     938           0 :         return xAcc;
     939             :     }
     940           6 :     if (mpViewShell != NULL)
     941             :     {
     942           6 :         xAcc = mpViewShell->CreateAccessibleDocumentView (this);
     943           6 :         SetAccessible(xAcc);
     944           6 :         return xAcc;
     945             :     }
     946             :     else
     947             :     {
     948             :         OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
     949           0 :         return vcl::Window::CreateAccessible ();
     950           6 :     }
     951             : }
     952             : 
     953             : // MT: Removed Windows::SwitchView() introduced with IA2 CWS.
     954             : // There are other notifications for this when the active view has chnaged, so
     955             : // please update the code to use that event mechanism
     956           0 : void Window::SwitchView()
     957             : {
     958           0 :     if (mpViewShell)
     959             :     {
     960           0 :         mpViewShell->SwitchViewFireFocus(GetAccessible(false));
     961             :     }
     962           0 : }
     963             : 
     964           0 : OUString Window::GetSurroundingText() const
     965             : {
     966           0 :     if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
     967           0 :         return OUString();
     968           0 :     else if ( mpViewShell->GetView()->IsTextEdit() )
     969             :     {
     970           0 :         OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
     971           0 :         return pOLV->GetEditView().GetSurroundingText();
     972             :     }
     973           0 :     return OUString();
     974             : }
     975             : 
     976           0 : Selection Window::GetSurroundingTextSelection() const
     977             : {
     978           0 :     if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
     979             :     {
     980           0 :         return Selection( 0, 0 );
     981             :     }
     982           0 :     else if ( mpViewShell->GetView()->IsTextEdit() )
     983             :     {
     984           0 :         OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
     985           0 :         return pOLV->GetEditView().GetSurroundingTextSelection();
     986             :     }
     987             :     else
     988             :     {
     989           0 :         return Selection( 0, 0 );
     990             :     }
     991             : }
     992             : 
     993         114 : } // end of namespace sd
     994             : 
     995             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10