1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <rtl/ustring.hxx>
23 #include <svx/svxids.hrc>
25 #include <sfx2/viewfrm.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/request.hxx>
28 #include <editeng/adjustitem.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <svx/svdoashp.hxx>
31 #include <svx/sdtagitm.hxx>
33 #include <ViewShell.hxx>
34 #include <ViewShellBase.hxx>
35 #include <ToolBarManager.hxx>
36 #include <svx/gallery.hxx>
37 #include <svl/itempool.hxx>
38 #include <svl/stritem.hxx>
42 #include <drawdoc.hxx>
47 FuConstructCustomShape::FuConstructCustomShape (
53 FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
57 rtl::Reference
<FuPoor
> FuConstructCustomShape::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
59 FuConstructCustomShape
* pFunc
;
60 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructCustomShape( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
61 xFunc
->DoExecute(rReq
);
62 pFunc
->SetPermanent( bPermanent
);
66 void FuConstructCustomShape::DoExecute( SfxRequest
& rReq
)
68 FuConstruct::DoExecute( rReq
);
70 const SfxItemSet
* pArgs
= rReq
.GetArgs();
73 const SfxStringItem
& rItm
= static_cast<const SfxStringItem
&>(pArgs
->Get( rReq
.GetSlot() ));
74 aCustomShape
= rItm
.GetValue();
77 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
78 ToolBarManager::ToolBarGroup::Function
,
79 ToolBarManager::msDrawingObjectToolBar
);
82 bool FuConstructCustomShape::MouseButtonDown(const MouseEvent
& rMEvt
)
84 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
86 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
88 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
90 mpWindow
->CaptureMouse();
91 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
93 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
95 SdrObject
* pObj
= mpView
->GetCreateObj();
98 SetAttributes( pObj
);
99 bool bForceFillStyle
= true;
100 bool bForceNoFillStyle
= false;
101 if ( static_cast<SdrObjCustomShape
*>(pObj
)->UseNoFillStyle() )
103 bForceFillStyle
= false;
104 bForceNoFillStyle
= true;
106 SfxItemSet
aAttr(mpDoc
->GetPool());
107 SetStyleSheet( aAttr
, pObj
, bForceFillStyle
, bForceNoFillStyle
);
108 pObj
->SetMergedItemSet(aAttr
);
115 bool FuConstructCustomShape::MouseButtonUp(const MouseEvent
& rMEvt
)
119 if(mpView
->IsCreateObj() && rMEvt
.IsLeft())
121 SdrObject
* pObj
= mpView
->GetCreateObj();
122 if( pObj
&& mpView
->EndCreateObj( SdrCreateCmd::ForceEnd
) )
127 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
130 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
135 void FuConstructCustomShape::Activate()
137 mpView
->SetCurrentObj( OBJ_CUSTOMSHAPE
);
138 FuConstruct::Activate();
142 * set attribute for the object to be created
144 void FuConstructCustomShape::SetAttributes( SdrObject
* pObj
)
146 bool bAttributesAppliedFromGallery
= false;
148 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
150 std::vector
< OUString
> aObjList
;
151 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
153 for ( std::vector
<OUString
>::size_type i
= 0; i
< aObjList
.size(); i
++ )
155 if ( aObjList
[ i
].equalsIgnoreAsciiCase( aCustomShape
) )
157 FmFormModel aFormModel
;
158 SfxItemPool
& rPool(aFormModel
.GetItemPool());
159 rPool
.FreezeIdRanges();
161 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aFormModel
) )
163 const SdrPage
* pPage
= aFormModel
.GetPage( 0 );
166 const SdrObject
* pSourceObj
= pPage
->GetObj( 0 );
169 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
171 pObj
->getSdrModelFromSdrObject().GetItemPool(),
173 // Ranges from SdrAttrObj:
174 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
175 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
176 SDRATTR_TEXTDIRECTION
,
177 SDRATTR_TEXTDIRECTION
,
178 // Graphic attributes, 3D properties,
179 // CustomShape properties:
181 SDRATTR_CUSTOMSHAPE_LAST
,
182 // Range from SdrTextObj:
183 EE_ITEMS_START
, EE_ITEMS_END
>{});
184 aDest
.Set( rSource
);
185 pObj
->SetMergedItemSet( aDest
);
186 sal_Int32 nAngle
= pSourceObj
->GetRotateAngle();
189 double a
= nAngle
* F_PI18000
;
190 pObj
->NbcRotate( pObj
->GetSnapRect().Center(), nAngle
, sin( a
), cos( a
) );
192 bAttributesAppliedFromGallery
= true;
201 if ( !bAttributesAppliedFromGallery
)
203 pObj
->SetMergedItem( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
204 pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
205 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
206 pObj
->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
207 static_cast<SdrObjCustomShape
*>(pObj
)->MergeDefaultAttributes( &aCustomShape
);
211 const OUString
& FuConstructCustomShape::GetShapeType() const
216 SdrObjectUniquePtr
FuConstructCustomShape::CreateDefaultObject(const sal_uInt16
, const ::tools::Rectangle
& rRectangle
)
218 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
219 mpView
->getSdrModelFromSdrView(),
220 mpView
->GetCurrentObjInventor(),
221 mpView
->GetCurrentObjIdentifier()));
225 ::tools::Rectangle
aRect( rRectangle
);
226 if ( doConstructOrthogonal() )
227 ImpForceQuadratic( aRect
);
228 pObj
->SetLogicRect( aRect
);
229 SetAttributes( pObj
.get() );
230 SfxItemSet
aAttr(mpDoc
->GetPool());
231 SetStyleSheet(aAttr
, pObj
.get());
232 pObj
->SetMergedItemSet(aAttr
);
238 bool FuConstructCustomShape::doConstructOrthogonal() const
240 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape
);
243 } // end of namespace sd
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */