tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / tabvwshb.cxx
blob4b00ce224bda288d1b11812e4e2c337b26df5148
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 <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>
54 #include <scmod.hxx>
55 #include <document.hxx>
56 #include <sc.hrc>
57 #include <client.hxx>
58 #include <fuinsert.hxx>
59 #include <docsh.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 );
83 if ( pClient )
84 return;
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());
91 if (bNegativeX)
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 );
111 namespace {
113 class PopupCallback : public cppu::WeakImplHelper<css::awt::XCallback>
115 ScTabViewShell* m_pViewShell;
116 SdrOle2Obj* m_pObject;
118 public:
119 explicit PopupCallback(ScTabViewShell* pViewShell, SdrOle2Obj* pObject)
120 : m_pViewShell(pViewShell)
121 , m_pObject(pObject)
124 // XCallback
125 virtual void SAL_CALL notify(const css::uno::Any& aData) override
127 uno::Sequence<beans::PropertyValue> aProperties;
128 if (!(aData >>= aProperties))
129 return;
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
159 RemoveHintWindow();
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 );
172 if ( !pClient )
173 pClient = new ScClient( this, pWin, &GetScDrawView()->GetModel(), pObj );
175 if (bNegativeX)
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 );
211 else
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 );
228 bErrorShown = true;
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));
256 uno::Any aAny;
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
272 if(GetScDrawView())
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();
284 if (!pView)
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);
297 if (pOle2Obj)
299 ActivateObject( pOle2Obj, nVerb );
301 else
303 OSL_FAIL("no object for Verb found");
306 return ERRCODE_NONE;
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
340 OSL_ASSERT( pView );
341 DeactivateOle();
342 pView->UnMarkAll();
344 auto pUndoManager = rScDoc.GetUndoManager();
345 if (pUndoManager->GetRedoActionCount())
347 pUndoManager->RemoveMark(nInsertWizardUndoMark);
349 else
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);
362 else
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);
383 MakeDrawLayer();
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();
392 switch ( nSlot )
394 case SID_INSERT_GRAPHIC:
395 FuInsertGraphic(*this, pWin, pView, &rModel, rReq);
396 // shell is set in MarkListHasChanged
397 break;
399 case SID_INSERT_AVMEDIA:
400 FuInsertMedia(*this, pWin, pView, &rModel, rReq);
401 // shell is set in MarkListHasChanged
402 break;
404 case SID_INSERT_DIAGRAM:
405 FuInsertChart(*this, pWin, pView, &rModel, rReq, LINK( this, ScTabViewShell, DialogClosedHdl ));
406 if (comphelper::LibreOfficeKit::isActive())
407 pDocSh->SetModified();
408 break;
410 case SID_INSERT_OBJECT:
411 case SID_INSERT_SMATH:
412 case SID_INSERT_FLOATINGFRAME:
413 FuInsertOLE(*this, pWin, pView, &rModel, rReq);
414 break;
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)
430 pDialog->Apply();
431 pDialog->disposeOnce();
432 xRequest->Done();
435 break;
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)
450 pDialog->Apply();
451 pDialog->disposeOnce();
454 break;
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));
465 pDialog->Execute();
466 break;
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);
501 break;
503 case SID_LINKS:
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)));
511 xError->run();
512 break;
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
523 pDlg->disposeOnce();
524 xRequest->Done();
528 break;
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!" );
535 if(pDescriptorItem)
537 //! merge with ScViewFunc::PasteDataFormat (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE)?
539 ScDrawView* pDrView = GetScDrawView();
540 SdrPageView* pPageView = pDrView ? pDrView->GetSdrPageView() : nullptr;
541 if(pPageView)
543 svx::ODataAccessDescriptor aDescriptor(pDescriptorItem->GetValue());
544 rtl::Reference<SdrObject> pNewDBField = pDrView->CreateFieldControl(aDescriptor);
546 if(pNewDBField)
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);
560 else
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();
566 while (pSubObj)
568 if ( dynamic_cast<const SdrUnoObj*>( pSubObj) != nullptr )
569 pSubObj->NbcSetLayer(SC_LAYER_CONTROLS);
570 else
571 pSubObj->NbcSetLayer(SC_LAYER_FRONT);
572 pSubObj = aIter.Next();
576 pView->InsertObjectAtView(pNewDBField.get(), *pPageView);
580 rReq.Done();
582 break;
584 case SID_FONTWORK_GALLERY_FLOATER:
585 svx::FontworkBar::execute(*pView, rReq, GetViewFrame().GetBindings());
586 rReq.Ignore();
587 break;
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();
601 while ( nWhich )
603 switch ( nWhich )
605 case SID_INSERT_DIAGRAM:
606 if ( bOle || bTabProt || !SvtModuleOptions().IsChartInstalled() || bShared )
607 rSet.DisableItem( nWhich );
608 break;
610 case SID_INSERT_SMATH:
611 if ( bOle || bTabProt || !SvtModuleOptions().IsMathInstalled() || bShared )
612 rSet.DisableItem( nWhich );
613 break;
615 case SID_INSERT_OBJECT:
616 case SID_INSERT_FLOATINGFRAME:
617 if ( bOle || bTabProt || bShared )
618 rSet.DisableItem( nWhich );
619 break;
621 case SID_INSERT_AVMEDIA:
622 case SID_FONTWORK_GALLERY_FLOATER:
623 if ( bTabProt || bShared )
624 rSet.DisableItem( nWhich );
625 break;
627 case SID_INSERT_SIGNATURELINE:
628 case SID_INSERT_QRCODE:
629 if ( bTabProt || bShared || (pSdrView && pSdrView->GetMarkedObjectList().GetMarkCount() != 0))
630 rSet.DisableItem( nWhich );
631 break;
632 case SID_EDIT_SIGNATURELINE:
633 case SID_SIGN_SIGNATURELINE:
634 if (!IsSignatureLineSelected() || IsSignatureLineSigned())
635 rSet.DisableItem(nWhich);
636 break;
638 case SID_EDIT_QRCODE:
639 if (!IsQRCodeSelected())
640 rSet.DisableItem(nWhich);
641 break;
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;
652 else
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);
664 break;
666 case SID_LINKS:
668 if (GetViewData().GetDocument().GetLinkManager()->GetLinks().empty())
669 rSet.DisableItem( SID_LINKS );
671 break;
673 nWhich = aIter.NextWhich();
677 bool ScTabViewShell::IsSignatureLineSelected()
679 SdrView* pSdrView = GetScDrawView();
680 if (!pSdrView)
681 return false;
683 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
684 if (rMarkList.GetMarkCount() != 1)
685 return false;
687 SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
688 if (!pPickObj)
689 return false;
691 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
692 if (!pGraphic)
693 return false;
695 return pGraphic->isSignatureLine();
698 bool ScTabViewShell::IsQRCodeSelected()
700 SdrView* pSdrView = GetScDrawView();
701 if (!pSdrView)
702 return false;
704 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
705 if (rMarkList.GetMarkCount() != 1)
706 return false;
708 SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
709 if (!pPickObj)
710 return false;
712 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
713 if (!pGraphic)
714 return false;
716 if(pGraphic->getQrCode())
718 return true;
720 else{
721 return false;
725 bool ScTabViewShell::IsSignatureLineSigned()
727 SdrView* pSdrView = GetScDrawView();
728 if (!pSdrView)
729 return false;
731 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
732 if (rMarkList.GetMarkCount() != 1)
733 return false;
735 SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
736 if (!pPickObj)
737 return false;
739 SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
740 if (!pGraphic)
741 return false;
743 return pGraphic->isSignatureLineSigned();
746 void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
748 SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
749 if (!pSh)
750 return;
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();
758 switch ( nSlot )
760 case SID_UNDO:
761 case SID_REDO:
762 if ( pUndoManager )
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;
781 if (bIsUndo)
783 if (pUndoManager->GetUndoActionCount() != 0)
784 pAction = pUndoManager->GetUndoAction();
786 else
788 if (pUndoManager->GetRedoActionCount() != 0)
789 pAction = pUndoManager->GetRedoAction();
791 if (pAction)
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;
805 else
807 rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
808 return;
814 // lock paint for more than one cell undo action (not for editing within a cell)
815 bool bLockPaint = ( nCount > 1 && pUndoManager == GetUndoManager() );
816 if ( bLockPaint )
817 pDocSh->LockPaint();
821 ScUndoRedoContext aUndoRedoContext;
822 aUndoRedoContext.SetUndoOffset(nUndoOffset);
824 for (sal_uInt16 i=0; i<nCount; i++)
826 if ( bIsUndo )
827 pUndoManager->UndoWithContext(aUndoRedoContext);
828 else
829 pUndoManager->RedoWithContext(aUndoRedoContext);
832 catch ( const uno::Exception& )
834 // no need to handle. By definition, the UndoManager handled this by clearing the
835 // Undo/Redo stacks
838 if ( bLockPaint )
839 pDocSh->UnlockPaint();
841 GetViewFrame().GetBindings().InvalidateAll(false);
843 break;
844 // default:
845 // GetViewFrame().ExecuteSlot( rReq );
849 void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
851 SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
852 if (!pSh)
853 return;
855 SfxUndoManager* pUndoManager = pSh->GetUndoManager();
856 ScUndoManager* pScUndoManager = dynamic_cast<ScUndoManager*>(pUndoManager);
858 SfxWhichIter aIter(rSet);
859 sal_uInt16 nWhich = aIter.FirstWhich();
860 while ( nWhich )
862 switch (nWhich)
864 case SID_GETUNDOSTRINGS:
865 case SID_GETREDOSTRINGS:
867 SfxStringListItem aStrLst( nWhich );
868 if ( pUndoManager )
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) );
879 rSet.Put( aStrLst );
881 break;
883 case SID_UNDO:
885 if (pScUndoManager)
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)));
896 else
898 rSet.Put( SfxStringItem( SID_UNDO, SvtResId(STR_UNDO)+pScUndoManager->GetUndoActionComment() ) );
901 else
902 rSet.DisableItem( SID_UNDO );
904 else
905 // get state from sfx view frame
906 GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
907 break;
909 case SID_REDO:
911 if (pScUndoManager)
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)));
921 else
923 rSet.Put(SfxStringItem(SID_REDO, SvtResId(STR_REDO) + pScUndoManager->GetRedoActionComment()));
926 else
927 rSet.DisableItem( SID_REDO );
929 else
930 // get state from sfx view frame
931 GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
932 break;
934 default:
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: */