merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / drawfunc / fuconcustomshape.cxx
blob30d1139c01ceb3601477d772a5ae6febaf5c278e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconcustomshape.cxx,v $
10 * $Revision: 1.13.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "fuconcustomshape.hxx"
35 #include <svx/svxenum.hxx>
36 #include <svx/gallery.hxx>
37 #include <sfx2/request.hxx>
38 #include <svx/fmmodel.hxx>
39 #include <svtools/itempool.hxx>
40 #include <svx/svdpage.hxx>
41 #include <svx/svdoashp.hxx>
42 #include <svx/eeitem.hxx>
43 #include <svx/sdtagitm.hxx>
44 #include "fuconuno.hxx"
45 #include "tabvwsh.hxx"
46 #include "sc.hrc"
47 #include "drawview.hxx"
48 #include <svx/adjitem.hxx>
50 #include <math.h>
52 //------------------------------------------------------------------------
54 FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
55 : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
57 const SfxItemSet* pArgs = rReq.GetArgs();
58 if ( pArgs )
60 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
61 aCustomShape = rItm.GetValue();
65 /*************************************************************************
67 |* Destruktor
69 \************************************************************************/
71 FuConstCustomShape::~FuConstCustomShape()
75 /*************************************************************************
77 |* MouseButtonDown-event
79 \************************************************************************/
81 BOOL __EXPORT FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
83 // #95491# remember button state for creation of own MouseEvents
84 SetMouseButtonCode(rMEvt.GetButtons());
86 BOOL bReturn = FuConstruct::MouseButtonDown(rMEvt);
87 if ( rMEvt.IsLeft() && !pView->IsAction() )
89 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
90 pWindow->CaptureMouse();
91 pView->BegCreateObj(aPnt);
93 SdrObject* pObj = pView->GetCreateObj();
94 if ( pObj )
96 SetAttributes( pObj );
97 sal_Bool bForceFillStyle = sal_True;
98 sal_Bool bForceNoFillStyle = sal_False;
99 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
101 bForceFillStyle = sal_False;
102 bForceNoFillStyle = sal_True;
104 if ( bForceNoFillStyle )
105 pObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) );
108 bReturn = TRUE;
110 return bReturn;
113 /*************************************************************************
115 |* MouseMove-event
117 \************************************************************************/
119 BOOL __EXPORT FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
121 return FuConstruct::MouseMove(rMEvt);
124 /*************************************************************************
126 |* MouseButtonUp-event
128 \************************************************************************/
130 BOOL __EXPORT FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
132 // #95491# remember button state for creation of own MouseEvents
133 SetMouseButtonCode(rMEvt.GetButtons());
135 BOOL bReturn = FALSE;
137 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
139 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
140 pView->EndCreateObj(SDRCREATE_FORCEEND);
141 bReturn = TRUE;
143 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
146 /*************************************************************************
148 |* Tastaturereignisse bearbeiten
150 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
151 |* FALSE.
153 \************************************************************************/
155 BOOL __EXPORT FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
157 BOOL bReturn = FuConstruct::KeyInput(rKEvt);
158 return(bReturn);
161 /*************************************************************************
163 |* Function aktivieren
165 \************************************************************************/
167 void FuConstCustomShape::Activate()
169 pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
171 aNewPointer = Pointer( POINTER_DRAW_RECT );
172 aOldPointer = pWindow->GetPointer();
173 pViewShell->SetActivePointer( aNewPointer );
175 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
176 if (pLayer)
177 pView->SetActiveLayer( pLayer->GetName() );
179 FuConstruct::Activate();
182 /*************************************************************************
184 |* Function deaktivieren
186 \************************************************************************/
188 void FuConstCustomShape::Deactivate()
190 FuConstruct::Deactivate();
192 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
193 if (pLayer)
194 pView->SetActiveLayer( pLayer->GetName() );
196 pViewShell->SetActivePointer( aOldPointer );
199 // #98185# Create default drawing objects via keyboard
200 SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
202 SdrObject* pObj = SdrObjFactory::MakeNewObject(
203 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
204 0L, pDrDoc);
205 if( pObj )
207 Rectangle aRectangle( rRectangle );
208 SetAttributes( pObj );
209 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
210 ImpForceQuadratic( aRectangle );
211 pObj->SetLogicRect( aRectangle );
213 return pObj;
216 /*************************************************************************
218 |* applying attributes
220 \************************************************************************/
222 void FuConstCustomShape::SetAttributes( SdrObject* pObj )
224 sal_Bool bAttributesAppliedFromGallery = sal_False;
226 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
228 std::vector< rtl::OUString > aObjList;
229 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
231 sal_uInt16 i;
232 for ( i = 0; i < aObjList.size(); i++ )
234 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
236 FmFormModel aFormModel;
237 SfxItemPool& rPool = aFormModel.GetItemPool();
238 rPool.FreezeIdRanges();
239 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
241 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
242 if( pSourceObj )
244 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
245 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
246 SDRATTR_START, SDRATTR_SHADOW_LAST,
247 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
248 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
249 // Graphic Attributes
250 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
251 // 3d Properties
252 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
253 // CustomShape properties
254 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
255 // range from SdrTextObj
256 EE_ITEMS_START, EE_ITEMS_END,
257 // end
258 0, 0);
259 aDest.Set( rSource );
260 pObj->SetMergedItemSet( aDest );
261 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
262 if ( nAngle )
264 double a = nAngle * F_PI18000;
265 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
267 bAttributesAppliedFromGallery = sal_True;
270 break;
275 if ( !bAttributesAppliedFromGallery )
277 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
278 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
279 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
280 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
281 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
285 // #i33136#
286 bool FuConstCustomShape::doConstructOrthogonal() const
288 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
291 // eof