Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuconcs.cxx
blob415a58c22ccc7a6280fdaa436cd1f34b82c66f6b
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>
26 #include <app.hrc>
27 #include <svl/aeitem.hxx>
28 #include <svx/xlnstwit.hxx>
29 #include <svx/xlnedwit.hxx>
30 #include <svx/xlnedit.hxx>
31 #include <svx/xlnstit.hxx>
32 #include <svx/xlnwtit.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <svx/sdtmfitm.hxx>
35 #include <svx/sxekitm.hxx>
36 #include <svx/sderitm.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/svdopath.hxx>
39 #include <svx/svdocirc.hxx>
40 #include <svl/intitem.hxx>
41 #include <sfx2/request.hxx>
42 #include <editeng/adjustitem.hxx>
43 #include <svx/xtable.hxx>
44 #include <svx/sdasitm.hxx>
45 #include <svx/svdoashp.hxx>
46 #include <svx/sdtagitm.hxx>
48 #include <svx/svdocapt.hxx>
50 #include <svx/svdomeas.hxx>
51 #include <ViewShell.hxx>
52 #include <ViewShellBase.hxx>
53 #include <ToolBarManager.hxx>
54 #include <editeng/writingmodeitem.hxx>
55 #include <svx/gallery.hxx>
56 #include <svl/itempool.hxx>
58 #include <View.hxx>
59 #include <sdpage.hxx>
60 #include <Window.hxx>
61 #include <stlpool.hxx>
62 #include <drawdoc.hxx>
64 namespace sd {
67 FuConstructCustomShape::FuConstructCustomShape (
68 ViewShell* pViewSh,
69 ::sd::Window* pWin,
70 ::sd::View* pView,
71 SdDrawDocument* pDoc,
72 SfxRequest& rReq ) :
73 FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
77 rtl::Reference<FuPoor> FuConstructCustomShape::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
79 FuConstructCustomShape* pFunc;
80 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructCustomShape( pViewSh, pWin, pView, pDoc, rReq ) );
81 xFunc->DoExecute(rReq);
82 pFunc->SetPermanent( bPermanent );
83 return xFunc;
86 void FuConstructCustomShape::DoExecute( SfxRequest& rReq )
88 FuConstruct::DoExecute( rReq );
90 const SfxItemSet* pArgs = rReq.GetArgs();
91 if ( pArgs )
93 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
94 aCustomShape = rItm.GetValue();
97 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
98 ToolBarManager::ToolBarGroup::Function,
99 ToolBarManager::msDrawingObjectToolBar);
102 bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
104 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
106 if ( rMEvt.IsLeft() && !mpView->IsAction() )
108 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
110 mpWindow->CaptureMouse();
111 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
113 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
115 SdrObject* pObj = mpView->GetCreateObj();
116 if ( pObj )
118 SetAttributes( pObj );
119 bool bForceFillStyle = true;
120 bool bForceNoFillStyle = false;
121 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
123 bForceFillStyle = false;
124 bForceNoFillStyle = true;
126 SfxItemSet aAttr(mpDoc->GetPool());
127 SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle );
128 pObj->SetMergedItemSet(aAttr);
132 return bReturn;
135 bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
137 bool bReturn(false);
139 if(mpView->IsCreateObj() && rMEvt.IsLeft())
141 SdrObject* pObj = mpView->GetCreateObj();
142 if( pObj && mpView->EndCreateObj( SdrCreateCmd::ForceEnd ) )
144 bReturn = true;
147 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
149 if (!bPermanent)
150 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
152 return bReturn;
155 void FuConstructCustomShape::Activate()
157 mpView->SetCurrentObj( OBJ_CUSTOMSHAPE );
158 FuConstruct::Activate();
162 * set attribute for the object to be created
164 void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
166 bool bAttributesAppliedFromGallery = false;
168 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
170 std::vector< OUString > aObjList;
171 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
173 for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
175 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
177 FmFormModel aFormModel;
178 SfxItemPool& rPool = aFormModel.GetItemPool();
179 rPool.FreezeIdRanges();
180 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
182 const SdrPage* pPage = aFormModel.GetPage( 0 );
183 if ( pPage )
185 const SdrObject* pSourceObj = pPage->GetObj( 0 );
186 if( pSourceObj )
188 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
189 SfxItemSet aDest(
190 pObj->getSdrModelFromSdrObject().GetItemPool(),
191 svl::Items<
192 // Ranges from SdrAttrObj:
193 SDRATTR_START, SDRATTR_SHADOW_LAST,
194 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
195 SDRATTR_TEXTDIRECTION,
196 SDRATTR_TEXTDIRECTION,
197 // Graphic attributes, 3D properties,
198 // CustomShape properties:
199 SDRATTR_GRAF_FIRST,
200 SDRATTR_CUSTOMSHAPE_LAST,
201 // Range from SdrTextObj:
202 EE_ITEMS_START, EE_ITEMS_END>{});
203 aDest.Set( rSource );
204 pObj->SetMergedItemSet( aDest );
205 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
206 if ( nAngle )
208 double a = nAngle * F_PI18000;
209 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
211 bAttributesAppliedFromGallery = true;
215 break;
220 if ( !bAttributesAppliedFromGallery )
222 pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
223 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
224 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
225 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
226 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
230 const OUString& FuConstructCustomShape::GetShapeType() const
232 return aCustomShape;
235 SdrObject* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& rRectangle)
237 SdrObject* pObj = SdrObjFactory::MakeNewObject(
238 mpView->getSdrModelFromSdrView(),
239 mpView->GetCurrentObjInventor(),
240 mpView->GetCurrentObjIdentifier());
242 if( pObj )
244 ::tools::Rectangle aRect( rRectangle );
245 if ( doConstructOrthogonal() )
246 ImpForceQuadratic( aRect );
247 pObj->SetLogicRect( aRect );
248 SetAttributes( pObj );
249 SfxItemSet aAttr(mpDoc->GetPool());
250 SetStyleSheet(aAttr, pObj);
251 pObj->SetMergedItemSet(aAttr);
253 return pObj;
256 // #i33136#
257 bool FuConstructCustomShape::doConstructOrthogonal() const
259 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
262 } // end of namespace sd
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */