Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / fuconcustomshape.cxx
blobef7df53356fcebdf8d6e2fff4f1f011f54277d8c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "fuconcustomshape.hxx"
22 #include <editeng/svxenum.hxx>
23 #include <svx/gallery.hxx>
24 #include <sfx2/request.hxx>
25 #include <svx/fmmodel.hxx>
26 #include <svl/itempool.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdoashp.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <svx/sdtagitm.hxx>
31 #include "fuconuno.hxx"
32 #include "tabvwsh.hxx"
33 #include "sc.hrc"
34 #include "drawview.hxx"
35 #include <editeng/adjustitem.hxx>
37 #include <math.h>
39 //------------------------------------------------------------------------
41 FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
42 : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
44 const SfxItemSet* pArgs = rReq.GetArgs();
45 if ( pArgs )
47 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
48 aCustomShape = rItm.GetValue();
52 /*************************************************************************
54 |* Destruktor
56 \************************************************************************/
58 FuConstCustomShape::~FuConstCustomShape()
62 /*************************************************************************
64 |* MouseButtonDown-event
66 \************************************************************************/
68 sal_Bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
70 // remember button state for creation of own MouseEvents
71 SetMouseButtonCode(rMEvt.GetButtons());
73 sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
74 if ( rMEvt.IsLeft() && !pView->IsAction() )
76 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
77 // Hack to align object to nearest grid position where object
78 // would be anchored ( if it were cell anchored )
79 // Get grid offset for current position ( note: aPnt is
80 // also adjusted )
81 Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
83 pWindow->CaptureMouse();
84 pView->BegCreateObj(aPnt);
86 SdrObject* pObj = pView->GetCreateObj();
87 if ( pObj )
89 SetAttributes( pObj );
90 sal_Bool bForceNoFillStyle = false;
91 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
92 bForceNoFillStyle = sal_True;
93 if ( bForceNoFillStyle )
94 pObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) );
95 pObj->SetGridOffset( aGridOff );
98 bReturn = sal_True;
100 return bReturn;
103 /*************************************************************************
105 |* MouseMove-event
107 \************************************************************************/
109 sal_Bool FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
111 return FuConstruct::MouseMove(rMEvt);
114 /*************************************************************************
116 |* MouseButtonUp-event
118 \************************************************************************/
120 sal_Bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
122 // remember button state for creation of own MouseEvents
123 SetMouseButtonCode(rMEvt.GetButtons());
125 sal_Bool bReturn = false;
127 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
129 pView->EndCreateObj(SDRCREATE_FORCEEND);
130 bReturn = sal_True;
132 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
135 /*************************************************************************
137 |* Tastaturereignisse bearbeiten
139 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
140 |* FALSE.
142 \************************************************************************/
144 sal_Bool FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
146 sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
147 return(bReturn);
150 /*************************************************************************
152 |* Function aktivieren
154 \************************************************************************/
156 void FuConstCustomShape::Activate()
158 pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
160 aNewPointer = Pointer( POINTER_DRAW_RECT );
161 aOldPointer = pWindow->GetPointer();
162 pViewShell->SetActivePointer( aNewPointer );
164 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
165 if (pLayer)
166 pView->SetActiveLayer( pLayer->GetName() );
168 FuConstruct::Activate();
171 /*************************************************************************
173 |* Function deaktivieren
175 \************************************************************************/
177 void FuConstCustomShape::Deactivate()
179 FuConstruct::Deactivate();
181 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
182 if (pLayer)
183 pView->SetActiveLayer( pLayer->GetName() );
185 pViewShell->SetActivePointer( aOldPointer );
188 // Create default drawing objects via keyboard
189 SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
191 SdrObject* pObj = SdrObjFactory::MakeNewObject(
192 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
193 0L, pDrDoc);
194 if( pObj )
196 Rectangle aRectangle( rRectangle );
197 SetAttributes( pObj );
198 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
199 ImpForceQuadratic( aRectangle );
200 pObj->SetLogicRect( aRectangle );
202 return pObj;
205 /*************************************************************************
207 |* applying attributes
209 \************************************************************************/
211 void FuConstCustomShape::SetAttributes( SdrObject* pObj )
213 sal_Bool bAttributesAppliedFromGallery = false;
215 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
217 std::vector< OUString > aObjList;
218 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
220 sal_uInt16 i;
221 for ( i = 0; i < aObjList.size(); i++ )
223 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
225 FmFormModel aFormModel;
226 SfxItemPool& rPool = aFormModel.GetItemPool();
227 rPool.FreezeIdRanges();
228 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
230 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
231 if( pSourceObj )
233 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
234 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
235 SDRATTR_START, SDRATTR_SHADOW_LAST,
236 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
237 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
238 // Graphic Attributes
239 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
240 // 3d Properties
241 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
242 // CustomShape properties
243 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
244 // range from SdrTextObj
245 EE_ITEMS_START, EE_ITEMS_END,
246 // end
247 0, 0);
248 aDest.Set( rSource );
249 pObj->SetMergedItemSet( aDest );
250 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
251 if ( nAngle )
253 double a = nAngle * F_PI18000;
254 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
256 bAttributesAppliedFromGallery = sal_True;
259 break;
264 if ( !bAttributesAppliedFromGallery )
266 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
267 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
268 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
269 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( false ) );
270 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
274 // #i33136#
275 bool FuConstCustomShape::doConstructOrthogonal() const
277 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */