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

Generated by: LCOV version 1.10