Line data Source code
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 <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>
45 :
46 : #include <math.h>
47 :
48 : using namespace com::sun::star;
49 :
50 0 : ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest& rReq )
51 0 : : SwDrawBase( pWrtShell, pEditWin, pSwView )
52 : {
53 0 : aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq );
54 0 : }
55 :
56 0 : OUString ConstCustomShape::GetShapeType() const
57 : {
58 0 : return aCustomShape;
59 : }
60 :
61 0 : OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest& rReq )
62 : {
63 0 : OUString aRet;
64 0 : const SfxItemSet* pArgs = rReq.GetArgs();
65 0 : if ( pArgs )
66 : {
67 0 : const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
68 0 : aRet = rItm.GetValue();
69 : }
70 0 : return aRet;
71 : }
72 :
73 0 : bool ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
74 : {
75 0 : bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
76 0 : if ( bReturn )
77 : {
78 0 : SdrView *pSdrView = m_pSh->GetDrawView();
79 0 : if ( pSdrView )
80 : {
81 0 : SdrObject* pObj = pSdrView->GetCreateObj();
82 0 : if ( pObj )
83 : {
84 0 : SetAttributes( pObj );
85 0 : bool bForceNoFillStyle = false;
86 0 : if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
87 0 : bForceNoFillStyle = true;
88 :
89 0 : SfxItemSet aAttr( m_pView->GetPool() );
90 0 : if ( bForceNoFillStyle )
91 0 : aAttr.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
92 0 : pObj->SetMergedItemSet(aAttr);
93 : }
94 : }
95 : }
96 0 : return bReturn;
97 : }
98 :
99 0 : bool ConstCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
100 : {
101 0 : return SwDrawBase::MouseButtonUp(rMEvt);
102 : }
103 :
104 0 : void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
105 : {
106 0 : m_pWin->SetSdrDrawMode( OBJ_CUSTOMSHAPE );
107 :
108 0 : SwDrawBase::Activate(nSlotId);
109 0 : }
110 :
111 : // applying attributes
112 :
113 0 : void ConstCustomShape::SetAttributes( SdrObject* pObj )
114 : {
115 0 : bool bAttributesAppliedFromGallery = false;
116 :
117 0 : if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
118 : {
119 0 : std::vector< OUString > aObjList;
120 0 : if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
121 : {
122 : sal_uInt16 i;
123 0 : for ( i = 0; i < aObjList.size(); i++ )
124 : {
125 0 : if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
126 : {
127 0 : FmFormModel aFormModel;
128 0 : SfxItemPool& rPool = aFormModel.GetItemPool();
129 0 : rPool.FreezeIdRanges();
130 0 : if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
131 : {
132 0 : const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
133 0 : if( pSourceObj )
134 : {
135 0 : const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
136 0 : SfxItemSet aDest( pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
137 : SDRATTR_START, SDRATTR_SHADOW_LAST,
138 : SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
139 : SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
140 : // Graphic Attributes
141 : SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
142 : // 3d Properties
143 : SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
144 : // CustomShape properties
145 : SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
146 : // range from SdrTextObj
147 : EE_ITEMS_START, EE_ITEMS_END,
148 : // end
149 0 : 0, 0);
150 0 : aDest.Set( rSource );
151 0 : pObj->SetMergedItemSet( aDest );
152 0 : sal_Int32 nAngle = pSourceObj->GetRotateAngle();
153 0 : if ( nAngle )
154 : {
155 0 : double a = nAngle * F_PI18000;
156 0 : pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
157 : }
158 0 : bAttributesAppliedFromGallery = true;
159 : }
160 : }
161 0 : break;
162 : }
163 : }
164 0 : }
165 : }
166 0 : if ( !bAttributesAppliedFromGallery )
167 : {
168 0 : pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER, RES_PARATR_ADJUST ) );
169 0 : pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
170 0 : pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
171 0 : pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
172 0 : static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
173 : }
174 0 : }
175 :
176 0 : void ConstCustomShape::CreateDefaultObject()
177 : {
178 0 : SwDrawBase::CreateDefaultObject();
179 0 : SdrView *pSdrView = m_pSh->GetDrawView();
180 0 : if ( pSdrView )
181 : {
182 0 : const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
183 0 : if ( rMarkList.GetMarkCount() == 1 )
184 : {
185 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
186 0 : if ( pObj && pObj->ISA( SdrObjCustomShape ) )
187 0 : SetAttributes( pObj );
188 : }
189 : }
190 0 : }
191 :
192 : // #i33136#
193 0 : bool ConstCustomShape::doConstructOrthogonal() const
194 : {
195 0 : return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
196 177 : }
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|