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