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