1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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 <svl/stritem.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdoashp.hxx>
29 #include <svx/xfillit0.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <svx/sdtagitm.hxx>
32 #include <tabvwsh.hxx>
33 #include <drawview.hxx>
34 #include <editeng/adjustitem.hxx>
35
36 #include <math.h>
37
38 using namespace com::sun::star;
39
FuConstCustomShape(ScTabViewShell & rViewSh,vcl::Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,const SfxRequest & rReq)40 FuConstCustomShape::FuConstCustomShape(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, const SfxRequest& rReq )
41 : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
42 {
43 const SfxItemSet* pArgs = rReq.GetArgs();
44 if ( pArgs )
45 {
46 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
47 aCustomShape = rItm.GetValue();
48 }
49 }
50
~FuConstCustomShape()51 FuConstCustomShape::~FuConstCustomShape()
52 {
53 }
54
MouseButtonDown(const MouseEvent & rMEvt)55 bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
56 {
57 // remember button state for creation of own MouseEvents
58 SetMouseButtonCode(rMEvt.GetButtons());
59
60 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
61 if ( rMEvt.IsLeft() && !pView->IsAction() )
62 {
63 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
64 pWindow->CaptureMouse();
65 pView->BegCreateObj(aPnt);
66
67 SdrObject* pObj = pView->GetCreateObj();
68 if ( pObj )
69 {
70 SetAttributes( pObj );
71 bool bForceNoFillStyle = false;
72 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
73 bForceNoFillStyle = true;
74 if ( bForceNoFillStyle )
75 pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
76 }
77
78 bReturn = true;
79 }
80 return bReturn;
81 }
82
MouseButtonUp(const MouseEvent & rMEvt)83 bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
84 {
85 // remember button state for creation of own MouseEvents
86 SetMouseButtonCode(rMEvt.GetButtons());
87
88 bool bReturn = false;
89
90 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
91 {
92 pView->EndCreateObj(SdrCreateCmd::ForceEnd);
93 bReturn = true;
94 }
95 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
96 }
97
Activate()98 void FuConstCustomShape::Activate()
99 {
100 pView->SetCurrentObj( OBJ_CUSTOMSHAPE );
101
102 aNewPointer = PointerStyle::DrawRect;
103 aOldPointer = pWindow->GetPointer();
104 rViewShell.SetActivePointer( aNewPointer );
105
106 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
107 if (pLayer)
108 pView->SetActiveLayer( pLayer->GetName() );
109
110 FuConstruct::Activate();
111 }
112
Deactivate()113 void FuConstCustomShape::Deactivate()
114 {
115 FuConstruct::Deactivate();
116
117 SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
118 if (pLayer)
119 pView->SetActiveLayer( pLayer->GetName() );
120
121 rViewShell.SetActivePointer( aOldPointer );
122 }
123
124 // Create default drawing objects via keyboard
CreateDefaultObject(const sal_uInt16,const tools::Rectangle & rRectangle)125 SdrObjectUniquePtr FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const tools::Rectangle& rRectangle)
126 {
127 SdrObjectUniquePtr pObj(SdrObjFactory::MakeNewObject(
128 *pDrDoc,
129 pView->GetCurrentObjInventor(),
130 pView->GetCurrentObjIdentifier()));
131
132 if( pObj )
133 {
134 tools::Rectangle aRectangle( rRectangle );
135 SetAttributes( pObj.get() );
136 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
137 ImpForceQuadratic( aRectangle );
138 pObj->SetLogicRect( aRectangle );
139 }
140
141 return pObj;
142 }
143
SetAttributes(SdrObject * pObj)144 void FuConstCustomShape::SetAttributes( SdrObject* pObj )
145 {
146 bool bAttributesAppliedFromGallery = false;
147
148 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
149 {
150 std::vector< OUString > aObjList;
151 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
152 {
153 for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
154 {
155 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
156 {
157 FmFormModel aFormModel;
158 SfxItemPool& rPool(aFormModel.GetItemPool());
159 rPool.FreezeIdRanges();
160
161 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
162 {
163 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
164 if( pSourceObj )
165 {
166 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
167 SfxItemSet aDest(
168 pObj->getSdrModelFromSdrObject().GetItemPool(),
169 svl::Items<
170 // Ranges from SdrAttrObj:
171 SDRATTR_START, SDRATTR_SHADOW_LAST,
172 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
173 SDRATTR_TEXTDIRECTION,
174 SDRATTR_TEXTDIRECTION,
175 // Graphic attributes, 3D properties,
176 // CustomShape properties:
177 SDRATTR_GRAF_FIRST,
178 SDRATTR_CUSTOMSHAPE_LAST,
179 // Range from SdrTextObj:
180 EE_ITEMS_START, EE_ITEMS_END>{});
181 aDest.Set( rSource );
182 pObj->SetMergedItemSet( aDest );
183 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
184 if ( nAngle )
185 {
186 double a = nAngle * F_PI18000;
187 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
188 }
189 bAttributesAppliedFromGallery = true;
190 }
191 }
192 break;
193 }
194 }
195 }
196 }
197 if ( !bAttributesAppliedFromGallery )
198 {
199 pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
200 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
201 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
202 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
203 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
204 }
205 }
206
207 // #i33136#
doConstructOrthogonal() const208 bool FuConstCustomShape::doConstructOrthogonal() const
209 {
210 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
211 }
212
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
214