xref: /aoo42x/main/sd/source/ui/func/fuconcs.cxx (revision 79aad27f)
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_sd.hxx"
26 
27 #include "fuconcs.hxx"
28 #include <svx/svdpagv.hxx>
29 
30 
31 #include <svx/svxids.hrc>
32 #include <svx/dialogs.hrc>
33 #include <svx/dialmgr.hxx>
34 
35 #include "app.hrc"
36 #include <svl/aeitem.hxx>
37 #include <svx/xlnstwit.hxx>
38 #include <svx/xlnedwit.hxx>
39 #include <svx/xlnedit.hxx>
40 #include <svx/xlnstit.hxx>
41 #include <svx/xlnwtit.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <svx/sdtmfitm.hxx>
44 #include <svx/sxekitm.hxx>
45 #include <svx/sderitm.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <svx/svdopath.hxx>
48 #include <svx/svdocirc.hxx>
49 #include <svl/intitem.hxx>
50 #include <sfx2/request.hxx>
51 #include <editeng/adjitem.hxx>
52 #include <svx/xtable.hxx>
53 #include <svx/sdasitm.hxx>
54 #include <svx/tbxcustomshapes.hxx>
55 #include <svx/svdoashp.hxx>
56 #include <svx/sdtagitm.hxx>
57 
58 // #88751#
59 #include <svx/svdocapt.hxx>
60 
61 // #97016#
62 #include <svx/svdomeas.hxx>
63 #include "ViewShell.hxx"
64 #include "ViewShellBase.hxx"
65 #include "ToolBarManager.hxx"
66 // #109583#
67 #include <editeng/writingmodeitem.hxx>
68 #include <svx/gallery.hxx>
69 #include <svl/itempool.hxx>
70 #include <com/sun/star/uno/Any.hxx>
71 
72 #include "sdresid.hxx"
73 #include "View.hxx"
74 #include "sdpage.hxx"
75 #include "Window.hxx"
76 #include "stlpool.hxx"
77 #include "drawdoc.hxx"
78 #include "res_bmp.hrc"
79 #include "glob.hrc"
80 
81 namespace sd {
82 
83 TYPEINIT1( FuConstructCustomShape, FuConstruct );
84 
85 /*************************************************************************
86 |*
87 |* Konstruktor
88 |*
89 \************************************************************************/
90 
FuConstructCustomShape(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)91 FuConstructCustomShape::FuConstructCustomShape (
92 		ViewShell* 			pViewSh,
93 		::sd::Window*		pWin,
94 		::sd::View*			pView,
95 		SdDrawDocument*		pDoc,
96 		SfxRequest&			rReq ) :
97 	FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
98 {
99 }
100 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq,bool bPermanent)101 FunctionReference FuConstructCustomShape::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
102 {
103 	FuConstructCustomShape* pFunc;
104 	FunctionReference xFunc( pFunc = new FuConstructCustomShape( pViewSh, pWin, pView, pDoc, rReq ) );
105 	xFunc->DoExecute(rReq);
106 	pFunc->SetPermanent( bPermanent );
107 	return xFunc;
108 }
109 
DoExecute(SfxRequest & rReq)110 void FuConstructCustomShape::DoExecute( SfxRequest& rReq )
111 {
112 	FuConstruct::DoExecute( rReq );
113 
114 	const SfxItemSet* pArgs = rReq.GetArgs();
115 	if ( pArgs )
116 	{
117 		const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
118 		aCustomShape = rItm.GetValue();
119 	}
120 
121     mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
122         ToolBarManager::TBG_FUNCTION,
123         ToolBarManager::msDrawingObjectToolBar);
124 }
125 
126 /*************************************************************************
127 |*
128 |* MouseButtonDown-event
129 |*
130 \************************************************************************/
131 
MouseButtonDown(const MouseEvent & rMEvt)132 sal_Bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
133 {
134 	sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
135 
136 	if ( rMEvt.IsLeft() && !mpView->IsAction() )
137 	{
138 		Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
139 
140 		mpWindow->CaptureMouse();
141 		sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
142 
143 		mpView->BegCreateObj(aPnt, (OutputDevice*) NULL, nDrgLog);
144 
145 		SdrObject* pObj = mpView->GetCreateObj();
146 		if ( pObj )
147 		{
148 			SetAttributes( pObj );
149 			sal_Bool bForceFillStyle = sal_True;
150 			sal_Bool bForceNoFillStyle = sal_False;
151 			if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
152 			{
153 				bForceFillStyle = sal_False;
154 				bForceNoFillStyle = sal_True;
155 			}
156 			SfxItemSet aAttr(mpDoc->GetPool());
157 			SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle );
158 			pObj->SetMergedItemSet(aAttr);
159 		}
160 	}
161 
162 	return bReturn;
163 }
164 
165 /*************************************************************************
166 |*
167 |* MouseMove-event
168 |*
169 \************************************************************************/
170 
MouseMove(const MouseEvent & rMEvt)171 sal_Bool FuConstructCustomShape::MouseMove(const MouseEvent& rMEvt)
172 {
173 	return FuConstruct::MouseMove(rMEvt);
174 }
175 
176 /*************************************************************************
177 |*
178 |* MouseButtonUp-event
179 |*
180 \************************************************************************/
181 
MouseButtonUp(const MouseEvent & rMEvt)182 sal_Bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
183 {
184 	sal_Bool bReturn(sal_False);
185 
186 	if(mpView->IsCreateObj() && rMEvt.IsLeft())
187 	{
188 		SdrObject* pObj = mpView->GetCreateObj();
189 		if( pObj && mpView->EndCreateObj( SDRCREATE_FORCEEND ) )
190 		{
191 			bReturn = sal_True;
192 		}
193 	}
194 	bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
195 
196 	if (!bPermanent)
197 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
198 
199 	return bReturn;
200 }
201 
202 /*************************************************************************
203 |*
204 |* Tastaturereignisse bearbeiten
205 |*
206 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
207 |* sal_False.
208 |*
209 \************************************************************************/
210 
KeyInput(const KeyEvent & rKEvt)211 sal_Bool FuConstructCustomShape::KeyInput(const KeyEvent& rKEvt)
212 {
213 	sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
214 	return(bReturn);
215 }
216 
217 /*************************************************************************
218 |*
219 |* Function aktivieren
220 |*
221 \************************************************************************/
222 
Activate()223 void FuConstructCustomShape::Activate()
224 {
225 	mpView->SetCurrentObj( OBJ_CUSTOMSHAPE );
226 	FuConstruct::Activate();
227 }
228 
229 /*************************************************************************
230 |*
231 |* Attribute fuer das zu erzeugende Objekt setzen
232 |*
233 \************************************************************************/
234 
SetAttributes(SdrObject * pObj)235 void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
236 {
237 	sal_Bool bAttributesAppliedFromGallery = sal_False;
238 
239 	if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
240 	{
241 		std::vector< rtl::OUString > aObjList;
242 		if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
243 		{
244 			sal_uInt16 i;
245 			for ( i = 0; i < aObjList.size(); i++ )
246 			{
247 				if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
248 				{
249 					FmFormModel aFormModel;
250 					SfxItemPool& rPool = aFormModel.GetItemPool();
251 					rPool.FreezeIdRanges();
252 					if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
253 					{
254 						const SdrPage* pPage = aFormModel.GetPage( 0 );
255 						if ( pPage )
256 						{
257 							const SdrObject* pSourceObj = pPage->GetObj( 0 );
258 							if( pSourceObj )
259 							{
260 								const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
261 								SfxItemSet aDest( pObj->GetModel()->GetItemPool(), 				// ranges from SdrAttrObj
262 								SDRATTR_START, SDRATTR_SHADOW_LAST,
263 								SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
264 								SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
265 								// Graphic Attributes
266 								SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
267 								// 3d Properties
268 								SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
269 								// CustomShape properties
270 								SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
271 								// range from SdrTextObj
272 								EE_ITEMS_START, EE_ITEMS_END,
273 								// end
274 								0, 0);
275 								aDest.Set( rSource );
276 								pObj->SetMergedItemSet( aDest );
277 								sal_Int32 nAngle = pSourceObj->GetRotateAngle();
278 								if ( nAngle )
279 								{
280 									double a = nAngle * F_PI18000;
281 									pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
282 								}
283 								bAttributesAppliedFromGallery = sal_True;
284 
285 
286 	/*
287 								com::sun::star::uno::Any aAny;
288 								if ( ((SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )).QueryValue( aAny ) )
289 								{
290 									aGeometryItem.PutValue( aAny );
291 									pObj->SetMergedItem( aGeometryItem );
292 									bAttributesAppliedFromGallery = sal_True;
293 								}
294 	*/
295 							}
296 						}
297 					}
298 					break;
299 				}
300 			}
301 		}
302 	}
303 	if ( !bAttributesAppliedFromGallery )
304 	{
305         pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
306 		pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
307 		pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
308 		pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
309 		((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
310 	}
311 }
312 
313 // #97016#
CreateDefaultObject(const sal_uInt16,const Rectangle & rRectangle)314 SdrObject* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const Rectangle& rRectangle)
315 {
316 	SdrObject* pObj = SdrObjFactory::MakeNewObject(
317 		mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
318 		0L, mpDoc);
319 
320 	if( pObj )
321 	{
322 		Rectangle aRect( rRectangle );
323 		if ( doConstructOrthogonal() )
324 			ImpForceQuadratic( aRect );
325 		pObj->SetLogicRect( aRect );
326 		SetAttributes( pObj );
327 		SfxItemSet aAttr(mpDoc->GetPool());
328 		SetStyleSheet(aAttr, pObj);
329 		pObj->SetMergedItemSet(aAttr);
330 	}
331 	return pObj;
332 }
333 
334 // #i33136#
doConstructOrthogonal() const335 bool FuConstructCustomShape::doConstructOrthogonal() const
336 {
337 	return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
338 }
339 
340 } // end of namespace sd
341