bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuconcs.cxx
blob03c1ad5e0b9e376a6844de592af02922a78884e1
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 "fuconcs.hxx"
21 #include <svx/svdpagv.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/dialogs.hrc>
25 #include <svx/dialmgr.hxx>
27 #include "app.hrc"
28 #include <svl/aeitem.hxx>
29 #include <svx/xlnstwit.hxx>
30 #include <svx/xlnedwit.hxx>
31 #include <svx/xlnedit.hxx>
32 #include <svx/xlnstit.hxx>
33 #include <svx/xlnwtit.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <svx/sdtmfitm.hxx>
36 #include <svx/sxekitm.hxx>
37 #include <svx/sderitm.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <svx/svdopath.hxx>
40 #include <svx/svdocirc.hxx>
41 #include <svl/intitem.hxx>
42 #include <sfx2/request.hxx>
43 #include <editeng/adjustitem.hxx>
44 #include <svx/xtable.hxx>
45 #include <svx/sdasitm.hxx>
46 #include <svx/tbxcustomshapes.hxx>
47 #include <svx/svdoashp.hxx>
48 #include <svx/sdtagitm.hxx>
50 #include <svx/svdocapt.hxx>
52 #include <svx/svdomeas.hxx>
53 #include "ViewShell.hxx"
54 #include "ViewShellBase.hxx"
55 #include "ToolBarManager.hxx"
56 #include <editeng/writingmodeitem.hxx>
57 #include <svx/gallery.hxx>
58 #include <svl/itempool.hxx>
59 #include <com/sun/star/uno/Any.hxx>
61 #include "sdresid.hxx"
62 #include "View.hxx"
63 #include "sdpage.hxx"
64 #include "Window.hxx"
65 #include "stlpool.hxx"
66 #include "drawdoc.hxx"
67 #include "res_bmp.hrc"
68 #include "glob.hrc"
70 namespace sd {
72 TYPEINIT1( FuConstructCustomShape, FuConstruct );
74 FuConstructCustomShape::FuConstructCustomShape (
75 ViewShell* pViewSh,
76 ::sd::Window* pWin,
77 ::sd::View* pView,
78 SdDrawDocument* pDoc,
79 SfxRequest& rReq ) :
80 FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
84 rtl::Reference<FuPoor> FuConstructCustomShape::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
86 FuConstructCustomShape* pFunc;
87 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructCustomShape( pViewSh, pWin, pView, pDoc, rReq ) );
88 xFunc->DoExecute(rReq);
89 pFunc->SetPermanent( bPermanent );
90 return xFunc;
93 void FuConstructCustomShape::DoExecute( SfxRequest& rReq )
95 FuConstruct::DoExecute( rReq );
97 const SfxItemSet* pArgs = rReq.GetArgs();
98 if ( pArgs )
100 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
101 aCustomShape = rItm.GetValue();
104 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
105 ToolBarManager::TBG_FUNCTION,
106 ToolBarManager::msDrawingObjectToolBar);
109 bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
111 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
113 if ( rMEvt.IsLeft() && !mpView->IsAction() )
115 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
117 mpWindow->CaptureMouse();
118 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
120 mpView->BegCreateObj(aPnt, (OutputDevice*) NULL, nDrgLog);
122 SdrObject* pObj = mpView->GetCreateObj();
123 if ( pObj )
125 SetAttributes( pObj );
126 bool bForceFillStyle = true;
127 bool bForceNoFillStyle = false;
128 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
130 bForceFillStyle = false;
131 bForceNoFillStyle = true;
133 SfxItemSet aAttr(mpDoc->GetPool());
134 SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle );
135 pObj->SetMergedItemSet(aAttr);
139 return bReturn;
142 bool FuConstructCustomShape::MouseMove(const MouseEvent& rMEvt)
144 return FuConstruct::MouseMove(rMEvt);
147 bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
149 bool bReturn(false);
151 if(mpView->IsCreateObj() && rMEvt.IsLeft())
153 SdrObject* pObj = mpView->GetCreateObj();
154 if( pObj && mpView->EndCreateObj( SDRCREATE_FORCEEND ) )
156 bReturn = true;
159 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
161 if (!bPermanent)
162 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
164 return bReturn;
168 * Process keyboard input
169 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
171 bool FuConstructCustomShape::KeyInput(const KeyEvent& rKEvt)
173 return FuConstruct::KeyInput(rKEvt);
176 void FuConstructCustomShape::Activate()
178 mpView->SetCurrentObj( OBJ_CUSTOMSHAPE );
179 FuConstruct::Activate();
183 * set attribute for the object to be created
185 void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
187 bool bAttributesAppliedFromGallery = false;
189 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
191 std::vector< OUString > aObjList;
192 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
194 sal_uInt16 i;
195 for ( i = 0; i < aObjList.size(); i++ )
197 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
199 FmFormModel aFormModel;
200 SfxItemPool& rPool = aFormModel.GetItemPool();
201 rPool.FreezeIdRanges();
202 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
204 const SdrPage* pPage = aFormModel.GetPage( 0 );
205 if ( pPage )
207 const SdrObject* pSourceObj = pPage->GetObj( 0 );
208 if( pSourceObj )
210 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
211 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
212 SDRATTR_START, SDRATTR_SHADOW_LAST,
213 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
214 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
215 // Graphic Attributes
216 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
217 // 3d Properties
218 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
219 // CustomShape properties
220 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
221 // range from SdrTextObj
222 EE_ITEMS_START, EE_ITEMS_END,
223 // end
224 0, 0);
225 aDest.Set( rSource );
226 pObj->SetMergedItemSet( aDest );
227 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
228 if ( nAngle )
230 double a = nAngle * F_PI18000;
231 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
233 bAttributesAppliedFromGallery = true;
236 com::sun::star::uno::Any aAny;
237 if ( ((SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )).QueryValue( aAny ) )
239 aGeometryItem.PutValue( aAny );
240 pObj->SetMergedItem( aGeometryItem );
241 bAttributesAppliedFromGallery = sal_True;
247 break;
252 if ( !bAttributesAppliedFromGallery )
254 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
255 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
256 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
257 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
258 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
262 SdrObject* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const Rectangle& rRectangle)
264 SdrObject* pObj = SdrObjFactory::MakeNewObject(
265 mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
266 0L, mpDoc);
268 if( pObj )
270 Rectangle aRect( rRectangle );
271 if ( doConstructOrthogonal() )
272 ImpForceQuadratic( aRect );
273 pObj->SetLogicRect( aRect );
274 SetAttributes( pObj );
275 SfxItemSet aAttr(mpDoc->GetPool());
276 SetStyleSheet(aAttr, pObj);
277 pObj->SetMergedItemSet(aAttr);
279 return pObj;
282 // #i33136#
283 bool FuConstructCustomShape::doConstructOrthogonal() const
285 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
288 } // end of namespace sd
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */