android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fuconcs.cxx
blobcce38d75c928cae19b2e750d3148ae31cf0a551a
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 <fuconcs.hxx>
21 #include <rtl/ustring.hxx>
23 #include <svx/svxids.hrc>
25 #include <sfx2/viewfrm.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/request.hxx>
28 #include <editeng/adjustitem.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <svx/svdoashp.hxx>
31 #include <svx/sdtagitm.hxx>
33 #include <ViewShell.hxx>
34 #include <ViewShellBase.hxx>
35 #include <ToolBarManager.hxx>
36 #include <svx/gallery.hxx>
37 #include <svx/sdooitm.hxx>
38 #include <svl/itempool.hxx>
39 #include <svl/stritem.hxx>
41 #include <View.hxx>
42 #include <Window.hxx>
43 #include <drawdoc.hxx>
45 namespace sd {
48 FuConstructCustomShape::FuConstructCustomShape (
49 ViewShell* pViewSh,
50 ::sd::Window* pWin,
51 ::sd::View* pView,
52 SdDrawDocument* pDoc,
53 SfxRequest& rReq ) :
54 FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
58 rtl::Reference<FuPoor> FuConstructCustomShape::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
60 FuConstructCustomShape* pFunc;
61 rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructCustomShape( pViewSh, pWin, pView, pDoc, rReq ) );
62 xFunc->DoExecute(rReq);
63 pFunc->SetPermanent( bPermanent );
64 return xFunc;
67 void FuConstructCustomShape::DoExecute( SfxRequest& rReq )
69 FuConstruct::DoExecute( rReq );
71 const SfxItemSet* pArgs = rReq.GetArgs();
72 if ( pArgs )
74 const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() ));
75 aCustomShape = rItm.GetValue();
78 mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
79 ToolBarManager::ToolBarGroup::Function,
80 ToolBarManager::msDrawingObjectToolBar);
83 bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt)
85 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
87 if ( rMEvt.IsLeft() && !mpView->IsAction() )
89 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
91 mpWindow->CaptureMouse();
92 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
94 mpView->BegCreateObj(aPnt, nullptr, nDrgLog);
96 SdrObject* pObj = mpView->GetCreateObj();
97 if ( pObj )
99 SetAttributes( pObj );
100 bool bForceFillStyle = true;
101 bool bForceNoFillStyle = false;
102 if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() )
104 bForceFillStyle = false;
105 bForceNoFillStyle = true;
107 SfxItemSet aAttr(mpDoc->GetPool());
108 SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle );
109 pObj->SetMergedItemSet(aAttr);
113 return bReturn;
116 bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt)
118 bool bReturn(false);
120 if(mpView->IsCreateObj() && rMEvt.IsLeft())
122 SdrObject* pObj = mpView->GetCreateObj();
123 if( pObj && mpView->EndCreateObj( SdrCreateCmd::ForceEnd ) )
125 bReturn = true;
127 else
129 //Drag was too small to create object, so insert default object at click pos
130 Point aClickPos(mpWindow->PixelToLogic(rMEvt.GetPosPixel()));
131 sal_uInt32 nDefaultObjectSize(1000);
132 sal_Int32 nCenterOffset(-sal_Int32(nDefaultObjectSize / 2));
133 aClickPos.AdjustX(nCenterOffset);
134 aClickPos.AdjustY(nCenterOffset);
136 SdrPageView *pPV = mpView->GetSdrPageView();
137 if(mpView->IsSnapEnabled())
138 aClickPos = mpView->GetSnapPos(aClickPos, pPV);
140 ::tools::Rectangle aNewObjectRectangle(aClickPos, Size(nDefaultObjectSize, nDefaultObjectSize));
141 rtl::Reference<SdrObject> pObjDefault = CreateDefaultObject(nSlotId, aNewObjectRectangle);
143 bReturn = mpView->InsertObjectAtView(pObjDefault.get(), *pPV);
146 bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
148 if (!bPermanent)
149 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
151 return bReturn;
154 void FuConstructCustomShape::Activate()
156 mpView->SetCurrentObj( SdrObjKind::CustomShape );
157 FuConstruct::Activate();
161 * set attribute for the object to be created
163 void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
165 bool bAttributesAppliedFromGallery = false;
167 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
169 std::vector< OUString > aObjList;
170 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
172 for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ )
174 if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) )
176 FmFormModel aFormModel;
177 SfxItemPool& rPool(aFormModel.GetItemPool());
178 rPool.FreezeIdRanges();
180 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) )
182 const SdrPage* pPage = aFormModel.GetPage( 0 );
183 if ( pPage )
185 const SdrObject* pSourceObj = pPage->GetObj( 0 );
186 if( pSourceObj )
188 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
189 SfxItemSetFixed<
190 // Ranges from SdrAttrObj:
191 SDRATTR_START, SDRATTR_SHADOW_LAST,
192 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
193 SDRATTR_TEXTDIRECTION,
194 SDRATTR_TEXTDIRECTION,
195 // Graphic attributes, 3D properties,
196 // CustomShape properties:
197 SDRATTR_GRAF_FIRST,
198 SDRATTR_CUSTOMSHAPE_LAST,
199 // Range from SdrTextObj:
200 EE_ITEMS_START, EE_ITEMS_END> aDest(pObj->getSdrModelFromSdrObject().GetItemPool());
201 aDest.Set( rSource );
202 pObj->SetMergedItemSet( aDest );
203 // Enables Word-wrap by default (tdf#134369)
204 pObj->SetMergedItem( SdrOnOffItem( SDRATTR_TEXT_WORDWRAP, true ) );
205 Degree100 nAngle = pSourceObj->GetRotateAngle();
206 if ( nAngle )
207 pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle );
208 bAttributesAppliedFromGallery = true;
212 break;
217 if ( !bAttributesAppliedFromGallery )
219 pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );
220 pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
221 pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
222 pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
223 static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape );
227 const OUString& FuConstructCustomShape::GetShapeType() const
229 return aCustomShape;
232 rtl::Reference<SdrObject> FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& rRectangle)
234 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
235 mpView->getSdrModelFromSdrView(),
236 mpView->GetCurrentObjInventor(),
237 mpView->GetCurrentObjIdentifier()));
239 if( pObj )
241 ::tools::Rectangle aRect( rRectangle );
242 if ( doConstructOrthogonal() )
243 ImpForceQuadratic( aRect );
244 pObj->SetLogicRect( aRect );
245 SetAttributes( pObj.get() );
246 SfxItemSet aAttr(mpDoc->GetPool());
247 SetStyleSheet(aAttr, pObj.get());
248 pObj->SetMergedItemSet(aAttr);
250 return pObj;
253 // #i33136#
254 bool FuConstructCustomShape::doConstructOrthogonal() const
256 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape);
259 } // end of namespace sd
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */