LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdglev.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 30 255 11.8 %
Date: 2014-04-11 Functions: 6 26 23.1 %
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 <svx/svdglev.hxx>
      22             : #include <math.h>
      23             : 
      24             : #include <svx/svdundo.hxx>
      25             : #include "svx/svdstr.hrc"
      26             : #include "svx/svdglob.hxx"
      27             : #include <svx/svdpagv.hxx>
      28             : #include <svx/svdglue.hxx>
      29             : #include <svx/svdtrans.hxx>
      30             : #include <svx/svdobj.hxx>
      31             : 
      32             : 
      33             : 
      34        5800 : void SdrGlueEditView::ImpClearVars()
      35             : {
      36        5800 : }
      37             : 
      38        5800 : SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
      39        5800 :     SdrPolyEditView(pModel1,pOut)
      40             : {
      41        5800 :     ImpClearVars();
      42        5800 : }
      43             : 
      44        5585 : SdrGlueEditView::~SdrGlueEditView()
      45             : {
      46        5585 : }
      47             : 
      48             : 
      49             : 
      50         400 : void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
      51             : {
      52         400 :     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
      53         410 :     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
      54          10 :         SdrMark* pM=GetSdrMarkByIndex(nm);
      55          10 :         SdrObject* pObj=pM->GetMarkedSdrObj();
      56          10 :         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
      57          10 :         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
      58          10 :         if (nPtAnz!=0) {
      59           0 :             SdrGluePointList* pGPL=NULL;
      60           0 :             if (bConst) {
      61           0 :                 const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
      62           0 :                 pGPL=(SdrGluePointList*)pConstGPL;
      63             :             } else {
      64           0 :                 pGPL=pObj->ForceGluePointList();
      65             :             }
      66           0 :             if (pGPL!=NULL)
      67             :             {
      68           0 :                 if(!bConst && IsUndoEnabled() )
      69           0 :                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
      70             : 
      71           0 :                 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
      72             :                 {
      73           0 :                     sal_uInt16 nPtId=*it;
      74           0 :                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
      75           0 :                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
      76             :                     {
      77           0 :                         SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
      78           0 :                         (*pDoFunc)(rGP,pObj,p1,p2,p3,p4,p5);
      79             :                     }
      80             :                 }
      81           0 :                 if (!bConst)
      82             :                 {
      83           0 :                     pObj->SetChanged();
      84           0 :                     pObj->BroadcastObjectChange();
      85             :                 }
      86             :             }
      87             :         }
      88             :     }
      89         400 :     if (!bConst && nMarkAnz!=0) pMod->SetChanged();
      90         400 : }
      91             : 
      92             : 
      93             : 
      94           0 : static void ImpGetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*, const void*)
      95             : {
      96           0 :     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
      97           0 :     bool& bFirst=*(bool*)pbFirst;
      98           0 :     if (nRet!=FUZZY) {
      99           0 :         sal_uInt16 nEsc = rGP.GetEscDir();
     100           0 :         bool bOn = (nEsc & *(sal_uInt16*)pnThisEsc) != 0;
     101           0 :         if (bFirst) {
     102           0 :             nRet = bOn ? 1 : 0;
     103           0 :             bFirst = false;
     104             :         }
     105           0 :         else if (nRet != (bOn ? 1 : 0)) nRet=FUZZY;
     106             :     }
     107           0 : }
     108             : 
     109         320 : TRISTATE SdrGlueEditView::IsMarkedGluePointsEscDir(sal_uInt16 nThisEsc) const
     110             : {
     111         320 :     ForceUndirtyMrkPnt();
     112         320 :     bool bFirst=true;
     113         320 :     sal_uInt16 nRet=0;
     114         320 :     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
     115         320 :     return (TRISTATE)nRet;
     116             : }
     117             : 
     118           0 : static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*, const void*)
     119             : {
     120           0 :     sal_uInt16 nEsc=rGP.GetEscDir();
     121           0 :     if (*(bool*)pbOn) nEsc|=*(sal_uInt16*)pnThisEsc;
     122           0 :     else nEsc&=~*(sal_uInt16*)pnThisEsc;
     123           0 :     rGP.SetEscDir(nEsc);
     124           0 : }
     125             : 
     126           0 : void SdrGlueEditView::SetMarkedGluePointsEscDir(sal_uInt16 nThisEsc, bool bOn)
     127             : {
     128           0 :     ForceUndirtyMrkPnt();
     129           0 :     BegUndo(ImpGetResStr(STR_EditSetGlueEscDir),GetDescriptionOfMarkedGluePoints());
     130           0 :     ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
     131           0 :     EndUndo();
     132           0 : }
     133             : 
     134             : 
     135             : 
     136           0 : static void ImpGetPercent(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*, const void*)
     137             : {
     138           0 :     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
     139           0 :     bool& bFirst=*(bool*)pbFirst;
     140           0 :     if (nRet!=FUZZY) {
     141           0 :         bool bOn=rGP.IsPercent();
     142           0 :         if (bFirst) { nRet=sal_uInt16(bOn); bFirst=false; }
     143           0 :         else if ((nRet!=0)!=bOn) nRet=FUZZY;
     144             :     }
     145           0 : }
     146             : 
     147          80 : TRISTATE SdrGlueEditView::IsMarkedGluePointsPercent() const
     148             : {
     149          80 :     ForceUndirtyMrkPnt();
     150          80 :     bool bFirst=true;
     151          80 :     sal_uInt16 nRet=sal_True;
     152          80 :     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
     153          80 :     return (TRISTATE)nRet;
     154             : }
     155             : 
     156           0 : static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*, const void*)
     157             : {
     158           0 :     Point aPos(rGP.GetAbsolutePos(*pObj));
     159           0 :     rGP.SetPercent(*(bool*)pbOn);
     160           0 :     rGP.SetAbsolutePos(aPos,*pObj);
     161           0 : }
     162             : 
     163           0 : void SdrGlueEditView::SetMarkedGluePointsPercent(bool bOn)
     164             : {
     165           0 :     ForceUndirtyMrkPnt();
     166           0 :     BegUndo(ImpGetResStr(STR_EditSetGluePercent),GetDescriptionOfMarkedGluePoints());
     167           0 :     ImpDoMarkedGluePoints(ImpSetPercent,false,&bOn);
     168           0 :     EndUndo();
     169           0 : }
     170             : 
     171             : 
     172             : 
     173           0 : static void ImpGetAlign(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet, const void*)
     174             : {
     175           0 :     sal_uInt16& nRet=*(sal_uInt16*)pnRet;
     176           0 :     bool& bFirst=*(bool*)pbFirst;
     177           0 :     bool& bDontCare=*(bool*)pbDontCare;
     178           0 :     bool bVert=*(bool*)pbVert;
     179           0 :     if (!bDontCare) {
     180           0 :         sal_uInt16 nAlg=0;
     181           0 :         if (bVert) {
     182           0 :             nAlg=rGP.GetVertAlign();
     183             :         } else {
     184           0 :             nAlg=rGP.GetHorzAlign();
     185             :         }
     186           0 :         if (bFirst) { nRet=nAlg; bFirst=false; }
     187           0 :         else if (nRet!=nAlg) {
     188           0 :             if (bVert) {
     189           0 :                 nRet=SDRVERTALIGN_DONTCARE;
     190             :             } else {
     191           0 :                 nRet=SDRHORZALIGN_DONTCARE;
     192             :             }
     193           0 :             bDontCare=true;
     194             :         }
     195             :     }
     196           0 : }
     197             : 
     198           0 : sal_uInt16 SdrGlueEditView::GetMarkedGluePointsAlign(bool bVert) const
     199             : {
     200           0 :     ForceUndirtyMrkPnt();
     201           0 :     bool bFirst=true;
     202           0 :     bool bDontCare=false;
     203           0 :     sal_uInt16 nRet=0;
     204           0 :     ((SdrGlueEditView*)this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
     205           0 :     return nRet;
     206             : }
     207             : 
     208           0 : static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*, const void*)
     209             : {
     210           0 :     Point aPos(rGP.GetAbsolutePos(*pObj));
     211           0 :     if (*(bool*)pbVert) { // bVert?
     212           0 :         rGP.SetVertAlign(*(sal_uInt16*)pnAlign);
     213             :     } else {
     214           0 :         rGP.SetHorzAlign(*(sal_uInt16*)pnAlign);
     215             :     }
     216           0 :     rGP.SetAbsolutePos(aPos,*pObj);
     217           0 : }
     218             : 
     219           0 : void SdrGlueEditView::SetMarkedGluePointsAlign(bool bVert, sal_uInt16 nAlign)
     220             : {
     221           0 :     ForceUndirtyMrkPnt();
     222           0 :     BegUndo(ImpGetResStr(STR_EditSetGlueAlign),GetDescriptionOfMarkedGluePoints());
     223           0 :     ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
     224           0 :     EndUndo();
     225           0 : }
     226             : 
     227           0 : void SdrGlueEditView::DeleteMarkedGluePoints()
     228             : {
     229           0 :     BrkAction();
     230           0 :     ForceUndirtyMrkPnt();
     231           0 :     const bool bUndo = IsUndoEnabled();
     232           0 :     if( bUndo )
     233           0 :         BegUndo(ImpGetResStr(STR_EditDelete),GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_DELETE);
     234             : 
     235           0 :     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
     236           0 :     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
     237             :     {
     238           0 :         SdrMark* pM=GetSdrMarkByIndex(nm);
     239           0 :         SdrObject* pObj=pM->GetMarkedSdrObj();
     240           0 :         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
     241           0 :         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
     242           0 :         if (nPtAnz!=0)
     243             :         {
     244           0 :             SdrGluePointList* pGPL=pObj->ForceGluePointList();
     245           0 :             if (pGPL!=NULL)
     246             :             {
     247           0 :                 if( bUndo )
     248           0 :                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
     249             : 
     250           0 :                 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
     251             :                 {
     252           0 :                     sal_uInt16 nPtId=*it;
     253           0 :                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
     254           0 :                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
     255             :                     {
     256           0 :                         pGPL->Delete(nGlueIdx);
     257             :                     }
     258             :                 }
     259           0 :                 pObj->SetChanged();
     260           0 :                 pObj->BroadcastObjectChange();
     261             :             }
     262             :         }
     263             :     }
     264           0 :     if( bUndo )
     265           0 :         EndUndo();
     266           0 :     UnmarkAllGluePoints();
     267           0 :     if (nMarkAnz!=0)
     268           0 :         pMod->SetChanged();
     269           0 : }
     270             : 
     271             : 
     272             : 
     273           0 : void SdrGlueEditView::ImpCopyMarkedGluePoints()
     274             : {
     275           0 :     const bool bUndo = IsUndoEnabled();
     276             : 
     277           0 :     if( bUndo )
     278           0 :         BegUndo();
     279             : 
     280           0 :     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
     281           0 :     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++)
     282             :     {
     283           0 :         SdrMark* pM=GetSdrMarkByIndex(nm);
     284           0 :         SdrObject* pObj=pM->GetMarkedSdrObj();
     285           0 :         SdrUShortCont* pPts=pM->GetMarkedGluePoints();
     286           0 :         SdrGluePointList* pGPL=pObj->ForceGluePointList();
     287           0 :         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
     288           0 :         if (nPtAnz!=0 && pGPL!=NULL)
     289             :         {
     290           0 :             if( bUndo )
     291           0 :                 AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
     292             : 
     293           0 :             SdrUShortCont aIdsToErase;
     294           0 :             SdrUShortCont aIdsToInsert;
     295           0 :             for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
     296             :             {
     297           0 :                 sal_uInt16 nPtId=*it;
     298           0 :                 sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
     299           0 :                 if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
     300             :                 {
     301           0 :                     SdrGluePoint aNewGP((*pGPL)[nGlueIdx]);  // clone GluePoint
     302           0 :                     sal_uInt16 nNewIdx=pGPL->Insert(aNewGP);     // and insert it
     303           0 :                     sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId();  // retrieve ID of new GluePoints
     304           0 :                     aIdsToErase.insert(nPtId);               // select it (instead of the old one)
     305           0 :                     aIdsToInsert.insert(nNewId);
     306             :                 }
     307             :             }
     308           0 :             for(SdrUShortCont::const_iterator it = aIdsToErase.begin(); it != aIdsToErase.end(); ++it)
     309           0 :                 pPts->erase(*it);
     310           0 :             pPts->insert(aIdsToInsert.begin(), aIdsToInsert.end());
     311             : 
     312             :         }
     313             :     }
     314           0 :     if( bUndo )
     315           0 :         EndUndo();
     316             : 
     317           0 :     if (nMarkAnz!=0)
     318           0 :         pMod->SetChanged();
     319           0 : }
     320             : 
     321             : 
     322             : 
     323           0 : void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4, const void* p5)
     324             : {
     325           0 :     sal_uIntPtr nMarkAnz=GetMarkedObjectCount();
     326           0 :     for (sal_uIntPtr nm=0; nm<nMarkAnz; nm++) {
     327           0 :         SdrMark* pM=GetSdrMarkByIndex(nm);
     328           0 :         SdrObject* pObj=pM->GetMarkedSdrObj();
     329           0 :         const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
     330           0 :         sal_uIntPtr nPtAnz=pPts==NULL ? 0 : pPts->size();
     331           0 :         if (nPtAnz!=0) {
     332           0 :             SdrGluePointList* pGPL=pObj->ForceGluePointList();
     333           0 :             if (pGPL!=NULL)
     334             :             {
     335           0 :                 if( IsUndoEnabled() )
     336           0 :                     AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
     337             : 
     338           0 :                 for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
     339             :                 {
     340           0 :                     sal_uInt16 nPtId=*it;
     341           0 :                     sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
     342           0 :                     if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
     343           0 :                         SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
     344           0 :                         Point aPos(rGP.GetAbsolutePos(*pObj));
     345           0 :                         (*pTrFunc)(aPos,p1,p2,p3,p4,p5);
     346           0 :                         rGP.SetAbsolutePos(aPos,*pObj);
     347             :                     }
     348             :                 }
     349           0 :                 pObj->SetChanged();
     350           0 :                 pObj->BroadcastObjectChange();
     351             :             }
     352             :         }
     353             :     }
     354           0 :     if (nMarkAnz!=0) pMod->SetChanged();
     355           0 : }
     356             : 
     357             : 
     358             : 
     359           0 : static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/, const void* /*p5*/)
     360             : {
     361           0 :     rPt.X()+=((const Size*)p1)->Width();
     362           0 :     rPt.Y()+=((const Size*)p1)->Height();
     363           0 : }
     364             : 
     365           0 : void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
     366             : {
     367           0 :     ForceUndirtyMrkPnt();
     368           0 :     OUString aStr(ImpGetResStr(STR_EditMove));
     369           0 :     if (bCopy) aStr += ImpGetResStr(STR_EditWithCopy);
     370           0 :     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_MOVE);
     371           0 :     if (bCopy) ImpCopyMarkedGluePoints();
     372           0 :     ImpTransformMarkedGluePoints(ImpMove,&rSiz);
     373           0 :     EndUndo();
     374           0 :     AdjustMarkHdl();
     375           0 : }
     376             : 
     377             : 
     378             : 
     379           0 : static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/, const void* /*p5*/)
     380             : {
     381           0 :     ResizePoint(rPt,*(const Point*)p1,*(const Fraction*)p2,*(const Fraction*)p3);
     382           0 : }
     383             : 
     384           0 : void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
     385             : {
     386           0 :     ForceUndirtyMrkPnt();
     387           0 :     OUString aStr(ImpGetResStr(STR_EditResize));
     388           0 :     if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
     389           0 :     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_RESIZE);
     390           0 :     if (bCopy) ImpCopyMarkedGluePoints();
     391           0 :     ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
     392           0 :     EndUndo();
     393           0 :     AdjustMarkHdl();
     394           0 : }
     395             : 
     396             : 
     397             : 
     398           0 : static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4, const void* /*p5*/)
     399             : {
     400           0 :     RotatePoint(rPt,*(const Point*)p1,*(const double*)p3,*(const double*)p4);
     401           0 : }
     402             : 
     403           0 : void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, long nWink, bool bCopy)
     404             : {
     405           0 :     ForceUndirtyMrkPnt();
     406           0 :     OUString aStr(ImpGetResStr(STR_EditRotate));
     407           0 :     if (bCopy) aStr+=ImpGetResStr(STR_EditWithCopy);
     408           0 :     BegUndo(aStr,GetDescriptionOfMarkedGluePoints(),SDRREPFUNC_OBJ_ROTATE);
     409           0 :     if (bCopy) ImpCopyMarkedGluePoints();
     410           0 :     double nSin=sin(nWink*nPi180);
     411           0 :     double nCos=cos(nWink*nPi180);
     412           0 :     ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nWink,&nSin,&nCos);
     413           0 :     EndUndo();
     414           0 :     AdjustMarkHdl();
     415           0 : }
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10