1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <sfx2/bindings.hxx> 33 #include <svx/htmlmode.hxx> 34 #include <svx/sdtacitm.hxx> 35 #include <svx/svdobj.hxx> 36 #include <svx/sdtagitm.hxx> 37 #include <svx/sdtakitm.hxx> 38 #include <svx/sdtaditm.hxx> 39 #include <svx/sdtaaitm.hxx> 40 #include <svx/svdview.hxx> 41 #include <svx/svdocapt.hxx> 42 #include <editeng/outlobj.hxx> 43 #ifndef _CMDID_H 44 #include <cmdid.h> 45 #endif 46 #ifndef _VIEW_HXX 47 #include <view.hxx> 48 #endif 49 #include <edtwin.hxx> 50 #include <wrtsh.hxx> 51 #include <viewopt.hxx> 52 #ifndef _DRAWBASE_HXX 53 #include <drawbase.hxx> 54 #endif 55 #include <concustomshape.hxx> 56 #include <svx/gallery.hxx> 57 #include <sfx2/request.hxx> 58 #ifndef _FM_FMMODEL_HXX 59 #include <svx/fmmodel.hxx> 60 #endif 61 #include <svl/itempool.hxx> 62 #include <svx/svdpage.hxx> 63 #include <svx/svdoashp.hxx> 64 #include <editeng/adjitem.hxx> 65 66 #include <math.h> 67 68 /************************************************************************* 69 |* 70 |* C'Tor 71 |* 72 \************************************************************************/ 73 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq ) 74 : SwDrawBase( pWrtShell, pEditWin, pSwView ) 75 { 76 aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq ); 77 } 78 79 /************************************************************************* 80 |* 81 \************************************************************************/ 82 83 rtl::OUString ConstCustomShape::GetShapeType() const 84 { 85 return aCustomShape; 86 } 87 88 //static 89 rtl::OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest& rReq ) 90 { 91 rtl::OUString aRet; 92 const SfxItemSet* pArgs = rReq.GetArgs(); 93 if ( pArgs ) 94 { 95 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() ); 96 aRet = rItm.GetValue(); 97 } 98 return aRet; 99 } 100 101 /************************************************************************* 102 |* 103 |* MouseButtonDown-event 104 |* 105 \************************************************************************/ 106 107 sal_Bool ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt) 108 { 109 sal_Bool bReturn = SwDrawBase::MouseButtonDown(rMEvt); 110 if ( bReturn ) 111 { 112 SdrView *pSdrView = m_pSh->GetDrawView(); 113 if ( pSdrView ) 114 { 115 SdrObject* pObj = pSdrView->GetCreateObj(); 116 if ( pObj ) 117 { 118 SetAttributes( pObj ); 119 sal_Bool bForceFillStyle = sal_True; 120 sal_Bool bForceNoFillStyle = sal_False; 121 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() ) 122 { 123 bForceFillStyle = sal_False; 124 bForceNoFillStyle = sal_True; 125 } 126 127 SfxItemSet aAttr( m_pView->GetPool() ); 128 if ( bForceNoFillStyle ) 129 aAttr.Put( XFillStyleItem( XFILL_NONE ) ); 130 pObj->SetMergedItemSet(aAttr); 131 } 132 } 133 } 134 return bReturn; 135 } 136 137 /************************************************************************* 138 |* 139 |* MouseButtonUp-event 140 |* 141 \************************************************************************/ 142 143 sal_Bool ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt) 144 { 145 return SwDrawBase::MouseButtonUp(rMEvt); 146 } 147 148 /************************************************************************* 149 |* 150 |* activate function 151 |* 152 \************************************************************************/ 153 154 void ConstCustomShape::Activate(const sal_uInt16 nSlotId) 155 { 156 m_pWin->SetSdrDrawMode( OBJ_CUSTOMSHAPE ); 157 158 SwDrawBase::Activate(nSlotId); 159 } 160 161 /************************************************************************* 162 |* 163 |* applying attributes 164 |* 165 \************************************************************************/ 166 167 void ConstCustomShape::SetAttributes( SdrObject* pObj ) 168 { 169 sal_Bool bAttributesAppliedFromGallery = sal_False; 170 171 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) ) 172 { 173 std::vector< rtl::OUString > aObjList; 174 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) ) 175 { 176 sal_uInt16 i; 177 for ( i = 0; i < aObjList.size(); i++ ) 178 { 179 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) ) 180 { 181 FmFormModel aFormModel; 182 SfxItemPool& rPool = aFormModel.GetItemPool(); 183 rPool.FreezeIdRanges(); 184 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) ) 185 { 186 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 ); 187 if( pSourceObj ) 188 { 189 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet(); 190 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj 191 SDRATTR_START, SDRATTR_SHADOW_LAST, 192 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST, 193 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 194 // Graphic Attributes 195 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST, 196 // 3d Properties 197 SDRATTR_3D_FIRST, SDRATTR_3D_LAST, 198 // CustomShape properties 199 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST, 200 // range from SdrTextObj 201 EE_ITEMS_START, EE_ITEMS_END, 202 // end 203 0, 0); 204 aDest.Set( rSource ); 205 pObj->SetMergedItemSet( aDest ); 206 sal_Int32 nAngle = pSourceObj->GetRotateAngle(); 207 if ( nAngle ) 208 { 209 double a = nAngle * F_PI18000; 210 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) ); 211 } 212 bAttributesAppliedFromGallery = sal_True; 213 } 214 } 215 break; 216 } 217 } 218 } 219 } 220 if ( !bAttributesAppliedFromGallery ) 221 { 222 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST ) ); 223 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) ); 224 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) ); 225 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) ); 226 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape ); 227 } 228 } 229 230 void ConstCustomShape::CreateDefaultObject() 231 { 232 SwDrawBase::CreateDefaultObject(); 233 SdrView *pSdrView = m_pSh->GetDrawView(); 234 if ( pSdrView ) 235 { 236 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList(); 237 if ( rMarkList.GetMarkCount() == 1 ) 238 { 239 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 240 if ( pObj && pObj->ISA( SdrObjCustomShape ) ) 241 SetAttributes( pObj ); 242 } 243 } 244 } 245 246 // #i33136# 247 bool ConstCustomShape::doConstructOrthogonal() const 248 { 249 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape); 250 } 251 252 // eof 253