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 <com/sun/star/chart2/data/XDataReceiver.hpp>
21 #include <com/sun/star/awt/XRequestCallback.hpp>
22 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <com/sun/star/embed/EmbedMisc.hpp>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 #include <vcl/errinf.hxx>
27 #include <sfx2/app.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <svx/svxdlg.hxx>
30 #include <svx/dataaccessdescriptor.hxx>
31 #include <svx/svditer.hxx>
32 #include <svx/svdmark.hxx>
33 #include <svx/svdograf.hxx>
34 #include <svx/svdogrp.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <svx/svdouno.hxx>
37 #include <svx/svdview.hxx>
38 #include <sfx2/linkmgr.hxx>
39 #include <svx/fontworkbar.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <svtools/soerr.hxx>
44 #include <svl/rectitem.hxx>
45 #include <svl/stritem.hxx>
46 #include <svl/slstitm.hxx>
47 #include <svl/whiter.hxx>
48 #include <svtools/strings.hrc>
49 #include <unotools/moduleoptions.hxx>
50 #include <sot/exchange.hxx>
51 #include <comphelper/diagnose_ex.hxx>
53 #include <tabvwsh.hxx>
55 #include <document.hxx>
58 #include <fuinsert.hxx>
60 #include <drawview.hxx>
61 #include <ChartRangeSelectionListener.hxx>
62 #include <gridwin.hxx>
63 #include <undomanager.hxx>
64 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
65 #include <svx/svdpagv.hxx>
66 #include <o3tl/temporary.hxx>
67 #include <officecfg/Office/Common.hxx>
69 #include <comphelper/lok.hxx>
71 using namespace com::sun::star
;
73 void ScTabViewShell::ConnectObject( const SdrOle2Obj
* pObj
)
75 // is called from paint
77 const uno::Reference
< embed::XEmbeddedObject
>& xObj
= pObj
->GetObjRef();
78 vcl::Window
* pWin
= GetActiveWin();
80 // when already connected do not execute SetObjArea/SetSizeScale again
82 SfxInPlaceClient
* pClient
= FindIPClient( xObj
, pWin
);
86 pClient
= new ScClient( this, pWin
, &GetScDrawView()->GetModel(), pObj
);
87 ScViewData
& rViewData
= GetViewData();
88 ScDocShell
* pDocSh
= rViewData
.GetDocShell();
89 ScDocument
& rDoc
= pDocSh
->GetDocument();
90 bool bNegativeX
= comphelper::LibreOfficeKit::isActive() && rDoc
.IsNegativePage(rViewData
.GetTabNo());
92 pClient
->SetNegativeX(true);
94 tools::Rectangle aRect
= pObj
->GetLogicRect();
95 Size aDrawSize
= aRect
.GetSize();
97 Size aOleSize
= pObj
->GetOrigObjSize();
99 Fraction
aScaleWidth (aDrawSize
.Width(), aOleSize
.Width() );
100 Fraction
aScaleHeight(aDrawSize
.Height(), aOleSize
.Height() );
101 aScaleWidth
.ReduceInaccurate(10); // compatible with SdrOle2Obj
102 aScaleHeight
.ReduceInaccurate(10);
103 pClient
->SetSizeScale(aScaleWidth
,aScaleHeight
);
105 // visible section is only changed inplace!
106 // the object area must be set after the scaling since it triggers the resizing
107 aRect
.SetSize( aOleSize
);
108 pClient
->SetObjArea( aRect
);
113 class PopupCallback
: public cppu::WeakImplHelper
<css::awt::XCallback
>
115 ScTabViewShell
* m_pViewShell
;
116 SdrOle2Obj
* m_pObject
;
119 explicit PopupCallback(ScTabViewShell
* pViewShell
, SdrOle2Obj
* pObject
)
120 : m_pViewShell(pViewShell
)
125 virtual void SAL_CALL
notify(const css::uno::Any
& aData
) override
127 uno::Sequence
<beans::PropertyValue
> aProperties
;
128 if (!(aData
>>= aProperties
))
131 awt::Rectangle xRectangle
;
132 sal_Int32 dimensionIndex
= 0;
133 OUString
sPivotTableName(u
"DataPilot1"_ustr
);
135 for (beans::PropertyValue
const& rProperty
: aProperties
)
137 if (rProperty
.Name
== "Rectangle")
138 rProperty
.Value
>>= xRectangle
;
139 if (rProperty
.Name
== "DimensionIndex")
140 rProperty
.Value
>>= dimensionIndex
;
141 if (rProperty
.Name
== "PivotTableName")
142 rProperty
.Value
>>= sPivotTableName
;
145 tools::Rectangle aChartRect
= m_pObject
->GetLogicRect();
147 Point
aPoint(xRectangle
.X
+ aChartRect
.Left(), xRectangle
.Y
+ aChartRect
.Top());
148 Size
aSize(xRectangle
.Width
, xRectangle
.Height
);
150 m_pViewShell
->DoDPFieldPopup(sPivotTableName
, dimensionIndex
, aPoint
, aSize
);
156 void ScTabViewShell::ActivateObject(SdrOle2Obj
* pObj
, sal_Int32 nVerb
)
158 // Do not leave the hint message box on top of the object
161 uno::Reference
< embed::XEmbeddedObject
> xObj
= pObj
->GetObjRef();
162 vcl::Window
* pWin
= GetActiveWin();
163 ErrCodeMsg nErr
= ERRCODE_NONE
;
164 bool bErrorShown
= false;
167 ScViewData
& rViewData
= GetViewData();
168 ScDocShell
* pDocSh
= rViewData
.GetDocShell();
169 ScDocument
& rDoc
= pDocSh
->GetDocument();
170 bool bNegativeX
= comphelper::LibreOfficeKit::isActive() && rDoc
.IsNegativePage(rViewData
.GetTabNo());
171 SfxInPlaceClient
* pClient
= FindIPClient( xObj
, pWin
);
173 pClient
= new ScClient( this, pWin
, &GetScDrawView()->GetModel(), pObj
);
176 pClient
->SetNegativeX(true);
178 if ( (sal_uInt32(nErr
.GetCode()) & ERRCODE_ERROR_MASK
) == 0 && xObj
.is() )
180 tools::Rectangle aRect
= pObj
->GetLogicRect();
183 // #i118485# center on BoundRect for activation,
184 // OLE may be sheared/rotated now
185 const tools::Rectangle
& rBoundRect
= pObj
->GetCurrentBoundRect();
186 const Point
aDelta(rBoundRect
.Center() - aRect
.Center());
187 aRect
.Move(aDelta
.X(), aDelta
.Y());
190 Size aDrawSize
= aRect
.GetSize();
192 MapMode
aMapMode( MapUnit::Map100thMM
);
193 Size aOleSize
= pObj
->GetOrigObjSize( &aMapMode
);
195 if ( pClient
->GetAspect() != embed::Aspects::MSOLE_ICON
196 && ( xObj
->getStatus( pClient
->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE
) )
198 // scale must always be 1 - change VisArea if different from client size
200 if ( aDrawSize
!= aOleSize
)
202 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( pClient
->GetAspect() ) );
203 aOleSize
= OutputDevice::LogicToLogic( aDrawSize
,
204 MapMode(MapUnit::Map100thMM
), MapMode(aUnit
));
205 awt::Size
aSz( aOleSize
.Width(), aOleSize
.Height() );
206 xObj
->setVisualAreaSize( pClient
->GetAspect(), aSz
);
208 Fraction
aOne( 1, 1 );
209 pClient
->SetSizeScale( aOne
, aOne
);
213 // calculate scale from client and VisArea size
215 Fraction
aScaleWidth (aDrawSize
.Width(), aOleSize
.Width() );
216 Fraction
aScaleHeight(aDrawSize
.Height(), aOleSize
.Height() );
217 aScaleWidth
.ReduceInaccurate(10); // compatible with SdrOle2Obj
218 aScaleHeight
.ReduceInaccurate(10);
219 pClient
->SetSizeScale(aScaleWidth
,aScaleHeight
);
222 // visible section is only changed inplace!
223 // the object area must be set after the scaling since it triggers the resizing
224 aRect
.SetSize( aOleSize
);
225 pClient
->SetObjArea( aRect
);
227 nErr
= pClient
->DoVerb( nVerb
);
229 // SfxViewShell::DoVerb shows its error messages
231 // attach listener to selection changes in chart that affect cell
232 // ranges, so those can be highlighted
233 // note: do that after DoVerb, so that the chart controller exists
234 if ( SvtModuleOptions().IsChartInstalled() )
236 SvGlobalName
aObjClsId ( xObj
->getClassID() );
237 if (SotExchange::IsChart( aObjClsId
))
241 uno::Reference
< embed::XComponentSupplier
> xSup( xObj
, uno::UNO_QUERY_THROW
);
242 uno::Reference
< chart2::data::XDataReceiver
> xDataReceiver(
243 xSup
->getComponent(), uno::UNO_QUERY_THROW
);
244 uno::Reference
< chart2::data::XRangeHighlighter
> xRangeHighlighter(
245 xDataReceiver
->getRangeHighlighter());
246 if (xRangeHighlighter
.is())
248 uno::Reference
< view::XSelectionChangeListener
> xListener(
249 new ScChartRangeSelectionListener( this ));
250 xRangeHighlighter
->addSelectionChangeListener( xListener
);
252 uno::Reference
<awt::XRequestCallback
> xPopupRequest(xDataReceiver
->getPopupRequest());
253 if (xPopupRequest
.is())
255 uno::Reference
<awt::XCallback
> xCallback(new PopupCallback(this, pObj
));
257 xPopupRequest
->addCallback(xCallback
, aAny
);
260 catch( const uno::Exception
& )
262 TOOLS_WARN_EXCEPTION( "sc", "Exception caught while querying chart" );
268 if (nErr
!= ERRCODE_NONE
&& !bErrorShown
)
269 ErrorHandler::HandleError(nErr
);
271 // #i118524# refresh handles to suppress for activated OLE
274 GetScDrawView()->AdjustMarkHdl();
276 //! SetDocumentName should already happen in Sfx ???
277 //TODO/LATER: how "SetDocumentName"?
278 //xIPObj->SetDocumentName( GetViewData().GetDocShell()->GetTitle() );
281 ErrCode
ScTabViewShell::DoVerb(sal_Int32 nVerb
)
283 SdrView
* pView
= GetScDrawView();
285 return ERRCODE_SO_NOTIMPL
; // should not be
287 SdrOle2Obj
* pOle2Obj
= nullptr;
289 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
290 if (rMarkList
.GetMarkCount() == 1)
292 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
293 if (pObj
->GetObjIdentifier() == SdrObjKind::OLE2
)
294 pOle2Obj
= static_cast<SdrOle2Obj
*>(pObj
);
299 ActivateObject( pOle2Obj
, nVerb
);
303 OSL_FAIL("no object for Verb found");
309 void ScTabViewShell::DeactivateOle()
311 // deactivate inplace editing if currently active
313 ScModule
* pScMod
= ScModule::get();
314 bool bUnoRefDialog
= pScMod
->IsRefDialogOpen() && pScMod
->GetCurRefDlgId() == WID_SIMPLE_REF
;
316 ScClient
* pClient
= static_cast<ScClient
*>(GetIPClient());
317 if ( pClient
&& pClient
->IsObjectInPlaceActive() && !bUnoRefDialog
)
318 pClient
->DeactivateObject();
321 void ScTabViewShell::SetInsertWizardUndoMark()
323 assert(m_InsertWizardUndoMark
== MARK_INVALID
);
324 m_InsertWizardUndoMark
= GetUndoManager()->MarkTopUndoAction();
327 IMPL_LINK( ScTabViewShell
, DialogClosedHdl
, css::ui::dialogs::DialogClosedEvent
*, pEvent
, void )
329 assert(m_InsertWizardUndoMark
!= MARK_INVALID
);
330 UndoStackMark nInsertWizardUndoMark
= m_InsertWizardUndoMark
;
331 m_InsertWizardUndoMark
= MARK_INVALID
;
332 if( pEvent
->DialogResult
== ui::dialogs::ExecutableDialogResults::CANCEL
)
334 ScTabView
* pTabView
= GetViewData().GetView();
335 ScDrawView
* pView
= pTabView
->GetScDrawView();
336 ScViewData
& rData
= GetViewData();
337 ScDocShell
* pScDocSh
= rData
.GetDocShell();
338 ScDocument
& rScDoc
= pScDocSh
->GetDocument();
339 // leave OLE inplace mode and unmark
344 auto pUndoManager
= rScDoc
.GetUndoManager();
345 if (pUndoManager
->GetRedoActionCount())
347 pUndoManager
->RemoveMark(nInsertWizardUndoMark
);
351 pUndoManager
->UndoMark(nInsertWizardUndoMark
);
352 pUndoManager
->ClearRedo();
355 // leave the draw shell
356 SetDrawShell( false );
358 // reset marked cell area
359 ScMarkData aMark
= GetViewData().GetMarkData();
360 GetViewData().GetViewShell()->SetMarkData(aMark
);
364 OSL_ASSERT( pEvent
->DialogResult
== ui::dialogs::ExecutableDialogResults::OK
);
365 //@todo maybe move chart to different table
369 void ScTabViewShell::ExecDrawIns(SfxRequest
& rReq
)
371 sal_uInt16 nSlot
= rReq
.GetSlot();
372 if (nSlot
!= SID_OBJECTRESIZE
)
374 ScModule::get()->InputEnterHandler();
375 UpdateInputHandler();
378 // insertion of border for Chart is cancelled:
379 FuPoor
* pPoor
= GetDrawFuncPtr();
380 if ( pPoor
&& pPoor
->GetSlotID() == SID_DRAW_CHART
)
381 GetViewData().GetDispatcher().Execute(SID_DRAW_CHART
, SfxCallMode::SLOT
| SfxCallMode::RECORD
);
385 ScTabView
* pTabView
= GetViewData().GetView();
386 vcl::Window
* pWin
= pTabView
->GetActiveWin();
387 ScDrawView
* pView
= pTabView
->GetScDrawView();
388 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
389 ScDocument
& rDoc
= pDocSh
->GetDocument();
390 SdrModel
& rModel
= pView
->GetModel();
394 case SID_INSERT_GRAPHIC
:
395 FuInsertGraphic(*this, pWin
, pView
, &rModel
, rReq
);
396 // shell is set in MarkListHasChanged
399 case SID_INSERT_AVMEDIA
:
400 FuInsertMedia(*this, pWin
, pView
, &rModel
, rReq
);
401 // shell is set in MarkListHasChanged
404 case SID_INSERT_DIAGRAM
:
405 FuInsertChart(*this, pWin
, pView
, &rModel
, rReq
, LINK( this, ScTabViewShell
, DialogClosedHdl
));
406 if (comphelper::LibreOfficeKit::isActive())
407 pDocSh
->SetModified();
410 case SID_INSERT_OBJECT
:
411 case SID_INSERT_SMATH
:
412 case SID_INSERT_FLOATINGFRAME
:
413 FuInsertOLE(*this, pWin
, pView
, &rModel
, rReq
);
416 case SID_INSERT_SIGNATURELINE
:
417 case SID_EDIT_SIGNATURELINE
:
419 const uno::Reference
<frame::XModel
> xModel( GetViewData().GetDocShell()->GetBaseModel() );
421 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
422 VclPtr
<AbstractSignatureLineDialog
> pDialog(pFact
->CreateSignatureLineDialog(
423 pWin
->GetFrameWeld(), xModel
, rReq
.GetSlot() == SID_EDIT_SIGNATURELINE
));
424 auto xRequest
= std::make_shared
<SfxRequest
>(rReq
);
425 rReq
.Ignore(); // the 'old' request is not relevant any more
426 pDialog
->StartExecuteAsync(
427 [pDialog
, xRequest
=std::move(xRequest
)] (sal_Int32 nResult
)->void
429 if (nResult
== RET_OK
)
431 pDialog
->disposeOnce();
438 case SID_SIGN_SIGNATURELINE
:
440 const uno::Reference
<frame::XModel
> xModel(
441 GetViewData().GetDocShell()->GetBaseModel());
443 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
444 VclPtr
<AbstractSignSignatureLineDialog
> pDialog(
445 pFact
->CreateSignSignatureLineDialog(GetFrameWeld(), xModel
));
446 pDialog
->StartExecuteAsync(
447 [pDialog
] (sal_Int32 nResult
)->void
449 if (nResult
== RET_OK
)
451 pDialog
->disposeOnce();
457 case SID_INSERT_QRCODE
:
458 case SID_EDIT_QRCODE
:
460 const uno::Reference
<frame::XModel
> xModel( GetViewData().GetDocShell()->GetBaseModel() );
462 VclAbstractDialogFactory
* pFact
= VclAbstractDialogFactory::Create();
463 ScopedVclPtr
<AbstractQrCodeGenDialog
> pDialog(pFact
->CreateQrCodeGenDialog(
464 pWin
->GetFrameWeld(), xModel
, rReq
.GetSlot() == SID_EDIT_QRCODE
));
469 case SID_OBJECTRESIZE
:
471 // the server would like to change the client size
473 SfxInPlaceClient
* pClient
= GetIPClient();
475 if ( pClient
&& pClient
->IsObjectInPlaceActive() )
477 const SfxRectangleItem
& rRect
= rReq
.GetArgs()->Get(SID_OBJECTRESIZE
);
478 tools::Rectangle
aRect( pWin
->PixelToLogic( rRect
.GetValue() ) );
480 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
481 if ( rMarkList
.GetMarkCount() != 0 )
483 if (rMarkList
.GetMarkCount() == 1)
485 SdrMark
* pMark
= rMarkList
.GetMark(0);
486 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
488 SdrObjKind nSdrObjKind
= pObj
->GetObjIdentifier();
490 if (nSdrObjKind
== SdrObjKind::OLE2
)
492 if ( static_cast<SdrOle2Obj
*>(pObj
)->GetObjRef().is() )
494 pObj
->SetLogicRect(aRect
);
505 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
506 if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
508 std::unique_ptr
<weld::MessageDialog
> xError(Application::CreateMessageDialog(
509 nullptr, VclMessageType::Warning
, VclButtonsType::Ok
,
510 SvtResId(STR_WARNING_EXTERNAL_LINK_EDIT_DISABLED
)));
515 VclPtr
<SfxAbstractLinksDialog
> pDlg(pFact
->CreateLinksDialog(pWin
->GetFrameWeld(), rDoc
.GetLinkManager()));
516 auto xRequest
= std::make_shared
<SfxRequest
>(rReq
);
517 rReq
.Ignore(); // the 'old' request is not relevant any more
518 pDlg
->StartExecuteAsync(
519 [this, pDlg
, xRequest
=std::move(xRequest
)] (sal_Int32
/*nResult*/)->void
521 GetViewFrame().GetBindings().Invalidate( SID_LINKS
);
522 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged
) ); // Navigator
530 case SID_FM_CREATE_FIELDCONTROL
:
532 const SfxUnoAnyItem
* pDescriptorItem
= rReq
.GetArg
<SfxUnoAnyItem
>(SID_FM_DATACCESS_DESCRIPTOR
);
533 OSL_ENSURE( pDescriptorItem
, "SID_FM_CREATE_FIELDCONTROL: invalid request args!" );
537 //! merge with ScViewFunc::PasteDataFormat (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE)?
539 ScDrawView
* pDrView
= GetScDrawView();
540 SdrPageView
* pPageView
= pDrView
? pDrView
->GetSdrPageView() : nullptr;
543 svx::ODataAccessDescriptor
aDescriptor(pDescriptorItem
->GetValue());
544 rtl::Reference
<SdrObject
> pNewDBField
= pDrView
->CreateFieldControl(aDescriptor
);
548 tools::Rectangle aVisArea
= pWin
->PixelToLogic(tools::Rectangle(Point(0,0), pWin
->GetOutputSizePixel()));
549 Point
aObjPos(aVisArea
.Center());
550 Size
aObjSize(pNewDBField
->GetLogicRect().GetSize());
551 aObjPos
.AdjustX( -(aObjSize
.Width() / 2) );
552 aObjPos
.AdjustY( -(aObjSize
.Height() / 2) );
553 tools::Rectangle
aNewObjectRectangle(aObjPos
, aObjSize
);
555 pNewDBField
->SetLogicRect(aNewObjectRectangle
);
557 // controls must be on control layer, groups on front layer
558 if ( dynamic_cast<const SdrUnoObj
*>( pNewDBField
.get() ) != nullptr )
559 pNewDBField
->NbcSetLayer(SC_LAYER_CONTROLS
);
561 pNewDBField
->NbcSetLayer(SC_LAYER_FRONT
);
562 if (dynamic_cast<const SdrObjGroup
*>( pNewDBField
.get() ) != nullptr)
564 SdrObjListIter
aIter( *pNewDBField
, SdrIterMode::DeepWithGroups
);
565 SdrObject
* pSubObj
= aIter
.Next();
568 if ( dynamic_cast<const SdrUnoObj
*>( pSubObj
) != nullptr )
569 pSubObj
->NbcSetLayer(SC_LAYER_CONTROLS
);
571 pSubObj
->NbcSetLayer(SC_LAYER_FRONT
);
572 pSubObj
= aIter
.Next();
576 pView
->InsertObjectAtView(pNewDBField
.get(), *pPageView
);
584 case SID_FONTWORK_GALLERY_FLOATER
:
585 svx::FontworkBar::execute(*pView
, rReq
, GetViewFrame().GetBindings());
591 void ScTabViewShell::GetDrawInsState(SfxItemSet
&rSet
)
593 bool bOle
= GetViewFrame().GetFrame().IsInPlace();
594 bool bTabProt
= GetViewData().GetDocument().IsTabProtected(GetViewData().GetTabNo());
595 ScDocShell
* pDocShell
= GetViewData().GetDocShell();
596 bool bShared
= pDocShell
&& pDocShell
->IsDocShared();
597 SdrView
* pSdrView
= GetScDrawView();
599 SfxWhichIter
aIter(rSet
);
600 sal_uInt16 nWhich
= aIter
.FirstWhich();
605 case SID_INSERT_DIAGRAM
:
606 if ( bOle
|| bTabProt
|| !SvtModuleOptions().IsChartInstalled() || bShared
)
607 rSet
.DisableItem( nWhich
);
610 case SID_INSERT_SMATH
:
611 if ( bOle
|| bTabProt
|| !SvtModuleOptions().IsMathInstalled() || bShared
)
612 rSet
.DisableItem( nWhich
);
615 case SID_INSERT_OBJECT
:
616 case SID_INSERT_FLOATINGFRAME
:
617 if ( bOle
|| bTabProt
|| bShared
)
618 rSet
.DisableItem( nWhich
);
621 case SID_INSERT_AVMEDIA
:
622 case SID_FONTWORK_GALLERY_FLOATER
:
623 if ( bTabProt
|| bShared
)
624 rSet
.DisableItem( nWhich
);
627 case SID_INSERT_SIGNATURELINE
:
628 case SID_INSERT_QRCODE
:
629 if ( bTabProt
|| bShared
|| (pSdrView
&& pSdrView
->GetMarkedObjectList().GetMarkCount() != 0))
630 rSet
.DisableItem( nWhich
);
632 case SID_EDIT_SIGNATURELINE
:
633 case SID_SIGN_SIGNATURELINE
:
634 if (!IsSignatureLineSelected() || IsSignatureLineSigned())
635 rSet
.DisableItem(nWhich
);
638 case SID_EDIT_QRCODE
:
639 if (!IsQRCodeSelected())
640 rSet
.DisableItem(nWhich
);
643 case SID_INSERT_GRAPHIC
:
644 if (bTabProt
|| bShared
)
646 // do not disable 'insert graphic' item if the currently marked area is editable (not protected)
647 // if there is no marked area, check the current cell
648 bool bDisableInsertImage
= true;
649 ScMarkData
& rMark
= GetViewData().GetMarkData();
650 if (!rMark
.GetMarkedRanges().empty() && GetViewData().GetDocument().IsSelectionEditable(rMark
))
651 bDisableInsertImage
= false;
654 if (GetViewData().GetDocument().IsBlockEditable
655 (GetViewData().GetTabNo(), GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetCurX(), GetViewData().GetCurY()))
657 bDisableInsertImage
= false;
661 if (bDisableInsertImage
)
662 rSet
.DisableItem(nWhich
);
668 if (GetViewData().GetDocument().GetLinkManager()->GetLinks().empty())
669 rSet
.DisableItem( SID_LINKS
);
673 nWhich
= aIter
.NextWhich();
677 bool ScTabViewShell::IsSignatureLineSelected()
679 SdrView
* pSdrView
= GetScDrawView();
683 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
684 if (rMarkList
.GetMarkCount() != 1)
687 SdrObject
* pPickObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
691 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
695 return pGraphic
->isSignatureLine();
698 bool ScTabViewShell::IsQRCodeSelected()
700 SdrView
* pSdrView
= GetScDrawView();
704 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
705 if (rMarkList
.GetMarkCount() != 1)
708 SdrObject
* pPickObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
712 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
716 if(pGraphic
->getQrCode())
725 bool ScTabViewShell::IsSignatureLineSigned()
727 SdrView
* pSdrView
= GetScDrawView();
731 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
732 if (rMarkList
.GetMarkCount() != 1)
735 SdrObject
* pPickObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
739 SdrGrafObj
* pGraphic
= dynamic_cast<SdrGrafObj
*>(pPickObj
);
743 return pGraphic
->isSignatureLineSigned();
746 void ScTabViewShell::ExecuteUndo(SfxRequest
& rReq
)
748 SfxShell
* pSh
= GetViewData().GetDispatcher().GetShell(0);
752 ScUndoManager
* pUndoManager
= static_cast<ScUndoManager
*>(pSh
->GetUndoManager());
754 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
755 ScDocShell
* pDocSh
= GetViewData().GetDocShell();
757 sal_uInt16 nSlot
= rReq
.GetSlot();
764 bool bIsUndo
= ( nSlot
== SID_UNDO
);
766 sal_uInt16 nCount
= 1;
767 const SfxPoolItem
* pItem
;
768 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlot
, true, &pItem
) == SfxItemState::SET
)
769 nCount
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
771 // Repair mode: allow undo/redo of all undo actions, even if access would
772 // be limited based on the view shell ID.
773 bool bRepair
= false;
774 if (pReqArgs
&& pReqArgs
->GetItemState(SID_REPAIRPACKAGE
, false, &pItem
) == SfxItemState::SET
)
775 bRepair
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
777 sal_uInt16 nUndoOffset
= 0;
778 if (comphelper::LibreOfficeKit::isActive() && !bRepair
)
780 SfxUndoAction
* pAction
= nullptr;
783 if (pUndoManager
->GetUndoActionCount() != 0)
784 pAction
= pUndoManager
->GetUndoAction();
788 if (pUndoManager
->GetRedoActionCount() != 0)
789 pAction
= pUndoManager
->GetRedoAction();
793 // If another view created the undo action, prevent undoing it from this view.
794 // Unless we know that the other view's undo action is independent from us.
795 ViewShellId nViewShellId
= GetViewShellId();
796 if (pAction
->GetViewShellId() != nViewShellId
)
798 sal_uInt16 nOffset
= 0;
799 if (pUndoManager
->IsViewUndoActionIndependent(this, nOffset
))
801 // Execute the undo with an offset: don't undo the top action, but an
802 // earlier one, since it's independent and that belongs to our view.
803 nUndoOffset
+= nOffset
;
807 rReq
.SetReturnValue(SfxUInt32Item(SID_UNDO
, static_cast<sal_uInt32
>(SID_REPAIRPACKAGE
)));
814 // lock paint for more than one cell undo action (not for editing within a cell)
815 bool bLockPaint
= ( nCount
> 1 && pUndoManager
== GetUndoManager() );
821 ScUndoRedoContext aUndoRedoContext
;
822 aUndoRedoContext
.SetUndoOffset(nUndoOffset
);
824 for (sal_uInt16 i
=0; i
<nCount
; i
++)
827 pUndoManager
->UndoWithContext(aUndoRedoContext
);
829 pUndoManager
->RedoWithContext(aUndoRedoContext
);
832 catch ( const uno::Exception
& )
834 // no need to handle. By definition, the UndoManager handled this by clearing the
839 pDocSh
->UnlockPaint();
841 GetViewFrame().GetBindings().InvalidateAll(false);
845 // GetViewFrame().ExecuteSlot( rReq );
849 void ScTabViewShell::GetUndoState(SfxItemSet
&rSet
)
851 SfxShell
* pSh
= GetViewData().GetDispatcher().GetShell(0);
855 SfxUndoManager
* pUndoManager
= pSh
->GetUndoManager();
856 ScUndoManager
* pScUndoManager
= dynamic_cast<ScUndoManager
*>(pUndoManager
);
858 SfxWhichIter
aIter(rSet
);
859 sal_uInt16 nWhich
= aIter
.FirstWhich();
864 case SID_GETUNDOSTRINGS
:
865 case SID_GETREDOSTRINGS
:
867 SfxStringListItem
aStrLst( nWhich
);
870 std::vector
<OUString
> &aList
= aStrLst
.GetList();
871 bool bIsUndo
= ( nWhich
== SID_GETUNDOSTRINGS
);
872 size_t nCount
= bIsUndo
? pUndoManager
->GetUndoActionCount() : pUndoManager
->GetRedoActionCount();
873 for (size_t i
=0; i
<nCount
; ++i
)
875 aList
.push_back( bIsUndo
? pUndoManager
->GetUndoActionComment(i
) :
876 pUndoManager
->GetRedoActionComment(i
) );
887 if (pScUndoManager
->GetUndoActionCount())
889 const SfxUndoAction
* pAction
= pScUndoManager
->GetUndoAction();
890 SfxViewShell
*pViewSh
= GetViewShell();
891 if (pViewSh
&& pAction
->GetViewShellId() != pViewSh
->GetViewShellId()
892 && !pScUndoManager
->IsViewUndoActionIndependent(this, o3tl::temporary(sal_uInt16())))
894 rSet
.Put(SfxUInt32Item(SID_UNDO
, static_cast<sal_uInt32
>(SID_REPAIRPACKAGE
)));
898 rSet
.Put( SfxStringItem( SID_UNDO
, SvtResId(STR_UNDO
)+pScUndoManager
->GetUndoActionComment() ) );
902 rSet
.DisableItem( SID_UNDO
);
905 // get state from sfx view frame
906 GetViewFrame().GetSlotState( nWhich
, nullptr, &rSet
);
913 if (pScUndoManager
->GetRedoActionCount())
915 const SfxUndoAction
* pAction
= pScUndoManager
->GetRedoAction();
916 SfxViewShell
*pViewSh
= GetViewShell();
917 if (pViewSh
&& pAction
->GetViewShellId() != pViewSh
->GetViewShellId())
919 rSet
.Put(SfxUInt32Item(SID_REDO
, static_cast<sal_uInt32
>(SID_REPAIRPACKAGE
)));
923 rSet
.Put(SfxStringItem(SID_REDO
, SvtResId(STR_REDO
) + pScUndoManager
->GetRedoActionComment()));
927 rSet
.DisableItem( SID_REDO
);
930 // get state from sfx view frame
931 GetViewFrame().GetSlotState( nWhich
, nullptr, &rSet
);
935 // get state from sfx view frame
936 GetViewFrame().GetSlotState( nWhich
, nullptr, &rSet
);
939 nWhich
= aIter
.NextWhich();
943 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */