update credits
[LibreOffice.git] / sw / source / ui / ribbar / concustomshape.cxx
blob58e3747e523783240eb7bad1b86bac6835b2f5d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sfx2/bindings.hxx>
21 #include <sfx2/htmlmode.hxx>
22 #include <svx/sdtacitm.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/sdtagitm.hxx>
25 #include <svx/sdtakitm.hxx>
26 #include <svx/sdtaditm.hxx>
27 #include <svx/sdtaaitm.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/svdocapt.hxx>
30 #include <editeng/outlobj.hxx>
31 #include <cmdid.h>
32 #include <view.hxx>
33 #include <edtwin.hxx>
34 #include <wrtsh.hxx>
35 #include <viewopt.hxx>
36 #include <drawbase.hxx>
37 #include <concustomshape.hxx>
38 #include <svx/gallery.hxx>
39 #include <sfx2/request.hxx>
40 #include <svx/fmmodel.hxx>
41 #include <svl/itempool.hxx>
42 #include <svx/svdpage.hxx>
43 #include <svx/svdoashp.hxx>
44 #include <editeng/adjustitem.hxx>
46 #include <math.h>
48 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq )
49 : SwDrawBase( pWrtShell, pEditWin, pSwView )
51 aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq );
54 OUString ConstCustomShape::GetShapeType() const
56 return aCustomShape;
59 OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest& rReq )
61 OUString aRet;
62 const SfxItemSet* pArgs = rReq.GetArgs();
63 if ( pArgs )
65 const SfxStringItem& rItm = (const SfxStringItem&)pArgs->Get( rReq.GetSlot() );
66 aRet = rItm.GetValue();
68 return aRet;
71 sal_Bool ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
73 sal_Bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
74 if ( bReturn )
76 SdrView *pSdrView = m_pSh->GetDrawView();
77 if ( pSdrView )
79 SdrObject* pObj = pSdrView->GetCreateObj();
80 if ( pObj )
82 SetAttributes( pObj );
83 bool bForceNoFillStyle = false;
84 if ( ((SdrObjCustomShape*)pObj)->UseNoFillStyle() )
85 bForceNoFillStyle = true;
87 SfxItemSet aAttr( m_pView->GetPool() );
88 if ( bForceNoFillStyle )
89 aAttr.Put( XFillStyleItem( XFILL_NONE ) );
90 pObj->SetMergedItemSet(aAttr);
94 return bReturn;
97 sal_Bool ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
99 return SwDrawBase::MouseButtonUp(rMEvt);
102 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
104 m_pWin->SetSdrDrawMode( OBJ_CUSTOMSHAPE );
106 SwDrawBase::Activate(nSlotId);
109 // applying attributes
111 void ConstCustomShape::SetAttributes( SdrObject* pObj )
113 bool bAttributesAppliedFromGallery = false;
115 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
117 std::vector< OUString > aObjList;
118 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
120 sal_uInt16 i;
121 for ( i = 0; i < aObjList.size(); i++ )
123 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
125 FmFormModel aFormModel;
126 SfxItemPool& rPool = aFormModel.GetItemPool();
127 rPool.FreezeIdRanges();
128 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
130 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
131 if( pSourceObj )
133 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
134 SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
135 SDRATTR_START, SDRATTR_SHADOW_LAST,
136 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
137 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
138 // Graphic Attributes
139 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
140 // 3d Properties
141 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
142 // CustomShape properties
143 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
144 // range from SdrTextObj
145 EE_ITEMS_START, EE_ITEMS_END,
146 // end
147 0, 0);
148 aDest.Set( rSource );
149 pObj->SetMergedItemSet( aDest );
150 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
151 if ( nAngle )
153 double a = nAngle * F_PI18000;
154 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
156 bAttributesAppliedFromGallery = true;
159 break;
164 if ( !bAttributesAppliedFromGallery )
166 pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST ) );
167 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
168 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
169 pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
170 ((SdrObjCustomShape*)pObj)->MergeDefaultAttributes( &aCustomShape );
174 void ConstCustomShape::CreateDefaultObject()
176 SwDrawBase::CreateDefaultObject();
177 SdrView *pSdrView = m_pSh->GetDrawView();
178 if ( pSdrView )
180 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
181 if ( rMarkList.GetMarkCount() == 1 )
183 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
184 if ( pObj && pObj->ISA( SdrObjCustomShape ) )
185 SetAttributes( pObj );
190 // #i33136#
191 bool ConstCustomShape::doConstructOrthogonal() const
193 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */