1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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>
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
)
67 void lcl_convertStringArguments(sal_uInt16 nSlot
, const std::unique_ptr
<SfxItemSet
>& pArgs
)
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...
77 int nValue
= fValue
* nPow
;
79 XLineWidthItem
aItem(nValue
);
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
;
89 aColor
= Color(sColor
.toInt32(16));
93 case SID_ATTR_LINE_COLOR
:
95 XLineColorItem
aLineColorItem(OUString(), aColor
);
96 pArgs
->Put(aLineColorItem
);
100 case SID_ATTR_FILL_COLOR
:
102 XFillColorItem
aFillColorItem(OUString(), aColor
);
103 pArgs
->Put(aFillColorItem
);
107 case SID_ATTR_SHADOW_COLOR
:
109 XColorItem
aItem(SDRATTR_SHADOWCOLOR
, aColor
);
115 if (SfxItemState::SET
== pArgs
->GetItemState(SID_FILL_GRADIENT_JSON
, false, &pItem
))
117 const SfxStringItem
* pJSON
= static_cast<const SfxStringItem
*>(pItem
);
120 XGradient aGradient
= XGradient::fromJSON(pJSON
->GetValue());
121 XFillGradientItem
aItem(aGradient
);
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();
148 rSet
.DisableItem( nWhich
);
149 nWhich
= aIter
.NextWhich();
153 static void lcl_setModified( const SfxObjectShell
* pShell
)
157 css::uno::Reference
< css::util::XModifiable
> xModif( pShell
->GetModel(), css::uno::UNO_QUERY
);
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();
192 case SID_ASSIGNMACRO
:
194 if ( pSingleSelectedObj
)
195 ExecuteMacroAssign(pSingleSelectedObj
, pWin
? pWin
->GetFrameWeld() : nullptr);
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);
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
:
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() )
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
);
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
:
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
);
271 if( pView
->AreObjectsMarked() )
273 std::unique_ptr
<SfxItemSet
> pNewArgs
= rReq
.GetArgs()->Clone();
274 lcl_convertStringArguments( rReq
.GetSlot(), pNewArgs
);
275 pView
->SetAttrToMarked( *pNewArgs
, false );
278 pView
->SetDefaultAttr( *rReq
.GetArgs(), false);
279 pView
->InvalidateAttribs();
283 case SID_ATTRIBUTES_LINE
:
284 ExecuteLineDlg( rReq
);
287 case SID_ATTRIBUTES_AREA
:
288 ExecuteAreaDlg( rReq
);
291 case SID_MEASURE_DLG
:
292 ExecuteMeasureDlg( rReq
);
295 case SID_DRAWTEXT_ATTR_DLG
:
296 ExecuteTextAttrDlg( rReq
);
299 case SID_DRAW_HLINK_EDIT
:
300 if ( pSingleSelectedObj
)
301 rViewData
.GetDispatcher().Execute( SID_HYPERLINK_DIALOG
);
304 case SID_DRAW_HLINK_DELETE
:
305 if ( pSingleSelectedObj
)
306 SetHlinkForObject( pSingleSelectedObj
, OUString() );
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
);
321 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
);
322 if ( pInfo
&& !pInfo
->GetHlink().isEmpty() )
323 ScGlobal::OpenURL( pInfo
->GetHlink(), OUString(), true );
327 case SID_ATTR_TRANSFORM
:
329 if ( pView
->AreObjectsMarked() )
331 const SfxItemSet
* pArgs
= rReq
.GetArgs();
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
)
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](
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());
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](
378 if (nResult
== RET_OK
)
380 pRequest
->Done(*(pDlg
->GetOutputItemSet()));
381 pView
->SetGeoAttrToMarked(*pDlg
->GetOutputItemSet());
384 lcl_invalidateTransformAttr(rViewData
.GetViewShell());
392 pView
->SetGeoAttrToMarked( *pArgs
);
395 lcl_invalidateTransformAttr(rViewData
.GetViewShell());
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);
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
;
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
)
442 const SfxItemSet
* pOutSet
= pMacroDlg
->GetOutputItemSet();
443 const SfxPoolItem
* pItem
;
444 if( SfxItemState::SET
!= pOutSet
->GetItemState( SID_ATTR_MACROITEM
, false, &pItem
))
448 const SvxMacro
* pMacro
= static_cast<const SvxMacroItem
*>(pItem
)->GetMacroTable().Get( SvMacroItemId::OnClick
);
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
);
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() );
481 pView
->MergeAttrFromMarked( aNewAttr
, false );
483 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
484 VclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSvxLineTabDialog( rViewData
.GetDialogParent(),
486 rViewData
.GetDocument().GetDrawLayer(),
490 pDlg
->StartExecuteAsync([=](sal_Int32 nResult
){
491 if ( nResult
== RET_OK
)
494 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), false );
496 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
498 pView
->InvalidateAttribs();
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() );
514 pView
->MergeAttrFromMarked( aNewAttr
, false );
516 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
517 weld::Window
* pWin
= rViewData
.GetDialogParent();
518 VclPtr
<AbstractSvxAreaTabDialog
> pDlg(pFact
->CreateSvxAreaTabDialog(
520 rViewData
.GetDocument().GetDrawLayer(), true));
522 pDlg
->StartExecuteAsync([=](sal_Int32 nResult
){
523 if ( nResult
== RET_OK
)
526 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), false );
528 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
530 pView
->InvalidateAttribs();
537 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest
& rReq
)
539 ScDrawView
* pView
= rViewData
.GetScDrawView();
540 bool bHasMarked
= pView
->AreObjectsMarked();
541 SfxItemSet
aNewAttr ( pView
->GetDefaultAttr() );
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
)
555 pView
->SetAttributes( *pDlg
->GetOutputItemSet() );
557 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
559 pView
->InvalidateAttribs();
564 void ScDrawShell::ExecuteMeasureDlg( SfxRequest
& rReq
)
566 ScDrawView
* pView
= rViewData
.GetScDrawView();
567 bool bHasMarked
= pView
->AreObjectsMarked();
568 SfxItemSet
aNewAttr ( pView
->GetDefaultAttr() );
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
)
582 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), false );
584 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
586 pView
->InvalidateAttribs();
591 void ScDrawShell::SetHlinkForObject( SdrObject
* pObj
, const OUString
& rHlnk
)
595 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
, true );
596 pInfo
->SetHlink( rHlnk
);
597 lcl_setModified( GetObjectShell() );
601 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */