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

Generated by: LCOV version 1.10