/src/libreoffice/sd/source/ui/func/fuconcs.cxx
Line | Count | Source |
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 <fuconcs.hxx> |
21 | | #include <rtl/ustring.hxx> |
22 | | |
23 | | #include <svx/svxids.hrc> |
24 | | |
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> |
32 | | |
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> |
40 | | |
41 | | #include <View.hxx> |
42 | | #include <Window.hxx> |
43 | | #include <drawdoc.hxx> |
44 | | |
45 | | namespace sd { |
46 | | |
47 | | |
48 | | FuConstructCustomShape::FuConstructCustomShape ( |
49 | | ViewShell& rViewSh, |
50 | | ::sd::Window* pWin, |
51 | | ::sd::View* pView, |
52 | | SdDrawDocument& rDoc, |
53 | | SfxRequest& rReq ) : |
54 | 0 | FuConstruct(rViewSh, pWin, pView, rDoc, rReq) |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | rtl::Reference<FuPoor> FuConstructCustomShape::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq, bool bPermanent ) |
59 | 0 | { |
60 | 0 | FuConstructCustomShape* pFunc; |
61 | 0 | rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructCustomShape( rViewSh, pWin, pView, rDoc, rReq ) ); |
62 | 0 | xFunc->DoExecute(rReq); |
63 | 0 | pFunc->SetPermanent( bPermanent ); |
64 | 0 | return xFunc; |
65 | 0 | } |
66 | | |
67 | | void FuConstructCustomShape::DoExecute( SfxRequest& rReq ) |
68 | 0 | { |
69 | 0 | FuConstruct::DoExecute( rReq ); |
70 | |
|
71 | 0 | const SfxItemSet* pArgs = rReq.GetArgs(); |
72 | 0 | if ( pArgs ) |
73 | 0 | { |
74 | 0 | const SfxStringItem& rItm = static_cast<const SfxStringItem&>(pArgs->Get( rReq.GetSlot() )); |
75 | 0 | aCustomShape = rItm.GetValue(); |
76 | 0 | } |
77 | |
|
78 | 0 | mrViewShell.GetViewShellBase().GetToolBarManager()->SetToolBar( |
79 | 0 | ToolBarManager::ToolBarGroup::Function, |
80 | 0 | ToolBarManager::msDrawingObjectToolBar); |
81 | 0 | } |
82 | | |
83 | | bool FuConstructCustomShape::MouseButtonDown(const MouseEvent& rMEvt) |
84 | 0 | { |
85 | 0 | bool bReturn = FuConstruct::MouseButtonDown(rMEvt); |
86 | |
|
87 | 0 | if ( rMEvt.IsLeft() && !mpView->IsAction() ) |
88 | 0 | { |
89 | 0 | Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) ); |
90 | |
|
91 | 0 | mpWindow->CaptureMouse(); |
92 | 0 | sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() ); |
93 | |
|
94 | 0 | mpView->BegCreateObj(aPnt, nullptr, nDrgLog); |
95 | |
|
96 | 0 | SdrObject* pObj = mpView->GetCreateObj(); |
97 | 0 | if ( pObj ) |
98 | 0 | { |
99 | 0 | SetAttributes( pObj ); |
100 | 0 | bool bForceFillStyle = true; |
101 | 0 | bool bForceNoFillStyle = false; |
102 | 0 | if ( static_cast<SdrObjCustomShape*>(pObj)->UseNoFillStyle() ) |
103 | 0 | { |
104 | 0 | bForceFillStyle = false; |
105 | 0 | bForceNoFillStyle = true; |
106 | 0 | } |
107 | 0 | SfxItemSet aAttr(mrDoc.GetPool()); |
108 | 0 | SetStyleSheet( aAttr, pObj, bForceFillStyle, bForceNoFillStyle ); |
109 | 0 | pObj->SetMergedItemSet(aAttr); |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | 0 | return bReturn; |
114 | 0 | } |
115 | | |
116 | | bool FuConstructCustomShape::MouseButtonUp(const MouseEvent& rMEvt) |
117 | 0 | { |
118 | 0 | if (rMEvt.IsLeft() && IsIgnoreUnexpectedMouseButtonUp()) |
119 | 0 | return false; |
120 | | |
121 | 0 | bool bReturn(false); |
122 | |
|
123 | 0 | if(mpView->IsCreateObj() && rMEvt.IsLeft()) |
124 | 0 | { |
125 | 0 | SdrObject* pObj = mpView->GetCreateObj(); |
126 | 0 | if( pObj && mpView->EndCreateObj( SdrCreateCmd::ForceEnd ) ) |
127 | 0 | { |
128 | 0 | bReturn = true; |
129 | 0 | } |
130 | 0 | else |
131 | 0 | { |
132 | | //Drag was too small to create object, so insert default object at click pos |
133 | 0 | Point aClickPos(mpWindow->PixelToLogic(rMEvt.GetPosPixel())); |
134 | 0 | sal_uInt32 nDefaultObjectSize(1000); |
135 | 0 | sal_Int32 nCenterOffset(-sal_Int32(nDefaultObjectSize / 2)); |
136 | 0 | aClickPos.AdjustX(nCenterOffset); |
137 | 0 | aClickPos.AdjustY(nCenterOffset); |
138 | |
|
139 | 0 | SdrPageView *pPV = mpView->GetSdrPageView(); |
140 | 0 | if(mpView->IsSnapEnabled()) |
141 | 0 | aClickPos = mpView->GetSnapPos(aClickPos, pPV); |
142 | |
|
143 | 0 | ::tools::Rectangle aNewObjectRectangle(aClickPos, Size(nDefaultObjectSize, nDefaultObjectSize)); |
144 | 0 | rtl::Reference<SdrObject> pObjDefault = CreateDefaultObject(nSlotId, aNewObjectRectangle); |
145 | |
|
146 | 0 | bReturn = mpView->InsertObjectAtView(pObjDefault.get(), *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR); |
147 | 0 | } |
148 | 0 | } |
149 | 0 | bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn; |
150 | |
|
151 | 0 | if (!bPermanent) |
152 | 0 | mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON); |
153 | |
|
154 | 0 | return bReturn; |
155 | 0 | } |
156 | | |
157 | | void FuConstructCustomShape::Activate() |
158 | 0 | { |
159 | 0 | mpView->SetCurrentObj( SdrObjKind::CustomShape ); |
160 | 0 | FuConstruct::Activate(); |
161 | 0 | } |
162 | | |
163 | | /** |
164 | | * set attribute for the object to be created |
165 | | */ |
166 | | void FuConstructCustomShape::SetAttributes( SdrObject* pObj ) |
167 | 0 | { |
168 | 0 | bool bAttributesAppliedFromGallery = false; |
169 | |
|
170 | 0 | if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) ) |
171 | 0 | { |
172 | 0 | std::vector< OUString > aObjList; |
173 | 0 | if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) ) |
174 | 0 | { |
175 | 0 | for ( std::vector<OUString>::size_type i = 0; i < aObjList.size(); i++ ) |
176 | 0 | { |
177 | 0 | if ( aObjList[ i ].equalsIgnoreAsciiCase( aCustomShape ) ) |
178 | 0 | { |
179 | 0 | FmFormModel aFormModel; |
180 | |
|
181 | 0 | if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aFormModel ) ) |
182 | 0 | { |
183 | 0 | const SdrPage* pPage = aFormModel.GetPage( 0 ); |
184 | 0 | if ( pPage ) |
185 | 0 | { |
186 | 0 | const SdrObject* pSourceObj = pPage->GetObj( 0 ); |
187 | 0 | if( pSourceObj ) |
188 | 0 | { |
189 | 0 | const SfxItemSet& rSource = pSourceObj->GetMergedItemSet(); |
190 | 0 | SfxItemSet aDest(SfxItemSet::makeFixedSfxItemSet< |
191 | | // Ranges from SdrAttrObj: |
192 | 0 | SDRATTR_START, SDRATTR_SHADOW_LAST, SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST, SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, |
193 | | // Graphic attributes, 3D properties, |
194 | | // CustomShape properties: |
195 | 0 | SDRATTR_GRAF_FIRST, SDRATTR_CUSTOMSHAPE_LAST, |
196 | | // Range from SdrTextObj: |
197 | 0 | EE_ITEMS_START, EE_ITEMS_END>(pObj->getSdrModelFromSdrObject().GetItemPool())); |
198 | 0 | aDest.Set( rSource ); |
199 | 0 | pObj->SetMergedItemSet( aDest ); |
200 | | // Enables Word-wrap by default (tdf#134369) |
201 | 0 | pObj->SetMergedItem( SdrOnOffItem( SDRATTR_TEXT_WORDWRAP, true ) ); |
202 | 0 | Degree100 nAngle = pSourceObj->GetRotateAngle(); |
203 | 0 | if ( nAngle ) |
204 | 0 | pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle ); |
205 | 0 | bAttributesAppliedFromGallery = true; |
206 | 0 | } |
207 | 0 | } |
208 | 0 | } |
209 | 0 | break; |
210 | 0 | } |
211 | 0 | } |
212 | 0 | } |
213 | 0 | } |
214 | 0 | if ( !bAttributesAppliedFromGallery ) |
215 | 0 | { |
216 | 0 | pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) ); |
217 | 0 | pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) ); |
218 | 0 | pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) ); |
219 | 0 | pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) ); |
220 | 0 | static_cast<SdrObjCustomShape*>(pObj)->MergeDefaultAttributes( &aCustomShape ); |
221 | 0 | } |
222 | 0 | } |
223 | | |
224 | | const OUString& FuConstructCustomShape::GetShapeType() const |
225 | 0 | { |
226 | 0 | return aCustomShape; |
227 | 0 | } |
228 | | |
229 | | rtl::Reference<SdrObject> FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& rRectangle) |
230 | 0 | { |
231 | 0 | rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject( |
232 | 0 | mpView->getSdrModelFromSdrView(), |
233 | 0 | mpView->GetCurrentObjInventor(), |
234 | 0 | mpView->GetCurrentObjIdentifier())); |
235 | |
|
236 | 0 | if( pObj ) |
237 | 0 | { |
238 | 0 | ::tools::Rectangle aRect( rRectangle ); |
239 | 0 | if ( doConstructOrthogonal() ) |
240 | 0 | ImpForceQuadratic( aRect ); |
241 | 0 | pObj->SetLogicRect( aRect ); |
242 | 0 | SetAttributes( pObj.get() ); |
243 | 0 | SfxItemSet aAttr(mrDoc.GetPool()); |
244 | 0 | SetStyleSheet(aAttr, pObj.get()); |
245 | 0 | pObj->SetMergedItemSet(aAttr); |
246 | 0 | } |
247 | 0 | return pObj; |
248 | 0 | } |
249 | | |
250 | | // #i33136# |
251 | | bool FuConstructCustomShape::doConstructOrthogonal() const |
252 | 0 | { |
253 | 0 | return SdrObjCustomShape::doConstructOrthogonal(aCustomShape); |
254 | 0 | } |
255 | | |
256 | | } // end of namespace sd |
257 | | |
258 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |