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