/src/libreoffice/chart2/source/controller/main/DrawCommandDispatch.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 "DrawCommandDispatch.hxx" |
21 | | #include <ChartController.hxx> |
22 | | #include <DrawViewWrapper.hxx> |
23 | | #include <chartview/DrawModelWrapper.hxx> |
24 | | |
25 | | #include <com/sun/star/frame/CommandGroup.hpp> |
26 | | #include <o3tl/unsafe_downcast.hxx> |
27 | | #include <o3tl/string_view.hxx> |
28 | | #include <vcl/svapp.hxx> |
29 | | #include <editeng/eeitem.hxx> |
30 | | #include <svx/strings.hrc> |
31 | | #include <svx/dialmgr.hxx> |
32 | | #include <svx/fmmodel.hxx> |
33 | | #include <svx/gallery.hxx> |
34 | | #include <svx/svdoashp.hxx> |
35 | | #include <svx/svdocapt.hxx> |
36 | | #include <svx/svdopath.hxx> |
37 | | #include <svx/svdpage.hxx> |
38 | | #include <svx/unoapi.hxx> |
39 | | #include <svx/xlnedit.hxx> |
40 | | #include <svx/xlnedwit.hxx> |
41 | | #include <svx/xlnwtit.hxx> |
42 | | #include <svx/xtable.hxx> |
43 | | #include <svx/sdtagitm.hxx> |
44 | | #include <basegfx/polygon/b2dpolygon.hxx> |
45 | | |
46 | | using namespace ::com::sun::star; |
47 | | using namespace ::com::sun::star::frame; |
48 | | |
49 | | using ::com::sun::star::uno::Reference; |
50 | | using ::com::sun::star::uno::Sequence; |
51 | | |
52 | | |
53 | | namespace chart |
54 | | { |
55 | | |
56 | | DrawCommandDispatch::DrawCommandDispatch( const Reference< uno::XComponentContext >& rxContext, |
57 | | ChartController* pController ) |
58 | 0 | :FeatureCommandDispatchBase( rxContext ) |
59 | 0 | ,m_pChartController( pController ) |
60 | 0 | { |
61 | 0 | } Unexecuted instantiation: chart::DrawCommandDispatch::DrawCommandDispatch(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, chart::ChartController*) Unexecuted instantiation: chart::DrawCommandDispatch::DrawCommandDispatch(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, chart::ChartController*) |
62 | | |
63 | | DrawCommandDispatch::~DrawCommandDispatch() |
64 | 0 | { |
65 | 0 | } |
66 | | |
67 | | bool DrawCommandDispatch::isFeatureSupported( const OUString& rCommandURL ) |
68 | 0 | { |
69 | 0 | ChartCommandID nFeatureId = ChartCommandID::NONE; |
70 | 0 | OUString aBaseCommand; |
71 | 0 | OUString aCustomShapeType; |
72 | 0 | return parseCommandURL( rCommandURL, &nFeatureId, &aBaseCommand, &aCustomShapeType ); |
73 | 0 | } |
74 | | |
75 | | static ::basegfx::B2DPolyPolygon getPolygon(TranslateId pResId, const SdrModel& rModel) |
76 | 0 | { |
77 | 0 | ::basegfx::B2DPolyPolygon aReturn; |
78 | 0 | XLineEndListRef pLineEndList = rModel.GetLineEndList(); |
79 | 0 | if ( pLineEndList.is() ) |
80 | 0 | { |
81 | 0 | OUString aName(SvxResId(pResId)); |
82 | 0 | tools::Long nCount = pLineEndList->Count(); |
83 | 0 | for ( tools::Long nIndex = 0; nIndex < nCount; ++nIndex ) |
84 | 0 | { |
85 | 0 | const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex); |
86 | 0 | if ( pEntry->GetName() == aName ) |
87 | 0 | { |
88 | 0 | aReturn = pEntry->GetLineEnd(); |
89 | 0 | break; |
90 | 0 | } |
91 | 0 | } |
92 | 0 | } |
93 | 0 | return aReturn; |
94 | 0 | } |
95 | | |
96 | | void DrawCommandDispatch::setAttributes( SdrObject* pObj ) |
97 | 0 | { |
98 | 0 | if ( !m_pChartController ) |
99 | 0 | return; |
100 | | |
101 | 0 | DrawModelWrapper* pDrawModelWrapper = m_pChartController->GetDrawModelWrapper(); |
102 | 0 | DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper(); |
103 | 0 | if ( !(pDrawModelWrapper && pDrawViewWrapper && pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::CustomShape) ) |
104 | 0 | return; |
105 | | |
106 | 0 | bool bAttributesAppliedFromGallery = false; |
107 | 0 | if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) ) |
108 | 0 | { |
109 | 0 | std::vector< OUString > aObjList; |
110 | 0 | if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) ) |
111 | 0 | { |
112 | 0 | for ( size_t i = 0; i < aObjList.size(); ++i ) |
113 | 0 | { |
114 | 0 | if ( aObjList[ i ].equalsIgnoreAsciiCase( m_aCustomShapeType ) ) |
115 | 0 | { |
116 | 0 | FmFormModel aModel; |
117 | |
|
118 | 0 | if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aModel ) ) |
119 | 0 | { |
120 | 0 | const SdrObject* pSourceObj = aModel.GetPage( 0 )->GetObj( 0 ); |
121 | 0 | if ( pSourceObj ) |
122 | 0 | { |
123 | 0 | const SfxItemSet& rSource = pSourceObj->GetMergedItemSet(); |
124 | | // Create a dynamic SfxItemSet |
125 | 0 | SfxItemSet aDest( |
126 | 0 | SfxItemSet::makeFixedSfxItemSet< |
127 | | // Ranges from SdrAttrObj: |
128 | 0 | SDRATTR_START, SDRATTR_SHADOW_LAST, SDRATTR_MISC_FIRST, |
129 | 0 | SDRATTR_MISC_LAST, SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, |
130 | | // Graphic attributes, 3D |
131 | | // properties, CustomShape |
132 | | // properties: |
133 | 0 | SDRATTR_GRAF_FIRST, SDRATTR_CUSTOMSHAPE_LAST, |
134 | | // Range from SdrTextObj: |
135 | 0 | EE_ITEMS_START, EE_ITEMS_END>( |
136 | 0 | pObj->getSdrModelFromSdrObject().GetItemPool())); |
137 | 0 | aDest.Set( rSource ); |
138 | 0 | pObj->SetMergedItemSet( aDest ); |
139 | 0 | Degree100 nAngle = pSourceObj->GetRotateAngle(); |
140 | 0 | if ( nAngle ) |
141 | 0 | pObj->NbcRotate( pObj->GetSnapRect().Center(), nAngle ); |
142 | 0 | bAttributesAppliedFromGallery = true; |
143 | 0 | } |
144 | 0 | } |
145 | 0 | break; |
146 | 0 | } |
147 | 0 | } |
148 | 0 | } |
149 | 0 | } |
150 | 0 | if ( !bAttributesAppliedFromGallery ) |
151 | 0 | { |
152 | 0 | pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) ); |
153 | 0 | pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) ); |
154 | 0 | pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) ); |
155 | |
|
156 | 0 | o3tl::unsafe_downcast< SdrObjCustomShape* >( pObj )->MergeDefaultAttributes( &m_aCustomShapeType ); |
157 | 0 | } |
158 | 0 | } |
159 | | |
160 | | void DrawCommandDispatch::setLineEnds( SfxItemSet& rAttr ) |
161 | 0 | { |
162 | 0 | if ( !(m_nFeatureId == ChartCommandID::DrawLineArrowEnd && m_pChartController) ) |
163 | 0 | return; |
164 | | |
165 | 0 | DrawModelWrapper* pDrawModelWrapper = m_pChartController->GetDrawModelWrapper(); |
166 | 0 | DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper(); |
167 | 0 | if ( !(pDrawModelWrapper && pDrawViewWrapper) ) |
168 | 0 | return; |
169 | | |
170 | 0 | ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, pDrawModelWrapper->getSdrModel() ) ); |
171 | 0 | if ( !aArrow.count() ) |
172 | 0 | { |
173 | 0 | ::basegfx::B2DPolygon aNewArrow; |
174 | 0 | aNewArrow.append( ::basegfx::B2DPoint( 10.0, 0.0 ) ); |
175 | 0 | aNewArrow.append( ::basegfx::B2DPoint( 0.0, 30.0) ); |
176 | 0 | aNewArrow.append( ::basegfx::B2DPoint( 20.0, 30.0 ) ); |
177 | 0 | aNewArrow.setClosed( true ); |
178 | 0 | aArrow.append( aNewArrow ); |
179 | 0 | } |
180 | |
|
181 | 0 | SfxItemSet aSet(pDrawViewWrapper->GetModel().GetItemPool()); |
182 | 0 | pDrawViewWrapper->GetAttributes( aSet ); |
183 | | |
184 | | // tdf#126823 - retrieve default arrow size for end width |
185 | | // generated in SdDrawDocument::CreateLayoutTemplates() |
186 | 0 | ::tools::Long nLineEndWidth = 200; |
187 | 0 | if (aSet.GetItemState(XATTR_LINEENDWIDTH) != SfxItemState::INVALID) |
188 | 0 | nLineEndWidth = aSet.Get(XATTR_LINEENDWIDTH).GetValue(); |
189 | |
|
190 | 0 | rAttr.Put( XLineEndItem( SvxResId( RID_SVXSTR_ARROW ), std::move(aArrow) ) ); |
191 | 0 | rAttr.Put(XLineEndWidthItem(nLineEndWidth)); |
192 | 0 | } |
193 | | |
194 | | // WeakComponentImplHelperBase |
195 | | void DrawCommandDispatch::disposing(std::unique_lock<std::mutex>& /*rGuard*/) |
196 | 0 | { |
197 | 0 | } |
198 | | |
199 | | // XEventListener |
200 | | void DrawCommandDispatch::disposing( const lang::EventObject& /* Source */ ) |
201 | 0 | { |
202 | 0 | } |
203 | | |
204 | | FeatureState DrawCommandDispatch::getState( const OUString& rCommand ) |
205 | 0 | { |
206 | 0 | FeatureState aReturn; |
207 | 0 | aReturn.bEnabled = false; |
208 | 0 | aReturn.aState <<= false; |
209 | |
|
210 | 0 | ChartCommandID nFeatureId = ChartCommandID::NONE; |
211 | 0 | OUString aBaseCommand; |
212 | 0 | OUString aCustomShapeType; |
213 | 0 | if ( parseCommandURL( rCommand, &nFeatureId, &aBaseCommand, &aCustomShapeType ) ) |
214 | 0 | { |
215 | 0 | switch ( nFeatureId ) |
216 | 0 | { |
217 | 0 | case ChartCommandID::DrawObjectSelect: |
218 | 0 | case ChartCommandID::DrawLine: |
219 | 0 | case ChartCommandID::DrawLineArrowEnd: |
220 | 0 | case ChartCommandID::DrawRect: |
221 | 0 | case ChartCommandID::DrawEllipse: |
222 | 0 | case ChartCommandID::DrawFreelineNoFill: |
223 | 0 | case ChartCommandID::DrawText: |
224 | 0 | case ChartCommandID::DrawCaption: |
225 | 0 | case ChartCommandID::DrawToolboxCsBasic: |
226 | 0 | case ChartCommandID::DrawToolboxCsSymbol: |
227 | 0 | case ChartCommandID::DrawToolboxCsArrow: |
228 | 0 | case ChartCommandID::DrawToolboxCsFlowchart: |
229 | 0 | case ChartCommandID::DrawToolboxCsCallout: |
230 | 0 | case ChartCommandID::DrawToolboxCsStar: |
231 | 0 | { |
232 | 0 | aReturn.bEnabled = true; |
233 | 0 | aReturn.aState <<= false; |
234 | 0 | } |
235 | 0 | break; |
236 | 0 | default: |
237 | 0 | { |
238 | 0 | aReturn.bEnabled = false; |
239 | 0 | aReturn.aState <<= false; |
240 | 0 | } |
241 | 0 | break; |
242 | 0 | } |
243 | 0 | } |
244 | | |
245 | 0 | return aReturn; |
246 | 0 | } |
247 | | |
248 | | void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< beans::PropertyValue>& rArgs ) |
249 | 0 | { |
250 | 0 | ChartDrawMode eDrawMode = CHARTDRAW_SELECT; |
251 | 0 | SdrObjKind eKind = SdrObjKind::NONE; |
252 | |
|
253 | 0 | ChartCommandID nFeatureId = ChartCommandID::NONE; |
254 | 0 | OUString aBaseCommand; |
255 | 0 | OUString aCustomShapeType; |
256 | 0 | if ( !parseCommandURL( rCommand, &nFeatureId, &aBaseCommand, &aCustomShapeType ) ) |
257 | 0 | return; |
258 | | |
259 | 0 | bool bCreate = false; |
260 | 0 | m_nFeatureId = nFeatureId; |
261 | 0 | m_aCustomShapeType = aCustomShapeType; |
262 | |
|
263 | 0 | switch ( nFeatureId ) |
264 | 0 | { |
265 | 0 | case ChartCommandID::DrawObjectSelect: |
266 | 0 | { |
267 | 0 | eDrawMode = CHARTDRAW_SELECT; |
268 | 0 | eKind = SdrObjKind::NONE; |
269 | 0 | } |
270 | 0 | break; |
271 | 0 | case ChartCommandID::DrawLine: |
272 | 0 | case ChartCommandID::DrawLineArrowEnd: |
273 | 0 | { |
274 | 0 | eDrawMode = CHARTDRAW_INSERT; |
275 | 0 | eKind = SdrObjKind::Line; |
276 | 0 | } |
277 | 0 | break; |
278 | 0 | case ChartCommandID::DrawRect: |
279 | 0 | { |
280 | 0 | eDrawMode = CHARTDRAW_INSERT; |
281 | 0 | eKind = SdrObjKind::Rectangle; |
282 | 0 | } |
283 | 0 | break; |
284 | 0 | case ChartCommandID::DrawEllipse: |
285 | 0 | { |
286 | 0 | eDrawMode = CHARTDRAW_INSERT; |
287 | 0 | eKind = SdrObjKind::CircleOrEllipse; |
288 | 0 | } |
289 | 0 | break; |
290 | 0 | case ChartCommandID::DrawFreelineNoFill: |
291 | 0 | { |
292 | 0 | eDrawMode = CHARTDRAW_INSERT; |
293 | 0 | eKind = SdrObjKind::FreehandLine; |
294 | 0 | } |
295 | 0 | break; |
296 | 0 | case ChartCommandID::DrawText: |
297 | 0 | { |
298 | 0 | eDrawMode = CHARTDRAW_INSERT; |
299 | 0 | eKind = SdrObjKind::Text; |
300 | 0 | bCreate = true; |
301 | 0 | } |
302 | 0 | break; |
303 | 0 | case ChartCommandID::DrawCaption: |
304 | 0 | { |
305 | 0 | eDrawMode = CHARTDRAW_INSERT; |
306 | 0 | eKind = SdrObjKind::Caption; |
307 | 0 | } |
308 | 0 | break; |
309 | 0 | case ChartCommandID::DrawToolboxCsBasic: |
310 | 0 | case ChartCommandID::DrawToolboxCsSymbol: |
311 | 0 | case ChartCommandID::DrawToolboxCsArrow: |
312 | 0 | case ChartCommandID::DrawToolboxCsFlowchart: |
313 | 0 | case ChartCommandID::DrawToolboxCsCallout: |
314 | 0 | case ChartCommandID::DrawToolboxCsStar: |
315 | 0 | { |
316 | 0 | eDrawMode = CHARTDRAW_INSERT; |
317 | 0 | eKind = SdrObjKind::CustomShape; |
318 | 0 | } |
319 | 0 | break; |
320 | 0 | default: |
321 | 0 | { |
322 | 0 | eDrawMode = CHARTDRAW_SELECT; |
323 | 0 | eKind = SdrObjKind::NONE; |
324 | 0 | } |
325 | 0 | break; |
326 | 0 | } |
327 | | |
328 | 0 | if ( !m_pChartController ) |
329 | 0 | return; |
330 | | |
331 | 0 | DrawViewWrapper* pDrawViewWrapper = m_pChartController->GetDrawViewWrapper(); |
332 | 0 | if ( !pDrawViewWrapper ) |
333 | 0 | return; |
334 | | |
335 | 0 | SolarMutexGuard aGuard; |
336 | 0 | m_pChartController->setDrawMode( eDrawMode ); |
337 | 0 | setInsertObj(eKind); |
338 | 0 | if ( bCreate ) |
339 | 0 | { |
340 | 0 | pDrawViewWrapper->SetCreateMode(); |
341 | 0 | } |
342 | |
|
343 | 0 | const beans::PropertyValue* pKeyModifier = std::find_if(rArgs.begin(), rArgs.end(), |
344 | 0 | [](const beans::PropertyValue& lhs) |
345 | 0 | {return lhs.Name == "KeyModifier";} ); |
346 | 0 | sal_Int16 nKeyModifier = 0; |
347 | 0 | if ( !(pKeyModifier != rArgs.end() && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1) ) |
348 | 0 | return; |
349 | | |
350 | 0 | if ( eDrawMode != CHARTDRAW_INSERT ) |
351 | 0 | return; |
352 | | |
353 | 0 | rtl::Reference<SdrObject> pObj = createDefaultObject( nFeatureId ); |
354 | 0 | if ( pObj ) |
355 | 0 | { |
356 | 0 | SdrPageView* pPageView = pDrawViewWrapper->GetSdrPageView(); |
357 | 0 | if (pDrawViewWrapper->InsertObjectAtView(pObj.get(), *pPageView)) |
358 | 0 | m_pChartController->SetAndApplySelection(Reference<drawing::XShape>(pObj->getUnoShape(), uno::UNO_QUERY)); |
359 | 0 | if ( nFeatureId == ChartCommandID::DrawText ) |
360 | 0 | { |
361 | 0 | m_pChartController->StartTextEdit(); |
362 | 0 | } |
363 | 0 | } |
364 | 0 | } |
365 | | |
366 | | void DrawCommandDispatch::describeSupportedFeatures() |
367 | 0 | { |
368 | 0 | implDescribeSupportedFeature( u".uno:SelectObject"_ustr, ChartCommandID::DrawObjectSelect, CommandGroup::INSERT ); |
369 | 0 | implDescribeSupportedFeature( u".uno:Line"_ustr, ChartCommandID::DrawLine, CommandGroup::INSERT ); |
370 | 0 | implDescribeSupportedFeature( u".uno:LineArrowEnd"_ustr, ChartCommandID::DrawLineArrowEnd, CommandGroup::INSERT ); |
371 | 0 | implDescribeSupportedFeature( u".uno:Rect"_ustr, ChartCommandID::DrawRect, CommandGroup::INSERT ); |
372 | 0 | implDescribeSupportedFeature( u".uno:Ellipse"_ustr, ChartCommandID::DrawEllipse, CommandGroup::INSERT ); |
373 | 0 | implDescribeSupportedFeature( u".uno:Freeline_Unfilled"_ustr, ChartCommandID::DrawFreelineNoFill, CommandGroup::INSERT ); |
374 | 0 | implDescribeSupportedFeature( u".uno:DrawText"_ustr, ChartCommandID::DrawText, CommandGroup::INSERT ); |
375 | 0 | implDescribeSupportedFeature( u".uno:DrawCaption"_ustr, ChartCommandID::DrawCaption, CommandGroup::INSERT ); |
376 | 0 | implDescribeSupportedFeature( u".uno:BasicShapes"_ustr, ChartCommandID::DrawToolboxCsBasic, CommandGroup::INSERT ); |
377 | 0 | implDescribeSupportedFeature( u".uno:SymbolShapes"_ustr, ChartCommandID::DrawToolboxCsSymbol, CommandGroup::INSERT ); |
378 | 0 | implDescribeSupportedFeature( u".uno:ArrowShapes"_ustr, ChartCommandID::DrawToolboxCsArrow, CommandGroup::INSERT ); |
379 | 0 | implDescribeSupportedFeature( u".uno:FlowChartShapes"_ustr, ChartCommandID::DrawToolboxCsFlowchart, CommandGroup::INSERT ); |
380 | 0 | implDescribeSupportedFeature( u".uno:CalloutShapes"_ustr, ChartCommandID::DrawToolboxCsCallout, CommandGroup::INSERT ); |
381 | 0 | implDescribeSupportedFeature( u".uno:StarShapes"_ustr, ChartCommandID::DrawToolboxCsStar, CommandGroup::INSERT ); |
382 | 0 | } |
383 | | |
384 | | void DrawCommandDispatch::setInsertObj(SdrObjKind eObj) |
385 | 0 | { |
386 | 0 | DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? m_pChartController->GetDrawViewWrapper() : nullptr ); |
387 | 0 | if ( pDrawViewWrapper ) |
388 | 0 | { |
389 | 0 | pDrawViewWrapper->SetCurrentObj( eObj /*, Inventor */); |
390 | 0 | } |
391 | 0 | } |
392 | | |
393 | | rtl::Reference<SdrObject> DrawCommandDispatch::createDefaultObject( const ChartCommandID nID ) |
394 | 0 | { |
395 | 0 | rtl::Reference<SdrObject> pObj; |
396 | 0 | DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? m_pChartController->GetDrawViewWrapper() : nullptr ); |
397 | 0 | DrawModelWrapper* pDrawModelWrapper = ( m_pChartController ? m_pChartController->GetDrawModelWrapper() : nullptr ); |
398 | |
|
399 | 0 | if ( pDrawViewWrapper && pDrawModelWrapper ) |
400 | 0 | { |
401 | 0 | rtl::Reference< SvxDrawPage > xDrawPage( pDrawModelWrapper->getMainDrawPage() ); |
402 | 0 | SdrPage* pPage = GetSdrPageFromXDrawPage( xDrawPage ); |
403 | 0 | if ( pPage ) |
404 | 0 | { |
405 | 0 | SolarMutexGuard aGuard; |
406 | |
|
407 | 0 | pObj = SdrObjFactory::MakeNewObject( |
408 | 0 | pDrawModelWrapper->getSdrModel(), |
409 | 0 | pDrawViewWrapper->GetCurrentObjInventor(), |
410 | 0 | pDrawViewWrapper->GetCurrentObjIdentifier()); |
411 | |
|
412 | 0 | if ( pObj ) |
413 | 0 | { |
414 | 0 | Size aObjectSize( 4000, 2500 ); |
415 | 0 | tools::Rectangle aPageRect( tools::Rectangle( Point( 0, 0 ), pPage->GetSize() ) ); |
416 | 0 | Point aObjectPos = aPageRect.Center(); |
417 | 0 | aObjectPos.AdjustX( -(aObjectSize.Width() / 2) ); |
418 | 0 | aObjectPos.AdjustY( -(aObjectSize.Height() / 2) ); |
419 | 0 | tools::Rectangle aRect( aObjectPos, aObjectSize ); |
420 | |
|
421 | 0 | switch ( nID ) |
422 | 0 | { |
423 | 0 | case ChartCommandID::DrawLine: |
424 | 0 | case ChartCommandID::DrawLineArrowEnd: |
425 | 0 | { |
426 | 0 | if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj.get()) ) |
427 | 0 | { |
428 | 0 | Point aStart = aRect.TopLeft(); |
429 | 0 | Point aEnd = aRect.BottomRight(); |
430 | 0 | sal_Int32 nYMiddle( ( aRect.Top() + aRect.Bottom() ) / 2 ); |
431 | 0 | basegfx::B2DPolygon aPoly; |
432 | 0 | aPoly.append( basegfx::B2DPoint( aStart.X(), nYMiddle ) ); |
433 | 0 | aPoly.append( basegfx::B2DPoint( aEnd.X(), nYMiddle ) ); |
434 | 0 | pathObj->SetPathPoly(basegfx::B2DPolyPolygon(aPoly)); |
435 | 0 | SfxItemSet aSet( pDrawModelWrapper->GetItemPool() ); |
436 | 0 | setLineEnds( aSet ); |
437 | 0 | pObj->SetMergedItemSet( aSet ); |
438 | 0 | } |
439 | 0 | } |
440 | 0 | break; |
441 | 0 | case ChartCommandID::DrawFreelineNoFill: |
442 | 0 | { |
443 | 0 | if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj.get()) ) |
444 | 0 | { |
445 | 0 | basegfx::B2DPolygon aInnerPoly; |
446 | 0 | aInnerPoly.append( basegfx::B2DPoint( aRect.Left(), aRect.Bottom() ) ); |
447 | 0 | aInnerPoly.appendBezierSegment( |
448 | 0 | basegfx::B2DPoint( aRect.Left(), aRect.Top() ), |
449 | 0 | basegfx::B2DPoint( aRect.Center().X(), aRect.Top() ), |
450 | 0 | basegfx::B2DPoint( aRect.Center().X(), aRect.Center().Y() ) ); |
451 | 0 | aInnerPoly.appendBezierSegment( |
452 | 0 | basegfx::B2DPoint( aRect.Center().X(), aRect.Bottom() ), |
453 | 0 | basegfx::B2DPoint( aRect.Right(), aRect.Bottom() ), |
454 | 0 | basegfx::B2DPoint( aRect.Right(), aRect.Top() ) ); |
455 | 0 | basegfx::B2DPolyPolygon aPoly; |
456 | 0 | aPoly.append( aInnerPoly ); |
457 | 0 | pathObj->SetPathPoly(aPoly); |
458 | 0 | } |
459 | 0 | } |
460 | 0 | break; |
461 | 0 | case ChartCommandID::DrawText: |
462 | 0 | case ChartCommandID::DrawTextVertical: |
463 | 0 | { |
464 | 0 | if ( SdrTextObj* pTextObj = DynCastSdrTextObj( pObj.get()) ) |
465 | 0 | { |
466 | 0 | pTextObj->SetLogicRect( aRect ); |
467 | 0 | bool bVertical = ( nID == ChartCommandID::DrawTextVertical ); |
468 | 0 | pTextObj->SetVerticalWriting( bVertical ); |
469 | 0 | if ( bVertical ) |
470 | 0 | { |
471 | 0 | SfxItemSet aSet( pDrawModelWrapper->GetItemPool() ); |
472 | 0 | aSet.Put( makeSdrTextAutoGrowWidthItem( true ) ); |
473 | 0 | aSet.Put( makeSdrTextAutoGrowHeightItem( false ) ); |
474 | 0 | aSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_TOP ) ); |
475 | 0 | aSet.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_RIGHT ) ); |
476 | 0 | pTextObj->SetMergedItemSet( aSet ); |
477 | 0 | } |
478 | 0 | } |
479 | 0 | } |
480 | 0 | break; |
481 | 0 | case ChartCommandID::DrawCaption: |
482 | 0 | case ChartCommandID::DrawCaptionVertical: |
483 | 0 | { |
484 | 0 | if ( SdrCaptionObj* pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj.get()) ) |
485 | 0 | { |
486 | 0 | bool bIsVertical( nID == ChartCommandID::DrawCaptionVertical ); |
487 | 0 | pCaptionObj->SetVerticalWriting( bIsVertical ); |
488 | 0 | if ( bIsVertical ) |
489 | 0 | { |
490 | 0 | SfxItemSet aSet( pObj->GetMergedItemSet() ); |
491 | 0 | aSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) ); |
492 | 0 | aSet.Put( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_RIGHT ) ); |
493 | 0 | pObj->SetMergedItemSet( aSet ); |
494 | 0 | } |
495 | 0 | pCaptionObj->SetLogicRect( aRect ); |
496 | 0 | pCaptionObj->SetTailPos( |
497 | 0 | aRect.TopLeft() - Point( aRect.GetWidth() / 2, aRect.GetHeight() / 2 ) ); |
498 | 0 | } |
499 | 0 | } |
500 | 0 | break; |
501 | 0 | default: |
502 | 0 | { |
503 | 0 | pObj->SetLogicRect( aRect ); |
504 | 0 | SfxItemSet aSet( pDrawModelWrapper->GetItemPool() ); |
505 | 0 | setAttributes( pObj.get() ); |
506 | 0 | pObj->SetMergedItemSet( aSet ); |
507 | 0 | } |
508 | 0 | break; |
509 | 0 | } |
510 | 0 | } |
511 | 0 | } |
512 | 0 | } |
513 | | |
514 | 0 | return pObj; |
515 | 0 | } |
516 | | |
517 | | bool DrawCommandDispatch::parseCommandURL( const OUString& rCommandURL, ChartCommandID* pnFeatureId, |
518 | | OUString* pBaseCommand, OUString* pCustomShapeType ) |
519 | 0 | { |
520 | 0 | bool bFound = true; |
521 | 0 | ChartCommandID nFeatureId = ChartCommandID::NONE; |
522 | 0 | OUString aBaseCommand; |
523 | 0 | OUString aType; |
524 | |
|
525 | 0 | sal_Int32 nIndex = std::min(sal_Int32(1), rCommandURL.getLength()); |
526 | 0 | std::u16string_view aToken = o3tl::getToken(rCommandURL, 0, '.', nIndex ); |
527 | 0 | if ( nIndex == -1 || aToken.empty() ) |
528 | 0 | { |
529 | 0 | aBaseCommand = rCommandURL; |
530 | 0 | SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( aBaseCommand ); |
531 | 0 | if ( aIter != m_aSupportedFeatures.end() ) |
532 | 0 | { |
533 | 0 | nFeatureId = aIter->second.nFeatureId; |
534 | |
|
535 | 0 | switch ( nFeatureId ) |
536 | 0 | { |
537 | 0 | case ChartCommandID::DrawToolboxCsBasic: |
538 | 0 | { |
539 | 0 | aType = "diamond"; |
540 | 0 | } |
541 | 0 | break; |
542 | 0 | case ChartCommandID::DrawToolboxCsSymbol: |
543 | 0 | { |
544 | 0 | aType = "smiley"; |
545 | 0 | } |
546 | 0 | break; |
547 | 0 | case ChartCommandID::DrawToolboxCsArrow: |
548 | 0 | { |
549 | 0 | aType = "left-right-arrow"; |
550 | 0 | } |
551 | 0 | break; |
552 | 0 | case ChartCommandID::DrawToolboxCsFlowchart: |
553 | 0 | { |
554 | 0 | aType = "flowchart-internal-storage"; |
555 | 0 | } |
556 | 0 | break; |
557 | 0 | case ChartCommandID::DrawToolboxCsCallout: |
558 | 0 | { |
559 | 0 | aType = "round-rectangular-callout"; |
560 | 0 | } |
561 | 0 | break; |
562 | 0 | case ChartCommandID::DrawToolboxCsStar: |
563 | 0 | { |
564 | 0 | aType = "star5"; |
565 | 0 | } |
566 | 0 | break; |
567 | 0 | default: |
568 | 0 | { |
569 | 0 | } |
570 | 0 | break; |
571 | 0 | } |
572 | 0 | } |
573 | 0 | else |
574 | 0 | { |
575 | 0 | bFound = false; |
576 | 0 | } |
577 | 0 | } |
578 | 0 | else |
579 | 0 | { |
580 | 0 | aBaseCommand = rCommandURL.copy( 0, nIndex - 1 ); |
581 | 0 | SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( aBaseCommand ); |
582 | 0 | if ( aIter != m_aSupportedFeatures.end() ) |
583 | 0 | { |
584 | 0 | nFeatureId = aIter->second.nFeatureId; |
585 | 0 | aType = rCommandURL.getToken( 0, '.', nIndex ); |
586 | 0 | } |
587 | 0 | else |
588 | 0 | { |
589 | 0 | bFound = false; |
590 | 0 | } |
591 | 0 | } |
592 | | |
593 | 0 | *pnFeatureId = nFeatureId; |
594 | 0 | *pBaseCommand = aBaseCommand; |
595 | 0 | *pCustomShapeType = aType; |
596 | |
|
597 | 0 | return bFound; |
598 | 0 | } |
599 | | |
600 | | } // namespace chart |
601 | | |
602 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |