Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sc/source/ui/view/tabvwshb.cxx
Line
Count
Source (jump to first uncovered line)
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 <com/sun/star/chart2/data/XDataReceiver.hpp>
21
#include <com/sun/star/awt/XRequestCallback.hpp>
22
#include <com/sun/star/awt/Rectangle.hpp>
23
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>
52
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>
68
69
#include <comphelper/lok.hxx>
70
71
using namespace com::sun::star;
72
73
void ScTabViewShell::ConnectObject( const SdrOle2Obj* pObj )
74
0
{
75
    // is called from paint
76
77
0
    const uno::Reference < embed::XEmbeddedObject >& xObj = pObj->GetObjRef();
78
0
    vcl::Window* pWin = GetActiveWin();
79
80
    // when already connected do not execute SetObjArea/SetSizeScale again
81
82
0
    SfxInPlaceClient* pClient = FindIPClient( xObj, pWin );
83
0
    if ( pClient )
84
0
        return;
85
86
0
    pClient = new ScClient( this, pWin, &GetScDrawView()->GetModel(), pObj );
87
0
    ScViewData& rViewData = GetViewData();
88
0
    ScDocShell& rDocSh = rViewData.GetDocShell();
89
0
    ScDocument& rDoc = rDocSh.GetDocument();
90
0
    bool bNegativeX = comphelper::LibreOfficeKit::isActive() && rDoc.IsNegativePage(rViewData.GetTabNo());
91
0
    if (bNegativeX)
92
0
        pClient->SetNegativeX(true);
93
94
0
    tools::Rectangle aRect = pObj->GetLogicRect();
95
0
    Size aDrawSize = aRect.GetSize();
96
97
0
    Size aOleSize = pObj->GetOrigObjSize();
98
99
0
    Fraction aScaleWidth (aDrawSize.Width(),  aOleSize.Width() );
100
0
    Fraction aScaleHeight(aDrawSize.Height(), aOleSize.Height() );
101
0
    aScaleWidth.ReduceInaccurate(10);       // compatible with SdrOle2Obj
102
0
    aScaleHeight.ReduceInaccurate(10);
103
0
    pClient->SetSizeScale(aScaleWidth,aScaleHeight);
104
105
    // visible section is only changed inplace!
106
    // the object area must be set after the scaling since it triggers the resizing
107
0
    aRect.SetSize( aOleSize );
108
0
    pClient->SetObjArea( aRect );
109
0
}
110
111
namespace {
112
113
class PopupCallback : public cppu::WeakImplHelper<css::awt::XCallback>
114
{
115
    ScTabViewShell* m_pViewShell;
116
    SdrOle2Obj* m_pObject;
117
118
public:
119
    explicit PopupCallback(ScTabViewShell* pViewShell, SdrOle2Obj* pObject)
120
0
        : m_pViewShell(pViewShell)
121
0
        , m_pObject(pObject)
122
0
    {}
123
124
    // XCallback
125
    virtual void SAL_CALL notify(const css::uno::Any& aData) override
126
0
    {
127
0
        uno::Sequence<beans::PropertyValue> aProperties;
128
0
        if (!(aData >>= aProperties))
129
0
            return;
130
131
0
        awt::Rectangle xRectangle;
132
0
        sal_Int32 dimensionIndex = 0;
133
0
        OUString sPivotTableName(u"DataPilot1"_ustr);
134
135
0
        for (beans::PropertyValue const& rProperty : aProperties)
136
0
        {
137
0
            if (rProperty.Name == "Rectangle")
138
0
                rProperty.Value >>= xRectangle;
139
0
            if (rProperty.Name == "DimensionIndex")
140
0
                rProperty.Value >>= dimensionIndex;
141
0
            if (rProperty.Name == "PivotTableName")
142
0
                rProperty.Value >>= sPivotTableName;
143
0
        }
144
145
0
        tools::Rectangle aChartRect = m_pObject->GetLogicRect();
146
147
0
        Point aPoint(xRectangle.X  + aChartRect.Left(), xRectangle.Y + aChartRect.Top());
148
0
        Size aSize(xRectangle.Width, xRectangle.Height);
149
150
0
        m_pViewShell->DoDPFieldPopup(sPivotTableName, dimensionIndex, aPoint, aSize);
151
0
    }
152
};
153
154
}
155
156
void ScTabViewShell::ActivateObject(SdrOle2Obj* pObj, sal_Int32 nVerb)
157
0
{
158
    // Do not leave the hint message box on top of the object
159
0
    RemoveHintWindow();
160
161
0
    uno::Reference < embed::XEmbeddedObject > xObj = pObj->GetObjRef();
162
0
    vcl::Window* pWin = GetActiveWin();
163
0
    ErrCodeMsg nErr = ERRCODE_NONE;
164
0
    bool bErrorShown = false;
165
166
0
    {
167
0
        ScViewData& rViewData = GetViewData();
168
0
        ScDocShell& rDocSh = rViewData.GetDocShell();
169
0
        ScDocument& rDoc = rDocSh.GetDocument();
170
0
        bool bNegativeX = comphelper::LibreOfficeKit::isActive() && rDoc.IsNegativePage(rViewData.GetTabNo());
171
0
        SfxInPlaceClient* pClient = FindIPClient( xObj, pWin );
172
0
        if ( !pClient )
173
0
            pClient = new ScClient( this, pWin, &GetScDrawView()->GetModel(), pObj );
174
175
0
        if (bNegativeX)
176
0
            pClient->SetNegativeX(true);
177
178
0
        if ( (sal_uInt32(nErr.GetCode()) & ERRCODE_ERROR_MASK) == 0 && xObj.is() )
179
0
        {
180
0
            tools::Rectangle aRect = pObj->GetLogicRect();
181
182
0
            {
183
                // #i118485# center on BoundRect for activation,
184
                // OLE may be sheared/rotated now
185
0
                const tools::Rectangle& rBoundRect = pObj->GetCurrentBoundRect();
186
0
                const Point aDelta(rBoundRect.Center() - aRect.Center());
187
0
                aRect.Move(aDelta.X(), aDelta.Y());
188
0
            }
189
190
0
            Size aDrawSize = aRect.GetSize();
191
192
0
            MapMode aMapMode( MapUnit::Map100thMM );
193
0
            Size aOleSize = pObj->GetOrigObjSize( &aMapMode );
194
195
0
            if ( pClient->GetAspect() != embed::Aspects::MSOLE_ICON
196
0
              && ( xObj->getStatus( pClient->GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
197
0
            {
198
                //  scale must always be 1 - change VisArea if different from client size
199
200
0
                if ( aDrawSize != aOleSize )
201
0
                {
202
0
                    MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( pClient->GetAspect() ) );
203
0
                    aOleSize = OutputDevice::LogicToLogic( aDrawSize,
204
0
                                MapMode(MapUnit::Map100thMM), MapMode(aUnit));
205
0
                    awt::Size aSz( aOleSize.Width(), aOleSize.Height() );
206
0
                    xObj->setVisualAreaSize( pClient->GetAspect(), aSz );
207
0
                }
208
0
                Fraction aOne( 1, 1 );
209
0
                pClient->SetSizeScale( aOne, aOne );
210
0
            }
211
0
            else
212
0
            {
213
                //  calculate scale from client and VisArea size
214
215
0
                Fraction aScaleWidth (aDrawSize.Width(),  aOleSize.Width() );
216
0
                Fraction aScaleHeight(aDrawSize.Height(), aOleSize.Height() );
217
0
                aScaleWidth.ReduceInaccurate(10);       // compatible with SdrOle2Obj
218
0
                aScaleHeight.ReduceInaccurate(10);
219
0
                pClient->SetSizeScale(aScaleWidth,aScaleHeight);
220
0
            }
221
222
            // visible section is only changed inplace!
223
            // the object area must be set after the scaling since it triggers the resizing
224
0
            aRect.SetSize( aOleSize );
225
0
            pClient->SetObjArea( aRect );
226
227
0
            nErr = pClient->DoVerb( nVerb );
228
0
            bErrorShown = true;
229
            // SfxViewShell::DoVerb shows its error messages
230
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
0
            if ( SvtModuleOptions().IsChartInstalled() )
235
0
            {
236
0
                SvGlobalName aObjClsId ( xObj->getClassID() );
237
0
                if (SotExchange::IsChart( aObjClsId ))
238
0
                {
239
0
                    try
240
0
                    {
241
0
                        uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY_THROW );
242
0
                        uno::Reference< chart2::data::XDataReceiver > xDataReceiver(
243
0
                            xSup->getComponent(), uno::UNO_QUERY_THROW );
244
0
                        uno::Reference< chart2::data::XRangeHighlighter > xRangeHighlighter(
245
0
                            xDataReceiver->getRangeHighlighter());
246
0
                        if (xRangeHighlighter.is())
247
0
                        {
248
0
                            uno::Reference< view::XSelectionChangeListener > xListener(
249
0
                                new ScChartRangeSelectionListener( this ));
250
0
                            xRangeHighlighter->addSelectionChangeListener( xListener );
251
0
                        }
252
0
                        uno::Reference<awt::XRequestCallback> xPopupRequest(xDataReceiver->getPopupRequest());
253
0
                        if (xPopupRequest.is())
254
0
                        {
255
0
                            uno::Reference<awt::XCallback> xCallback(new PopupCallback(this, pObj));
256
0
                            uno::Any aAny;
257
0
                            xPopupRequest->addCallback(xCallback, aAny);
258
0
                        }
259
0
                    }
260
0
                    catch( const uno::Exception & )
261
0
                    {
262
0
                        TOOLS_WARN_EXCEPTION( "sc", "Exception caught while querying chart" );
263
0
                    }
264
0
                }
265
0
            }
266
0
        }
267
0
    }
268
0
    if (nErr != ERRCODE_NONE && !bErrorShown)
269
0
        ErrorHandler::HandleError(nErr);
270
271
    // #i118524# refresh handles to suppress for activated OLE
272
0
    if(GetScDrawView())
273
0
    {
274
0
        GetScDrawView()->AdjustMarkHdl();
275
0
    }
276
    //! SetDocumentName should already happen in Sfx ???
277
    //TODO/LATER: how "SetDocumentName"?
278
    //xIPObj->SetDocumentName( GetViewData().GetDocShell().GetTitle() );
279
0
}
280
281
ErrCode ScTabViewShell::DoVerb(sal_Int32 nVerb)
282
0
{
283
0
    SdrView* pView = GetScDrawView();
284
0
    if (!pView)
285
0
        return ERRCODE_SO_NOTIMPL;          // should not be
286
287
0
    SdrOle2Obj* pOle2Obj = nullptr;
288
289
0
    const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
290
0
    if (rMarkList.GetMarkCount() == 1)
291
0
    {
292
0
        SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
293
0
        if (pObj->GetObjIdentifier() == SdrObjKind::OLE2)
294
0
            pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
295
0
    }
296
297
0
    if (pOle2Obj)
298
0
    {
299
0
        ActivateObject( pOle2Obj, nVerb );
300
0
    }
301
0
    else
302
0
    {
303
0
        OSL_FAIL("no object for Verb found");
304
0
    }
305
306
0
    return ERRCODE_NONE;
307
0
}
308
309
void ScTabViewShell::DeactivateOle()
310
0
{
311
    // deactivate inplace editing if currently active
312
313
0
    ScModule* pScMod = ScModule::get();
314
0
    bool bUnoRefDialog = pScMod->IsRefDialogOpen() && pScMod->GetCurRefDlgId() == WID_SIMPLE_REF;
315
316
0
    ScClient* pClient = static_cast<ScClient*>(GetIPClient());
317
0
    if ( pClient && pClient->IsObjectInPlaceActive() && !bUnoRefDialog )
318
0
        pClient->DeactivateObject();
319
0
}
320
321
void ScTabViewShell::SetInsertWizardUndoMark()
322
0
{
323
0
    assert(m_InsertWizardUndoMark == MARK_INVALID);
324
0
    m_InsertWizardUndoMark = GetUndoManager()->MarkTopUndoAction();
325
0
}
326
327
IMPL_LINK( ScTabViewShell, DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, pEvent, void )
328
0
{
329
0
    assert(m_InsertWizardUndoMark != MARK_INVALID);
330
0
    UndoStackMark nInsertWizardUndoMark = m_InsertWizardUndoMark;
331
0
    m_InsertWizardUndoMark = MARK_INVALID;
332
0
    if( pEvent->DialogResult == ui::dialogs::ExecutableDialogResults::CANCEL )
333
0
    {
334
0
        ScTabView* pTabView = GetViewData().GetView();
335
0
        ScDrawView* pView = pTabView->GetScDrawView();
336
0
        ScViewData& rData = GetViewData();
337
0
        ScDocShell& pScDocSh = rData.GetDocShell();
338
0
        ScDocument& rScDoc = pScDocSh.GetDocument();
339
        // leave OLE inplace mode and unmark
340
0
        OSL_ASSERT( pView );
341
0
        DeactivateOle();
342
0
        pView->UnMarkAll();
343
344
0
        auto pUndoManager = rScDoc.GetUndoManager();
345
0
        if (pUndoManager->GetRedoActionCount())
346
0
        {
347
0
            pUndoManager->RemoveMark(nInsertWizardUndoMark);
348
0
        }
349
0
        else
350
0
        {
351
0
            pUndoManager->UndoMark(nInsertWizardUndoMark);
352
0
            pUndoManager->ClearRedo();
353
0
        }
354
355
        // leave the draw shell
356
0
        SetDrawShell( false );
357
358
        // reset marked cell area
359
0
        ScMarkData aMark = GetViewData().GetMarkData();
360
0
        GetViewData().GetViewShell()->SetMarkData(aMark);
361
0
    }
362
0
    else
363
0
    {
364
0
        OSL_ASSERT( pEvent->DialogResult == ui::dialogs::ExecutableDialogResults::OK );
365
        //@todo maybe move chart to different table
366
0
    }
367
0
}
368
369
void ScTabViewShell::ExecDrawIns(SfxRequest& rReq)
370
0
{
371
0
    sal_uInt16 nSlot = rReq.GetSlot();
372
0
    if (nSlot != SID_OBJECTRESIZE )
373
0
    {
374
0
        ScModule::get()->InputEnterHandler();
375
0
        UpdateInputHandler();
376
0
    }
377
378
    // insertion of border for Chart is cancelled:
379
0
    FuPoor* pPoor = GetDrawFuncPtr();
380
0
    if ( pPoor && pPoor->GetSlotID() == SID_DRAW_CHART )
381
0
        GetViewData().GetDispatcher().Execute(SID_DRAW_CHART, SfxCallMode::SLOT | SfxCallMode::RECORD);
382
383
0
    MakeDrawLayer();
384
385
0
    ScTabView*   pTabView  = GetViewData().GetView();
386
0
    vcl::Window*      pWin      = pTabView->GetActiveWin();
387
0
    ScDrawView*  pView     = pTabView->GetScDrawView();
388
0
    ScDocShell&  rDocSh    = GetViewData().GetDocShell();
389
0
    ScDocument&  rDoc      = rDocSh.GetDocument();
390
0
    SdrModel& rModel = pView->GetModel();
391
392
0
    switch ( nSlot )
393
0
    {
394
0
        case SID_INSERT_GRAPHIC:
395
0
            FuInsertGraphic(*this, pWin, pView, rModel, rReq);
396
            // shell is set in MarkListHasChanged
397
0
            break;
398
399
0
        case SID_INSERT_AVMEDIA:
400
0
            FuInsertMedia(*this, pWin, pView, rModel, rReq);
401
            // shell is set in MarkListHasChanged
402
0
            break;
403
404
0
        case SID_INSERT_DIAGRAM:
405
0
            FuInsertChart(*this, pWin, pView, rModel, rReq, LINK( this, ScTabViewShell, DialogClosedHdl ));
406
0
            if (comphelper::LibreOfficeKit::isActive())
407
0
                rDocSh.SetModified();
408
0
            break;
409
410
0
        case SID_INSERT_OBJECT:
411
0
        case SID_INSERT_SMATH:
412
0
        case SID_INSERT_FLOATINGFRAME:
413
0
            FuInsertOLE(*this, pWin, pView, rModel, rReq);
414
0
            break;
415
416
0
        case SID_INSERT_SIGNATURELINE:
417
0
        case SID_EDIT_SIGNATURELINE:
418
0
            {
419
0
                const uno::Reference<frame::XModel> xModel( GetViewData().GetDocShell().GetBaseModel() );
420
421
0
                VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
422
0
                VclPtr<AbstractSignatureLineDialog> pDialog(pFact->CreateSignatureLineDialog(
423
0
                    pWin->GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_SIGNATURELINE));
424
0
                auto xRequest = std::make_shared<SfxRequest>(rReq);
425
0
                rReq.Ignore(); // the 'old' request is not relevant any more
426
0
                pDialog->StartExecuteAsync(
427
0
                    [pDialog, xRequest=std::move(xRequest)] (sal_Int32 nResult)->void
428
0
                    {
429
0
                        if (nResult == RET_OK)
430
0
                            pDialog->Apply();
431
0
                        pDialog->disposeOnce();
432
0
                        xRequest->Done();
433
0
                    }
434
0
                );
435
0
                break;
436
0
            }
437
438
0
        case SID_SIGN_SIGNATURELINE:
439
0
            {
440
0
                const uno::Reference<frame::XModel> xModel(
441
0
                    GetViewData().GetDocShell().GetBaseModel());
442
443
0
                VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
444
0
                VclPtr<AbstractSignSignatureLineDialog> pDialog(
445
0
                    pFact->CreateSignSignatureLineDialog(GetFrameWeld(), xModel));
446
0
                pDialog->StartExecuteAsync(
447
0
                    [pDialog] (sal_Int32 nResult)->void
448
0
                    {
449
0
                        if (nResult == RET_OK)
450
0
                            pDialog->Apply();
451
0
                        pDialog->disposeOnce();
452
0
                    }
453
0
                );
454
0
                break;
455
0
            }
456
457
0
        case SID_INSERT_QRCODE:
458
0
        case SID_EDIT_QRCODE:
459
0
            {
460
0
                const uno::Reference<frame::XModel> xModel( GetViewData().GetDocShell().GetBaseModel() );
461
462
0
                VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
463
0
                ScopedVclPtr<AbstractQrCodeGenDialog> pDialog(pFact->CreateQrCodeGenDialog(
464
0
                    pWin->GetFrameWeld(), xModel, rReq.GetSlot() == SID_EDIT_QRCODE));
465
0
                pDialog->Execute();
466
0
                break;
467
0
            }
468
469
0
            case SID_OBJECTRESIZE:
470
0
            {
471
                //         the server would like to change the client size
472
473
0
                SfxInPlaceClient* pClient = GetIPClient();
474
475
0
                if ( pClient && pClient->IsObjectInPlaceActive() )
476
0
                {
477
0
                    const SfxRectangleItem& rRect = rReq.GetArgs()->Get(SID_OBJECTRESIZE);
478
0
                    tools::Rectangle aRect( pWin->PixelToLogic( rRect.GetValue() ) );
479
480
0
                    const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
481
0
                    if ( rMarkList.GetMarkCount() != 0 )
482
0
                    {
483
0
                        if (rMarkList.GetMarkCount() == 1)
484
0
                        {
485
0
                            SdrMark* pMark = rMarkList.GetMark(0);
486
0
                            SdrObject* pObj = pMark->GetMarkedSdrObj();
487
488
0
                            SdrObjKind nSdrObjKind = pObj->GetObjIdentifier();
489
490
0
                            if (nSdrObjKind == SdrObjKind::OLE2)
491
0
                            {
492
0
                                if ( static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
493
0
                                {
494
0
                                    pObj->SetLogicRect(aRect);
495
0
                                }
496
0
                            }
497
0
                        }
498
0
                    }
499
0
                }
500
0
            }
501
0
            break;
502
503
0
        case SID_LINKS:
504
0
            {
505
0
                SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
506
0
                if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
507
0
                {
508
0
                    std::unique_ptr<weld::MessageDialog> xError(Application::CreateMessageDialog(
509
0
                        nullptr, VclMessageType::Warning, VclButtonsType::Ok,
510
0
                        SvtResId(STR_WARNING_EXTERNAL_LINK_EDIT_DISABLED)));
511
0
                    xError->run();
512
0
                    break;
513
0
                }
514
515
0
                VclPtr<SfxAbstractLinksDialog> pDlg(pFact->CreateLinksDialog(pWin->GetFrameWeld(), rDoc.GetLinkManager()));
516
0
                auto xRequest = std::make_shared<SfxRequest>(rReq);
517
0
                rReq.Ignore(); // the 'old' request is not relevant any more
518
0
                pDlg->StartExecuteAsync(
519
0
                    [this, pDlg, xRequest=std::move(xRequest)] (sal_Int32 /*nResult*/)->void
520
0
                    {
521
0
                        GetViewFrame().GetBindings().Invalidate( SID_LINKS );
522
0
                        SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) );     // Navigator
523
0
                        pDlg->disposeOnce();
524
0
                        xRequest->Done();
525
0
                    }
526
0
                );
527
0
            }
528
0
            break;
529
530
0
        case SID_FM_CREATE_FIELDCONTROL:
531
0
            {
532
0
                const SfxUnoAnyItem* pDescriptorItem = rReq.GetArg<SfxUnoAnyItem>(SID_FM_DATACCESS_DESCRIPTOR);
533
0
                OSL_ENSURE( pDescriptorItem, "SID_FM_CREATE_FIELDCONTROL: invalid request args!" );
534
535
0
                if(pDescriptorItem)
536
0
                {
537
                    //! merge with ScViewFunc::PasteDataFormat (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE)?
538
539
0
                    ScDrawView* pDrView = GetScDrawView();
540
0
                    SdrPageView* pPageView = pDrView ? pDrView->GetSdrPageView() : nullptr;
541
0
                    if(pPageView)
542
0
                    {
543
0
                        svx::ODataAccessDescriptor aDescriptor(pDescriptorItem->GetValue());
544
0
                        rtl::Reference<SdrObject> pNewDBField = pDrView->CreateFieldControl(aDescriptor);
545
546
0
                        if(pNewDBField)
547
0
                        {
548
0
                            tools::Rectangle aVisArea = pWin->PixelToLogic(tools::Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
549
0
                            Point aObjPos(aVisArea.Center());
550
0
                            Size aObjSize(pNewDBField->GetLogicRect().GetSize());
551
0
                            aObjPos.AdjustX( -(aObjSize.Width() / 2) );
552
0
                            aObjPos.AdjustY( -(aObjSize.Height() / 2) );
553
0
                            tools::Rectangle aNewObjectRectangle(aObjPos, aObjSize);
554
555
0
                            pNewDBField->SetLogicRect(aNewObjectRectangle);
556
557
                            // controls must be on control layer, groups on front layer
558
0
                            if ( dynamic_cast<const SdrUnoObj*>( pNewDBField.get() ) !=  nullptr )
559
0
                                pNewDBField->NbcSetLayer(SC_LAYER_CONTROLS);
560
0
                            else
561
0
                                pNewDBField->NbcSetLayer(SC_LAYER_FRONT);
562
0
                            if (dynamic_cast<const SdrObjGroup*>( pNewDBField.get() ) !=  nullptr)
563
0
                            {
564
0
                                SdrObjListIter aIter( *pNewDBField, SdrIterMode::DeepWithGroups );
565
0
                                SdrObject* pSubObj = aIter.Next();
566
0
                                while (pSubObj)
567
0
                                {
568
0
                                    if ( dynamic_cast<const SdrUnoObj*>( pSubObj) !=  nullptr )
569
0
                                        pSubObj->NbcSetLayer(SC_LAYER_CONTROLS);
570
0
                                    else
571
0
                                        pSubObj->NbcSetLayer(SC_LAYER_FRONT);
572
0
                                    pSubObj = aIter.Next();
573
0
                                }
574
0
                            }
575
576
0
                            pView->InsertObjectAtView(pNewDBField.get(), *pPageView);
577
0
                        }
578
0
                    }
579
0
                }
580
0
                rReq.Done();
581
0
            }
582
0
            break;
583
584
0
        case SID_FONTWORK_GALLERY_FLOATER:
585
0
            svx::FontworkBar::execute(*pView, rReq, GetViewFrame().GetBindings());
586
0
            rReq.Ignore();
587
0
            break;
588
0
    }
589
0
}
590
591
void ScTabViewShell::GetDrawInsState(SfxItemSet &rSet)
592
0
{
593
0
    bool bOle = GetViewFrame().GetFrame().IsInPlace();
594
0
    bool bTabProt = GetViewData().GetDocument().IsTabProtected(GetViewData().GetTabNo());
595
0
    ScDocShell& rDocShell = GetViewData().GetDocShell();
596
0
    bool bShared = rDocShell.IsDocShared();
597
0
    SdrView* pSdrView = GetScDrawView();
598
599
0
    SfxWhichIter aIter(rSet);
600
0
    sal_uInt16 nWhich = aIter.FirstWhich();
601
0
    while ( nWhich )
602
0
    {
603
0
        switch ( nWhich )
604
0
        {
605
0
            case SID_INSERT_DIAGRAM:
606
0
                if ( bOle || bTabProt || !SvtModuleOptions().IsChartInstalled() || bShared )
607
0
                    rSet.DisableItem( nWhich );
608
0
                break;
609
610
0
            case SID_INSERT_SMATH:
611
0
                if ( bOle || bTabProt || !SvtModuleOptions().IsMathInstalled() || bShared )
612
0
                    rSet.DisableItem( nWhich );
613
0
                break;
614
615
0
            case SID_INSERT_OBJECT:
616
0
            case SID_INSERT_FLOATINGFRAME:
617
0
                if ( bOle || bTabProt || bShared )
618
0
                    rSet.DisableItem( nWhich );
619
0
                break;
620
621
0
            case SID_INSERT_AVMEDIA:
622
0
            case SID_FONTWORK_GALLERY_FLOATER:
623
0
                if ( bTabProt || bShared )
624
0
                    rSet.DisableItem( nWhich );
625
0
                break;
626
627
0
            case SID_INSERT_SIGNATURELINE:
628
0
            case SID_INSERT_QRCODE:
629
0
                if ( bTabProt || bShared || (pSdrView && pSdrView->GetMarkedObjectList().GetMarkCount() != 0))
630
0
                    rSet.DisableItem( nWhich );
631
0
                break;
632
0
            case SID_EDIT_SIGNATURELINE:
633
0
            case SID_SIGN_SIGNATURELINE:
634
0
                if (!IsSignatureLineSelected() || IsSignatureLineSigned())
635
0
                    rSet.DisableItem(nWhich);
636
0
                break;
637
638
0
            case SID_EDIT_QRCODE:
639
0
                if (!IsQRCodeSelected())
640
0
                    rSet.DisableItem(nWhich);
641
0
                break;
642
643
0
            case SID_INSERT_GRAPHIC:
644
0
                if (bTabProt || bShared)
645
0
                {
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
0
                    bool bDisableInsertImage = true;
649
0
                    ScMarkData& rMark = GetViewData().GetMarkData();
650
0
                    if (!rMark.GetMarkedRanges().empty() && GetViewData().GetDocument().IsSelectionEditable(rMark))
651
0
                        bDisableInsertImage = false;
652
0
                    else
653
0
                    {
654
0
                        if (GetViewData().GetDocument().IsBlockEditable
655
0
                            (GetViewData().GetTabNo(), GetViewData().GetCurX(), GetViewData().GetCurY(), GetViewData().GetCurX(), GetViewData().GetCurY()))
656
0
                        {
657
0
                            bDisableInsertImage = false;
658
0
                        }
659
0
                    }
660
661
0
                    if (bDisableInsertImage)
662
0
                        rSet.DisableItem(nWhich);
663
0
                }
664
0
                break;
665
666
0
            case SID_LINKS:
667
0
                {
668
0
                    if (GetViewData().GetDocument().GetLinkManager()->GetLinks().empty())
669
0
                        rSet.DisableItem( SID_LINKS );
670
0
                }
671
0
                break;
672
0
        }
673
0
        nWhich = aIter.NextWhich();
674
0
    }
675
0
}
676
677
bool ScTabViewShell::IsSignatureLineSelected()
678
0
{
679
0
    SdrView* pSdrView = GetScDrawView();
680
0
    if (!pSdrView)
681
0
        return false;
682
683
0
    const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
684
0
    if (rMarkList.GetMarkCount() != 1)
685
0
        return false;
686
687
0
    SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
688
0
    if (!pPickObj)
689
0
        return false;
690
691
0
    SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
692
0
    if (!pGraphic)
693
0
        return false;
694
695
0
    return pGraphic->isSignatureLine();
696
0
}
697
698
bool ScTabViewShell::IsQRCodeSelected()
699
0
{
700
0
    SdrView* pSdrView = GetScDrawView();
701
0
    if (!pSdrView)
702
0
        return false;
703
704
0
    const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
705
0
    if (rMarkList.GetMarkCount() != 1)
706
0
        return false;
707
708
0
    SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
709
0
    if (!pPickObj)
710
0
        return false;
711
712
0
    SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
713
0
    if (!pGraphic)
714
0
        return false;
715
716
0
    if(pGraphic->getQrCode())
717
0
    {
718
0
        return true;
719
0
    }
720
0
    else{
721
0
        return false;
722
0
    }
723
0
}
724
725
bool ScTabViewShell::IsSignatureLineSigned()
726
0
{
727
0
    SdrView* pSdrView = GetScDrawView();
728
0
    if (!pSdrView)
729
0
        return false;
730
731
0
    const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
732
0
    if (rMarkList.GetMarkCount() != 1)
733
0
        return false;
734
735
0
    SdrObject* pPickObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
736
0
    if (!pPickObj)
737
0
        return false;
738
739
0
    SdrGrafObj* pGraphic = dynamic_cast<SdrGrafObj*>(pPickObj);
740
0
    if (!pGraphic)
741
0
        return false;
742
743
0
    return pGraphic->isSignatureLineSigned();
744
0
}
745
746
void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
747
0
{
748
0
    SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
749
0
    if (!pSh)
750
0
        return;
751
752
0
    ScUndoManager* pUndoManager = static_cast<ScUndoManager*>(pSh->GetUndoManager());
753
754
0
    const SfxItemSet* pReqArgs = rReq.GetArgs();
755
0
    ScDocShell& rDocSh = GetViewData().GetDocShell();
756
757
0
    sal_uInt16 nSlot = rReq.GetSlot();
758
0
    switch ( nSlot )
759
0
    {
760
0
        case SID_UNDO:
761
0
        case SID_REDO:
762
0
            if ( pUndoManager )
763
0
            {
764
0
                bool bIsUndo = ( nSlot == SID_UNDO );
765
766
0
                sal_uInt16 nCount = 1;
767
0
                const SfxPoolItem* pItem;
768
0
                if ( pReqArgs && pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
769
0
                    nCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
770
771
                // Repair mode: allow undo/redo of all undo actions, even if access would
772
                // be limited based on the view shell ID.
773
0
                bool bRepair = false;
774
0
                if (pReqArgs && pReqArgs->GetItemState(SID_REPAIRPACKAGE, false, &pItem) == SfxItemState::SET)
775
0
                    bRepair = static_cast<const SfxBoolItem*>(pItem)->GetValue();
776
777
0
                sal_uInt16 nUndoOffset = 0;
778
0
                if (comphelper::LibreOfficeKit::isActive() && !bRepair)
779
0
                {
780
0
                    SfxUndoAction* pAction = nullptr;
781
0
                    if (bIsUndo)
782
0
                    {
783
0
                        if (pUndoManager->GetUndoActionCount() != 0)
784
0
                            pAction = pUndoManager->GetUndoAction();
785
0
                    }
786
0
                    else
787
0
                    {
788
0
                        if (pUndoManager->GetRedoActionCount() != 0)
789
0
                            pAction = pUndoManager->GetRedoAction();
790
0
                    }
791
0
                    if (pAction)
792
0
                    {
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
0
                        ViewShellId nViewShellId = GetViewShellId();
796
0
                        if (pAction->GetViewShellId() != nViewShellId)
797
0
                        {
798
0
                            sal_uInt16 nOffset = 0;
799
0
                            if (pUndoManager->IsViewUndoActionIndependent(this, nOffset))
800
0
                            {
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
0
                                nUndoOffset += nOffset;
804
0
                            }
805
0
                            else
806
0
                            {
807
0
                                rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
808
0
                                return;
809
0
                            }
810
0
                        }
811
0
                    }
812
0
                }
813
814
                // lock paint for more than one cell undo action (not for editing within a cell)
815
0
                bool bLockPaint = ( nCount > 1 && pUndoManager == GetUndoManager() );
816
0
                if ( bLockPaint )
817
0
                    rDocSh.LockPaint();
818
819
0
                try
820
0
                {
821
0
                    ScUndoRedoContext aUndoRedoContext;
822
0
                    aUndoRedoContext.SetUndoOffset(nUndoOffset);
823
824
0
                    for (sal_uInt16 i=0; i<nCount; i++)
825
0
                    {
826
0
                        if ( bIsUndo )
827
0
                            pUndoManager->UndoWithContext(aUndoRedoContext);
828
0
                        else
829
0
                            pUndoManager->RedoWithContext(aUndoRedoContext);
830
0
                    }
831
0
                }
832
0
                catch ( const uno::Exception& )
833
0
                {
834
                    // no need to handle. By definition, the UndoManager handled this by clearing the
835
                    // Undo/Redo stacks
836
0
                }
837
838
0
                if ( bLockPaint )
839
0
                    rDocSh.UnlockPaint();
840
841
0
                GetViewFrame().GetBindings().InvalidateAll(false);
842
0
            }
843
0
            break;
844
//      default:
845
//          GetViewFrame().ExecuteSlot( rReq );
846
0
    }
847
0
}
848
849
void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
850
0
{
851
0
    SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
852
0
    if (!pSh)
853
0
        return;
854
855
0
    SfxUndoManager* pUndoManager = pSh->GetUndoManager();
856
0
    ScUndoManager* pScUndoManager = dynamic_cast<ScUndoManager*>(pUndoManager);
857
858
0
    SfxWhichIter aIter(rSet);
859
0
    sal_uInt16 nWhich = aIter.FirstWhich();
860
0
    while ( nWhich )
861
0
    {
862
0
        switch (nWhich)
863
0
        {
864
0
            case SID_GETUNDOSTRINGS:
865
0
            case SID_GETREDOSTRINGS:
866
0
                {
867
0
                    SfxStringListItem aStrLst( nWhich );
868
0
                    if ( pUndoManager )
869
0
                    {
870
0
                        std::vector<OUString> &aList = aStrLst.GetList();
871
0
                        bool bIsUndo = ( nWhich == SID_GETUNDOSTRINGS );
872
0
                        size_t nCount = bIsUndo ? pUndoManager->GetUndoActionCount() : pUndoManager->GetRedoActionCount();
873
0
                        for (size_t i=0; i<nCount; ++i)
874
0
                        {
875
0
                            aList.push_back( bIsUndo ? pUndoManager->GetUndoActionComment(i) :
876
0
                                                       pUndoManager->GetRedoActionComment(i) );
877
0
                        }
878
0
                    }
879
0
                    rSet.Put( aStrLst );
880
0
                }
881
0
                break;
882
883
0
            case SID_UNDO:
884
0
            {
885
0
                if (pScUndoManager)
886
0
                {
887
0
                    if (pScUndoManager->GetUndoActionCount())
888
0
                    {
889
0
                        const SfxUndoAction* pAction = pScUndoManager->GetUndoAction();
890
0
                        SfxViewShell *pViewSh = GetViewShell();
891
0
                        if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId()
892
0
                            && !pScUndoManager->IsViewUndoActionIndependent(this, o3tl::temporary(sal_uInt16())))
893
0
                        {
894
0
                            rSet.Put(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
895
0
                        }
896
0
                        else
897
0
                        {
898
0
                            rSet.Put( SfxStringItem( SID_UNDO, SvtResId(STR_UNDO)+pScUndoManager->GetUndoActionComment() ) );
899
0
                        }
900
0
                    }
901
0
                    else
902
0
                        rSet.DisableItem( SID_UNDO );
903
0
                }
904
0
                else
905
                    // get state from sfx view frame
906
0
                    GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
907
0
                break;
908
0
            }
909
0
            case SID_REDO:
910
0
            {
911
0
                if (pScUndoManager)
912
0
                {
913
0
                    if (pScUndoManager->GetRedoActionCount())
914
0
                    {
915
0
                        const SfxUndoAction* pAction = pScUndoManager->GetRedoAction();
916
0
                        SfxViewShell *pViewSh = GetViewShell();
917
0
                        if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId())
918
0
                        {
919
0
                            rSet.Put(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
920
0
                        }
921
0
                        else
922
0
                        {
923
0
                            rSet.Put(SfxStringItem(SID_REDO, SvtResId(STR_REDO) + pScUndoManager->GetRedoActionComment()));
924
0
                        }
925
0
                    }
926
0
                    else
927
0
                        rSet.DisableItem( SID_REDO );
928
0
                }
929
0
                else
930
                    // get state from sfx view frame
931
0
                    GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
932
0
                break;
933
0
            }
934
0
            default:
935
                // get state from sfx view frame
936
0
                GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
937
0
        }
938
939
0
        nWhich = aIter.NextWhich();
940
0
    }
941
0
}
942
943
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */