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