LibreOffice Module sc (master)  1
fuconcustomshape.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 <fuconcustomshape.hxx>
21 #include <editeng/svxenum.hxx>
22 #include <svx/gallery.hxx>
23 #include <sfx2/request.hxx>
24 #include <svx/fmmodel.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/stritem.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdoashp.hxx>
29 #include <svx/xfillit0.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <svx/sdtagitm.hxx>
32 #include <tabvwsh.hxx>
33 #include <drawview.hxx>
34 #include <editeng/adjustitem.hxx>
35 
36 using namespace com::sun::star;
37 
39  : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
40 {
41  const SfxItemSet* pArgs = rReq.GetArgs();
42  if ( pArgs )
43  {
44  const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
45  aCustomShape = rItm.GetValue();
46  }
47 }
48 
50 {
51 }
52 
54 {
55  // remember button state for creation of own MouseEvents
57 
58  bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
59  if ( rMEvt.IsLeft() && !pView->IsAction() )
60  {
61  Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
63  pView->BegCreateObj(aPnt);
64 
65  SdrObject* pObj = pView->GetCreateObj();
66  if ( pObj )
67  {
68  SetAttributes( pObj );
69  bool bForceNoFillStyle = false;
70  if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
71  bForceNoFillStyle = true;
72  if ( bForceNoFillStyle )
73  pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
74  }
75 
76  bReturn = true;
77  }
78  return bReturn;
79 }
80 
82 {
83  // remember button state for creation of own MouseEvents
85 
86  bool bReturn = false;
87 
88  if ( pView->IsCreateObj() && rMEvt.IsLeft() )
89  {
90  pView->EndCreateObj(SdrCreateCmd::ForceEnd);
91  bReturn = true;
92  }
93  return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
94 }
95 
97 {
98  pView->SetCurrentObj( SdrObjKind::CustomShape );
99 
100  aNewPointer = PointerStyle::DrawRect;
103 
105 }
106 
108 {
110 
112 }
113 
114 // Create default drawing objects via keyboard
116 {
118  *pDrDoc,
121 
122  if( pObj )
123  {
124  tools::Rectangle aRectangle( rRectangle );
125  SetAttributes( pObj.get() );
127  ImpForceQuadratic( aRectangle );
128  pObj->SetLogicRect( aRectangle );
129  }
130 
131  return pObj;
132 }
133 
135 {
136  bool bAttributesAppliedFromGallery = false;
137 
139  {
140  std::vector< OUString > aObjList;
142  {
143  for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
144  {
145  if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
146  {
147  FmFormModel aFormModel;
148  SfxItemPool& rPool(aFormModel.GetItemPool());
149  rPool.FreezeIdRanges();
150 
152  {
153  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
154  if( pSourceObj )
155  {
156  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
158  // Ranges from SdrAttrObj:
162  SDRATTR_TEXTDIRECTION,
163  // Graphic attributes, 3D properties,
164  // CustomShape properties:
167  // Range from SdrTextObj:
170  aDest.Set( rSource );
171  pObj->SetMergedItemSet( aDest );
172  Degree100 nAngle = pSourceObj->GetRotateAngle();
173  if ( nAngle )
174  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
175  bAttributesAppliedFromGallery = true;
176  }
177  }
178  break;
179  }
180  }
181  }
182  }
183  if ( !bAttributesAppliedFromGallery )
184  {
185  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
189  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
190  }
191 }
192 
193 // #i33136#
195 {
197 }
198 
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle &rRectangle) override
void CaptureMouse()
virtual bool doConstructOrthogonal() const override
bool EndCreateObj(SdrCreateCmd eCmd)
PointerStyle aOldPointer
Definition: fudraw.hxx:31
FuConstCustomShape(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, const SfxRequest &rReq)
bool BegCreateObj(const Point &rPnt, OutputDevice *pOut=nullptr, short nMinMov=-3)
virtual void NbcRotate(const Point &rRef, Degree100 nAngle, double sn, double cs)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
static bool doConstructOrthogonal(std::u16string_view rName)
SdrObject * GetObj(size_t nNum) const
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
void SetAttributes(SdrObject *pObj)
constexpr sal_uInt16 EE_ITEMS_END(EE_FEATURE_END)
SdrModel * pDrDoc
Definition: fupoor.hxx:45
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
const SfxItemSet * GetArgs() const
constexpr sal_uInt16 SDRATTR_MISC_LAST(SDRATTR_TEXT_CHAINNEXTNAME)
Draw rectangle.
Definition: fuconstr.hxx:27
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
SdrOnOffItem makeSdrTextAutoGrowHeightItem(bool bAuto)
virtual const tools::Rectangle & GetSnapRect() const
std::deque< AttachedObject_Impl > aObjList
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
sal_uInt16 GetButtons() const
void SetMouseButtonCode(sal_uInt16 nNew)
Definition: fupoor.hxx:70
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
ScTabViewShell & rViewShell
Definition: fupoor.hxx:43
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:46
PointerStyle GetPointer() const
SDRTEXTHORZADJUST_BLOCK
constexpr TypedWhichId< SvxWritingModeItem > SDRATTR_TEXTDIRECTION(SDRATTR_NOTPERSIST_FIRST+34)
int i
SdrObject * GetCreateObj() const
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:894
const OUString & GetValue() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
constexpr sal_uInt16 EE_ITEMS_START(OWN_ATTR_VALUE_END+1)
SdrModel & getSdrModelFromSdrObject() const
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
constexpr sal_uInt16 SDRATTR_GRAF_FIRST(SDRATTR_NOTPERSIST_LAST+1)
void SetMergedItem(const SfxPoolItem &rItem)
Point PixelToLogic(const Point &rDevicePt) const
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
constexpr Point Center() const
bool IsCreateObj() const
virtual bool IsAction() const override
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
const SfxItemSet & GetMergedItemSet() const
virtual ~FuConstCustomShape() override
bool IsLeft() const
virtual void Activate() override
ScDrawView * pView
Definition: fupoor.hxx:42
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
const Point & GetPosPixel() const
PointerStyle aNewPointer
Definition: fudraw.hxx:30
static void ImpForceQuadratic(tools::Rectangle &rRect)
Definition: fupoor.cxx:225
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SfxItemPool & GetItemPool() const
SdrObjKind GetCurrentObjIdentifier() 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)
virtual void Activate()
Definition: fupoor.cxx:61
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:44
SdrInventor GetCurrentObjInventor() const
static sal_uInt32 GetSdrObjCount(std::u16string_view rThemeName)
SDRTEXTVERTADJUST_CENTER
virtual void Deactivate()
Definition: fupoor.cxx:65
virtual void Deactivate() override