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/itempool.hxx>
26 #include <svl/stritem.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdoashp.hxx>
29 #include <svx/xfillit0.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <svx/sdtagitm.hxx>
32 #include <tabvwsh.hxx>
33 #include <drawview.hxx>
34 #include <editeng/adjustitem.hxx>
38 using namespace com::sun::star
;
40 FuConstCustomShape::FuConstCustomShape(ScTabViewShell
& rViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
, SdrModel
* pDoc
, const SfxRequest
& rReq
)
41 : FuConstruct(rViewSh
, pWin
, pViewP
, pDoc
, rReq
)
43 const SfxItemSet
* pArgs
= rReq
.GetArgs();
46 const SfxStringItem
& rItm
= static_cast<const SfxStringItem
&>(pArgs
->Get( rReq
.GetSlot() ));
47 aCustomShape
= rItm
.GetValue();
51 FuConstCustomShape::~FuConstCustomShape()
55 bool FuConstCustomShape::MouseButtonDown(const MouseEvent
& rMEvt
)
57 // remember button state for creation of own MouseEvents
58 SetMouseButtonCode(rMEvt
.GetButtons());
60 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
61 if ( rMEvt
.IsLeft() && !pView
->IsAction() )
63 Point
aPnt( pWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
64 pWindow
->CaptureMouse();
65 pView
->BegCreateObj(aPnt
);
67 SdrObject
* pObj
= pView
->GetCreateObj();
70 SetAttributes( pObj
);
71 bool bForceNoFillStyle
= false;
72 if ( static_cast<SdrObjCustomShape
*>(pObj
)->UseNoFillStyle() )
73 bForceNoFillStyle
= true;
74 if ( bForceNoFillStyle
)
75 pObj
->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE
) );
83 bool FuConstCustomShape::MouseButtonUp(const MouseEvent
& rMEvt
)
85 // remember button state for creation of own MouseEvents
86 SetMouseButtonCode(rMEvt
.GetButtons());
90 if ( pView
->IsCreateObj() && rMEvt
.IsLeft() )
92 pView
->EndCreateObj(SdrCreateCmd::ForceEnd
);
95 return (FuConstruct::MouseButtonUp(rMEvt
) || bReturn
);
98 void FuConstCustomShape::Activate()
100 pView
->SetCurrentObj( OBJ_CUSTOMSHAPE
);
102 aNewPointer
= PointerStyle::DrawRect
;
103 aOldPointer
= pWindow
->GetPointer();
104 rViewShell
.SetActivePointer( aNewPointer
);
106 SdrLayer
* pLayer
= pView
->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS
);
108 pView
->SetActiveLayer( pLayer
->GetName() );
110 FuConstruct::Activate();
113 void FuConstCustomShape::Deactivate()
115 FuConstruct::Deactivate();
117 SdrLayer
* pLayer
= pView
->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT
);
119 pView
->SetActiveLayer( pLayer
->GetName() );
121 rViewShell
.SetActivePointer( aOldPointer
);
124 // Create default drawing objects via keyboard
125 SdrObjectUniquePtr
FuConstCustomShape::CreateDefaultObject(const sal_uInt16
/* nID */, const tools::Rectangle
& rRectangle
)
127 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
129 pView
->GetCurrentObjInventor(),
130 pView
->GetCurrentObjIdentifier()));
134 tools::Rectangle
aRectangle( rRectangle
);
135 SetAttributes( pObj
.get() );
136 if ( SdrObjCustomShape::doConstructOrthogonal( aCustomShape
) )
137 ImpForceQuadratic( aRectangle
);
138 pObj
->SetLogicRect( aRectangle
);
144 void FuConstCustomShape::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 SdrObject
* pSourceObj
= aFormModel
.GetPage( 0 )->GetObj( 0 );
166 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
168 pObj
->getSdrModelFromSdrObject().GetItemPool(),
170 // Ranges from SdrAttrObj:
171 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
172 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
173 SDRATTR_TEXTDIRECTION
,
174 SDRATTR_TEXTDIRECTION
,
175 // Graphic attributes, 3D properties,
176 // CustomShape properties:
178 SDRATTR_CUSTOMSHAPE_LAST
,
179 // Range from SdrTextObj:
180 EE_ITEMS_START
, EE_ITEMS_END
>{});
181 aDest
.Set( rSource
);
182 pObj
->SetMergedItemSet( aDest
);
183 sal_Int32 nAngle
= pSourceObj
->GetRotateAngle();
186 double a
= nAngle
* F_PI18000
;
187 pObj
->NbcRotate( pObj
->GetSnapRect().Center(), nAngle
, sin( a
), cos( a
) );
189 bAttributesAppliedFromGallery
= true;
197 if ( !bAttributesAppliedFromGallery
)
199 pObj
->SetMergedItem( SvxAdjustItem( SvxAdjust::Center
, EE_PARA_JUST
) );
200 pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
201 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
202 pObj
->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
203 static_cast<SdrObjCustomShape
*>(pObj
)->MergeDefaultAttributes( &aCustomShape
);
208 bool FuConstCustomShape::doConstructOrthogonal() const
210 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape
);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */