nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / ui / drawfunc / drawsh.cxx
blob76470eb90caa57951a9ac49f9d7beffb77bc6034
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/svxdlg.hxx>
21 #include <svx/dialogs.hrc>
22 #include <sc.hrc>
24 #include <editeng/eeitem.hxx>
25 #include <svx/fontwork.hxx>
26 #include <svx/svdpage.hxx>
27 #include <sfx2/app.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <svl/whiter.hxx>
35 #include <drawsh.hxx>
36 #include <drwlayer.hxx>
37 #include <strings.hrc>
38 #include <viewdata.hxx>
39 #include <document.hxx>
40 #include <drawview.hxx>
41 #include <scresid.hxx>
42 #include <svx/svdobj.hxx>
43 #include <tabvwsh.hxx>
44 #include <gridwin.hxx>
45 #include <sfx2/bindings.hxx>
47 #define ShellClass_ScDrawShell
48 #include <scslots.hxx>
50 #include <userdat.hxx>
51 #include <svl/macitem.hxx>
52 #include <sfx2/evntconf.hxx>
53 #include <sfx2/viewsh.hxx>
54 #include <com/sun/star/util/XModifiable.hpp>
55 #include <memory>
56 #include <svx/xlnwtit.hxx>
57 #include <svx/chrtitem.hxx>
58 #include <svx/xlnclit.hxx>
59 #include <svx/xflclit.hxx>
60 #include <svx/xflgrit.hxx>
61 #include <editeng/colritem.hxx>
63 SFX_IMPL_INTERFACE(ScDrawShell, SfxShell)
65 namespace
67 void lcl_convertStringArguments(sal_uInt16 nSlot, const std::unique_ptr<SfxItemSet>& pArgs)
69 Color aColor;
70 const SfxPoolItem* pItem = nullptr;
72 if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem))
74 double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue();
75 // FIXME: different units...
76 int nPow = 100;
77 int nValue = fValue * nPow;
79 XLineWidthItem aItem(nValue);
80 pArgs->Put(aItem);
82 else if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pItem))
84 OUString sColor = static_cast<const SfxStringItem*>(pItem)->GetValue();
86 if (sColor == "transparent")
87 aColor = COL_TRANSPARENT;
88 else
89 aColor = Color(sColor.toInt32(16));
91 switch (nSlot)
93 case SID_ATTR_LINE_COLOR:
95 XLineColorItem aLineColorItem(OUString(), aColor);
96 pArgs->Put(aLineColorItem);
97 break;
100 case SID_ATTR_FILL_COLOR:
102 XFillColorItem aFillColorItem(OUString(), aColor);
103 pArgs->Put(aFillColorItem);
104 break;
107 case SID_ATTR_SHADOW_COLOR:
109 XColorItem aItem(SDRATTR_SHADOWCOLOR, aColor);
110 pArgs->Put(aItem);
111 break;
115 if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem))
117 const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem);
118 if (pJSON)
120 XGradient aGradient = XGradient::fromJSON(pJSON->GetValue());
121 XFillGradientItem aItem(aGradient);
122 pArgs->Put(aItem);
128 void ScDrawShell::InitInterface_Impl()
130 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT,
131 SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server,
132 ToolbarId::Draw_Objectbar);
134 GetStaticInterface()->RegisterPopupMenu("draw");
136 GetStaticInterface()->RegisterChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
139 // disable the unwanted Accelerators
141 void ScDrawShell::StateDisableItems( SfxItemSet &rSet )
143 SfxWhichIter aIter(rSet);
144 sal_uInt16 nWhich = aIter.FirstWhich();
146 while (nWhich)
148 rSet.DisableItem( nWhich );
149 nWhich = aIter.NextWhich();
153 static void lcl_setModified( const SfxObjectShell* pShell )
155 if ( pShell )
157 css::uno::Reference< css::util::XModifiable > xModif( pShell->GetModel(), css::uno::UNO_QUERY );
158 if ( xModif.is() )
159 xModif->setModified( true );
163 static void lcl_invalidateTransformAttr(const ScTabViewShell* pViewShell)
165 SfxBindings& rBindings=pViewShell->GetViewFrame()->GetBindings();
166 rBindings.Invalidate(SID_ATTR_TRANSFORM_WIDTH);
167 rBindings.Invalidate(SID_ATTR_TRANSFORM_HEIGHT);
168 rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_X);
169 rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_Y);
170 rBindings.Invalidate(SID_ATTR_TRANSFORM_ANGLE);
171 rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_X);
172 rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_Y);
173 rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOWIDTH);
174 rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOHEIGHT);
177 void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
179 sal_uInt16 nSlot = rReq.GetSlot();
180 vcl::Window* pWin = rViewData.GetActiveWin();
181 ScDrawView* pView = rViewData.GetScDrawView();
182 SdrModel* pDoc = rViewData.GetDocument().GetDrawLayer();
184 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
185 const size_t nMarkCount = rMarkList.GetMarkCount();
186 SdrObject* pSingleSelectedObj = nullptr;
187 if ( nMarkCount > 0 )
188 pSingleSelectedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
190 switch ( nSlot )
192 case SID_ASSIGNMACRO:
194 if ( pSingleSelectedObj )
195 ExecuteMacroAssign(pSingleSelectedObj, pWin ? pWin->GetFrameWeld() : nullptr);
197 break;
199 case SID_TEXT_STANDARD: // delete hard text attributes
201 SfxItemSet aEmptyAttr(GetPool(), svl::Items<EE_ITEMS_START, EE_ITEMS_END>{});
202 pView->SetAttributes(aEmptyAttr, true);
204 break;
206 case SID_ATTR_LINE_STYLE:
207 case SID_ATTR_LINEEND_STYLE:
208 case SID_ATTR_LINE_START:
209 case SID_ATTR_LINE_END:
210 case SID_ATTR_LINE_DASH:
211 case SID_ATTR_LINE_WIDTH:
212 case SID_ATTR_LINE_COLOR:
213 case SID_ATTR_LINE_TRANSPARENCE:
214 case SID_ATTR_LINE_JOINT:
215 case SID_ATTR_LINE_CAP:
216 case SID_ATTR_FILL_STYLE:
217 case SID_ATTR_FILL_COLOR:
218 case SID_ATTR_FILL_GRADIENT:
219 case SID_ATTR_FILL_HATCH:
220 case SID_ATTR_FILL_BITMAP:
221 case SID_ATTR_FILL_TRANSPARENCE:
222 case SID_ATTR_FILL_FLOATTRANSPARENCE:
224 // #i25616#
225 case SID_ATTR_FILL_SHADOW:
226 case SID_ATTR_SHADOW_TRANSPARENCE:
227 case SID_ATTR_SHADOW_COLOR:
228 case SID_ATTR_SHADOW_XDISTANCE:
229 case SID_ATTR_SHADOW_YDISTANCE:
231 // if toolbar is vertical :
232 if ( !rReq.GetArgs() )
234 switch ( nSlot )
236 case SID_ATTR_LINE_STYLE:
237 case SID_ATTR_LINE_DASH:
238 case SID_ATTR_LINE_WIDTH:
239 case SID_ATTR_LINE_COLOR:
240 case SID_ATTR_LINE_TRANSPARENCE:
241 case SID_ATTR_LINE_JOINT:
242 case SID_ATTR_LINE_CAP:
243 ExecuteLineDlg( rReq );
244 break;
246 case SID_ATTR_FILL_STYLE:
247 case SID_ATTR_FILL_COLOR:
248 case SID_ATTR_FILL_GRADIENT:
249 case SID_ATTR_FILL_HATCH:
250 case SID_ATTR_FILL_BITMAP:
251 case SID_ATTR_FILL_TRANSPARENCE:
252 case SID_ATTR_FILL_FLOATTRANSPARENCE:
254 // #i25616#
255 case SID_ATTR_FILL_SHADOW:
256 case SID_ATTR_SHADOW_TRANSPARENCE:
257 case SID_ATTR_SHADOW_COLOR:
258 case SID_ATTR_SHADOW_XDISTANCE:
259 case SID_ATTR_SHADOW_YDISTANCE:
260 ExecuteAreaDlg( rReq );
261 break;
263 default:
264 break;
267 return;
271 if( pView->AreObjectsMarked() )
273 std::unique_ptr<SfxItemSet> pNewArgs = rReq.GetArgs()->Clone();
274 lcl_convertStringArguments( rReq.GetSlot(), pNewArgs );
275 pView->SetAttrToMarked( *pNewArgs, false );
277 else
278 pView->SetDefaultAttr( *rReq.GetArgs(), false);
279 pView->InvalidateAttribs();
281 break;
283 case SID_ATTRIBUTES_LINE:
284 ExecuteLineDlg( rReq );
285 break;
287 case SID_ATTRIBUTES_AREA:
288 ExecuteAreaDlg( rReq );
289 break;
291 case SID_MEASURE_DLG:
292 ExecuteMeasureDlg( rReq );
293 break;
295 case SID_DRAWTEXT_ATTR_DLG:
296 ExecuteTextAttrDlg( rReq );
297 break;
299 case SID_DRAW_HLINK_EDIT:
300 if ( pSingleSelectedObj )
301 rViewData.GetDispatcher().Execute( SID_HYPERLINK_DIALOG );
302 break;
304 case SID_DRAW_HLINK_DELETE:
305 if ( pSingleSelectedObj )
306 SetHlinkForObject( pSingleSelectedObj, OUString() );
307 break;
309 case SID_OPEN_HYPERLINK:
310 if ( nMarkCount == 1 )
312 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
313 if ( pObj->IsGroupObject() )
315 SdrPageView* pPV = nullptr;
316 SdrObject* pHit = pView->PickObj(pWin->PixelToLogic(rViewData.GetMousePosPixel()), pView->getHitTolLog(), pPV, SdrSearchOptions::DEEP);
317 if (pHit)
318 pObj = pHit;
321 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
322 if ( pInfo && !pInfo->GetHlink().isEmpty() )
323 ScGlobal::OpenURL( pInfo->GetHlink(), OUString(), true );
325 break;
327 case SID_ATTR_TRANSFORM:
329 if ( pView->AreObjectsMarked() )
331 const SfxItemSet* pArgs = rReq.GetArgs();
333 if( !pArgs )
335 if( rMarkList.GetMark(0) != nullptr )
337 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
338 std::shared_ptr<SfxRequest> pRequest = std::make_shared<SfxRequest>(rReq);
340 if( pObj->GetObjIdentifier() == OBJ_CAPTION )
342 // Caption Itemset
343 SfxItemSet aNewAttr(pDoc->GetItemPool());
344 pView->GetAttributes(aNewAttr);
345 // Size and Position Itemset
346 SfxItemSet aNewGeoAttr(pView->GetGeoAttrFromMarked());
348 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
349 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateCaptionDialog(pWin ? pWin->GetFrameWeld() : nullptr, pView));
351 const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
352 SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
353 aCombSet.Put( aNewAttr );
354 aCombSet.Put( aNewGeoAttr );
355 pDlg->SetInputSet( &aCombSet );
357 pDlg->StartExecuteAsync([pDlg, pRequest, pView, this](
358 sal_Int32 nResult){
359 if (nResult == RET_OK)
361 pRequest->Done(*(pDlg->GetOutputItemSet()));
362 pView->SetAttributes(*pDlg->GetOutputItemSet());
363 pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
366 lcl_invalidateTransformAttr(rViewData.GetViewShell());
367 pDlg->disposeOnce();
370 else
372 SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
373 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
374 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxTransformTabDialog(pWin ? pWin->GetFrameWeld() : nullptr, &aNewAttr, pView));
376 pDlg->StartExecuteAsync([pDlg, pRequest, pView, this](
377 sal_Int32 nResult){
378 if (nResult == RET_OK)
380 pRequest->Done(*(pDlg->GetOutputItemSet()));
381 pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
384 lcl_invalidateTransformAttr(rViewData.GetViewShell());
385 pDlg->disposeOnce();
391 else
392 pView->SetGeoAttrToMarked( *pArgs );
395 lcl_invalidateTransformAttr(rViewData.GetViewShell());
397 break;
399 case SID_ATTR_GLOW_COLOR:
400 case SID_ATTR_GLOW_RADIUS:
401 case SID_ATTR_GLOW_TRANSPARENCY:
402 case SID_ATTR_SOFTEDGE_RADIUS:
403 if (const SfxItemSet* pNewArgs = rReq.GetArgs())
404 pView->SetAttrToMarked(*pNewArgs, false);
405 rReq.Done();
406 break;
408 default:
409 break;
413 void ScDrawShell::ExecuteMacroAssign(SdrObject* pObj, weld::Window* pWin)
415 SvxMacroItem aItem ( SfxGetpApp()->GetPool().GetWhich( SID_ATTR_MACROITEM ) );
416 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
417 if ( !pInfo->GetMacro().isEmpty() )
419 SvxMacroTableDtor aTab;
420 const OUString& sMacro = pInfo->GetMacro();
421 aTab.Insert(SvMacroItemId::OnClick, SvxMacro(sMacro, OUString()));
422 aItem.SetMacroTable( aTab );
425 // create empty itemset for macro-dlg
426 std::unique_ptr<SfxItemSet> pItemSet(new SfxItemSet(SfxGetpApp()->GetPool(), svl::Items<SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG>{} ));
427 pItemSet->Put ( aItem );
429 SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
430 aNamesItem.AddEvent( ScResId(RID_SCSTR_ONCLICK), OUString(), SvMacroItemId::OnClick );
431 pItemSet->Put( aNamesItem );
433 css::uno::Reference < css::frame::XFrame > xFrame;
434 if (GetViewShell())
435 xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
437 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
438 ScopedVclPtr<SfxAbstractDialog> pMacroDlg(pFact->CreateEventConfigDialog( pWin, *pItemSet, xFrame ));
439 if ( pMacroDlg->Execute() != RET_OK )
440 return;
442 const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
443 const SfxPoolItem* pItem;
444 if( SfxItemState::SET != pOutSet->GetItemState( SID_ATTR_MACROITEM, false, &pItem ))
445 return;
447 OUString sMacro;
448 const SvxMacro* pMacro = static_cast<const SvxMacroItem*>(pItem)->GetMacroTable().Get( SvMacroItemId::OnClick );
449 if ( pMacro )
450 sMacro = pMacro->GetMacName();
452 if ( pObj->IsGroupObject() )
454 SdrObjList* pOL = pObj->GetSubList();
455 const size_t nObj = pOL->GetObjCount();
456 for ( size_t index=0; index<nObj; ++index )
458 pInfo = ScDrawLayer::GetMacroInfo( pOL->GetObj(index), true );
459 pInfo->SetMacro( sMacro );
462 else
463 pInfo->SetMacro( sMacro );
464 lcl_setModified( GetObjectShell() );
467 void ScDrawShell::ExecuteLineDlg( const SfxRequest& rReq )
469 ScDrawView* pView = rViewData.GetScDrawView();
470 bool bHasMarked = pView->AreObjectsMarked();
471 const SdrObject* pObj = nullptr;
472 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
474 std::shared_ptr<SfxRequest> pRequest = std::make_shared<SfxRequest>(rReq);
476 if( rMarkList.GetMarkCount() == 1 )
477 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
479 SfxItemSet aNewAttr( pView->GetDefaultAttr() );
480 if( bHasMarked )
481 pView->MergeAttrFromMarked( aNewAttr, false );
483 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
484 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxLineTabDialog( rViewData.GetDialogParent(),
485 &aNewAttr,
486 rViewData.GetDocument().GetDrawLayer(),
487 pObj,
488 bHasMarked));
490 pDlg->StartExecuteAsync([=](sal_Int32 nResult){
491 if ( nResult == RET_OK )
493 if( bHasMarked )
494 pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
495 else
496 pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
498 pView->InvalidateAttribs();
499 pRequest->Done();
501 pDlg->disposeOnce();
505 void ScDrawShell::ExecuteAreaDlg( const SfxRequest& rReq )
507 ScDrawView* pView = rViewData.GetScDrawView();
508 bool bHasMarked = pView->AreObjectsMarked();
510 std::shared_ptr<SfxRequest> pRequest = std::make_shared<SfxRequest>(rReq);
512 SfxItemSet aNewAttr( pView->GetDefaultAttr() );
513 if( bHasMarked )
514 pView->MergeAttrFromMarked( aNewAttr, false );
516 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
517 weld::Window* pWin = rViewData.GetDialogParent();
518 VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(
519 pWin, &aNewAttr,
520 rViewData.GetDocument().GetDrawLayer(), true));
522 pDlg->StartExecuteAsync([=](sal_Int32 nResult){
523 if ( nResult == RET_OK )
525 if( bHasMarked )
526 pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
527 else
528 pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
530 pView->InvalidateAttribs();
531 pRequest->Done();
533 pDlg->disposeOnce();
537 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq )
539 ScDrawView* pView = rViewData.GetScDrawView();
540 bool bHasMarked = pView->AreObjectsMarked();
541 SfxItemSet aNewAttr ( pView->GetDefaultAttr() );
543 if( bHasMarked )
544 pView->MergeAttrFromMarked( aNewAttr, false );
546 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
547 weld::Window* pWin = rViewData.GetDialogParent();
548 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(pWin, &aNewAttr, pView));
550 sal_uInt16 nResult = pDlg->Execute();
552 if ( RET_OK == nResult )
554 if ( bHasMarked )
555 pView->SetAttributes( *pDlg->GetOutputItemSet() );
556 else
557 pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
559 pView->InvalidateAttribs();
560 rReq.Done();
564 void ScDrawShell::ExecuteMeasureDlg( SfxRequest& rReq )
566 ScDrawView* pView = rViewData.GetScDrawView();
567 bool bHasMarked = pView->AreObjectsMarked();
568 SfxItemSet aNewAttr ( pView->GetDefaultAttr() );
570 if( bHasMarked )
571 pView->MergeAttrFromMarked( aNewAttr, false );
573 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
574 weld::Window* pWin = rViewData.GetDialogParent();
575 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog(pWin, aNewAttr, pView, RID_SVXPAGE_MEASURE));
577 sal_uInt16 nResult = pDlg->Execute();
579 if ( RET_OK == nResult )
581 if ( bHasMarked )
582 pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
583 else
584 pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
586 pView->InvalidateAttribs();
587 rReq.Done();
591 void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const OUString& rHlnk )
593 if ( pObj )
595 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
596 pInfo->SetHlink( rHlnk );
597 lcl_setModified( GetObjectShell() );
601 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */