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 <fuconcustomshape.hxx>
21 #include <editeng/svxenum.hxx>
22 #include <svx/gallery.hxx>
23 #include <sfx2/request.hxx>
24 #include <svx/fmmodel.hxx>
25 #include <svl/stritem.hxx>
26 #include <svx/svdpage.hxx>
27 #include <svx/svdoashp.hxx>
28 #include <svx/xfillit0.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <svx/sdtagitm.hxx>
31 #include <tabvwsh.hxx>
32 #include <drawview.hxx>
33 #include <editeng/adjustitem.hxx>
35 using namespace com::sun::star
;
37 FuConstCustomShape::FuConstCustomShape(ScTabViewShell
& rViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
, SdrModel
* pDoc
, const SfxRequest
& rReq
)
38 : FuConstruct(rViewSh
, pWin
, pViewP
, pDoc
, rReq
)
40 const SfxItemSet
* pArgs
= rReq
.GetArgs();
43 const SfxStringItem
& rItm
= static_cast<const SfxStringItem
&>(pArgs
->Get( rReq
.GetSlot() ));
44 aCustomShape
= rItm
.GetValue();
48 FuConstCustomShape::~FuConstCustomShape()
52 bool FuConstCustomShape::MouseButtonDown(const MouseEvent
& rMEvt
)
54 // remember button state for creation of own MouseEvents
55 SetMouseButtonCode(rMEvt
.GetButtons());
57 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
58 if ( rMEvt
.IsLeft() && !pView
->IsAction() )
60 Point
aPnt( pWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
61 pWindow
->CaptureMouse();
62 pView
->BegCreateObj(aPnt
);
64 SdrObject
* pObj
= pView
->GetCreateObj();
67 SetAttributes( pObj
);
68 bool bForceNoFillStyle
= false;
69 if ( static_cast<SdrObjCustomShape
*>(pObj
)->UseNoFillStyle() )
70 bForceNoFillStyle
= true;
71 if ( bForceNoFillStyle
)
72 pObj
->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE
) );
80 bool FuConstCustomShape::MouseButtonUp(const MouseEvent
& rMEvt
)
82 // remember button state for creation of own MouseEvents
83 SetMouseButtonCode(rMEvt
.GetButtons());
87 if ( pView
->IsCreateObj() && rMEvt
.IsLeft() )
89 pView
->EndCreateObj(SdrCreateCmd::ForceEnd
);
92 return (FuConstruct::MouseButtonUp(rMEvt
) || bReturn
);
95 void FuConstCustomShape::Activate()
97 pView
->SetCurrentObj( SdrObjKind::CustomShape
);
99 aNewPointer
= PointerStyle::DrawRect
;
100 aOldPointer
= pWindow
->GetPointer();
101 rViewShell
.SetActivePointer( aNewPointer
);
103 FuConstruct::Activate();
106 void FuConstCustomShape::Deactivate()
108 FuConstruct::Deactivate();
110 rViewShell
.SetActivePointer( aOldPointer
);
113 // Create default drawing objects via keyboard
114 rtl::Reference
<SdrObject
> FuConstCustomShape::CreateDefaultObject(const sal_uInt16
/* nID */, const tools::Rectangle
& rRectangle
)
116 rtl::Reference
<SdrObject
> pObj(SdrObjFactory::MakeNewObject(
118 pView
->GetCurrentObjInventor(),
119 pView
->GetCurrentObjIdentifier()));
123 tools::Rectangle
aRectangle( rRectangle
);
124 SetAttributes( pObj
.get() );
125 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape
) )
126 ImpForceQuadratic( aRectangle
);
127 pObj
->SetLogicRect( aRectangle
);
133 void FuConstCustomShape::SetAttributes( SdrObject
* pObj
)
135 bool bAttributesAppliedFromGallery
= false;
137 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
139 std::vector
< OUString
> aObjList
;
140 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
142 for ( std::vector
<OUString
>::size_type i
= 0; i
< aObjList
.size(); i
++ )
144 if ( aObjList
[ i
].equalsIgnoreAsciiCase( aCustomShape
) )
146 FmFormModel aFormModel
;
148 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aFormModel
) )
150 const SdrObject
* pSourceObj
= aFormModel
.GetPage( 0 )->GetObj( 0 );
153 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
155 // Ranges from SdrAttrObj:
156 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
157 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
158 SDRATTR_TEXTDIRECTION
,
159 SDRATTR_TEXTDIRECTION
,
160 // Graphic attributes, 3D properties,
161 // CustomShape properties:
163 SDRATTR_CUSTOMSHAPE_LAST
,
164 // Range from SdrTextObj:
165 EE_ITEMS_START
, EE_ITEMS_END
> aDest(
166 pObj
->getSdrModelFromSdrObject().GetItemPool());
167 aDest
.Set( rSource
);
168 pObj
->SetMergedItemSet( aDest
);
169 Degree100 nAngle
= pSourceObj
->GetRotateAngle();
171 pObj
->NbcRotate( pObj
->GetSnapRect().Center(), nAngle
);
172 bAttributesAppliedFromGallery
= true;
180 if ( !bAttributesAppliedFromGallery
)
182 pObj
->SetMergedItem( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
183 pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
184 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
185 pObj
->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
186 static_cast<SdrObjCustomShape
*>(pObj
)->MergeDefaultAttributes( &aCustomShape
);
191 bool FuConstCustomShape::doConstructOrthogonal() const
193 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */