fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / fuconcustomshape.cxx
blobd48f6da8937add13d73982286309d22a5266f022
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 .
20 #include "fuconcustomshape.hxx"
21 #include <editeng/svxenum.hxx>
22 #include <svx/gallery.hxx>
23 #include <sfx2/request.hxx>
24 #include <svx/fmmodel.hxx>
25 #include <svl/itempool.hxx>
26 #include <svx/svdpage.hxx>
27 #include <svx/svdoashp.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <svx/sdtagitm.hxx>
30 #include "fuconuno.hxx"
31 #include "tabvwsh.hxx"
32 #include "sc.hrc"
33 #include "drawview.hxx"
34 #include <editeng/adjustitem.hxx>
36 #include <math.h>
38 using namespace com::sun::star;
40 FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
41 : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
43 const SfxItemSet* pArgs = rReq.GetArgs();
44 if ( pArgs )
46 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
47 aCustomShape = rItm.GetValue();
51 /*************************************************************************
53 |* Destruktor
55 \************************************************************************/
57 FuConstCustomShape::~FuConstCustomShape()
61 /*************************************************************************
63 |* MouseButtonDown-event
65 \************************************************************************/
67 bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
69 // remember button state for creation of own MouseEvents
70 SetMouseButtonCode(rMEvt.GetButtons());
72 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
73 if ( rMEvt.IsLeft() && !pView->IsAction() )
75 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
76 // Hack to align object to nearest grid position where object
77 // would be anchored ( if it were cell anchored )
78 // Get grid offset for current position ( note: aPnt is
79 // also adjusted )
80 Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
82 pWindow->CaptureMouse();
83 pView->BegCreateObj(aPnt);
85 SdrObject* pObj = pView->GetCreateObj();
86 if ( pObj )
88 SetAttributes( pObj );
89 bool bForceNoFillStyle = false;
90 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
91 bForceNoFillStyle = true;
92 if ( bForceNoFillStyle )
93 pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
94 pObj->SetGridOffset( aGridOff );
97 bReturn = true;
99 return bReturn;
102 /*************************************************************************
104 |* MouseMove-event
106 \************************************************************************/
108 bool FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
110 return FuConstruct::MouseMove(rMEvt);
113 /*************************************************************************
115 |* MouseButtonUp-event
117 \************************************************************************/
119 bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
121 // remember button state for creation of own MouseEvents
122 SetMouseButtonCode(rMEvt.GetButtons());
124 bool bReturn = false;
126 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
128 pView->EndCreateObj(SDRCREATE_FORCEEND);
129 bReturn = true;
131 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
134 /*************************************************************************
136 |* Tastaturereignisse bearbeiten
138 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
139 |* FALSE.
141 \************************************************************************/
143 bool FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
145 return FuConstruct::KeyInput(rKEvt);
148 /*************************************************************************
150 |* Function aktivieren
152 \************************************************************************/
154 void FuConstCustomShape::Activate()
156 pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
158 aNewPointer = Pointer( PointerStyle::DrawRect );
159 aOldPointer = pWindow->GetPointer();
160 pViewShell->SetActivePointer( aNewPointer );
162 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
163 if (pLayer)
164 pView->SetActiveLayer( pLayer->GetName() );
166 FuConstruct::Activate();
169 /*************************************************************************
171 |* Function deaktivieren
173 \************************************************************************/
175 void FuConstCustomShape::Deactivate()
177 FuConstruct::Deactivate();
179 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
180 if (pLayer)
181 pView->SetActiveLayer( pLayer->GetName() );
183 pViewShell->SetActivePointer( aOldPointer );
186 // Create default drawing objects via keyboard
187 SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
189 SdrObject* pObj = SdrObjFactory::MakeNewObject(
190 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
191 0L, pDrDoc);
192 if( pObj )
194 Rectangle aRectangle( rRectangle );
195 SetAttributes( pObj );
196 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
197 ImpForceQuadratic( aRectangle );
198 pObj->SetLogicRect( aRectangle );
200 return pObj;
203 /*************************************************************************
205 |* applying attributes
207 \************************************************************************/
209 void FuConstCustomShape::SetAttributes( SdrObject* pObj )
211 bool bAttributesAppliedFromGallery = false;
213 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
215 std::vector< OUString > aObjList;
216 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
218 sal_uInt16 i;
219 for ( i = 0; i < aObjList.size(); i++ )
221 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
223 FmFormModel aFormModel;
224 SfxItemPool& rPool = aFormModel.GetItemPool();
225 rPool.FreezeIdRanges();
226 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
228 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
229 if( pSourceObj )
231 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
232 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
233 SDRATTR_START, SDRATTR_SHADOW_LAST,
234 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
235 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
236 // Graphic Attributes
237 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
238 // 3d Properties
239 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
240 // CustomShape properties
241 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
242 // range from SdrTextObj
243 EE_ITEMS_START, EE_ITEMS_END,
244 // end
245 0, 0);
246 aDest.Set( rSource );
247 pObj->SetMergedItemSet( aDest );
248 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
249 if ( nAngle )
251 double a = nAngle * F_PI18000;
252 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
254 bAttributesAppliedFromGallery = true;
257 break;
262 if ( !bAttributesAppliedFromGallery )
264 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
265 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
266 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
267 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
268 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
272 // #i33136#
273 bool FuConstCustomShape::doConstructOrthogonal() const
275 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */