android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / uibase / ribbar / concustomshape.cxx
blob56030fc42d354f24af4dafd0c5e84c43c511fb02
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
39 using namespace com::sun::star;
41 ConstCustomShape::ConstCustomShape( SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView, SfxRequest const & rReq )
42 : SwDrawBase( pWrtShell, pEditWin, pSwView )
44 m_aCustomShape = ConstCustomShape::GetShapeTypeFromRequest( rReq );
47 const OUString& ConstCustomShape::GetShapeType() const
49 return m_aCustomShape;
52 OUString ConstCustomShape::GetShapeTypeFromRequest( SfxRequest const & rReq )
54 OUString aRet;
55 const SfxItemSet* pArgs = rReq.GetArgs();
56 if ( pArgs )
58 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
59 aRet = rItm.GetValue();
61 return aRet;
64 bool ConstCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
66 bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
67 if ( bReturn )
69 SdrView *pSdrView = m_pSh->GetDrawView();
70 if ( pSdrView )
72 SdrObject* pObj = pSdrView->GetCreateObj();
73 if ( pObj )
75 SetAttributes( pObj );
76 bool bForceNoFillStyle = false;
77 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
78 bForceNoFillStyle = true;
80 SfxItemSet aAttr( m_pView->GetPool() );
81 if ( bForceNoFillStyle )
82 aAttr.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
83 pObj->SetMergedItemSet(aAttr);
87 return bReturn;
90 void ConstCustomShape::Activate(const sal_uInt16 nSlotId)
92 m_pWin->SetSdrDrawMode( SdrObjKind::CustomShape );
94 SwDrawBase::Activate(nSlotId);
97 // applying attributes
99 void ConstCustomShape::SetAttributes( SdrObject* pObj )
101 bool bAttributesAppliedFromGallery = false;
103 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
105 std::vector< OUString > aObjList;
106 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
108 for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
110 if ( aObjList[ i ].equalsIgnoreAsciiCase( m_aCustomShape ) )
112 FmFormModel aFormModel;
113 SfxItemPool& rPool(aFormModel.GetItemPool());
114 rPool.FreezeIdRanges();
116 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
118 const SdrObject* pSourceObj = aFormModel.GetPage( 0 )->GetObj( 0 );
119 if( pSourceObj )
121 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
122 SfxItemSetFixed<
123 // Ranges from SdrAttrObj:
124 SDRATTR_START, SDRATTR_SHADOW_LAST,
125 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
126 SDRATTR_TEXTDIRECTION,
127 SDRATTR_TEXTDIRECTION,
128 // Graphic attributes, 3D properties,
129 // CustomShape properties:
130 SDRATTR_GRAF_FIRST,
131 SDRATTR_CUSTOMSHAPE_LAST,
132 // Range from SdrTextObj:
133 EE_ITEMS_START, EE_ITEMS_END>
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;
143 break;
148 if ( !bAttributesAppliedFromGallery )
150 pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, RES_PARATR_ADJUST ) );
151 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
152 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
153 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
154 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &m_aCustomShape );
158 void ConstCustomShape::CreateDefaultObject()
160 SwDrawBase::CreateDefaultObject();
161 SdrView *pSdrView = m_pSh->GetDrawView();
162 if ( pSdrView )
164 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
165 if ( rMarkList.GetMarkCount() == 1 )
167 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
168 if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
169 SetAttributes( pObj );
174 void ConstCustomShape::CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize)
176 SwDrawBase::CreateDefaultObjectAtPosWithSize(aPos, aSize);
177 SdrView *pSdrView = m_pSh->GetDrawView();
178 if ( pSdrView )
180 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
181 if ( rMarkList.GetMarkCount() == 1 )
183 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
184 if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
185 SetAttributes( pObj );
190 // #i33136#
191 bool ConstCustomShape::doConstructOrthogonal() const
193 return SdrObjCustomShape::doConstructOrthogonal(m_aCustomShape);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */