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 using namespace com::sun::star;
40 
41 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest const & rReq )
42  : SwDrawBase( pWrtShell, pEditWin, pSwView )
43 {
45 }
46 
47 const OUString& ConstCustomShape::GetShapeType() const
48 {
49  return m_aCustomShape;
50 }
51 
53 {
54  OUString aRet;
55  const SfxItemSet* pArgs = rReq.GetArgs();
56  if ( pArgs )
57  {
58  const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
59  aRet = rItm.GetValue();
60  }
61  return aRet;
62 }
63 
65 {
66  bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
67  if ( bReturn )
68  {
69  SdrView *pSdrView = m_pSh->GetDrawView();
70  if ( pSdrView )
71  {
72  SdrObject* pObj = pSdrView->GetCreateObj();
73  if ( pObj )
74  {
75  SetAttributes( pObj );
76  bool bForceNoFillStyle = false;
77  if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
78  bForceNoFillStyle = true;
79 
80  SfxItemSet aAttr( m_pView->GetPool() );
81  if ( bForceNoFillStyle )
82  aAttr.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
83  pObj->SetMergedItemSet(aAttr);
84  }
85  }
86  }
87  return bReturn;
88 }
89 
90 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
91 {
92  m_pWin->SetSdrDrawMode( SdrObjKind::CustomShape );
93 
94  SwDrawBase::Activate(nSlotId);
95 }
96 
97 // applying attributes
98 
100 {
101  bool bAttributesAppliedFromGallery = false;
102 
104  {
105  std::vector< OUString > aObjList;
107  {
108  for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
109  {
110  if ( aObjList[ i ].equalsIgnoreAsciiCase( m_aCustomShape ) )
111  {
112  FmFormModel aFormModel;
113  SfxItemPool& rPool(aFormModel.GetItemPool());
114  rPool.FreezeIdRanges();
115 
117  {
118  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
119  if( pSourceObj )
120  {
121  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
123  // Ranges from SdrAttrObj:
127  SDRATTR_TEXTDIRECTION,
128  // Graphic attributes, 3D properties,
129  // CustomShape properties:
132  // Range from SdrTextObj:
134  aDest( pObj->getSdrModelFromSdrObject().GetItemPool() );
135  aDest.Set( rSource );
136  pObj->SetMergedItemSet( aDest );
137  Degree100 nAngle = pSourceObj->GetRotateAngle();
138  if ( nAngle )
139  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
140  bAttributesAppliedFromGallery = true;
141  }
142  }
143  break;
144  }
145  }
146  }
147  }
148  if ( !bAttributesAppliedFromGallery )
149  {
150  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, RES_PARATR_ADJUST ) );
154  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &m_aCustomShape );
155  }
156 }
157 
159 {
161  SdrView *pSdrView = m_pSh->GetDrawView();
162  if ( pSdrView )
163  {
164  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
165  if ( rMarkList.GetMarkCount() == 1 )
166  {
167  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
168  if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
169  SetAttributes( pObj );
170  }
171  }
172 }
173 
174 // #i33136#
176 {
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
size_t GetMarkCount() const
SdrView * GetDrawView()
Definition: vnew.cxx:373
virtual void NbcRotate(const Point &rRef, Degree100 nAngle, double sn, double cs)
virtual void Activate(const sal_uInt16 nSlotId) override
static bool doConstructOrthogonal(std::u16string_view rName)
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)
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:96
std::deque< AttachedObject_Impl > aObjList
virtual void CreateDefaultObject() override
void SetSdrDrawMode(SdrObjKind eSdrObjectKind)
Definition: edtwin.hxx:216
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
virtual void Activate(const sal_uInt16 nSlotId)
Definition: drawbase.cxx:427
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
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:59
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 Point Center() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
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
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SfxItemPool & GetItemPool() const
virtual Degree100 GetRotateAngle() const
static bool GetSdrObj(std::u16string_view rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
constexpr sal_uInt16 SDRATTR_MISC_FIRST(SDRATTR_CAPTION_LAST+1)
constexpr TypedWhichId< SvxAdjustItem > RES_PARATR_ADJUST(64)
Definition: view.hxx:144
static sal_uInt32 GetSdrObjCount(std::u16string_view rThemeName)
SDRTEXTVERTADJUST_CENTER