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