bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuconcs.cxx
blob45586622e4d4a0f694fc98729672248cc0eac81d
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 .
21 #include "fuconcs.hxx"
22 #include <svx/svdpagv.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
29 #include "app.hrc"
30 #include <svl/aeitem.hxx>
31 #include <svx/xlnstwit.hxx>
32 #include <svx/xlnedwit.hxx>
33 #include <svx/xlnedit.hxx>
34 #include <svx/xlnstit.hxx>
35 #include <svx/xlnwtit.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <svx/sdtmfitm.hxx>
38 #include <svx/sxekitm.hxx>
39 #include <svx/sderitm.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <svx/svdopath.hxx>
42 #include <svx/svdocirc.hxx>
43 #include <svl/intitem.hxx>
44 #include <sfx2/request.hxx>
45 #include <editeng/adjustitem.hxx>
46 #include <svx/xtable.hxx>
47 #include <svx/sdasitm.hxx>
48 #include <svx/tbxcustomshapes.hxx>
49 #include <svx/svdoashp.hxx>
50 #include <svx/sdtagitm.hxx>
52 #include <svx/svdocapt.hxx>
54 #include <svx/svdomeas.hxx>
55 #include "ViewShell.hxx"
56 #include "ViewShellBase.hxx"
57 #include "ToolBarManager.hxx"
58 #include <editeng/writingmodeitem.hxx>
59 #include <svx/gallery.hxx>
60 #include <svl/itempool.hxx>
61 #include <com/sun/star/uno/Any.hxx>
63 #include "sdresid.hxx"
64 #include "View.hxx"
65 #include "sdpage.hxx"
66 #include "Window.hxx"
67 #include "stlpool.hxx"
68 #include "drawdoc.hxx"
69 #include "res_bmp.hrc"
70 #include "glob.hrc"
72 namespace sd {
74 TYPEINIT1( FuConstructCustomShape, FuConstruct );
77 FuConstructCustomShape::FuConstructCustomShape (
78 ViewShell* pViewSh,
79 ::sd::Window* pWin,
80 ::sd::View* pView,
81 SdDrawDocument* pDoc,
82 SfxRequest& rReq ) :
83 FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
87 FunctionReference FuConstructCustomShape::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
89 FuConstructCustomShape* pFunc;
90 FunctionReference xFunc( pFunc = new FuConstructCustomShape( pViewSh, pWin, pView, pDoc, rReq ) );
91 xFunc->DoExecute(rReq);
92 pFunc->SetPermanent( bPermanent );
93 return xFunc;
96 void FuConstructCustomShape::DoExecute( SfxRequest& rReq )
98 FuConstruct::DoExecute( rReq );
100 const SfxItemSet* pArgs = rReq.GetArgs();
101 if ( pArgs )
103 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
104 aCustomShape = rItm.GetValue();
107 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
108 ToolBarManager::TBG_FUNCTION,
109 ToolBarManager::msDrawingObjectToolBar);
113 sal_Bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
115 sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
117 if ( rMEvt.IsLeft() && !mpView->IsAction() )
119 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
121 mpWindow->CaptureMouse();
122 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
124 mpView->BegCreateObj(aPnt, (OutputDevice*) NULL, nDrgLog);
126 SdrObject* pObj = mpView->GetCreateObj();
127 if ( pObj )
129 SetAttributes( pObj );
130 sal_Bool bForceFillStyle = sal_True;
131 sal_Bool bForceNoFillStyle = sal_False;
132 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
134 bForceFillStyle = sal_False;
135 bForceNoFillStyle = sal_True;
137 SfxItemSet aAttr(mpDoc->GetPool());
138 SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle );
139 pObj->SetMergedItemSet(aAttr);
143 return bReturn;
147 sal_Bool FuConstructCustomShape::MouseMove(const MouseEvent& rMEvt)
149 return FuConstruct::MouseMove(rMEvt);
153 sal_Bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
155 sal_Bool bReturn(sal_False);
157 if(mpView->IsCreateObj() && rMEvt.IsLeft())
159 SdrObject* pObj = mpView->GetCreateObj();
160 if( pObj && mpView->EndCreateObj( SDRCREATE_FORCEEND ) )
162 bReturn = sal_True;
165 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
167 if (!bPermanent)
168 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
170 return bReturn;
174 * Process keyboard input
175 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
177 sal_Bool FuConstructCustomShape::KeyInput(const KeyEvent& rKEvt)
179 sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
180 return(bReturn);
184 void FuConstructCustomShape::Activate()
186 mpView->SetCurrentObj( OBJ_CUSTOMSHAPE );
187 FuConstruct::Activate();
191 * set attribute for the object to be created
193 void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
195 sal_Bool bAttributesAppliedFromGallery = sal_False;
197 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
199 std::vector< OUString > aObjList;
200 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
202 sal_uInt16 i;
203 for ( i = 0; i < aObjList.size(); i++ )
205 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
207 FmFormModel aFormModel;
208 SfxItemPool& rPool = aFormModel.GetItemPool();
209 rPool.FreezeIdRanges();
210 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
212 const SdrPage* pPage = aFormModel.GetPage( 0 );
213 if ( pPage )
215 const SdrObject* pSourceObj = pPage->GetObj( 0 );
216 if( pSourceObj )
218 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
219 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
220 SDRATTR_START, SDRATTR_SHADOW_LAST,
221 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
222 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
223 // Graphic Attributes
224 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
225 // 3d Properties
226 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
227 // CustomShape properties
228 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
229 // range from SdrTextObj
230 EE_ITEMS_START, EE_ITEMS_END,
231 // end
232 0, 0);
233 aDest.Set( rSource );
234 pObj->SetMergedItemSet( aDest );
235 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
236 if ( nAngle )
238 double a = nAngle * F_PI18000;
239 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
241 bAttributesAppliedFromGallery = sal_True;
245 com::sun::star::uno::Any aAny;
246 if ( ((SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )).QueryValue( aAny ) )
248 aGeometryItem.PutValue( aAny );
249 pObj->SetMergedItem( aGeometryItem );
250 bAttributesAppliedFromGallery = sal_True;
256 break;
261 if ( !bAttributesAppliedFromGallery )
263 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
264 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
265 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
266 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
267 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
271 SdrObject* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const Rectangle& rRectangle)
273 SdrObject* pObj = SdrObjFactory::MakeNewObject(
274 mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
275 0L, mpDoc);
277 if( pObj )
279 Rectangle aRect( rRectangle );
280 if ( doConstructOrthogonal() )
281 ImpForceQuadratic( aRect );
282 pObj->SetLogicRect( aRect );
283 SetAttributes( pObj );
284 SfxItemSet aAttr(mpDoc->GetPool());
285 SetStyleSheet(aAttr, pObj);
286 pObj->SetMergedItemSet(aAttr);
288 return pObj;
291 // #i33136#
292 bool FuConstructCustomShape::doConstructOrthogonal() const
294 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
297 } // end of namespace sd
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */