1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include "fuconcustomshape.hxx"
32 #include <editeng/svxenum.hxx>
33 #include <svx/gallery.hxx>
34 #include <sfx2/request.hxx>
35 #include <svx/fmmodel.hxx>
36 #include <svl/itempool.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/svdoashp.hxx>
39 #include <editeng/eeitem.hxx>
40 #include <svx/sdtagitm.hxx>
41 #include "fuconuno.hxx"
42 #include "tabvwsh.hxx"
43 #include "sc.hrc"
44 #include "drawview.hxx"
45 #include <editeng/adjitem.hxx>
46 
47 #include <math.h>
48 
49 //------------------------------------------------------------------------
50 
51 FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
52     : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
53 {
54 	const SfxItemSet* pArgs = rReq.GetArgs();
55 	if ( pArgs )
56 	{
57 		const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
58 		aCustomShape = rItm.GetValue();
59 	}
60 }
61 
62 /*************************************************************************
63 |*
64 |* Destruktor
65 |*
66 \************************************************************************/
67 
68 FuConstCustomShape::~FuConstCustomShape()
69 {
70 }
71 
72 /*************************************************************************
73 |*
74 |* MouseButtonDown-event
75 |*
76 \************************************************************************/
77 
78 sal_Bool __EXPORT FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
79 {
80 	// #95491# remember button state for creation of own MouseEvents
81 	SetMouseButtonCode(rMEvt.GetButtons());
82 
83 	sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
84 	if ( rMEvt.IsLeft() && !pView->IsAction() )
85 	{
86 		Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
87 		pWindow->CaptureMouse();
88 		pView->BegCreateObj(aPnt);
89 
90 		SdrObject* pObj = pView->GetCreateObj();
91 		if ( pObj )
92 		{
93 			SetAttributes( pObj );
94 			sal_Bool bForceFillStyle = sal_True;
95 			sal_Bool bForceNoFillStyle = sal_False;
96 			if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
97 			{
98 				bForceFillStyle = sal_False;
99 				bForceNoFillStyle = sal_True;
100 			}
101 			if ( bForceNoFillStyle )
102 				pObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) );
103 		}
104 
105 		bReturn = sal_True;
106 	}
107 	return bReturn;
108 }
109 
110 /*************************************************************************
111 |*
112 |* MouseMove-event
113 |*
114 \************************************************************************/
115 
116 sal_Bool __EXPORT FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
117 {
118 	return FuConstruct::MouseMove(rMEvt);
119 }
120 
121 /*************************************************************************
122 |*
123 |* MouseButtonUp-event
124 |*
125 \************************************************************************/
126 
127 sal_Bool __EXPORT FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
128 {
129 	// #95491# remember button state for creation of own MouseEvents
130 	SetMouseButtonCode(rMEvt.GetButtons());
131 
132 	sal_Bool bReturn = sal_False;
133 
134 	if ( pView->IsCreateObj() && rMEvt.IsLeft() )
135 	{
136 		Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
137 		pView->EndCreateObj(SDRCREATE_FORCEEND);
138 		bReturn = sal_True;
139 	}
140 	return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
141 }
142 
143 /*************************************************************************
144 |*
145 |* Tastaturereignisse bearbeiten
146 |*
147 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
148 |* FALSE.
149 |*
150 \************************************************************************/
151 
152 sal_Bool __EXPORT FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
153 {
154 	sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
155 	return(bReturn);
156 }
157 
158 /*************************************************************************
159 |*
160 |* Function aktivieren
161 |*
162 \************************************************************************/
163 
164 void FuConstCustomShape::Activate()
165 {
166 	pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
167 
168 	aNewPointer = Pointer( POINTER_DRAW_RECT );
169 	aOldPointer = pWindow->GetPointer();
170 	pViewShell->SetActivePointer( aNewPointer );
171 
172 	SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
173 	if (pLayer)
174 		pView->SetActiveLayer( pLayer->GetName() );
175 
176 	FuConstruct::Activate();
177 }
178 
179 /*************************************************************************
180 |*
181 |* Function deaktivieren
182 |*
183 \************************************************************************/
184 
185 void FuConstCustomShape::Deactivate()
186 {
187 	FuConstruct::Deactivate();
188 
189 	SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
190 	if (pLayer)
191 		pView->SetActiveLayer( pLayer->GetName() );
192 
193 	pViewShell->SetActivePointer( aOldPointer );
194 }
195 
196 // #98185# Create default drawing objects via keyboard
197 SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
198 {
199 	SdrObject* pObj = SdrObjFactory::MakeNewObject(
200 		pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
201 		0L, pDrDoc);
202 	if( pObj )
203 	{
204 		Rectangle aRectangle( rRectangle );
205 		SetAttributes( pObj );
206 		if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
207 			ImpForceQuadratic( aRectangle );
208 		pObj->SetLogicRect( aRectangle );
209 	}
210 	return pObj;
211 }
212 
213 /*************************************************************************
214 |*
215 |* applying attributes
216 |*
217 \************************************************************************/
218 
219 void FuConstCustomShape::SetAttributes( SdrObject* pObj )
220 {
221 	sal_Bool bAttributesAppliedFromGallery = sal_False;
222 
223 	if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
224 	{
225 		std::vector< rtl::OUString > aObjList;
226 		if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
227 		{
228 			sal_uInt16 i;
229 			for ( i = 0; i < aObjList.size(); i++ )
230 			{
231 				if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
232 				{
233 					FmFormModel aFormModel;
234 					SfxItemPool& rPool = aFormModel.GetItemPool();
235 					rPool.FreezeIdRanges();
236 					if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
237 					{
238 						const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
239 						if( pSourceObj )
240 						{
241 							const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
242 							SfxItemSet aDest( pObj->GetModel()->GetItemPool(), 				// ranges from SdrAttrObj
243 							SDRATTR_START, SDRATTR_SHADOW_LAST,
244 							SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
245 							SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
246 							// Graphic Attributes
247 							SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
248 							// 3d Properties
249 							SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
250 							// CustomShape properties
251 							SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
252 							// range from SdrTextObj
253 							EE_ITEMS_START, EE_ITEMS_END,
254 							// end
255 							0, 0);
256 							aDest.Set( rSource );
257 							pObj->SetMergedItemSet( aDest );
258 							sal_Int32 nAngle = pSourceObj->GetRotateAngle();
259 							if ( nAngle )
260 							{
261 								double a = nAngle * F_PI18000;
262 								pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
263 							}
264 							bAttributesAppliedFromGallery = sal_True;
265 						}
266 					}
267 					break;
268 				}
269 			}
270 		}
271 	}
272 	if ( !bAttributesAppliedFromGallery )
273 	{
274         pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
275 		pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
276 		pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
277 		pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
278 		((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
279 	}
280 }
281 
282 // #i33136#
283 bool FuConstCustomShape::doConstructOrthogonal() const
284 {
285 	return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
286 }
287 
288 // eof
289