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 #include <math.h>
37 
38 using namespace com::sun::star;
39 
41  : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
42 {
43  const SfxItemSet* pArgs = rReq.GetArgs();
44  if ( pArgs )
45  {
46  const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
47  aCustomShape = rItm.GetValue();
48  }
49 }
50 
52 {
53 }
54 
56 {
57  // remember button state for creation of own MouseEvents
59 
60  bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
61  if ( rMEvt.IsLeft() && !pView->IsAction() )
62  {
63  Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
65  pView->BegCreateObj(aPnt);
66 
67  SdrObject* pObj = pView->GetCreateObj();
68  if ( pObj )
69  {
70  SetAttributes( pObj );
71  bool bForceNoFillStyle = false;
72  if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
73  bForceNoFillStyle = true;
74  if ( bForceNoFillStyle )
75  pObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
76  }
77 
78  bReturn = true;
79  }
80  return bReturn;
81 }
82 
84 {
85  // remember button state for creation of own MouseEvents
87 
88  bool bReturn = false;
89 
90  if ( pView->IsCreateObj() && rMEvt.IsLeft() )
91  {
92  pView->EndCreateObj(SdrCreateCmd::ForceEnd);
93  bReturn = true;
94  }
95  return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
96 }
97 
99 {
101 
102  aNewPointer = PointerStyle::DrawRect;
105 
107  if (pLayer)
108  pView->SetActiveLayer( pLayer->GetName() );
109 
111 }
112 
114 {
116 
118  if (pLayer)
119  pView->SetActiveLayer( pLayer->GetName() );
120 
122 }
123 
124 // Create default drawing objects via keyboard
126 {
128  *pDrDoc,
131 
132  if( pObj )
133  {
134  tools::Rectangle aRectangle( rRectangle );
135  SetAttributes( pObj.get() );
137  ImpForceQuadratic( aRectangle );
138  pObj->SetLogicRect( aRectangle );
139  }
140 
141  return pObj;
142 }
143 
145 {
146  bool bAttributesAppliedFromGallery = false;
147 
149  {
150  std::vector< OUString > aObjList;
152  {
153  for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
154  {
155  if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
156  {
157  FmFormModel aFormModel;
158  SfxItemPool& rPool(aFormModel.GetItemPool());
159  rPool.FreezeIdRanges();
160 
162  {
163  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
164  if( pSourceObj )
165  {
166  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
167  SfxItemSet aDest(
169  svl::Items<
170  // Ranges from SdrAttrObj:
174  SDRATTR_TEXTDIRECTION,
175  // Graphic attributes, 3D properties,
176  // CustomShape properties:
179  // Range from SdrTextObj:
181  aDest.Set( rSource );
182  pObj->SetMergedItemSet( aDest );
183  sal_Int32 nAngle = pSourceObj->GetRotateAngle();
184  if ( nAngle )
185  {
186  double a = nAngle * F_PI18000;
187  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
188  }
189  bAttributesAppliedFromGallery = true;
190  }
191  }
192  break;
193  }
194  }
195  }
196  }
197  if ( !bAttributesAppliedFromGallery )
198  {
199  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
203  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
204  }
205 }
206 
207 // #i33136#
209 {
211 }
212 
213 /* 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:32
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 bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
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:46
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:26
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
SdrOnOffItem makeSdrTextAutoGrowHeightItem(bool bAuto)
virtual tools::Long GetRotateAngle() const
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:71
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
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
uno_Any a
SdrObject * GetCreateObj() const
void SetActivePointer(PointerStyle nPointer)
Definition: tabview.cxx:892
const OUString & GetValue() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
const OUString & GetName() const
constexpr sal_uInt16 EE_ITEMS_START(OWN_ATTR_VALUE_END+1)
SdrModel & getSdrModelFromSdrObject() const
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
SdrLayer * GetLayerPerID(SdrLayerID nID)
constexpr sal_uInt16 SDRATTR_GRAF_FIRST(SDRATTR_NOTPERSIST_LAST+1)
void SetMergedItem(const SfxPoolItem &rItem)
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
bool IsCreateObj() const
Point PixelToLogic(const Point &rDevicePt) 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
constexpr SdrLayerID SC_LAYER_FRONT(0)
const SfxItemSet & GetMergedItemSet() const
virtual ~FuConstCustomShape() override
bool IsLeft() const
virtual void Activate() override
ScDrawView * pView
Definition: fupoor.hxx:43
#define F_PI18000
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
const Point & GetPosPixel() const
void SetActiveLayer(const OUString &rName)
PointerStyle aNewPointer
Definition: fudraw.hxx:31
static void ImpForceQuadratic(tools::Rectangle &rRect)
Definition: fupoor.cxx:223
OBJ_CUSTOMSHAPE
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SfxItemPool & GetItemPool() const
SdrObjKind GetCurrentObjIdentifier() const
static bool doConstructOrthogonal(const OUString &rName)
static bool GetSdrObj(std::u16string_view rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
const SdrLayerAdmin & GetLayerAdmin() const
virtual void NbcRotate(const Point &rRef, tools::Long nAngle, double sn, double cs)
constexpr sal_uInt16 SDRATTR_MISC_FIRST(SDRATTR_CAPTION_LAST+1)
SdrModel * GetModel() const
constexpr SdrLayerID SC_LAYER_CONTROLS(3)
virtual void Activate()
Definition: fupoor.cxx:59
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:45
SdrInventor GetCurrentObjInventor() const
Point Center() const
static sal_uInt32 GetSdrObjCount(std::u16string_view rThemeName)
SDRTEXTVERTADJUST_CENTER
virtual void Deactivate()
Definition: fupoor.cxx:63
virtual void Deactivate() override