LibreOffice Module sw (master)  1
concustomshape.cxx
Go to the documentation of this file.
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/eeitem.hxx>
31 #include <editeng/outlobj.hxx>
32 #include <cmdid.h>
33 #include <view.hxx>
34 #include <edtwin.hxx>
35 #include <wrtsh.hxx>
36 #include <viewopt.hxx>
37 #include <drawbase.hxx>
38 #include <concustomshape.hxx>
39 #include <svx/gallery.hxx>
40 #include <sfx2/request.hxx>
41 #include <svx/fmmodel.hxx>
42 #include <svl/itempool.hxx>
43 #include <svl/stritem.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdoashp.hxx>
46 #include <svx/xfillit0.hxx>
47 #include <editeng/adjustitem.hxx>
48 
49 #include <math.h>
50 
51 using namespace com::sun::star;
52 
53 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest const & rReq )
54  : SwDrawBase( pWrtShell, pEditWin, pSwView )
55 {
57 }
58 
59 const OUString& ConstCustomShape::GetShapeType() const
60 {
61  return aCustomShape;
62 }
63 
65 {
66  OUString aRet;
67  const SfxItemSet* pArgs = rReq.GetArgs();
68  if ( pArgs )
69  {
70  const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
71  aRet = rItm.GetValue();
72  }
73  return aRet;
74 }
75 
77 {
78  bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
79  if ( bReturn )
80  {
81  SdrView *pSdrView = m_pSh->GetDrawView();
82  if ( pSdrView )
83  {
84  SdrObject* pObj = pSdrView->GetCreateObj();
85  if ( pObj )
86  {
87  SetAttributes( pObj );
88  bool bForceNoFillStyle = false;
89  if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
90  bForceNoFillStyle = true;
91 
92  SfxItemSet aAttr( m_pView->GetPool() );
93  if ( bForceNoFillStyle )
94  aAttr.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
95  pObj->SetMergedItemSet(aAttr);
96  }
97  }
98  }
99  return bReturn;
100 }
101 
102 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
103 {
105 
106  SwDrawBase::Activate(nSlotId);
107 }
108 
109 // applying attributes
110 
112 {
113  bool bAttributesAppliedFromGallery = false;
114 
116  {
117  std::vector< OUString > aObjList;
119  {
120  for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
121  {
122  if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
123  {
124  FmFormModel aFormModel;
125  SfxItemPool& rPool(aFormModel.GetItemPool());
126  rPool.FreezeIdRanges();
127 
129  {
130  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
131  if( pSourceObj )
132  {
133  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
134  SfxItemSet aDest(
136  svl::Items<
137  // Ranges from SdrAttrObj:
141  SDRATTR_TEXTDIRECTION,
142  // Graphic attributes, 3D properties,
143  // CustomShape properties:
146  // Range from SdrTextObj:
148  aDest.Set( rSource );
149  pObj->SetMergedItemSet( aDest );
150  sal_Int32 nAngle = pSourceObj->GetRotateAngle();
151  if ( nAngle )
152  {
153  double a = nAngle * F_PI18000;
154  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
155  }
156  bAttributesAppliedFromGallery = true;
157  }
158  }
159  break;
160  }
161  }
162  }
163  }
164  if ( !bAttributesAppliedFromGallery )
165  {
166  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, RES_PARATR_ADJUST ) );
170  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
171  }
172 }
173 
175 {
177  SdrView *pSdrView = m_pSh->GetDrawView();
178  if ( pSdrView )
179  {
180  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
181  if ( rMarkList.GetMarkCount() == 1 )
182  {
183  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
184  if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
185  SetAttributes( pObj );
186  }
187  }
188 }
189 
190 // #i33136#
192 {
194 }
195 
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
#define EE_ITEMS_START
size_t GetMarkCount() const
static sal_uInt32 GetSdrObjCount(const OUString &rThemeName)
OBJ_CUSTOMSHAPE
SdrView * GetDrawView()
Definition: vnew.cxx:375
#define SDRATTR_CUSTOMSHAPE_LAST
virtual void Activate(const sal_uInt16 nSlotId) override
SdrObject * GetObj(size_t nNum) const
virtual bool doConstructOrthogonal() const override
SwWrtShell * m_pSh
Definition: drawbase.hxx:36
SdrMark * GetMark(size_t nNum) const
#define SDRATTR_MISC_LAST
const SfxItemSet * GetArgs() const
static bool GetSdrObj(const OUString &rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
SdrOnOffItem makeSdrTextAutoGrowHeightItem(bool bAuto)
virtual const tools::Rectangle & GetSnapRect() const
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
std::deque< AttachedObject_Impl > aObjList
virtual void CreateDefaultObject() override
#define SDRATTR_SHADOW_LAST
void SetSdrDrawMode(SdrObjKind eSdrObjectKind)
Definition: edtwin.hxx:212
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
virtual void Activate(const sal_uInt16 nSlotId)
Definition: drawbase.cxx:429
virtual void NbcRotate(const Point &rRef, long nAngle, double sn, double cs)
VclPtr< SwEditWin > m_pWin
Definition: drawbase.hxx:37
void SetAttributes(SdrObject *pObj)
SfxItemPool & GetPool() const
ConstCustomShape(SwWrtShell *pSh, SwEditWin *pWin, SwView *pView, SfxRequest const &rReq)
SdrObject * GetMarkedSdrObj() const
SDRTEXTHORZADJUST_BLOCK
uno_Any a
virtual void CreateDefaultObject()
Definition: drawbase.cxx:514
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
SdrObject * GetCreateObj() const
static OUString GetShapeTypeFromRequest(SfxRequest const &rReq)
int i
const OUString & GetValue() const
const SdrMarkList & GetMarkedObjectList() const
#define SDRATTR_MISC_FIRST
const SdrPage * GetPage(sal_uInt16 nPgNum) const
SdrModel & getSdrModelFromSdrObject() const
#define SDRATTR_TEXTDIRECTION
virtual bool MouseButtonDown(const MouseEvent &rMEvt)
Definition: drawbase.cxx:64
void SetMergedItem(const SfxPoolItem &rItem)
#define SDRATTR_START
#define SDRATTR_GRAF_FIRST
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
sal_uInt16 GetSlot() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SwView * m_pView
Definition: drawbase.hxx:35
const OUString & GetShapeType() const
const SfxItemSet & GetMergedItemSet() const
#define F_PI18000
#define RES_PARATR_ADJUST
Definition: hintids.hxx:163
virtual long GetRotateAngle() const
const SfxItemPool & GetItemPool() const
static bool doConstructOrthogonal(const OUString &rName)
Point Center() const
Definition: view.hxx:146
SDRTEXTVERTADJUST_CENTER
#define EE_ITEMS_END