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 <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 
43 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest const & rReq )
44  : SwDrawBase( pWrtShell, pEditWin, pSwView )
45 {
47 }
48 
49 const OUString& ConstCustomShape::GetShapeType() const
50 {
51  return aCustomShape;
52 }
53 
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 
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 
92 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
93 {
95 
96  SwDrawBase::Activate(nSlotId);
97 }
98 
99 // applying attributes
100 
102 {
103  bool bAttributesAppliedFromGallery = false;
104 
106  {
107  std::vector< OUString > 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 
119  {
120  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
121  if( pSourceObj )
122  {
123  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
124  SfxItemSet aDest(
126  svl::Items<
127  // Ranges from SdrAttrObj:
131  SDRATTR_TEXTDIRECTION,
132  // Graphic attributes, 3D properties,
133  // CustomShape properties:
136  // Range from SdrTextObj:
138  aDest.Set( rSource );
139  pObj->SetMergedItemSet( aDest );
140  sal_Int32 nAngle = pSourceObj->GetRotateAngle();
141  if ( nAngle )
142  {
143  double a = nAngle * F_PI18000;
144  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
145  }
146  bAttributesAppliedFromGallery = true;
147  }
148  }
149  break;
150  }
151  }
152  }
153  }
154  if ( !bAttributesAppliedFromGallery )
155  {
156  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, RES_PARATR_ADJUST ) );
160  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
161  }
162 }
163 
165 {
167  SdrView *pSdrView = m_pSh->GetDrawView();
168  if ( pSdrView )
169  {
170  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
171  if ( rMarkList.GetMarkCount() == 1 )
172  {
173  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
174  if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
175  SetAttributes( pObj );
176  }
177  }
178 }
179 
180 // #i33136#
182 {
184 }
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
size_t GetMarkCount() const
static sal_uInt32 GetSdrObjCount(const OUString &rThemeName)
OBJ_CUSTOMSHAPE
SdrView * GetDrawView()
Definition: vnew.cxx:375
virtual void Activate(const sal_uInt16 nSlotId) override
SdrObject * GetObj(size_t nNum) const
virtual bool doConstructOrthogonal() const override
constexpr sal_uInt16 EE_ITEMS_END(EE_FEATURE_END)
SwWrtShell * m_pSh
Definition: drawbase.hxx:36
SdrMark * GetMark(size_t nNum) const
const SfxItemSet * GetArgs() const
constexpr sal_uInt16 SDRATTR_MISC_LAST(SDRATTR_TEXT_CHAINNEXTNAME)
static bool GetSdrObj(const OUString &rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
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
void SetSdrDrawMode(SdrObjKind eSdrObjectKind)
Definition: edtwin.hxx:214
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
virtual void Activate(const sal_uInt16 nSlotId)
Definition: drawbase.cxx:427
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
constexpr TypedWhichId< SvxWritingModeItem > SDRATTR_TEXTDIRECTION(SDRATTR_NOTPERSIST_FIRST+34)
int i
uno_Any a
virtual void CreateDefaultObject()
Definition: drawbase.cxx:512
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)
const OUString & GetValue() const
const SdrMarkList & GetMarkedObjectList() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
constexpr sal_uInt16 EE_ITEMS_START(OWN_ATTR_VALUE_END+1)
SdrModel & getSdrModelFromSdrObject() const
constexpr sal_uInt16 SDRATTR_GRAF_FIRST(SDRATTR_NOTPERSIST_LAST+1)
virtual bool MouseButtonDown(const MouseEvent &rMEvt)
Definition: drawbase.cxx:62
void SetMergedItem(const SfxPoolItem &rItem)
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
constexpr sal_uInt16 SDRATTR_SHADOW_LAST(SDRATTR_SHADOWBLUR)
sal_uInt16 GetSlot() const
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
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
virtual long GetRotateAngle() const
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SfxItemPool & GetItemPool() const
static bool doConstructOrthogonal(const OUString &rName)
constexpr sal_uInt16 SDRATTR_MISC_FIRST(SDRATTR_CAPTION_LAST+1)
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
Point Center() const
Definition: view.hxx:144
SDRTEXTVERTADJUST_CENTER