LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/svdraw - svdpagv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 309 470 65.7 %
Date: 2013-07-09 Functions: 37 47 78.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 <svx/svdpagv.hxx>
      21             : #include <com/sun/star/awt/XWindow.hpp>
      22             : #include <com/sun/star/awt/PosSize.hpp>
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <svx/svdoutl.hxx>
      25             : #include <svx/xpoly.hxx>
      26             : #include <svx/svdouno.hxx>
      27             : #include <svx/svdpage.hxx>
      28             : #include <svx/svdview.hxx>
      29             : 
      30             : #include <svx/svdedxv.hxx>
      31             : #include <editeng/outliner.hxx>
      32             : #include <svx/svdetc.hxx>
      33             : #include <svx/svdobj.hxx>
      34             : #include "svx/svditer.hxx"
      35             : #include <svx/svdogrp.hxx>
      36             : #include <svx/svdtypes.hxx>
      37             : #include <svx/svdoole2.hxx>
      38             : 
      39             : #include <svx/sdr/contact/objectcontactofpageview.hxx>
      40             : #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
      41             : #include <svx/fmview.hxx>
      42             : 
      43             : // for search on vector
      44             : #include <algorithm>
      45             : 
      46             : using namespace ::rtl;
      47             : using namespace ::com::sun::star;
      48             : #include <svx/sdrpagewindow.hxx>
      49             : #include <svx/sdrpaintwindow.hxx>
      50             : 
      51             : DBG_NAME(SdrPageView);
      52             : 
      53             : ////////////////////////////////////////////////////////////////////////////////////////////////////
      54             : // interface to SdrPageWindow
      55             : 
      56       35700 : SdrPageWindow* SdrPageView::FindPageWindow(SdrPaintWindow& rPaintWindow) const
      57             : {
      58       35750 :     for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
      59             :     {
      60       33837 :         if(&((*a)->GetPaintWindow()) == &rPaintWindow)
      61             :         {
      62       33787 :             return *a;
      63             :         }
      64             :     }
      65             : 
      66        1913 :     return 0L;
      67             : }
      68             : 
      69         396 : const SdrPageWindow* SdrPageView::FindPatchedPageWindow( const OutputDevice& _rOutDev ) const
      70             : {
      71        1224 :     for (   SdrPageWindowVector::const_iterator loop = maPageWindows.begin();
      72         816 :             loop != maPageWindows.end();
      73             :             ++loop
      74             :         )
      75             :     {
      76         408 :         const SdrPageWindow& rPageWindow( *(*loop) );
      77         408 :         const SdrPaintWindow& rPaintWindow( rPageWindow.GetOriginalPaintWindow() ? *rPageWindow.GetOriginalPaintWindow() : rPageWindow.GetPaintWindow() );
      78         408 :         if ( &rPaintWindow.GetOutputDevice() == &_rOutDev )
      79             :         {
      80         396 :             return &rPageWindow;
      81             :         }
      82             :     }
      83             : 
      84           0 :     return NULL;
      85             : }
      86             : 
      87       28153 : SdrPageWindow* SdrPageView::FindPageWindow(const OutputDevice& rOutDev) const
      88             : {
      89       50242 :     for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
      90             :     {
      91       28431 :         if(&((*a)->GetPaintWindow().GetOutputDevice()) == &rOutDev)
      92             :         {
      93        6342 :             return *a;
      94             :         }
      95             :     }
      96             : 
      97       21811 :     return 0L;
      98             : }
      99             : 
     100       10256 : SdrPageWindow* SdrPageView::GetPageWindow(sal_uInt32 nIndex) const
     101             : {
     102       10256 :     if(nIndex < maPageWindows.size())
     103             :     {
     104       10256 :         return maPageWindows[nIndex];
     105             :     }
     106             : 
     107           0 :     return 0L;
     108             : }
     109             : 
     110        3732 : void SdrPageView::ClearPageWindows()
     111             : {
     112        5369 :     for(SdrPageWindowVector::const_iterator a = maPageWindows.begin(); a != maPageWindows.end(); ++a)
     113             :     {
     114        1637 :         delete *a;
     115             :     }
     116             : 
     117        3732 :     maPageWindows.clear();
     118        3732 : }
     119             : 
     120        1913 : void SdrPageView::AppendPageWindow(SdrPageWindow& rNew)
     121             : {
     122        1913 :     maPageWindows.push_back(&rNew);
     123        1913 : }
     124             : 
     125         273 : SdrPageWindow* SdrPageView::RemovePageWindow(SdrPageWindow& rOld)
     126             : {
     127         273 :     const SdrPageWindowVector::iterator aFindResult = ::std::find(maPageWindows.begin(), maPageWindows.end(), &rOld);
     128             : 
     129         273 :     if(aFindResult != maPageWindows.end())
     130             :     {
     131             :         // remember return value
     132         273 :         SdrPageWindow* pSdrPageWindow = *aFindResult;
     133         273 :         maPageWindows.erase(aFindResult);
     134         273 :         return pSdrPageWindow;
     135             :     }
     136             : 
     137           0 :     return 0L;
     138             : }
     139             : 
     140             : //////////////////////////////////////////////////////////////////////////////
     141             : 
     142        1932 : SdrPageView::SdrPageView(SdrPage* pPage1, SdrView& rNewView)
     143             : :   mrView(rNewView),
     144             :     // col_auto color lets the view takes the default SvxColorConfig entry
     145             :     maDocumentColor( COL_AUTO ),
     146             :     maBackgroundColor(COL_AUTO ), // #i48367# also react on autocolor
     147        1932 :     mpPreparedPageWindow(0) // #i72752#
     148             : {
     149             :     DBG_CTOR(SdrPageView,NULL);
     150        1932 :     mpPage = pPage1;
     151             : 
     152        1932 :     if(mpPage)
     153             :     {
     154        1932 :         aPgOrg.X()=mpPage->GetLftBorder();
     155        1932 :         aPgOrg.Y()=mpPage->GetUppBorder();
     156             :     }
     157        1932 :     mbHasMarked = sal_False;
     158        1932 :     aLayerVisi.SetAll();
     159        1932 :     aLayerPrn.SetAll();
     160             : 
     161        1932 :     mbVisible = sal_False;
     162        1932 :     pAktList = NULL;
     163        1932 :     pAktGroup = NULL;
     164        1932 :     SetAktGroupAndList(NULL, mpPage);
     165             : 
     166        3842 :     for(sal_uInt32 a(0L); a < rNewView.PaintWindowCount(); a++)
     167             :     {
     168        1910 :         AddPaintWindowToPageView(*rNewView.GetPaintWindow(a));
     169             :     }
     170        1932 : }
     171             : 
     172        3858 : SdrPageView::~SdrPageView()
     173             : {
     174             :     DBG_DTOR(SdrPageView,NULL);
     175             : 
     176             :     // cleanup window vector
     177        1929 :     ClearPageWindows();
     178        1929 : }
     179             : 
     180        1913 : SdrPageWindow& SdrPageView::CreateNewPageWindowEntry(SdrPaintWindow& rPaintWindow)
     181             : {
     182        1913 :     SdrPageWindow& rWindow = *(new SdrPageWindow(*this, rPaintWindow));
     183        1913 :     AppendPageWindow(rWindow);
     184             : 
     185        1913 :     return rWindow;
     186             : }
     187             : 
     188        3823 : void SdrPageView::AddPaintWindowToPageView(SdrPaintWindow& rPaintWindow)
     189             : {
     190        3823 :     if(!FindPageWindow(rPaintWindow))
     191             :     {
     192        1913 :         CreateNewPageWindowEntry(rPaintWindow);
     193             :     }
     194        3823 : }
     195             : 
     196         273 : void SdrPageView::RemovePaintWindowFromPageView(SdrPaintWindow& rPaintWindow)
     197             : {
     198         273 :     SdrPageWindow* pCandidate = FindPageWindow(rPaintWindow);
     199             : 
     200         273 :     if(pCandidate)
     201             :     {
     202         273 :         pCandidate = RemovePageWindow(*pCandidate);
     203             : 
     204         273 :         if(pCandidate)
     205             :         {
     206         273 :             delete pCandidate;
     207             :         }
     208             :     }
     209         273 : }
     210             : 
     211         396 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > SdrPageView::GetControlContainer( const OutputDevice& _rDevice ) const
     212             : {
     213         396 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > xReturn;
     214         396 :     const SdrPageWindow* pCandidate = FindPatchedPageWindow( _rDevice );
     215             : 
     216         396 :     if ( pCandidate )
     217         396 :         xReturn = pCandidate->GetControlContainer( true );
     218             : 
     219         396 :     return xReturn;
     220             : }
     221             : 
     222         708 : void SdrPageView::ModelHasChanged()
     223             : {
     224         708 :     if (GetAktGroup()!=NULL) CheckAktGroup();
     225         708 : }
     226             : 
     227           1 : sal_Bool SdrPageView::IsReadOnly() const
     228             : {
     229           1 :     return (0L == GetPage() || GetView().GetModel()->IsReadOnly() || GetPage()->IsReadOnly() || GetObjList()->IsReadOnly());
     230             : }
     231             : 
     232        1932 : void SdrPageView::Show()
     233             : {
     234        1932 :     if(!IsVisible())
     235             :     {
     236        1932 :         mbVisible = sal_True;
     237        1932 :         InvalidateAllWin();
     238             : 
     239        3842 :         for(sal_uInt32 a(0L); a < GetView().PaintWindowCount(); a++)
     240             :         {
     241        1910 :             AddPaintWindowToPageView(*GetView().GetPaintWindow(a));
     242             :         }
     243             :     }
     244        1932 : }
     245             : 
     246        1803 : void SdrPageView::Hide()
     247             : {
     248        1803 :     if(IsVisible())
     249             :     {
     250        1803 :         InvalidateAllWin();
     251        1803 :         mbVisible = sal_False;
     252        1803 :         ClearPageWindows();
     253             :     }
     254        1803 : }
     255             : 
     256           0 : Rectangle SdrPageView::GetPageRect() const
     257             : {
     258           0 :     if (GetPage()==NULL) return Rectangle();
     259           0 :     return Rectangle(Point(),Size(GetPage()->GetWdt()+1,GetPage()->GetHgt()+1));
     260             : }
     261             : 
     262        6802 : void SdrPageView::InvalidateAllWin()
     263             : {
     264        6802 :     if(IsVisible() && GetPage())
     265             :     {
     266        6802 :         Rectangle aRect(Point(0,0),Size(GetPage()->GetWdt()+1,GetPage()->GetHgt()+1));
     267        6802 :         aRect.Union(GetPage()->GetAllObjBoundRect());
     268        6802 :         GetView().InvalidateAllWin(aRect);
     269             :     }
     270        6802 : }
     271             : 
     272             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     273             : 
     274        7766 : void SdrPageView::PrePaint()
     275             : {
     276        7766 :     const sal_uInt32 nCount(PageWindowCount());
     277             : 
     278       15631 :     for(sal_uInt32 a(0); a < nCount; a++)
     279             :     {
     280        7865 :         SdrPageWindow* pCandidate = GetPageWindow(a);
     281             : 
     282        7865 :         if(pCandidate)
     283             :         {
     284        7865 :             pCandidate->PrePaint();
     285             :         }
     286             :     }
     287        7766 : }
     288             : 
     289         969 : void SdrPageView::CompleteRedraw(SdrPaintWindow& rPaintWindow, const Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector) const
     290             : {
     291         969 :     if(GetPage())
     292             :     {
     293         969 :         SdrPageWindow* pPageWindow = FindPageWindow(rPaintWindow);
     294         969 :         bool bIsTempTarget(false);
     295             : 
     296         969 :         if(!pPageWindow)
     297             :         {
     298             :             // create temp PageWindow
     299           0 :             pPageWindow = new SdrPageWindow(*((SdrPageView*)this), rPaintWindow);
     300           0 :             bIsTempTarget = true;
     301             :         }
     302             : 
     303             :         // do the redraw
     304         969 :         pPageWindow->PrepareRedraw(rReg);
     305         969 :         pPageWindow->RedrawAll(pRedirector);
     306             : 
     307             :         // get rid of temp PageWindow
     308         969 :         if(bIsTempTarget)
     309             :         {
     310           0 :             delete pPageWindow;
     311           0 :             pPageWindow = 0L;
     312             :         }
     313             :     }
     314         969 : }
     315             : 
     316             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     317             : // #i74769# use SdrPaintWindow directly
     318             : 
     319       45704 : void SdrPageView::setPreparedPageWindow(SdrPageWindow* pKnownTarget)
     320             : {
     321             :     // #i72752# remember prepared SdrPageWindow
     322       45704 :     mpPreparedPageWindow = pKnownTarget;
     323       45704 : }
     324             : 
     325       22145 : void SdrPageView::DrawLayer(SdrLayerID nID, OutputDevice* pGivenTarget, sdr::contact::ViewObjectContactRedirector* pRedirector, const Rectangle& rRect) const
     326             : {
     327       22145 :     if(GetPage())
     328             :     {
     329       22145 :         if(pGivenTarget)
     330             :         {
     331       22145 :             const SdrPageWindow* pKnownTarget = FindPageWindow(*pGivenTarget);
     332             : 
     333       22145 :             if(pKnownTarget)
     334             :             {
     335             :                 // paint known target
     336         334 :                 pKnownTarget->RedrawLayer(&nID, pRedirector);
     337             :             }
     338             :             else
     339             :             {
     340             :                 // #i72752# DrawLayer() uses a OutputDevice different from BeginDrawLayer. This happens
     341             :                 // e.g. when SW paints a single text line in text edit mode. Try to use it
     342       21811 :                 SdrPageWindow* pPreparedTarget = mpPreparedPageWindow;
     343             : 
     344       21811 :                 if(pPreparedTarget)
     345             :                 {
     346             :                     // if we have a prepared target, do not use a new SdrPageWindow since this
     347             :                     // works but is expensive. Just use a temporary PaintWindow
     348       21811 :                     SdrPaintWindow aTemporaryPaintWindow(mrView, *pGivenTarget);
     349             : 
     350             :                     // Copy existing paint region to use the same as prepared in BeginDrawLayer
     351       21811 :                     SdrPaintWindow& rExistingPaintWindow = pPreparedTarget->GetPaintWindow();
     352       21811 :                     const Region& rExistingRegion = rExistingPaintWindow.GetRedrawRegion();
     353       21811 :                     if ( rRect.IsEmpty() )
     354       10113 :                         aTemporaryPaintWindow.SetRedrawRegion(rExistingRegion);
     355             :                     else
     356       11698 :                         aTemporaryPaintWindow.SetRedrawRegion(Region(rRect));
     357             : 
     358             :                     // patch the ExistingPageWindow
     359       21811 :                     pPreparedTarget->patchPaintWindow(aTemporaryPaintWindow);
     360             : 
     361             :                     // redraw the layer
     362       21811 :                     pPreparedTarget->RedrawLayer(&nID, pRedirector);
     363             : 
     364             :                     // restore the ExistingPageWindow
     365       21811 :                     pPreparedTarget->unpatchPaintWindow();
     366             :                 }
     367             :                 else
     368             :                 {
     369             :                     OSL_FAIL("SdrPageView::DrawLayer: Creating temporary SdrPageWindow (ObjectContact), this should never be needed (!)");
     370             : 
     371             :                     // None of the known OutputDevices is the target of this paint, use
     372             :                     // a temporary SdrPageWindow for this Redraw.
     373           0 :                     SdrPaintWindow aTemporaryPaintWindow(mrView, *pGivenTarget);
     374           0 :                     SdrPageWindow aTemporaryPageWindow(*((SdrPageView*)this), aTemporaryPaintWindow);
     375             : 
     376             :                     // #i72752#
     377             :                     // Copy existing paint region if other PageWindows exist, this was created by
     378             :                     // PrepareRedraw() from BeginDrawLayer(). Needs to be used e.g. when suddenly SW
     379             :                     // paints into an unknown device other than the view was created for (e.g. VirtualDevice)
     380           0 :                     if(PageWindowCount())
     381             :                     {
     382           0 :                         SdrPageWindow* pExistingPageWindow = GetPageWindow(0L);
     383           0 :                         SdrPaintWindow& rExistingPaintWindow = pExistingPageWindow->GetPaintWindow();
     384           0 :                         const Region& rExistingRegion = rExistingPaintWindow.GetRedrawRegion();
     385           0 :                         aTemporaryPaintWindow.SetRedrawRegion(rExistingRegion);
     386             :                     }
     387             : 
     388           0 :                     aTemporaryPageWindow.RedrawLayer(&nID, pRedirector);
     389             :                 }
     390             :             }
     391             :         }
     392             :         else
     393             :         {
     394             :             // paint in all known windows
     395           0 :             for(sal_uInt32 a(0L); a < PageWindowCount(); a++)
     396             :             {
     397           0 :                 SdrPageWindow* pTarget = GetPageWindow(a);
     398           0 :                 pTarget->RedrawLayer(&nID, pRedirector);
     399             :             }
     400             :         }
     401             :     }
     402       22145 : }
     403             : 
     404           6 : void SdrPageView::SetDesignMode( bool _bDesignMode ) const
     405             : {
     406          12 :     for ( sal_uInt32 i = 0L; i < PageWindowCount(); ++i )
     407             :     {
     408           6 :         const SdrPageWindow& rPageViewWindow = *GetPageWindow(i);
     409           6 :         rPageViewWindow.SetDesignMode( _bDesignMode );
     410             :     }
     411           6 : }
     412             : 
     413             : ////////////////////////////////////////////////////////////////////////////////////////////////////
     414             : 
     415          13 : void SdrPageView::DrawPageViewGrid(OutputDevice& rOut, const Rectangle& rRect, Color aColor)
     416             : {
     417          13 :     if (GetPage()==NULL)
     418          13 :         return;
     419             : 
     420          13 :     long nx1=GetView().aGridBig.Width();
     421          13 :     long nx2=GetView().aGridFin.Width();
     422          13 :     long ny1=GetView().aGridBig.Height();
     423          13 :     long ny2=GetView().aGridFin.Height();
     424             : 
     425          13 :     if (nx1==0) nx1=nx2;
     426          13 :     if (nx2==0) nx2=nx1;
     427          13 :     if (ny1==0) ny1=ny2;
     428          13 :     if (ny2==0) ny2=ny1;
     429          13 :     if (nx1==0) { nx1=ny1; nx2=ny2; }
     430          13 :     if (ny1==0) { ny1=nx1; ny2=nx2; }
     431          13 :     if (nx1<0) nx1=-nx1;
     432          13 :     if (nx2<0) nx2=-nx2;
     433          13 :     if (ny1<0) ny1=-ny1;
     434          13 :     if (ny2<0) ny2=-ny2;
     435             : 
     436          13 :     if (nx1!=0)
     437             :     {
     438             :         // no more global output size, use window size instead to decide grid sizes
     439          13 :         long nScreenWdt = rOut.GetOutputSizePixel().Width();
     440             : 
     441          13 :         long nMinDotPix=2;
     442          13 :         long nMinLinPix=4;
     443             : 
     444          13 :         if (nScreenWdt>=1600)
     445             :         {
     446           0 :             nMinDotPix=4;
     447           0 :             nMinLinPix=8;
     448             :         }
     449          13 :         else if (nScreenWdt>=1024)
     450             :         {
     451           0 :             nMinDotPix=3;
     452           0 :             nMinLinPix=6;
     453             :         }
     454             :         else
     455             :         { // e. g. 640x480
     456          13 :             nMinDotPix=2;
     457          13 :             nMinLinPix=4;
     458             :         }
     459          13 :         Size aMinDotDist(rOut.PixelToLogic(Size(nMinDotPix,nMinDotPix)));
     460          13 :         Size aMinLinDist(rOut.PixelToLogic(Size(nMinLinPix,nMinLinPix)));
     461          13 :         bool bHoriSolid=nx2<aMinDotDist.Width();
     462          13 :         bool bVertSolid=ny2<aMinDotDist.Height();
     463             :         // enlarge line offset (minimum 4 pixels)
     464             :         // enlarge by: *2 *5 *10 *20 *50 *100 ...
     465          13 :         int nTgl=0;
     466          13 :         long nVal0=nx1;
     467          26 :         while (nx1<aMinLinDist.Width())
     468             :         {
     469           0 :             long a=nx1;
     470             : 
     471           0 :             if (nTgl==0) nx1*=2;
     472           0 :             if (nTgl==1) nx1=nVal0*5; // => nx1*=2.5
     473           0 :             if (nTgl==2) nx1*=2;
     474             : 
     475           0 :             nVal0=a;
     476           0 :             nTgl++; if (nTgl>=3) nTgl=0;
     477             :         }
     478          13 :         nTgl=0;
     479          13 :         nVal0=ny1;
     480          26 :         while (ny1<aMinLinDist.Height())
     481             :         {
     482           0 :             long a=ny1;
     483             : 
     484           0 :             if (nTgl==0) ny1*=2;
     485           0 :             if (nTgl==1) ny1=nVal0*5; // => ny1*=2.5
     486           0 :             if (nTgl==2) ny1*=2;
     487             : 
     488           0 :             nVal0=a;
     489           0 :             nTgl++;
     490             : 
     491           0 :             if (nTgl>=3) nTgl=0;
     492             :         }
     493             : 
     494          13 :         bool bHoriFine=nx2<nx1;
     495          13 :         bool bVertFine=ny2<ny1;
     496          13 :         bool bHoriLines=bHoriSolid || bHoriFine || !bVertFine;
     497          13 :         bool bVertLines=bVertSolid || bVertFine;
     498             : 
     499          13 :         Color aColorMerk( rOut.GetLineColor() );
     500          13 :         rOut.SetLineColor( aColor );
     501             : 
     502          13 :         bool bMap0=rOut.IsMapModeEnabled();
     503             : 
     504          13 :         long nWrX=0;
     505          13 :         long nWrY=0;
     506          13 :         Point aOrg(aPgOrg);
     507          13 :         long x1=GetPage()->GetLftBorder()+1+nWrX;
     508          13 :         long x2=GetPage()->GetWdt()-GetPage()->GetRgtBorder()-1+nWrY;
     509          13 :         long y1=GetPage()->GetUppBorder()+1+nWrX;
     510          13 :         long y2=GetPage()->GetHgt()-GetPage()->GetLwrBorder()-1+nWrY;
     511          13 :         const SdrPageGridFrameList* pFrames=GetPage()->GetGridFrameList(this,NULL);
     512             : 
     513          13 :         sal_uInt16 nGridPaintAnz=1;
     514          13 :         if (pFrames!=NULL) nGridPaintAnz=pFrames->GetCount();
     515          26 :         for (sal_uInt16 nGridPaintNum=0; nGridPaintNum<nGridPaintAnz; nGridPaintNum++) {
     516          13 :             if (pFrames!=NULL) {
     517          13 :                 const SdrPageGridFrame& rGF=(*pFrames)[nGridPaintNum];
     518          13 :                 nWrX=rGF.GetPaperRect().Left();
     519          13 :                 nWrY=rGF.GetPaperRect().Top();
     520          13 :                 x1=rGF.GetUserArea().Left();
     521          13 :                 x2=rGF.GetUserArea().Right();
     522          13 :                 y1=rGF.GetUserArea().Top();
     523          13 :                 y2=rGF.GetUserArea().Bottom();
     524          13 :                 aOrg=rGF.GetUserArea().TopLeft();
     525          13 :                 aOrg-=rGF.GetPaperRect().TopLeft();
     526             :             }
     527          13 :             if (!rRect.IsEmpty()) {
     528          13 :                 Size a1PixSiz(rOut.PixelToLogic(Size(1,1)));
     529          13 :                 long nX1Pix=a1PixSiz.Width();  // add 1 pixel of tolerance
     530          13 :                 long nY1Pix=a1PixSiz.Height();
     531          13 :                 if (x1<rRect.Left()  -nX1Pix) x1=rRect.Left()  -nX1Pix;
     532          13 :                 if (x2>rRect.Right() +nX1Pix) x2=rRect.Right() +nX1Pix;
     533          13 :                 if (y1<rRect.Top()   -nY1Pix) y1=rRect.Top()   -nY1Pix;
     534          13 :                 if (y2>rRect.Bottom()+nY1Pix) y2=rRect.Bottom()+nY1Pix;
     535             :             }
     536             : 
     537          13 :             long xBigOrg=aOrg.X()+nWrX;
     538          13 :             while (xBigOrg>=x1) xBigOrg-=nx1;
     539          13 :             while (xBigOrg<x1) xBigOrg+=nx1;
     540          13 :             long xFinOrg=xBigOrg;
     541          13 :             while (xFinOrg>=x1) xFinOrg-=nx2;
     542          13 :             while (xFinOrg<x1) xFinOrg+=nx2;
     543             : 
     544          13 :             long yBigOrg=aOrg.Y()+nWrY;
     545          13 :             while (yBigOrg>=y1) yBigOrg-=ny1;
     546          13 :             while (yBigOrg<y1) yBigOrg+=ny1;
     547          13 :             long yFinOrg=yBigOrg;
     548          13 :             while (yFinOrg>=y1) yFinOrg-=ny2;
     549          13 :             while (yFinOrg<y1) yFinOrg+=ny2;
     550             : 
     551          13 :             if( x1 <= x2 && y1 <= y2 )
     552             :             {
     553          13 :                 if( bHoriLines )
     554             :                 {
     555          13 :                     sal_uIntPtr nGridFlags = ( bHoriSolid ? GRID_HORZLINES : GRID_DOTS );
     556          13 :                     sal_uInt16 nSteps = sal_uInt16(nx1 / nx2);
     557          13 :                     sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((nx1 * 1000L)/ nSteps) - (nx2 * 1000L) ) : 0;
     558          13 :                     sal_uInt32 nStepOffset = 0;
     559          13 :                     sal_uInt16 nPointOffset = 0;
     560             : 
     561         129 :                     for(sal_uInt16 a=0;a<nSteps;a++)
     562             :                     {
     563             :                         // draw
     564             :                         rOut.DrawGrid(
     565         116 :                             Rectangle( xFinOrg + (a * nx2) + nPointOffset, yBigOrg, x2, y2 ),
     566         232 :                             Size( nx1, ny1 ), nGridFlags );
     567             : 
     568             :                         // do a step
     569         116 :                         nStepOffset += nRestPerStepMul1000;
     570         293 :                         while(nStepOffset >= 1000)
     571             :                         {
     572          61 :                             nStepOffset -= 1000;
     573          61 :                             nPointOffset++;
     574             :                         }
     575             :                     }
     576             :                 }
     577             : 
     578          13 :                 if( bVertLines )
     579             :                 {
     580          13 :                     sal_uIntPtr nGridFlags = ( bVertSolid ? GRID_VERTLINES : GRID_DOTS );
     581          13 :                     sal_uInt16 nSteps = sal_uInt16(ny1 / ny2);
     582          13 :                     sal_uInt32 nRestPerStepMul1000 = nSteps ? ( ((ny1 * 1000L)/ nSteps) - (ny2 * 1000L) ) : 0;
     583          13 :                     sal_uInt32 nStepOffset = 0;
     584          13 :                     sal_uInt16 nPointOffset = 0;
     585             : 
     586         109 :                     for(sal_uInt16 a=0;a<nSteps;a++)
     587             :                     {
     588             :                         // draw
     589             :                         rOut.DrawGrid(
     590          96 :                             Rectangle( xBigOrg, yFinOrg + (a * ny2) + nPointOffset, x2, y2 ),
     591         192 :                             Size( nx1, ny1 ), nGridFlags );
     592             : 
     593             :                         // do a step
     594          96 :                         nStepOffset += nRestPerStepMul1000;
     595         222 :                         while(nStepOffset >= 1000)
     596             :                         {
     597          30 :                             nStepOffset -= 1000;
     598          30 :                             nPointOffset++;
     599             :                         }
     600             :                     }
     601             :                 }
     602             :             }
     603             :         }
     604             : 
     605          13 :         rOut.EnableMapMode(bMap0);
     606          13 :         rOut.SetLineColor(aColorMerk);
     607             :     }
     608             : }
     609             : 
     610        3933 : void SdrPageView::AdjHdl()
     611             : {
     612        3933 :     GetView().AdjustMarkHdl();
     613        3933 : }
     614             : 
     615        5457 : void SdrPageView::SetLayer(const XubString& rName, SetOfByte& rBS, sal_Bool bJa)
     616             : {
     617        5457 :     if(!GetPage())
     618        5457 :         return;
     619             : 
     620        5457 :     SdrLayerID nID = GetPage()->GetLayerAdmin().GetLayerID(rName, sal_True);
     621             : 
     622        5457 :     if(SDRLAYER_NOTFOUND != nID)
     623        5457 :         rBS.Set(nID, bJa);
     624             : }
     625             : 
     626        6915 : sal_Bool SdrPageView::IsLayer(const XubString& rName, const SetOfByte& rBS) const
     627             : {
     628        6915 :     if(!GetPage())
     629           0 :         return sal_False;
     630             : 
     631        6915 :     sal_Bool bRet(sal_False);
     632             : 
     633        6915 :     if(rName.Len())
     634             :     {
     635        6915 :         SdrLayerID nId = GetPage()->GetLayerAdmin().GetLayerID(rName, sal_True);
     636             : 
     637        6915 :         if(SDRLAYER_NOTFOUND != nId)
     638             :         {
     639        6915 :             bRet = rBS.IsSet(nId);
     640             :         }
     641             :     }
     642             : 
     643        6915 :     return bRet;
     644             : }
     645             : 
     646         191 : sal_Bool SdrPageView::IsObjMarkable(SdrObject* pObj) const
     647             : {
     648         191 :     if(pObj)
     649             :     {
     650             :         // excluded from selection?
     651         191 :         if(pObj->IsMarkProtect())
     652             :         {
     653           0 :             return sal_False;
     654             :         }
     655             : 
     656             :         // only visible are selectable
     657         191 :         if( !pObj->IsVisible() )
     658             :         {
     659           0 :             return sal_False;
     660             :         }
     661             : 
     662         191 :         if(pObj->ISA(SdrObjGroup))
     663             :         {
     664             :             // If object is a Group object, visibility may depend on
     665             :             // multiple layers. If one object is markable, Group is markable.
     666          14 :             SdrObjList* pObjList = ((SdrObjGroup*)pObj)->GetSubList();
     667             : 
     668          14 :             if(pObjList && pObjList->GetObjCount())
     669             :             {
     670          14 :                 sal_Bool bGroupIsMarkable(sal_False);
     671             : 
     672          28 :                 for(sal_uInt32 a(0L); !bGroupIsMarkable && a < pObjList->GetObjCount(); a++)
     673             :                 {
     674          14 :                     SdrObject* pCandidate = pObjList->GetObj(a);
     675             : 
     676             :                     // call recursively
     677          14 :                     if(IsObjMarkable(pCandidate))
     678             :                     {
     679          14 :                         bGroupIsMarkable = sal_True;
     680             :                     }
     681             :                 }
     682             : 
     683          14 :                 return bGroupIsMarkable;
     684             :             }
     685             :             else
     686             :             {
     687             :                 // #i43302#
     688             :                 // Allow empty groups to be selected to be able to delete them
     689           0 :                 return sal_True;
     690             :             }
     691             :         }
     692             :         else
     693             :         {
     694             :             // the layer has to be visible and must not be locked
     695         177 :             SdrLayerID nL = pObj->GetLayer();
     696         177 :             return (aLayerVisi.IsSet(sal_uInt8(nL)) && !aLayerLock.IsSet(sal_uInt8(nL)));
     697             :         }
     698             :     }
     699             : 
     700           0 :     return sal_False;
     701             : }
     702             : 
     703           0 : void SdrPageView::SetPageOrigin(const Point& rOrg)
     704             : {
     705           0 :     if (rOrg!=aPgOrg) {
     706           0 :         aPgOrg=rOrg;
     707           0 :         if (GetView().IsGridVisible()) {
     708           0 :             InvalidateAllWin();
     709             :         }
     710             :     }
     711           0 : }
     712             : 
     713           0 : void SdrPageView::ImpInvalidateHelpLineArea(sal_uInt16 nNum) const
     714             : {
     715           0 :     if (GetView().IsHlplVisible() && nNum<aHelpLines.GetCount()) {
     716           0 :         const SdrHelpLine& rHL=aHelpLines[nNum];
     717             : 
     718           0 :         for(sal_uInt32 a(0L); a < GetView().PaintWindowCount(); a++)
     719             :         {
     720           0 :             SdrPaintWindow* pCandidate = GetView().GetPaintWindow(a);
     721             : 
     722           0 :             if(pCandidate->OutputToWindow())
     723             :             {
     724           0 :                 OutputDevice& rOutDev = pCandidate->GetOutputDevice();
     725           0 :                 Rectangle aR(rHL.GetBoundRect(rOutDev));
     726           0 :                 Size aSiz(rOutDev.PixelToLogic(Size(1,1)));
     727           0 :                 aR.Left() -= aSiz.Width();
     728           0 :                 aR.Right() += aSiz.Width();
     729           0 :                 aR.Top() -= aSiz.Height();
     730           0 :                 aR.Bottom() += aSiz.Height();
     731           0 :                 ((SdrView&)GetView()).InvalidateOneWin((Window&)rOutDev, aR);
     732             :             }
     733             :         }
     734             :     }
     735           0 : }
     736             : 
     737          70 : void SdrPageView::SetHelpLines(const SdrHelpLineList& rHLL)
     738             : {
     739          70 :     aHelpLines=rHLL;
     740          70 :     InvalidateAllWin();
     741          70 : }
     742             : 
     743           0 : void SdrPageView::SetHelpLine(sal_uInt16 nNum, const SdrHelpLine& rNewHelpLine)
     744             : {
     745           0 :     if (nNum<aHelpLines.GetCount() && aHelpLines[nNum]!=rNewHelpLine) {
     746           0 :         bool bNeedRedraw = true;
     747           0 :         if (aHelpLines[nNum].GetKind()==rNewHelpLine.GetKind()) {
     748           0 :             switch (rNewHelpLine.GetKind()) {
     749           0 :                 case SDRHELPLINE_VERTICAL  : if (aHelpLines[nNum].GetPos().X()==rNewHelpLine.GetPos().X()) bNeedRedraw = false; break;
     750           0 :                 case SDRHELPLINE_HORIZONTAL: if (aHelpLines[nNum].GetPos().Y()==rNewHelpLine.GetPos().Y()) bNeedRedraw = false; break;
     751           0 :                 default: break;
     752             :             } // switch
     753             :         }
     754           0 :         if (bNeedRedraw) ImpInvalidateHelpLineArea(nNum);
     755           0 :         aHelpLines[nNum]=rNewHelpLine;
     756           0 :         if (bNeedRedraw) ImpInvalidateHelpLineArea(nNum);
     757             :     }
     758           0 : }
     759             : 
     760           0 : void SdrPageView::DeleteHelpLine(sal_uInt16 nNum)
     761             : {
     762           0 :     if (nNum<aHelpLines.GetCount()) {
     763           0 :         ImpInvalidateHelpLineArea(nNum);
     764           0 :         aHelpLines.Delete(nNum);
     765             :     }
     766           0 : }
     767             : 
     768           0 : void SdrPageView::InsertHelpLine(const SdrHelpLine& rHL, sal_uInt16 nNum)
     769             : {
     770           0 :     if (nNum > aHelpLines.GetCount())
     771           0 :         nNum = aHelpLines.GetCount();
     772           0 :     aHelpLines.Insert(rHL,nNum);
     773           0 :     if (GetView().IsHlplVisible())
     774           0 :         ImpInvalidateHelpLineArea(nNum);
     775           0 : }
     776             : 
     777             : // set current group and list
     778        1932 : void SdrPageView::SetAktGroupAndList(SdrObject* pNewGroup, SdrObjList* pNewList)
     779             : {
     780        1932 :     if(pAktGroup != pNewGroup)
     781             :     {
     782           0 :         pAktGroup = pNewGroup;
     783             :     }
     784        1932 :     if(pAktList != pNewList)
     785             :     {
     786        1932 :         pAktList = pNewList;
     787             :     }
     788        1932 : }
     789             : 
     790           0 : sal_Bool SdrPageView::EnterGroup(SdrObject* pObj)
     791             : {
     792           0 :     sal_Bool bRet(sal_False);
     793             : 
     794           0 :     if(pObj && pObj->IsGroupObject())
     795             :     {
     796           0 :         sal_Bool bGlueInvalidate(GetView().ImpIsGlueVisible());
     797             : 
     798           0 :         if(bGlueInvalidate)
     799             :         {
     800           0 :             GetView().GlueInvalidate();
     801             :         }
     802             : 
     803             :         // deselect all
     804           0 :         GetView().UnmarkAll();
     805             : 
     806             :         // set current group and list
     807           0 :         SdrObjList* pNewObjList = pObj->GetSubList();
     808           0 :         SetAktGroupAndList(pObj, pNewObjList);
     809             : 
     810             :         // select contained object if only one object is contained,
     811             :         // else select nothing and let the user decide what to do next
     812           0 :         if(pNewObjList && pNewObjList->GetObjCount() == 1)
     813             :         {
     814           0 :             SdrObject* pFirstObject = pNewObjList->GetObj(0L);
     815             : 
     816           0 :             if(GetView().GetSdrPageView())
     817             :             {
     818           0 :                 GetView().MarkObj(pFirstObject, GetView().GetSdrPageView());
     819             :             }
     820             :         }
     821             : 
     822             :         // build new handles
     823           0 :         GetView().AdjustMarkHdl();
     824             : 
     825             :         // invalidate only when view wants to visualize group entering
     826           0 :         if(GetView().DoVisualizeEnteredGroup())
     827             :         {
     828           0 :             InvalidateAllWin();
     829             :         }
     830             : 
     831           0 :         if (bGlueInvalidate)
     832             :         {
     833           0 :             GetView().GlueInvalidate();
     834             :         }
     835             : 
     836           0 :         bRet = sal_True;
     837             :     }
     838             : 
     839           0 :     return bRet;
     840             : }
     841             : 
     842           0 : void SdrPageView::LeaveOneGroup()
     843             : {
     844           0 :     if(GetAktGroup())
     845             :     {
     846           0 :         sal_Bool bGlueInvalidate = (GetView().ImpIsGlueVisible());
     847             : 
     848           0 :         if(bGlueInvalidate)
     849           0 :             GetView().GlueInvalidate();
     850             : 
     851           0 :         SdrObject* pLastGroup = GetAktGroup();
     852           0 :         SdrObject* pParentGroup = GetAktGroup()->GetUpGroup();
     853           0 :         SdrObjList* pParentList = GetPage();
     854             : 
     855           0 :         if(pParentGroup)
     856           0 :             pParentList = pParentGroup->GetSubList();
     857             : 
     858             :         // deselect everything
     859           0 :         GetView().UnmarkAll();
     860             : 
     861             :         // allocations, pAktGroup and pAktList need to be set
     862           0 :         SetAktGroupAndList(pParentGroup, pParentList);
     863             : 
     864             :         // select the group we just left
     865           0 :         if(pLastGroup)
     866           0 :             if(GetView().GetSdrPageView())
     867           0 :                 GetView().MarkObj(pLastGroup, GetView().GetSdrPageView());
     868             : 
     869           0 :         GetView().AdjustMarkHdl();
     870             : 
     871             :         // invalidate only if view wants to visualize group entering
     872           0 :         if(GetView().DoVisualizeEnteredGroup())
     873           0 :             InvalidateAllWin();
     874             : 
     875           0 :         if(bGlueInvalidate)
     876           0 :             GetView().GlueInvalidate();
     877             :     }
     878           0 : }
     879             : 
     880           0 : void SdrPageView::LeaveAllGroup()
     881             : {
     882           0 :     if(GetAktGroup())
     883             :     {
     884           0 :         sal_Bool bGlueInvalidate = (GetView().ImpIsGlueVisible());
     885             : 
     886           0 :         if(bGlueInvalidate)
     887           0 :             GetView().GlueInvalidate();
     888             : 
     889           0 :         SdrObject* pLastGroup = GetAktGroup();
     890             : 
     891             :         // deselect everything
     892           0 :         GetView().UnmarkAll();
     893             : 
     894             :         // allocations, pAktGroup and pAktList always need to be set
     895           0 :         SetAktGroupAndList(NULL, GetPage());
     896             : 
     897             :         // find and select uppermost group
     898           0 :         if(pLastGroup)
     899             :         {
     900           0 :             while(pLastGroup->GetUpGroup())
     901           0 :                 pLastGroup = pLastGroup->GetUpGroup();
     902             : 
     903           0 :             if(GetView().GetSdrPageView())
     904           0 :                 GetView().MarkObj(pLastGroup, GetView().GetSdrPageView());
     905             :         }
     906             : 
     907           0 :         GetView().AdjustMarkHdl();
     908             : 
     909             :         // invalidate only when view wants to visualize group entering
     910           0 :         if(GetView().DoVisualizeEnteredGroup())
     911           0 :             InvalidateAllWin();
     912             : 
     913           0 :         if(bGlueInvalidate)
     914           0 :             GetView().GlueInvalidate();
     915             :     }
     916           0 : }
     917             : 
     918        3280 : sal_uInt16 SdrPageView::GetEnteredLevel() const
     919             : {
     920        3280 :     sal_uInt16 nAnz=0;
     921        3280 :     SdrObject* pGrp=GetAktGroup();
     922        6560 :     while (pGrp!=NULL) {
     923           0 :         nAnz++;
     924           0 :         pGrp=pGrp->GetUpGroup();
     925             :     }
     926        3280 :     return nAnz;
     927             : }
     928             : 
     929           0 : void SdrPageView::CheckAktGroup()
     930             : {
     931           0 :     SdrObject* pGrp=GetAktGroup();
     932           0 :     while (pGrp!=NULL &&
     933           0 :            (!pGrp->IsInserted() || pGrp->GetObjList()==NULL ||
     934           0 :             pGrp->GetPage()==NULL || pGrp->GetModel()==NULL)) { // anything outside of the borders?
     935           0 :         pGrp=pGrp->GetUpGroup();
     936             :     }
     937           0 :     if (pGrp!=GetAktGroup()) {
     938           0 :         if (pGrp!=NULL) EnterGroup(pGrp);
     939           0 :         else LeaveAllGroup();
     940             :     }
     941           0 : }
     942             : 
     943             : // Set background color for svx at SdrPageViews
     944         828 : void SdrPageView::SetApplicationBackgroundColor(Color aBackgroundColor)
     945             : {
     946         828 :     maBackgroundColor = aBackgroundColor;
     947         828 : }
     948             : 
     949         656 : Color SdrPageView::GetApplicationBackgroundColor() const
     950             : {
     951         656 :     return maBackgroundColor;
     952             : }
     953             : 
     954             : // Set document color for svx at SdrPageViews
     955         137 : void SdrPageView::SetApplicationDocumentColor(Color aDocumentColor)
     956             : {
     957         137 :     maDocumentColor = aDocumentColor;
     958         137 : }
     959             : 
     960        2035 : Color SdrPageView::GetApplicationDocumentColor() const
     961             : {
     962        2035 :     return maDocumentColor;
     963         258 : }
     964             : 
     965             : 
     966             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10