LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - fuconcustomshape.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 101 1.0 %
Date: 2014-11-03 Functions: 2 14 14.3 %
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 "fuconcustomshape.hxx"
      21             : #include <editeng/svxenum.hxx>
      22             : #include <svx/gallery.hxx>
      23             : #include <sfx2/request.hxx>
      24             : #include <svx/fmmodel.hxx>
      25             : #include <svl/itempool.hxx>
      26             : #include <svx/svdpage.hxx>
      27             : #include <svx/svdoashp.hxx>
      28             : #include <editeng/eeitem.hxx>
      29             : #include <svx/sdtagitm.hxx>
      30             : #include "fuconuno.hxx"
      31             : #include "tabvwsh.hxx"
      32             : #include "sc.hrc"
      33             : #include "drawview.hxx"
      34             : #include <editeng/adjustitem.hxx>
      35             : 
      36             : #include <math.h>
      37             : 
      38             : using namespace com::sun::star;
      39             : 
      40           0 : FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
      41           0 :     : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
      42             : {
      43           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
      44           0 :     if ( pArgs )
      45             :     {
      46           0 :         const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
      47           0 :         aCustomShape = rItm.GetValue();
      48             :     }
      49           0 : }
      50             : 
      51             : /*************************************************************************
      52             : |*
      53             : |* Destruktor
      54             : |*
      55             : \************************************************************************/
      56             : 
      57           0 : FuConstCustomShape::~FuConstCustomShape()
      58             : {
      59           0 : }
      60             : 
      61             : /*************************************************************************
      62             : |*
      63             : |* MouseButtonDown-event
      64             : |*
      65             : \************************************************************************/
      66             : 
      67           0 : bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
      68             : {
      69             :     // remember button state for creation of own MouseEvents
      70           0 :     SetMouseButtonCode(rMEvt.GetButtons());
      71             : 
      72           0 :     bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
      73           0 :     if ( rMEvt.IsLeft() && !pView->IsAction() )
      74             :     {
      75           0 :         Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
      76             :         // Hack  to align object to nearest grid position where object
      77             :         // would be anchored ( if it were cell anchored )
      78             :         // Get grid offset for current position ( note: aPnt is
      79             :         // also adjusted )
      80           0 :         Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
      81             : 
      82           0 :         pWindow->CaptureMouse();
      83           0 :         pView->BegCreateObj(aPnt);
      84             : 
      85           0 :         SdrObject* pObj = pView->GetCreateObj();
      86           0 :         if ( pObj )
      87             :         {
      88           0 :             SetAttributes( pObj );
      89           0 :             bool bForceNoFillStyle = false;
      90           0 :             if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
      91           0 :                 bForceNoFillStyle = true;
      92           0 :             if ( bForceNoFillStyle )
      93           0 :                 pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
      94           0 :             pObj->SetGridOffset( aGridOff );
      95             :         }
      96             : 
      97           0 :         bReturn = true;
      98             :     }
      99           0 :     return bReturn;
     100             : }
     101             : 
     102             : /*************************************************************************
     103             : |*
     104             : |* MouseMove-event
     105             : |*
     106             : \************************************************************************/
     107             : 
     108           0 : bool FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
     109             : {
     110           0 :     return FuConstruct::MouseMove(rMEvt);
     111             : }
     112             : 
     113             : /*************************************************************************
     114             : |*
     115             : |* MouseButtonUp-event
     116             : |*
     117             : \************************************************************************/
     118             : 
     119           0 : bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
     120             : {
     121             :     // remember button state for creation of own MouseEvents
     122           0 :     SetMouseButtonCode(rMEvt.GetButtons());
     123             : 
     124           0 :     bool bReturn = false;
     125             : 
     126           0 :     if ( pView->IsCreateObj() && rMEvt.IsLeft() )
     127             :     {
     128           0 :         pView->EndCreateObj(SDRCREATE_FORCEEND);
     129           0 :         bReturn = true;
     130             :     }
     131           0 :     return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
     132             : }
     133             : 
     134             : /*************************************************************************
     135             : |*
     136             : |* Tastaturereignisse bearbeiten
     137             : |*
     138             : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
     139             : |* FALSE.
     140             : |*
     141             : \************************************************************************/
     142             : 
     143           0 : bool FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
     144             : {
     145           0 :     return FuConstruct::KeyInput(rKEvt);
     146             : }
     147             : 
     148             : /*************************************************************************
     149             : |*
     150             : |* Function aktivieren
     151             : |*
     152             : \************************************************************************/
     153             : 
     154           0 : void FuConstCustomShape::Activate()
     155             : {
     156           0 :     pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
     157             : 
     158           0 :     aNewPointer = Pointer( POINTER_DRAW_RECT );
     159           0 :     aOldPointer = pWindow->GetPointer();
     160           0 :     pViewShell->SetActivePointer( aNewPointer );
     161             : 
     162           0 :     SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
     163           0 :     if (pLayer)
     164           0 :         pView->SetActiveLayer( pLayer->GetName() );
     165             : 
     166           0 :     FuConstruct::Activate();
     167           0 : }
     168             : 
     169             : /*************************************************************************
     170             : |*
     171             : |* Function deaktivieren
     172             : |*
     173             : \************************************************************************/
     174             : 
     175           0 : void FuConstCustomShape::Deactivate()
     176             : {
     177           0 :     FuConstruct::Deactivate();
     178             : 
     179           0 :     SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
     180           0 :     if (pLayer)
     181           0 :         pView->SetActiveLayer( pLayer->GetName() );
     182             : 
     183           0 :     pViewShell->SetActivePointer( aOldPointer );
     184           0 : }
     185             : 
     186             : // Create default drawing objects via keyboard
     187           0 : SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
     188             : {
     189             :     SdrObject* pObj = SdrObjFactory::MakeNewObject(
     190           0 :         pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
     191           0 :         0L, pDrDoc);
     192           0 :     if( pObj )
     193             :     {
     194           0 :         Rectangle aRectangle( rRectangle );
     195           0 :         SetAttributes( pObj );
     196           0 :         if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
     197           0 :             ImpForceQuadratic( aRectangle );
     198           0 :         pObj->SetLogicRect( aRectangle );
     199             :     }
     200           0 :     return pObj;
     201             : }
     202             : 
     203             : /*************************************************************************
     204             : |*
     205             : |* applying attributes
     206             : |*
     207             : \************************************************************************/
     208             : 
     209           0 : void FuConstCustomShape::SetAttributes( SdrObject* pObj )
     210             : {
     211           0 :     bool bAttributesAppliedFromGallery = false;
     212             : 
     213           0 :     if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
     214             :     {
     215           0 :         std::vector< OUString > aObjList;
     216           0 :         if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
     217             :         {
     218             :             sal_uInt16 i;
     219           0 :             for ( i = 0; i < aObjList.size(); i++ )
     220             :             {
     221           0 :                 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
     222             :                 {
     223           0 :                     FmFormModel aFormModel;
     224           0 :                     SfxItemPool& rPool = aFormModel.GetItemPool();
     225           0 :                     rPool.FreezeIdRanges();
     226           0 :                     if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
     227             :                     {
     228           0 :                         const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
     229           0 :                         if( pSourceObj )
     230             :                         {
     231           0 :                             const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
     232           0 :                             SfxItemSet aDest( pObj->GetModel()->GetItemPool(),              // ranges from SdrAttrObj
     233             :                             SDRATTR_START, SDRATTR_SHADOW_LAST,
     234             :                             SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
     235             :                             SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
     236             :                             // Graphic Attributes
     237             :                             SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
     238             :                             // 3d Properties
     239             :                             SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
     240             :                             // CustomShape properties
     241             :                             SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
     242             :                             // range from SdrTextObj
     243             :                             EE_ITEMS_START, EE_ITEMS_END,
     244             :                             // end
     245           0 :                             0, 0);
     246           0 :                             aDest.Set( rSource );
     247           0 :                             pObj->SetMergedItemSet( aDest );
     248           0 :                             sal_Int32 nAngle = pSourceObj->GetRotateAngle();
     249           0 :                             if ( nAngle )
     250             :                             {
     251           0 :                                 double a = nAngle * F_PI18000;
     252           0 :                                 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
     253             :                             }
     254           0 :                             bAttributesAppliedFromGallery = true;
     255             :                         }
     256             :                     }
     257           0 :                     break;
     258             :                 }
     259             :             }
     260           0 :         }
     261             :     }
     262           0 :     if ( !bAttributesAppliedFromGallery )
     263             :     {
     264           0 :         pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
     265           0 :         pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
     266           0 :         pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
     267           0 :         pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
     268           0 :         static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
     269             :     }
     270           0 : }
     271             : 
     272             : // #i33136#
     273           0 : bool FuConstCustomShape::doConstructOrthogonal() const
     274             : {
     275           0 :     return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
     276         228 : }
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10