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