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 }
108 
110 {
112 
114 }
115 
116 // Create default drawing objects via keyboard
118 {
120  *pDrDoc,
123 
124  if( pObj )
125  {
126  tools::Rectangle aRectangle( rRectangle );
127  SetAttributes( pObj.get() );
129  ImpForceQuadratic( aRectangle );
130  pObj->SetLogicRect( aRectangle );
131  }
132 
133  return pObj;
134 }
135 
137 {
138  bool bAttributesAppliedFromGallery = false;
139 
141  {
142  std::vector< OUString > aObjList;
144  {
145  for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
146  {
147  if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
148  {
149  FmFormModel aFormModel;
150  SfxItemPool& rPool(aFormModel.GetItemPool());
151  rPool.FreezeIdRanges();
152 
154  {
155  const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
156  if( pSourceObj )
157  {
158  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
159  SfxItemSet aDest(
161  svl::Items<
162  // Ranges from SdrAttrObj:
166  SDRATTR_TEXTDIRECTION,
167  // Graphic attributes, 3D properties,
168  // CustomShape properties:
171  // Range from SdrTextObj:
173  aDest.Set( rSource );
174  pObj->SetMergedItemSet( aDest );
175  Degree100 nAngle = pSourceObj->GetRotateAngle();
176  if ( nAngle )
177  pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
178  bAttributesAppliedFromGallery = true;
179  }
180  }
181  break;
182  }
183  }
184  }
185  }
186  if ( !bAttributesAppliedFromGallery )
187  {
188  pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
192  static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
193  }
194 }
195 
196 // #i33136#
198 {
200 }
201 
202 /* 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
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)
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:223
OBJ_CUSTOMSHAPE
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
const SfxItemPool & GetItemPool() const
SdrObjKind GetCurrentObjIdentifier() const
virtual Degree100 GetRotateAngle() const
static bool doConstructOrthogonal(const OUString &rName)
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:59
VclPtr< vcl::Window > pWindow
Definition: fupoor.hxx:44
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