1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "fuconcustomshape.hxx" 32*cdf0e10cSrcweir #include <editeng/svxenum.hxx> 33*cdf0e10cSrcweir #include <svx/gallery.hxx> 34*cdf0e10cSrcweir #include <sfx2/request.hxx> 35*cdf0e10cSrcweir #include <svx/fmmodel.hxx> 36*cdf0e10cSrcweir #include <svl/itempool.hxx> 37*cdf0e10cSrcweir #include <svx/svdpage.hxx> 38*cdf0e10cSrcweir #include <svx/svdoashp.hxx> 39*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 40*cdf0e10cSrcweir #include <svx/sdtagitm.hxx> 41*cdf0e10cSrcweir #include "fuconuno.hxx" 42*cdf0e10cSrcweir #include "tabvwsh.hxx" 43*cdf0e10cSrcweir #include "sc.hrc" 44*cdf0e10cSrcweir #include "drawview.hxx" 45*cdf0e10cSrcweir #include <editeng/adjitem.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <math.h> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //------------------------------------------------------------------------ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq ) 52*cdf0e10cSrcweir : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir const SfxItemSet* pArgs = rReq.GetArgs(); 55*cdf0e10cSrcweir if ( pArgs ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() ); 58*cdf0e10cSrcweir aCustomShape = rItm.GetValue(); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /************************************************************************* 63*cdf0e10cSrcweir |* 64*cdf0e10cSrcweir |* Destruktor 65*cdf0e10cSrcweir |* 66*cdf0e10cSrcweir \************************************************************************/ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir FuConstCustomShape::~FuConstCustomShape() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /************************************************************************* 73*cdf0e10cSrcweir |* 74*cdf0e10cSrcweir |* MouseButtonDown-event 75*cdf0e10cSrcweir |* 76*cdf0e10cSrcweir \************************************************************************/ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir sal_Bool __EXPORT FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir // #95491# remember button state for creation of own MouseEvents 81*cdf0e10cSrcweir SetMouseButtonCode(rMEvt.GetButtons()); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt); 84*cdf0e10cSrcweir if ( rMEvt.IsLeft() && !pView->IsAction() ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) ); 87*cdf0e10cSrcweir pWindow->CaptureMouse(); 88*cdf0e10cSrcweir pView->BegCreateObj(aPnt); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir SdrObject* pObj = pView->GetCreateObj(); 91*cdf0e10cSrcweir if ( pObj ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir SetAttributes( pObj ); 94*cdf0e10cSrcweir sal_Bool bForceFillStyle = sal_True; 95*cdf0e10cSrcweir sal_Bool bForceNoFillStyle = sal_False; 96*cdf0e10cSrcweir if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir bForceFillStyle = sal_False; 99*cdf0e10cSrcweir bForceNoFillStyle = sal_True; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir if ( bForceNoFillStyle ) 102*cdf0e10cSrcweir pObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir bReturn = sal_True; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir return bReturn; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir /************************************************************************* 111*cdf0e10cSrcweir |* 112*cdf0e10cSrcweir |* MouseMove-event 113*cdf0e10cSrcweir |* 114*cdf0e10cSrcweir \************************************************************************/ 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir sal_Bool __EXPORT FuConstCustomShape::MouseMove(const MouseEvent& rMEvt) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return FuConstruct::MouseMove(rMEvt); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /************************************************************************* 122*cdf0e10cSrcweir |* 123*cdf0e10cSrcweir |* MouseButtonUp-event 124*cdf0e10cSrcweir |* 125*cdf0e10cSrcweir \************************************************************************/ 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir sal_Bool __EXPORT FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir // #95491# remember button state for creation of own MouseEvents 130*cdf0e10cSrcweir SetMouseButtonCode(rMEvt.GetButtons()); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir sal_Bool bReturn = sal_False; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir if ( pView->IsCreateObj() && rMEvt.IsLeft() ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) ); 137*cdf0e10cSrcweir pView->EndCreateObj(SDRCREATE_FORCEEND); 138*cdf0e10cSrcweir bReturn = sal_True; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir return (FuConstruct::MouseButtonUp(rMEvt) || bReturn); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir /************************************************************************* 144*cdf0e10cSrcweir |* 145*cdf0e10cSrcweir |* Tastaturereignisse bearbeiten 146*cdf0e10cSrcweir |* 147*cdf0e10cSrcweir |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls 148*cdf0e10cSrcweir |* FALSE. 149*cdf0e10cSrcweir |* 150*cdf0e10cSrcweir \************************************************************************/ 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir sal_Bool __EXPORT FuConstCustomShape::KeyInput(const KeyEvent& rKEvt) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir sal_Bool bReturn = FuConstruct::KeyInput(rKEvt); 155*cdf0e10cSrcweir return(bReturn); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir /************************************************************************* 159*cdf0e10cSrcweir |* 160*cdf0e10cSrcweir |* Function aktivieren 161*cdf0e10cSrcweir |* 162*cdf0e10cSrcweir \************************************************************************/ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void FuConstCustomShape::Activate() 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir aNewPointer = Pointer( POINTER_DRAW_RECT ); 169*cdf0e10cSrcweir aOldPointer = pWindow->GetPointer(); 170*cdf0e10cSrcweir pViewShell->SetActivePointer( aNewPointer ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS); 173*cdf0e10cSrcweir if (pLayer) 174*cdf0e10cSrcweir pView->SetActiveLayer( pLayer->GetName() ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir FuConstruct::Activate(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir /************************************************************************* 180*cdf0e10cSrcweir |* 181*cdf0e10cSrcweir |* Function deaktivieren 182*cdf0e10cSrcweir |* 183*cdf0e10cSrcweir \************************************************************************/ 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void FuConstCustomShape::Deactivate() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir FuConstruct::Deactivate(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT); 190*cdf0e10cSrcweir if (pLayer) 191*cdf0e10cSrcweir pView->SetActiveLayer( pLayer->GetName() ); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir pViewShell->SetActivePointer( aOldPointer ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // #98185# Create default drawing objects via keyboard 197*cdf0e10cSrcweir SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir SdrObject* pObj = SdrObjFactory::MakeNewObject( 200*cdf0e10cSrcweir pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), 201*cdf0e10cSrcweir 0L, pDrDoc); 202*cdf0e10cSrcweir if( pObj ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir Rectangle aRectangle( rRectangle ); 205*cdf0e10cSrcweir SetAttributes( pObj ); 206*cdf0e10cSrcweir if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) ) 207*cdf0e10cSrcweir ImpForceQuadratic( aRectangle ); 208*cdf0e10cSrcweir pObj->SetLogicRect( aRectangle ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir return pObj; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir /************************************************************************* 214*cdf0e10cSrcweir |* 215*cdf0e10cSrcweir |* applying attributes 216*cdf0e10cSrcweir |* 217*cdf0e10cSrcweir \************************************************************************/ 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void FuConstCustomShape::SetAttributes( SdrObject* pObj ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir sal_Bool bAttributesAppliedFromGallery = sal_False; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir std::vector< rtl::OUString > aObjList; 226*cdf0e10cSrcweir if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir sal_uInt16 i; 229*cdf0e10cSrcweir for ( i = 0; i < aObjList.size(); i++ ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir FmFormModel aFormModel; 234*cdf0e10cSrcweir SfxItemPool& rPool = aFormModel.GetItemPool(); 235*cdf0e10cSrcweir rPool.FreezeIdRanges(); 236*cdf0e10cSrcweir if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 ); 239*cdf0e10cSrcweir if( pSourceObj ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir const SfxItemSet& rSource = pSourceObj->GetMergedItemSet(); 242*cdf0e10cSrcweir SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj 243*cdf0e10cSrcweir SDRATTR_START, SDRATTR_SHADOW_LAST, 244*cdf0e10cSrcweir SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST, 245*cdf0e10cSrcweir SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 246*cdf0e10cSrcweir // Graphic Attributes 247*cdf0e10cSrcweir SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST, 248*cdf0e10cSrcweir // 3d Properties 249*cdf0e10cSrcweir SDRATTR_3D_FIRST, SDRATTR_3D_LAST, 250*cdf0e10cSrcweir // CustomShape properties 251*cdf0e10cSrcweir SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST, 252*cdf0e10cSrcweir // range from SdrTextObj 253*cdf0e10cSrcweir EE_ITEMS_START, EE_ITEMS_END, 254*cdf0e10cSrcweir // end 255*cdf0e10cSrcweir 0, 0); 256*cdf0e10cSrcweir aDest.Set( rSource ); 257*cdf0e10cSrcweir pObj->SetMergedItemSet( aDest ); 258*cdf0e10cSrcweir sal_Int32 nAngle = pSourceObj->GetRotateAngle(); 259*cdf0e10cSrcweir if ( nAngle ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir double a = nAngle * F_PI18000; 262*cdf0e10cSrcweir pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) ); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir bAttributesAppliedFromGallery = sal_True; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir break; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir if ( !bAttributesAppliedFromGallery ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) ); 275*cdf0e10cSrcweir pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) ); 276*cdf0e10cSrcweir pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) ); 277*cdf0e10cSrcweir pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) ); 278*cdf0e10cSrcweir ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // #i33136# 283*cdf0e10cSrcweir bool FuConstCustomShape::doConstructOrthogonal() const 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir return SdrObjCustomShape::doConstructOrthogonal(aCustomShape); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir // eof 289