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