LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuconstr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 140 8.6 %
Date: 2015-06-13 12:38:46 Functions: 5 17 29.4 %
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 "fuconstr.hxx"
      21             : 
      22             : #include <svx/svxids.hrc>
      23             : #include <svl/aeitem.hxx>
      24             : #include <svx/svdpagv.hxx>
      25             : #include <svx/xdef.hxx>
      26             : #include <svx/xfillit0.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <sfx2/viewfrm.hxx>
      29             : 
      30             : #include "app.hrc"
      31             : #include "glob.hrc"
      32             : #include "fudraw.hxx"
      33             : #include "View.hxx"
      34             : #include "Window.hxx"
      35             : #include "ViewShell.hxx"
      36             : #include "drawdoc.hxx"
      37             : #include "FrameView.hxx"
      38             : #include "sdpage.hxx"
      39             : #include "sdresid.hxx"
      40             : #include "stlpool.hxx"
      41             : #include <svx/globl3d.hxx>
      42             : 
      43             : using namespace com::sun::star;
      44             : 
      45             : namespace sd {
      46             : 
      47           0 : TYPEINIT1( FuConstruct, FuDraw );
      48             : 
      49           3 : FuConstruct::FuConstruct (
      50             :     ViewShell*      pViewSh,
      51             :     ::sd::Window*           pWin,
      52             :     ::sd::View*         pView,
      53             :     SdDrawDocument* pDoc,
      54             :     SfxRequest&     rReq)
      55             :     : FuDraw(pViewSh, pWin, pView, pDoc, rReq),
      56           3 :       bSelectionChanged(false)
      57             : {
      58           3 : }
      59             : 
      60           0 : void FuConstruct::DoExecute( SfxRequest& rReq )
      61             : {
      62           0 :     FuDraw::DoExecute( rReq );
      63           0 : }
      64             : 
      65           0 : bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
      66             : {
      67           0 :     bool bReturn = FuDraw::MouseButtonDown(rMEvt);
      68             : 
      69           0 :     bMBDown = true;
      70           0 :     bSelectionChanged = false;
      71             : 
      72           0 :     if ( mpView->IsAction() )
      73             :     {
      74           0 :         return true;
      75             :     }
      76             : 
      77           0 :     bFirstMouseMove = true;
      78           0 :     aDragTimer.Start();
      79             : 
      80           0 :     aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
      81           0 :     sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
      82             : 
      83           0 :     if (rMEvt.IsLeft() && mpView->IsExtendedMouseEventDispatcherEnabled())
      84             :     {
      85           0 :         mpWindow->CaptureMouse();
      86             : 
      87           0 :         SdrHdl* pHdl = mpView->PickHandle(aMDPos);
      88             : 
      89           0 :         if ( pHdl != NULL || mpView->IsMarkedHit(aMDPos, nHitLog) )
      90             :         {
      91           0 :             sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
      92           0 :             mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
      93           0 :             bReturn = true;
      94             :         }
      95           0 :         else if ( mpView->AreObjectsMarked() )
      96             :         {
      97           0 :             mpView->UnmarkAll();
      98           0 :             bReturn = true;
      99             :         }
     100             :     }
     101             : 
     102           0 :     return bReturn;
     103             : }
     104             : 
     105           0 : bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
     106             : {
     107           0 :     FuDraw::MouseMove(rMEvt);
     108             : 
     109           0 :     if (aDragTimer.IsActive() )
     110             :     {
     111           0 :         if( bFirstMouseMove )
     112           0 :             bFirstMouseMove = false;
     113             :         else
     114           0 :             aDragTimer.Stop();
     115             :     }
     116             : 
     117           0 :     Point aPix(rMEvt.GetPosPixel());
     118           0 :     Point aPnt( mpWindow->PixelToLogic(aPix) );
     119             : 
     120           0 :     if ( mpView->IsAction() )
     121             :     {
     122           0 :         ForceScroll(aPix);
     123           0 :         mpView->MovAction(aPnt);
     124             :     }
     125             : 
     126           0 :     return true;
     127             : }
     128             : 
     129           0 : bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
     130             : {
     131           0 :     bool bReturn = true;
     132             : 
     133           0 :     if (aDragTimer.IsActive() )
     134             :     {
     135           0 :         aDragTimer.Stop();
     136           0 :         bIsInDragMode = false;
     137             :     }
     138             : 
     139           0 :     FuDraw::MouseButtonUp(rMEvt);
     140             : 
     141           0 :     Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
     142             : 
     143           0 :     if ( mpView && mpView->IsDragObj() )
     144             :     {
     145           0 :         FrameView* pFrameView = mpViewShell->GetFrameView();
     146           0 :         bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
     147             : 
     148           0 :         if (bDragWithCopy)
     149             :         {
     150           0 :             bDragWithCopy = !mpView->IsPresObjSelected(false, true);
     151             :         }
     152             : 
     153           0 :         mpView->SetDragWithCopy(bDragWithCopy);
     154           0 :         mpView->EndDragObj( mpView->IsDragWithCopy() );
     155             :     }
     156           0 :     else if ( mpView && mpView->IsMarkObj() )
     157             :     {
     158           0 :         mpView->EndMarkObj();
     159             :     }
     160             :     else
     161             :     {
     162           0 :         bReturn = false;
     163             :     }
     164             : 
     165           0 :     if ( mpView &&  !mpView->IsAction() )
     166             :     {
     167           0 :         mpWindow->ReleaseMouse();
     168           0 :         sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
     169             : 
     170           0 :         if ( !mpView->AreObjectsMarked() )
     171             :         {
     172             :             SdrObject* pObj;
     173             :             SdrPageView* pPV;
     174           0 :             sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
     175             : 
     176           0 :             if (!mpView->PickObj(aPnt, mpView->getHitTolLog(), pObj, pPV))
     177             :             {
     178           0 :                 mpView->MarkObj(aPnt, nHitLog);
     179             :             }
     180             : 
     181           0 :             mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
     182             :         }
     183           0 :         else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
     184           0 :                  !bSelectionChanged                   &&
     185           0 :                  std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
     186           0 :                  std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
     187             :         {
     188             :             // toggle between selection and rotation
     189           0 :             SdrObject* pSingleObj = NULL;
     190             : 
     191           0 :             if (mpView->GetMarkedObjectList().GetMarkCount()==1)
     192             :             {
     193           0 :                 pSingleObj = mpView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
     194             :             }
     195             : 
     196           0 :             if (mpView->GetDragMode() == SDRDRAG_MOVE && mpView->IsRotateAllowed() &&
     197           0 :                 (mpViewShell->GetFrameView()->IsClickChangeRotation() ||
     198           0 :                  (pSingleObj && pSingleObj->GetObjInventor()==E3dInventor)))
     199             :             {
     200           0 :                 mpView->SetDragMode(SDRDRAG_ROTATE);
     201             :             }
     202             :             else
     203             :             {
     204           0 :                 mpView->SetDragMode(SDRDRAG_MOVE);
     205             :             }
     206             :         }
     207             :     }
     208             : 
     209           0 :     sal_uInt16 nClicks = rMEvt.GetClicks();
     210             : 
     211           0 :     if (nClicks == 2 && rMEvt.IsLeft() && bMBDown &&
     212           0 :         !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift() )
     213             :     {
     214           0 :         DoubleClick(rMEvt);
     215             :     }
     216           0 :     bMBDown = false;
     217             : 
     218           0 :     return bReturn;
     219             : }
     220             : 
     221             : /**
     222             :  * Process keyboard input
     223             :  * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
     224             :  */
     225           0 : bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
     226             : {
     227           0 :     bool bReturn = false;
     228             : 
     229           0 :     if ( !bReturn )
     230           0 :         bReturn = FuDraw::KeyInput(rKEvt);
     231             : 
     232           0 :     return bReturn;
     233             : }
     234             : 
     235           3 : void FuConstruct::Activate()
     236             : {
     237           3 :     mpView->SetEditMode(SDREDITMODE_CREATE);
     238           3 :     FuDraw::Activate();
     239           3 : }
     240             : 
     241           6 : void FuConstruct::Deactivate()
     242             : {
     243           6 :     FuDraw::Deactivate();
     244           6 :     mpView->SetEditMode(SDREDITMODE_EDIT);
     245           6 : }
     246             : 
     247             : /**
     248             :  * set style sheet for the object to be created
     249             :  */
     250           0 : void FuConstruct::SetStyleSheet(SfxItemSet& rAttr, SdrObject* pObj)
     251             : {
     252             :     bool bUseFillStyle, bUseNoFillStyle;
     253           0 :     bUseFillStyle = bUseNoFillStyle = false;
     254             : 
     255           0 :     switch( nSlotId )
     256             :     {
     257             :     case SID_DRAW_RECT:
     258             :     case SID_DRAW_RECT_ROUND:
     259             :     case SID_DRAW_SQUARE:
     260             :     case SID_DRAW_SQUARE_ROUND:
     261             :     case SID_DRAW_ELLIPSE:
     262             :     case SID_DRAW_PIE:
     263             :     case SID_DRAW_ELLIPSECUT:
     264             :     case SID_DRAW_CIRCLE:
     265             :     case SID_DRAW_CIRCLEPIE:
     266             :     case SID_DRAW_CIRCLECUT:
     267             :     case SID_DRAW_POLYGON:
     268             :     case SID_DRAW_XPOLYGON:
     269             :     case SID_DRAW_FREELINE:
     270             :     case SID_DRAW_BEZIER_FILL:
     271             :     {
     272           0 :         bUseFillStyle = true;
     273           0 :         break;
     274             :     }
     275             :     case  SID_DRAW_RECT_NOFILL:
     276             :     case SID_DRAW_RECT_ROUND_NOFILL:
     277             :     case SID_DRAW_SQUARE_NOFILL:
     278             :     case SID_DRAW_SQUARE_ROUND_NOFILL:
     279             :     case SID_DRAW_ELLIPSE_NOFILL:
     280             :     case SID_DRAW_PIE_NOFILL:
     281             :     case SID_DRAW_ELLIPSECUT_NOFILL:
     282             :     case SID_DRAW_CIRCLE_NOFILL:
     283             :     case SID_DRAW_CIRCLEPIE_NOFILL:
     284             :     case SID_DRAW_CIRCLECUT_NOFILL:
     285             :     case SID_DRAW_POLYGON_NOFILL:
     286             :     case SID_DRAW_XPOLYGON_NOFILL:
     287             :     case SID_DRAW_FREELINE_NOFILL:
     288             :     case SID_DRAW_LINE:
     289             :     case SID_DRAW_XLINE:
     290             :     case SID_CONNECTOR_ARROW_START:
     291             :     case SID_CONNECTOR_ARROW_END:
     292             :     case SID_CONNECTOR_ARROWS:
     293             :     case SID_CONNECTOR_CIRCLE_START:
     294             :     case SID_CONNECTOR_CIRCLE_END:
     295             :     case SID_CONNECTOR_CIRCLES:
     296             :     case SID_CONNECTOR_LINE:
     297             :     case SID_CONNECTOR_LINE_ARROW_START:
     298             :     case SID_CONNECTOR_LINE_ARROW_END:
     299             :     case SID_CONNECTOR_LINE_ARROWS:
     300             :     case SID_CONNECTOR_LINE_CIRCLE_START:
     301             :     case SID_CONNECTOR_LINE_CIRCLE_END:
     302             :     case SID_CONNECTOR_LINE_CIRCLES:
     303             :     case SID_CONNECTOR_CURVE:
     304             :     case SID_CONNECTOR_CURVE_ARROW_START:
     305             :     case SID_CONNECTOR_CURVE_ARROW_END:
     306             :     case SID_CONNECTOR_CURVE_ARROWS:
     307             :     case SID_CONNECTOR_CURVE_CIRCLE_START:
     308             :     case SID_CONNECTOR_CURVE_CIRCLE_END:
     309             :     case SID_CONNECTOR_CURVE_CIRCLES:
     310             :     case SID_CONNECTOR_LINES:
     311             :     case SID_CONNECTOR_LINES_ARROW_START:
     312             :     case SID_CONNECTOR_LINES_ARROW_END:
     313             :     case SID_CONNECTOR_LINES_ARROWS:
     314             :     case SID_CONNECTOR_LINES_CIRCLE_START:
     315             :     case SID_CONNECTOR_LINES_CIRCLE_END:
     316             :     case SID_CONNECTOR_LINES_CIRCLES:
     317             :     case SID_DRAW_BEZIER_NOFILL:
     318             :     case SID_LINE_ARROW_END:
     319             :     {
     320           0 :         bUseNoFillStyle = true;
     321           0 :         break;
     322             :     }
     323             :     }
     324           0 :     SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
     325           0 : }
     326             : 
     327           0 : void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
     328             :         const bool bForceFillStyle, const bool bForceNoFillStyle )
     329             : {
     330           0 :     SdPage* pPage = static_cast<SdPage*>(mpView->GetSdrPageView()->GetPage());
     331           0 :     if ( pPage->IsMasterPage() && pPage->GetPageKind() == PK_STANDARD &&
     332           0 :          mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
     333             :     {
     334             :         /**********************************************
     335             :         * Objects was created on the slide master page
     336             :         ***********************************************/
     337           0 :         OUString aName( pPage->GetLayoutName() );
     338           0 :         sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + strlen(SD_LT_SEPARATOR);
     339           0 :         aName = aName.copy(0, n) + SD_RESSTR(STR_LAYOUT_BACKGROUNDOBJECTS);
     340             :         SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
     341           0 :                                                 GetStyleSheetPool()->
     342           0 :                                                 Find(aName, SD_STYLE_FAMILY_MASTERPAGE));
     343             :         DBG_ASSERT(pSheet, "StyleSheet missing");
     344           0 :         if (pSheet)
     345             :         {
     346             :             // applying style sheet for background objects
     347           0 :             pObj->SetStyleSheet(pSheet, false);
     348           0 :             SfxItemSet& rSet = pSheet->GetItemSet();
     349           0 :             const XFillStyleItem& rFillStyle = static_cast<const XFillStyleItem&>(rSet.Get(XATTR_FILLSTYLE));
     350           0 :             if ( bForceFillStyle )
     351             :             {
     352           0 :                 if (rFillStyle.GetValue() == drawing::FillStyle_NONE)
     353           0 :                     rAttr.Put(XFillStyleItem(drawing::FillStyle_SOLID));
     354             :             }
     355           0 :             else if ( bForceNoFillStyle )
     356             :             {
     357           0 :                 if (rFillStyle.GetValue() != drawing::FillStyle_NONE)
     358           0 :                     rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
     359             :             }
     360           0 :         }
     361             :     }
     362             :     else
     363             :     {
     364             :         /***********************************
     365             :         * object was created on normal page
     366             :         ************************************/
     367           0 :         if ( bForceNoFillStyle )
     368             :         {
     369           0 :             OUString aName(SD_RESSTR(STR_POOLSHEET_OBJWITHOUTFILL));
     370             :             SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
     371           0 :                                          GetStyleSheetPool()->
     372           0 :                                          Find(aName, SD_STYLE_FAMILY_GRAPHICS));
     373             :             DBG_ASSERT(pSheet, "Stylesheet missing");
     374           0 :             if (pSheet)
     375             :             {
     376           0 :                 pObj->SetStyleSheet(pSheet, false);
     377           0 :                 SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
     378           0 :                 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
     379           0 :                 pObj->SetMergedItemSet(aAttr);
     380             :             }
     381             :             else
     382             :             {
     383           0 :                 SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
     384           0 :                 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
     385           0 :                 pObj->SetMergedItemSet(aAttr);
     386           0 :             }
     387             :         }
     388             :     }
     389           0 : }
     390             : 
     391          66 : } // end of namespace sd
     392             : 
     393             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11