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 <svx/sdooitm.hxx>
38 #include <svl/itempool.hxx>
39 #include <svl/stritem.hxx>
43 #include <drawdoc.hxx>
48 FuConstructCustomShape::FuConstructCustomShape (
54 FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
58 rtl::Reference
<FuPoor
> FuConstructCustomShape::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
60 FuConstructCustomShape
* pFunc
;
61 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructCustomShape( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
62 xFunc
->DoExecute(rReq
);
63 pFunc
->SetPermanent( bPermanent
);
67 void FuConstructCustomShape::DoExecute( SfxRequest
& rReq
)
69 FuConstruct::DoExecute( rReq
);
71 const SfxItemSet
* pArgs
= rReq
.GetArgs();
74 const SfxStringItem
& rItm
= static_cast<const SfxStringItem
&>(pArgs
->Get( rReq
.GetSlot() ));
75 aCustomShape
= rItm
.GetValue();
78 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
79 ToolBarManager::ToolBarGroup::Function
,
80 ToolBarManager::msDrawingObjectToolBar
);
83 bool FuConstructCustomShape::MouseButtonDown(const MouseEvent
& rMEvt
)
85 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
87 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
89 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
91 mpWindow
->CaptureMouse();
92 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(mpView
->GetDragThresholdPixels(),0)).Width() );
94 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
96 SdrObject
* pObj
= mpView
->GetCreateObj();
99 SetAttributes( pObj
);
100 bool bForceFillStyle
= true;
101 bool bForceNoFillStyle
= false;
102 if ( static_cast<SdrObjCustomShape
*>(pObj
)->UseNoFillStyle() )
104 bForceFillStyle
= false;
105 bForceNoFillStyle
= true;
107 SfxItemSet
aAttr(mpDoc
->GetPool());
108 SetStyleSheet( aAttr
, pObj
, bForceFillStyle
, bForceNoFillStyle
);
109 pObj
->SetMergedItemSet(aAttr
);
116 bool FuConstructCustomShape::MouseButtonUp(const MouseEvent
& rMEvt
)
120 if(mpView
->IsCreateObj() && rMEvt
.IsLeft())
122 SdrObject
* pObj
= mpView
->GetCreateObj();
123 if( pObj
&& mpView
->EndCreateObj( SdrCreateCmd::ForceEnd
) )
129 //Drag was too small to create object, so insert default object at click pos
130 Point
aClickPos(mpWindow
->PixelToLogic(rMEvt
.GetPosPixel()));
131 sal_uInt32
nDefaultObjectSize(1000);
132 sal_Int32
nCenterOffset(-sal_Int32(nDefaultObjectSize
/ 2));
133 aClickPos
.AdjustX(nCenterOffset
);
134 aClickPos
.AdjustY(nCenterOffset
);
136 SdrPageView
*pPV
= mpView
->GetSdrPageView();
137 if(mpView
->IsSnapEnabled())
138 aClickPos
= mpView
->GetSnapPos(aClickPos
, pPV
);
140 ::tools::Rectangle
aNewObjectRectangle(aClickPos
, Size(nDefaultObjectSize
, nDefaultObjectSize
));
141 rtl::Reference
<SdrObject
> pObjDefault
= CreateDefaultObject(nSlotId
, aNewObjectRectangle
);
143 bReturn
= mpView
->InsertObjectAtView(pObjDefault
.get(), *pPV
);
146 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
149 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
154 void FuConstructCustomShape::Activate()
156 mpView
->SetCurrentObj( SdrObjKind::CustomShape
);
157 FuConstruct::Activate();
161 * set attribute for the object to be created
163 void FuConstructCustomShape::SetAttributes( SdrObject
* pObj
)
165 bool bAttributesAppliedFromGallery
= false;
167 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
169 std::vector
< OUString
> aObjList
;
170 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
172 for ( std::vector
<OUString
>::size_type i
= 0; i
< aObjList
.size(); i
++ )
174 if ( aObjList
[ i
].equalsIgnoreAsciiCase( aCustomShape
) )
176 FmFormModel aFormModel
;
177 SfxItemPool
& rPool(aFormModel
.GetItemPool());
178 rPool
.FreezeIdRanges();
180 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aFormModel
) )
182 const SdrPage
* pPage
= aFormModel
.GetPage( 0 );
185 const SdrObject
* pSourceObj
= pPage
->GetObj( 0 );
188 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
190 // Ranges from SdrAttrObj:
191 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
192 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
193 SDRATTR_TEXTDIRECTION
,
194 SDRATTR_TEXTDIRECTION
,
195 // Graphic attributes, 3D properties,
196 // CustomShape properties:
198 SDRATTR_CUSTOMSHAPE_LAST
,
199 // Range from SdrTextObj:
200 EE_ITEMS_START
, EE_ITEMS_END
> aDest(pObj
->getSdrModelFromSdrObject().GetItemPool());
201 aDest
.Set( rSource
);
202 pObj
->SetMergedItemSet( aDest
);
203 // Enables Word-wrap by default (tdf#134369)
204 pObj
->SetMergedItem( SdrOnOffItem( SDRATTR_TEXT_WORDWRAP
, true ) );
205 Degree100 nAngle
= pSourceObj
->GetRotateAngle();
207 pObj
->NbcRotate( pObj
->GetSnapRect().Center(), nAngle
);
208 bAttributesAppliedFromGallery
= true;
217 if ( !bAttributesAppliedFromGallery
)
219 pObj
->SetMergedItem( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
220 pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
221 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
222 pObj
->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
223 static_cast<SdrObjCustomShape
*>(pObj
)->MergeDefaultAttributes( &aCustomShape
);
227 const OUString
& FuConstructCustomShape::GetShapeType() const
232 rtl::Reference
<SdrObject
> FuConstructCustomShape::CreateDefaultObject(const sal_uInt16
, const ::tools::Rectangle
& rRectangle
)
234 rtl::Reference
<SdrObject
> pObj(SdrObjFactory::MakeNewObject(
235 mpView
->getSdrModelFromSdrView(),
236 mpView
->GetCurrentObjInventor(),
237 mpView
->GetCurrentObjIdentifier()));
241 ::tools::Rectangle
aRect( rRectangle
);
242 if ( doConstructOrthogonal() )
243 ImpForceQuadratic( aRect
);
244 pObj
->SetLogicRect( aRect
);
245 SetAttributes( pObj
.get() );
246 SfxItemSet
aAttr(mpDoc
->GetPool());
247 SetStyleSheet(aAttr
, pObj
.get());
248 pObj
->SetMergedItemSet(aAttr
);
254 bool FuConstructCustomShape::doConstructOrthogonal() const
256 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape
);
259 } // end of namespace sd
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */