1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <svx/svdobj.hxx>
21 #include <svx/sdtagitm.hxx>
22 #include <svx/svdview.hxx>
23 #include <editeng/eeitem.hxx>
24 #include <view.hxx>
25 #include <edtwin.hxx>
26 #include <wrtsh.hxx>
27 #include <drawbase.hxx>
28 #include <concustomshape.hxx>
29 #include <svx/gallery.hxx>
30 #include <sfx2/request.hxx>
31 #include <svx/fmmodel.hxx>
32 #include <svl/itempool.hxx>
33 #include <svl/stritem.hxx>
34 #include <svx/svdpage.hxx>
35 #include <svx/svdoashp.hxx>
36 #include <svx/xfillit0.hxx>
37 #include <editeng/adjustitem.hxx>
38
39 #include <math.h>
40
41 using namespace com::sun::star;
42
ConstCustomShape(SwWrtShell * pWrtShell,SwEditWin * pEditWin,SwView * pSwView,SfxRequest const & rReq)43 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest const & rReq )
44 : SwDrawBase( pWrtShell, pEditWin, pSwView )
45 {
46 aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq );
47 }
48
GetShapeType() const49 const OUString& ConstCustomShape::GetShapeType() const
50 {
51 return aCustomShape;
52 }
53
GetShapeTypeFromRequest(SfxRequest const & rReq)54 OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest const & rReq )
55 {
56 OUString aRet;
57 const SfxItemSet* pArgs = rReq.GetArgs();
58 if ( pArgs )
59 {
60 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
61 aRet = rItm.GetValue();
62 }
63 return aRet;
64 }
65
MouseButtonDown(const MouseEvent & rMEvt)66 bool ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
67 {
68 bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
69 if ( bReturn )
70 {
71 SdrView *pSdrView = m_pSh->GetDrawView();
72 if ( pSdrView )
73 {
74 SdrObject* pObj = pSdrView->GetCreateObj();
75 if ( pObj )
76 {
77 SetAttributes( pObj );
78 bool bForceNoFillStyle = false;
79 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
80 bForceNoFillStyle = true;
81
82 SfxItemSet aAttr( m_pView->GetPool() );
83 if ( bForceNoFillStyle )
84 aAttr.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
85 pObj->SetMergedItemSet(aAttr);
86 }
87 }
88 }
89 return bReturn;
90 }
91
Activate(const sal_uInt16 nSlotId)92 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
93 {
94 m_pWin->SetSdrDrawMode( OBJ_CUSTOMSHAPE );
95
96 SwDrawBase::Activate(nSlotId);
97 }
98
99 // applying attributes
100
SetAttributes(SdrObject * pObj)101 void ConstCustomShape::SetAttributes( SdrObject* pObj )
102 {
103 bool bAttributesAppliedFromGallery = false;
104
105 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
106 {
107 std::vector< OUString > aObjList;
108 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
109 {
110 for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
111 {
112 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
113 {
114 FmFormModel aFormModel;
115 SfxItemPool& rPool(aFormModel.GetItemPool());
116 rPool.FreezeIdRanges();
117
118 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
119 {
120 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
121 if( pSourceObj )
122 {
123 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
124 SfxItemSet aDest(
125 pObj->getSdrModelFromSdrObject().GetItemPool(),
126 svl::Items<
127 // Ranges from SdrAttrObj:
128 SDRATTR_START, SDRATTR_SHADOW_LAST,
129 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
130 SDRATTR_TEXTDIRECTION,
131 SDRATTR_TEXTDIRECTION,
132 // Graphic attributes, 3D properties,
133 // CustomShape properties:
134 SDRATTR_GRAF_FIRST,
135 SDRATTR_CUSTOMSHAPE_LAST,
136 // Range from SdrTextObj:
137 EE_ITEMS_START, EE_ITEMS_END>{});
138 aDest.Set( rSource );
139 pObj->SetMergedItemSet( aDest );
140 Degree100 nAngle = pSourceObj->GetRotateAngle();
141 if ( nAngle )
142 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
143 bAttributesAppliedFromGallery = true;
144 }
145 }
146 break;
147 }
148 }
149 }
150 }
151 if ( !bAttributesAppliedFromGallery )
152 {
153 pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, RES_PARATR_ADJUST ) );
154 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
155 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
156 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
157 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
158 }
159 }
160
CreateDefaultObject()161 void ConstCustomShape::CreateDefaultObject()
162 {
163 SwDrawBase::CreateDefaultObject();
164 SdrView *pSdrView = m_pSh->GetDrawView();
165 if ( pSdrView )
166 {
167 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
168 if ( rMarkList.GetMarkCount() == 1 )
169 {
170 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
171 if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
172 SetAttributes( pObj );
173 }
174 }
175 }
176
177 // #i33136#
doConstructOrthogonal() const178 bool ConstCustomShape::doConstructOrthogonal() const
179 {
180 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
181 }
182
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
184