merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / ribbar / concustomshape.cxx
bloba155f1c1792211442bbc408f7704bcd999808223
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: concustomshape.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <sfx2/bindings.hxx>
36 #include <svx/htmlmode.hxx>
37 #include <svx/sdtacitm.hxx>
38 #include <svx/svdobj.hxx>
39 #include <svx/sdtagitm.hxx>
40 #include <svx/sdtakitm.hxx>
41 #include <svx/sdtaditm.hxx>
42 #include <svx/sdtaaitm.hxx>
43 #include <svx/svdview.hxx>
44 #include <svx/svdocapt.hxx>
45 #include <svx/outlobj.hxx>
46 #ifndef _CMDID_H
47 #include <cmdid.h>
48 #endif
49 #ifndef _VIEW_HXX
50 #include <view.hxx>
51 #endif
52 #include <edtwin.hxx>
53 #include <wrtsh.hxx>
54 #include <viewopt.hxx>
55 #ifndef _DRAWBASE_HXX
56 #include <drawbase.hxx>
57 #endif
58 #include <concustomshape.hxx>
59 #include <svx/gallery.hxx>
60 #include <sfx2/request.hxx>
61 #ifndef _FM_FMMODEL_HXX
62 #include <svx/fmmodel.hxx>
63 #endif
64 #include <svtools/itempool.hxx>
65 #include <svx/svdpage.hxx>
66 #include <svx/svdoashp.hxx>
67 #include <svx/adjitem.hxx>
69 #include <math.h>
71 /*************************************************************************
73 |* C'Tor
75 \************************************************************************/
76 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq )
77 : SwDrawBase( pWrtShell, pEditWin, pSwView )
79 aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq );
82 /*************************************************************************
84 \************************************************************************/
86 rtl::OUString ConstCustomShape::GetShapeType() const
88 return aCustomShape;
91 //static
92 rtl::OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest& rReq )
94 rtl::OUString aRet;
95 const SfxItemSet* pArgs = rReq.GetArgs();
96 if ( pArgs )
98 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
99 aRet = rItm.GetValue();
101 return aRet;
104 /*************************************************************************
106 |* MouseButtonDown-event
108 \************************************************************************/
110 BOOL ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
112 BOOL bReturn = SwDrawBase::MouseButtonDown(rMEvt);
113 if ( bReturn )
115 SdrView *pSdrView = m_pSh->GetDrawView();
116 if ( pSdrView )
118 SdrObject* pObj = pSdrView->GetCreateObj();
119 if ( pObj )
121 SetAttributes( pObj );
122 sal_Bool bForceFillStyle = sal_True;
123 sal_Bool bForceNoFillStyle = sal_False;
124 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
126 bForceFillStyle = sal_False;
127 bForceNoFillStyle = sal_True;
130 SfxItemSet aAttr( m_pView->GetPool() );
131 if ( bForceNoFillStyle )
132 aAttr.Put( XFillStyleItem( XFILL_NONE ) );
133 pObj->SetMergedItemSet(aAttr);
137 return bReturn;
140 /*************************************************************************
142 |* MouseButtonUp-event
144 \************************************************************************/
146 BOOL ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
148 return SwDrawBase::MouseButtonUp(rMEvt);
151 /*************************************************************************
153 |* activate function
155 \************************************************************************/
157 void ConstCustomShape::Activate(const USHORT nSlotId)
159 m_pWin->SetSdrDrawMode( OBJ_CUSTOMSHAPE );
161 SwDrawBase::Activate(nSlotId);
164 /*************************************************************************
166 |* applying attributes
168 \************************************************************************/
170 void ConstCustomShape::SetAttributes( SdrObject* pObj )
172 sal_Bool bAttributesAppliedFromGallery = sal_False;
174 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
176 std::vector< rtl::OUString > aObjList;
177 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
179 sal_uInt16 i;
180 for ( i = 0; i < aObjList.size(); i++ )
182 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
184 FmFormModel aFormModel;
185 SfxItemPool& rPool = aFormModel.GetItemPool();
186 rPool.FreezeIdRanges();
187 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
189 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
190 if( pSourceObj )
192 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
193 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
194 SDRATTR_START, SDRATTR_SHADOW_LAST,
195 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
196 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
197 // Graphic Attributes
198 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
199 // 3d Properties
200 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
201 // CustomShape properties
202 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
203 // range from SdrTextObj
204 EE_ITEMS_START, EE_ITEMS_END,
205 // end
206 0, 0);
207 aDest.Set( rSource );
208 pObj->SetMergedItemSet( aDest );
209 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
210 if ( nAngle )
212 double a = nAngle * F_PI18000;
213 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
215 bAttributesAppliedFromGallery = sal_True;
218 break;
223 if ( !bAttributesAppliedFromGallery )
225 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST ) );
226 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
227 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
228 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
229 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
233 void ConstCustomShape::CreateDefaultObject()
235 SwDrawBase::CreateDefaultObject();
236 SdrView *pSdrView = m_pSh->GetDrawView();
237 if ( pSdrView )
239 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
240 if ( rMarkList.GetMarkCount() == 1 )
242 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
243 if ( pObj && pObj->ISA( SdrObjCustomShape ) )
244 SetAttributes( pObj );
249 // #i33136#
250 bool ConstCustomShape::doConstructOrthogonal() const
252 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
255 // eof