Line data Source code
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 :
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/adjitem.hxx>
36 :
37 : #include <math.h>
38 :
39 : //------------------------------------------------------------------------
40 :
41 0 : FuConstCustomShape::FuConstCustomShape( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP, SdrModel* pDoc, SfxRequest& rReq )
42 0 : : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
43 : {
44 0 : const SfxItemSet* pArgs = rReq.GetArgs();
45 0 : if ( pArgs )
46 : {
47 0 : const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
48 0 : aCustomShape = rItm.GetValue();
49 : }
50 0 : }
51 :
52 : /*************************************************************************
53 : |*
54 : |* Destruktor
55 : |*
56 : \************************************************************************/
57 :
58 0 : FuConstCustomShape::~FuConstCustomShape()
59 : {
60 0 : }
61 :
62 : /*************************************************************************
63 : |*
64 : |* MouseButtonDown-event
65 : |*
66 : \************************************************************************/
67 :
68 0 : sal_Bool FuConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
69 : {
70 : // remember button state for creation of own MouseEvents
71 0 : SetMouseButtonCode(rMEvt.GetButtons());
72 :
73 0 : sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
74 0 : if ( rMEvt.IsLeft() && !pView->IsAction() )
75 : {
76 0 : 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 0 : Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
82 :
83 0 : pWindow->CaptureMouse();
84 0 : pView->BegCreateObj(aPnt);
85 :
86 0 : SdrObject* pObj = pView->GetCreateObj();
87 0 : if ( pObj )
88 : {
89 0 : SetAttributes( pObj );
90 0 : sal_Bool bForceNoFillStyle = false;
91 0 : if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
92 0 : bForceNoFillStyle = sal_True;
93 0 : if ( bForceNoFillStyle )
94 0 : pObj->SetMergedItem( XFillStyleItem( XFILL_NONE ) );
95 0 : pObj->SetGridOffset( aGridOff );
96 : }
97 :
98 0 : bReturn = sal_True;
99 : }
100 0 : return bReturn;
101 : }
102 :
103 : /*************************************************************************
104 : |*
105 : |* MouseMove-event
106 : |*
107 : \************************************************************************/
108 :
109 0 : sal_Bool FuConstCustomShape::MouseMove(const MouseEvent& rMEvt)
110 : {
111 0 : return FuConstruct::MouseMove(rMEvt);
112 : }
113 :
114 : /*************************************************************************
115 : |*
116 : |* MouseButtonUp-event
117 : |*
118 : \************************************************************************/
119 :
120 0 : sal_Bool FuConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
121 : {
122 : // remember button state for creation of own MouseEvents
123 0 : SetMouseButtonCode(rMEvt.GetButtons());
124 :
125 0 : sal_Bool bReturn = false;
126 :
127 0 : if ( pView->IsCreateObj() && rMEvt.IsLeft() )
128 : {
129 0 : pView->EndCreateObj(SDRCREATE_FORCEEND);
130 0 : bReturn = sal_True;
131 : }
132 0 : return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
133 : }
134 :
135 : /*************************************************************************
136 : |*
137 : |* Tastaturereignisse bearbeiten
138 : |*
139 : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
140 : |* FALSE.
141 : |*
142 : \************************************************************************/
143 :
144 0 : sal_Bool FuConstCustomShape::KeyInput(const KeyEvent& rKEvt)
145 : {
146 0 : sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
147 0 : return(bReturn);
148 : }
149 :
150 : /*************************************************************************
151 : |*
152 : |* Function aktivieren
153 : |*
154 : \************************************************************************/
155 :
156 0 : void FuConstCustomShape::Activate()
157 : {
158 0 : pView->SetCurrentObj( OBJ_CUSTOMSHAPE, SdrInventor );
159 :
160 0 : aNewPointer = Pointer( POINTER_DRAW_RECT );
161 0 : aOldPointer = pWindow->GetPointer();
162 0 : pViewShell->SetActivePointer( aNewPointer );
163 :
164 0 : SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
165 0 : if (pLayer)
166 0 : pView->SetActiveLayer( pLayer->GetName() );
167 :
168 0 : FuConstruct::Activate();
169 0 : }
170 :
171 : /*************************************************************************
172 : |*
173 : |* Function deaktivieren
174 : |*
175 : \************************************************************************/
176 :
177 0 : void FuConstCustomShape::Deactivate()
178 : {
179 0 : FuConstruct::Deactivate();
180 :
181 0 : SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
182 0 : if (pLayer)
183 0 : pView->SetActiveLayer( pLayer->GetName() );
184 :
185 0 : pViewShell->SetActivePointer( aOldPointer );
186 0 : }
187 :
188 : // Create default drawing objects via keyboard
189 0 : SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
190 : {
191 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
192 0 : pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
193 0 : 0L, pDrDoc);
194 0 : if( pObj )
195 : {
196 0 : Rectangle aRectangle( rRectangle );
197 0 : SetAttributes( pObj );
198 0 : if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape ) )
199 0 : ImpForceQuadratic( aRectangle );
200 0 : pObj->SetLogicRect( aRectangle );
201 : }
202 0 : return pObj;
203 : }
204 :
205 : /*************************************************************************
206 : |*
207 : |* applying attributes
208 : |*
209 : \************************************************************************/
210 :
211 0 : void FuConstCustomShape::SetAttributes( SdrObject* pObj )
212 : {
213 0 : sal_Bool bAttributesAppliedFromGallery = false;
214 :
215 0 : if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
216 : {
217 0 : std::vector< rtl::OUString > aObjList;
218 0 : if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
219 : {
220 : sal_uInt16 i;
221 0 : for ( i = 0; i < aObjList.size(); i++ )
222 : {
223 0 : if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
224 : {
225 0 : FmFormModel aFormModel;
226 0 : SfxItemPool& rPool = aFormModel.GetItemPool();
227 0 : rPool.FreezeIdRanges();
228 0 : if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
229 : {
230 0 : const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
231 0 : if( pSourceObj )
232 : {
233 0 : const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
234 0 : 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, 0);
248 0 : aDest.Set( rSource );
249 0 : pObj->SetMergedItemSet( aDest );
250 0 : sal_Int32 nAngle = pSourceObj->GetRotateAngle();
251 0 : if ( nAngle )
252 : {
253 0 : double a = nAngle * F_PI18000;
254 0 : pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
255 : }
256 0 : bAttributesAppliedFromGallery = sal_True;
257 : }
258 : }
259 0 : break;
260 : }
261 : }
262 0 : }
263 : }
264 0 : if ( !bAttributesAppliedFromGallery )
265 : {
266 0 : pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, 0 ) );
267 0 : pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
268 0 : pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
269 0 : pObj->SetMergedItem( SdrTextAutoGrowHeightItem( false ) );
270 0 : ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
271 : }
272 0 : }
273 :
274 : // #i33136#
275 0 : bool FuConstCustomShape::doConstructOrthogonal() const
276 : {
277 0 : return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
278 15 : }
279 :
280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|