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