Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/uiview/view.cxx
Line
Count
Source
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 <sal/config.h>
21
22
#include <string_view>
23
24
#include <config_features.h>
25
#include <config_wasm_strip.h>
26
27
#include <stdlib.h>
28
#include <hintids.hxx>
29
#include <comphelper/diagnose_ex.hxx>
30
#include <comphelper/string.hxx>
31
#include <comphelper/lok.hxx>
32
#include <o3tl/any.hxx>
33
#include <o3tl/string_view.hxx>
34
#include <officecfg/Office/Common.hxx>
35
#include <vcl/graph.hxx>
36
#include <vcl/inputctx.hxx>
37
#include <svl/eitem.hxx>
38
#include <unotools/configmgr.hxx>
39
#include <unotools/lingucfg.hxx>
40
#include <unotools/useroptions.hxx>
41
#include <sfx2/dispatch.hxx>
42
#include <sfx2/docfile.hxx>
43
#include <sfx2/objface.hxx>
44
#include <sfx2/request.hxx>
45
#include <svx/ruler.hxx>
46
#include <svx/srchdlg.hxx>
47
#include <svx/fmshell.hxx>
48
#include <svx/extrusionbar.hxx>
49
#include <svx/fontworkbar.hxx>
50
#include <svx/fmview.hxx>
51
#include <unotxvw.hxx>
52
#include <cmdid.h>
53
#include <svl/hint.hxx>
54
#include <swmodule.hxx>
55
#include <inputwin.hxx>
56
#include <uivwimp.hxx>
57
#include <edtwin.hxx>
58
#include <textsh.hxx>
59
#include <listsh.hxx>
60
#include <tabsh.hxx>
61
#include <grfsh.hxx>
62
#include <mediash.hxx>
63
#include <docsh.hxx>
64
#include <frmsh.hxx>
65
#include <olesh.hxx>
66
#include <drawsh.hxx>
67
#include <drawbase.hxx>
68
#include <drformsh.hxx>
69
#include <drwtxtsh.hxx>
70
#include <beziersh.hxx>
71
#include <navsh.hxx>
72
#include <globdoc.hxx>
73
#include <scroll.hxx>
74
#include <gloshdl.hxx>
75
#include <usrpref.hxx>
76
#include <srcview.hxx>
77
#include <doc.hxx>
78
#include <IDocumentUndoRedo.hxx>
79
#include <IDocumentSettingAccess.hxx>
80
#include <IDocumentDrawModelAccess.hxx>
81
#include <DocumentFieldsManager.hxx>
82
#include <IDocumentState.hxx>
83
#include <IDocumentLayoutAccess.hxx>
84
#include <drawdoc.hxx>
85
#include <wdocsh.hxx>
86
#include <wrtsh.hxx>
87
#include <barcfg.hxx>
88
#include <pview.hxx>
89
#include <swdtflvr.hxx>
90
#include <prtopt.hxx>
91
#include <unotxdoc.hxx>
92
#include <com/sun/star/frame/FrameSearchFlag.hpp>
93
#include <com/sun/star/frame/XLayoutManager.hpp>
94
#include <com/sun/star/scanner/ScannerContext.hpp>
95
#include <com/sun/star/scanner/XScannerManager2.hpp>
96
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
97
#include <com/sun/star/sdb/XDatabaseContext.hpp>
98
#include <com/sun/star/sdb/DatabaseContext.hpp>
99
#include <toolkit/helper/vclunohelper.hxx>
100
#include <sal/log.hxx>
101
102
#include <formatclipboard.hxx>
103
#include <PostItMgr.hxx>
104
#include <annotsh.hxx>
105
#include <swruler.hxx>
106
#include <svx/theme/ThemeColorChangerCommon.hxx>
107
#include <com/sun/star/document/XDocumentProperties.hpp>
108
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
109
110
#include <comphelper/propertyvalue.hxx>
111
#include <comphelper/servicehelper.hxx>
112
#include <framework/windowstatehelper.hxx>
113
#include <sfx2/lokhelper.hxx>
114
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
115
#include <svtools/embedhlp.hxx>
116
#include <tools/UnitConversion.hxx>
117
118
#include <svx/sdr/overlay/overlayselection.hxx>
119
#include <svx/sdr/overlay/overlayobject.hxx>
120
#include <svx/sdr/overlay/overlaymanager.hxx>
121
#include <svx/sdrpaintwindow.hxx>
122
#include <svx/svdview.hxx>
123
#include <node2lay.hxx>
124
#include <cntfrm.hxx>
125
#include <IDocumentRedlineAccess.hxx>
126
127
using namespace ::com::sun::star;
128
using namespace ::com::sun::star::uno;
129
using namespace ::com::sun::star::lang;
130
using namespace ::com::sun::star::scanner;
131
using namespace ::com::sun::star::sdb;
132
133
4.02k
#define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS
134
135
// Statics. OMG.
136
137
bool bDocSzUpdated = true;
138
139
SvxSearchItem*  SwView::s_pSrchItem   = nullptr;
140
141
bool            SwView::s_bExtra      = false;
142
bool            SwView::s_bFound      = false;
143
bool            SwView::s_bJustOpened = false;
144
145
std::unique_ptr<SearchAttrItemList>  SwView::s_xSearchList;
146
std::unique_ptr<SearchAttrItemList>  SwView::s_xReplaceList;
147
148
SfxDispatcher &SwView::GetDispatcher()
149
25.9k
{
150
25.9k
    return *GetViewFrame().GetDispatcher();
151
25.9k
}
152
153
void SwView::ImpSetVerb( SelectionType nSelType )
154
4.02k
{
155
4.02k
    Sequence<embed::VerbDescriptor> newVerbs;
156
4.02k
    if ( !GetViewFrame().GetFrame().IsInPlace() &&
157
4.02k
         (SelectionType::Ole|SelectionType::Graphic) & nSelType )
158
0
    {
159
0
        FlyProtectFlags eProtectFlags = m_pWrtShell->IsSelObjProtected(FlyProtectFlags::Content);
160
0
        if (eProtectFlags == FlyProtectFlags::NONE || nSelType & SelectionType::Ole)
161
0
        {
162
0
            if ( nSelType & SelectionType::Ole )
163
0
            {
164
0
                try
165
0
                {
166
0
                    newVerbs = GetWrtShell().GetOLEObject()->getSupportedVerbs();
167
0
                }
168
0
                catch (css::uno::Exception&)
169
0
                {
170
0
                    DBG_UNHANDLED_EXCEPTION("sw.ui", "Failed to retrieve supported verbs");
171
0
                }
172
0
            }
173
0
        }
174
0
    }
175
4.02k
    if (m_bVerbsActive || newVerbs.hasElements())
176
0
    {
177
0
        SetVerbs(newVerbs);
178
0
        m_bVerbsActive = newVerbs.hasElements();
179
0
    }
180
4.02k
}
181
182
// Called by the SwEditWin when it gets the focus.
183
184
void SwView::GotFocus() const
185
0
{
186
    // if we got the focus, and the form shell *is* on the top of the dispatcher
187
    // stack, then we need to rebuild the stack (the form shell doesn't belong to
188
    // the top then)
189
0
    const SfxDispatcher& rDispatcher = const_cast< SwView* >( this )->GetDispatcher();
190
0
    SfxShell* pTopShell = rDispatcher.GetShell( 0 );
191
0
    FmFormShell* pAsFormShell = dynamic_cast<FmFormShell*>( pTopShell  );
192
0
    if ( pAsFormShell )
193
0
    {
194
0
        pAsFormShell->ForgetActiveControl();
195
0
        const_cast< SwView* >( this )->AttrChangedNotify(nullptr);
196
0
    }
197
0
    else if ( m_pPostItMgr )
198
0
    {
199
0
        SwAnnotationShell* pAsAnnotationShell = dynamic_cast<SwAnnotationShell*>( pTopShell  );
200
0
        if ( pAsAnnotationShell )
201
0
        {
202
0
            m_pPostItMgr->SetActiveSidebarWin(nullptr);
203
0
            const_cast< SwView* >( this )->AttrChangedNotify(nullptr);
204
0
        }
205
0
    }
206
0
    if (SwWrtShell* pWrtShell = GetWrtShellPtr())
207
0
    {
208
0
        SwWrtShell& rWrtShell = GetWrtShell();
209
0
        rWrtShell.GetDoc()->getIDocumentLayoutAccess().SetCurrentViewShell( pWrtShell );
210
0
        rWrtShell.GetDoc()->getIDocumentSettingAccess().set( DocumentSettingId::BROWSE_MODE,
211
0
                                 rWrtShell.GetViewOptions()->getBrowseMode() &&
212
0
                                 !rWrtShell.GetViewOptions()->getDraftView() );
213
0
    }
214
0
}
215
216
// called by the FormShell when a form control is focused. This is
217
// a request to put the form shell on the top of the dispatcher stack
218
219
IMPL_LINK_NOARG(SwView, FormControlActivated, LinkParamNone*, void)
220
0
{
221
    // if a form control has been activated, and the form shell is not on the top
222
    // of the dispatcher stack, then we need to activate it
223
0
    const SfxDispatcher& rDispatcher = GetDispatcher();
224
0
    const SfxShell* pTopShell = rDispatcher.GetShell( 0 );
225
0
    const FmFormShell* pAsFormShell = dynamic_cast<const FmFormShell*>( pTopShell  );
226
0
    if ( !pAsFormShell )
227
0
    {
228
        // if we're editing text currently, cancel this
229
0
        SdrView *pSdrView = m_pWrtShell ? m_pWrtShell->GetDrawView() : nullptr;
230
0
        if ( pSdrView && pSdrView->IsTextEdit() )
231
0
            pSdrView->SdrEndTextEdit( true );
232
233
0
        AttrChangedNotify(nullptr);
234
0
    }
235
0
}
236
237
namespace
238
{
239
uno::Reference<frame::XLayoutManager> getLayoutManager(const SfxViewFrame& rViewFrame)
240
0
{
241
0
    uno::Reference<frame::XLayoutManager> xLayoutManager;
242
0
    uno::Reference<beans::XPropertySet> xPropSet(rViewFrame.GetFrame().GetFrameInterface(),
243
0
                                                 uno::UNO_QUERY);
244
0
    if (xPropSet.is())
245
0
    {
246
0
        try
247
0
        {
248
0
            xLayoutManager.set(xPropSet->getPropertyValue(u"LayoutManager"_ustr), uno::UNO_QUERY);
249
0
        }
250
0
        catch (const Exception& e)
251
0
        {
252
0
            SAL_WARN("sw.ui", "Failure getting layout manager: " + e.Message);
253
0
        }
254
0
    }
255
0
    return xLayoutManager;
256
0
}
257
}
258
259
void SwView::SetUIElementVisibility(const OUString& sElementURL, bool bShow) const
260
0
{
261
0
    if (auto xLayoutManager = getLayoutManager(GetViewFrame()))
262
0
    {
263
0
        if (!xLayoutManager->getElement(sElementURL).is())
264
0
            xLayoutManager->createElement(sElementURL);
265
266
0
        if (bShow)
267
0
            xLayoutManager->showElement(sElementURL);
268
0
        else
269
0
            xLayoutManager->hideElement(sElementURL);
270
0
    }
271
0
}
272
273
void SwView::ShowUIElement(const OUString& sElementURL) const
274
0
{
275
0
    SetUIElementVisibility(sElementURL, true);
276
0
}
277
278
void SwView::HideUIElement(const OUString& sElementURL) const
279
0
{
280
0
    SetUIElementVisibility(sElementURL, false);
281
0
}
282
283
void SwView::SelectShell()
284
14.9k
{
285
    // Attention: Maintain the SelectShell for the WebView additionally
286
287
    // In case of m_bDying, our SfxShells are already gone, don't try to select a shell at all.
288
14.9k
    if(m_bInDtor || m_bDying)
289
0
        return;
290
291
    // Decision if the UpdateTable has to be called
292
14.9k
    bool bUpdateTable = false;
293
14.9k
    const SwFrameFormat* pCurTableFormat = m_pWrtShell->GetTableFormat();
294
14.9k
    if(pCurTableFormat && pCurTableFormat != m_pLastTableFormat)
295
16
    {
296
16
        bUpdateTable = true; // can only be executed later
297
16
    }
298
14.9k
    m_pLastTableFormat = pCurTableFormat;
299
300
    //SEL_TBL and SEL_TBL_CELLS can be ORed!
301
14.9k
    SelectionType nNewSelectionType = m_pWrtShell->GetSelectionType()
302
14.9k
                                & ~SelectionType::TableCell;
303
304
    // Determine if a different fly frame was selected.
305
14.9k
    bool bUpdateFly = false;
306
14.9k
    const SwFrameFormat* pCurFlyFormat = nullptr;
307
14.9k
    if (m_nSelectionType & SelectionType::Ole || m_nSelectionType & SelectionType::Graphic)
308
4.02k
    {
309
4.02k
        pCurFlyFormat = m_pWrtShell->GetFlyFrameFormat();
310
4.02k
    }
311
14.9k
    if (pCurFlyFormat && pCurFlyFormat != m_pLastFlyFormat)
312
0
    {
313
0
        bUpdateFly = true;
314
0
    }
315
14.9k
    m_pLastFlyFormat = pCurFlyFormat;
316
317
14.9k
    if ( m_pFormShell && m_pFormShell->IsActiveControl() )
318
0
        nNewSelectionType |= SelectionType::FormControl;
319
320
14.9k
    if ( nNewSelectionType == m_nSelectionType &&
321
10.9k
        !(m_nSelectionType == SelectionType::Ole && m_pWrtShell->IsOLEMath()) )
322
10.9k
    {
323
10.9k
        GetViewFrame().GetBindings().InvalidateAll( false );
324
10.9k
        if ( m_nSelectionType & SelectionType::Ole ||
325
10.9k
             m_nSelectionType & SelectionType::Graphic )
326
            // For graphs and OLE the verb can be modified of course!
327
0
            ImpSetVerb( nNewSelectionType );
328
329
10.9k
        if (bUpdateFly)
330
0
        {
331
0
            SfxViewFrame& rViewFrame = GetViewFrame();
332
0
            uno::Reference<frame::XFrame> xFrame = rViewFrame.GetFrame().GetFrameInterface();
333
0
            if (xFrame.is())
334
0
            {
335
                // Invalidate cached dispatch objects.
336
0
                xFrame->contextChanged();
337
0
            }
338
0
        }
339
10.9k
    }
340
4.02k
    else
341
4.02k
    {
342
343
4.02k
        SfxDispatcher &rDispatcher = GetDispatcher();
344
4.02k
        SwToolbarConfigItem* pBarCfg = SwModule::get()->GetToolbarConfig();
345
346
4.02k
        if ( m_pShell )
347
6
        {
348
6
            rDispatcher.Flush();        // Really erase all cached shells
349
            //Remember to the old selection which toolbar was visible
350
6
            ToolbarId eId = rDispatcher.GetObjectBarId(SFX_OBJECTBAR_OBJECT);
351
6
            if (eId != ToolbarId::None)
352
6
                pBarCfg->SetTopToolbar(m_nSelectionType, eId);
353
354
27
            for ( sal_uInt16 i = 0; true; ++i )
355
27
            {
356
27
                SfxShell *pSfxShell = rDispatcher.GetShell( i );
357
27
                if  (  dynamic_cast< const SwBaseShell *>( pSfxShell ) !=  nullptr
358
12
                    || dynamic_cast< const SwDrawTextShell *>( pSfxShell ) !=  nullptr
359
12
                    || dynamic_cast< const svx::ExtrusionBar*>( pSfxShell ) !=  nullptr
360
12
                    || dynamic_cast< const svx::FontworkBar*>( pSfxShell ) !=  nullptr
361
12
                    || dynamic_cast< const SwAnnotationShell *>( pSfxShell ) !=  nullptr
362
27
                    )
363
15
                {
364
15
                    rDispatcher.Pop( *pSfxShell, SfxDispatcherPopFlags::POP_DELETE );
365
15
                }
366
12
                else if ( dynamic_cast< const FmFormShell *>( pSfxShell ) !=  nullptr )
367
6
                {
368
6
                    rDispatcher.Pop( *pSfxShell );
369
6
                }
370
6
                else
371
6
                    break;
372
27
            }
373
6
        }
374
375
4.02k
        bool bInitFormShell = false;
376
4.02k
        if (!m_pFormShell)
377
4.02k
        {
378
4.02k
            bInitFormShell = true;
379
4.02k
            m_pFormShell = new FmFormShell( this );
380
4.02k
            m_pFormShell->SetControlActivationHandler( LINK( this, SwView, FormControlActivated ) );
381
4.02k
            StartListening(*m_pFormShell);
382
4.02k
        }
383
384
4.02k
        bool bSetExtInpCntxt = false;
385
4.02k
        m_nSelectionType = nNewSelectionType;
386
4.02k
        ShellMode eShellMode;
387
388
4.02k
        if ( !( m_nSelectionType & SelectionType::FormControl ) )
389
4.02k
            rDispatcher.Push( *m_pFormShell );
390
391
4.02k
        m_pShell = new SwNavigationShell( *this );
392
4.02k
        rDispatcher.Push( *m_pShell );
393
394
4.02k
        if ( m_nSelectionType & SelectionType::Ole )
395
0
        {
396
0
            eShellMode = ShellMode::Object;
397
0
            m_pShell = new SwOleShell( *this );
398
0
            rDispatcher.Push( *m_pShell );
399
0
        }
400
4.02k
        else if ( m_nSelectionType & SelectionType::Frame
401
4.02k
            || m_nSelectionType & SelectionType::Graphic)
402
0
        {
403
0
            eShellMode = ShellMode::Frame;
404
0
            m_pShell = new SwFrameShell( *this );
405
0
            rDispatcher.Push( *m_pShell );
406
0
            if(m_nSelectionType & SelectionType::Graphic )
407
0
            {
408
0
                eShellMode = ShellMode::Graphic;
409
0
                m_pShell = new SwGrfShell( *this );
410
0
                rDispatcher.Push( *m_pShell );
411
0
            }
412
0
        }
413
4.02k
        else if ( m_nSelectionType & SelectionType::DrawObject )
414
0
        {
415
0
            eShellMode = ShellMode::Draw;
416
0
            m_pShell = new SwDrawShell( *this );
417
0
            rDispatcher.Push( *m_pShell );
418
419
0
            if ( m_nSelectionType & SelectionType::Ornament )
420
0
            {
421
0
                eShellMode = ShellMode::Bezier;
422
0
                m_pShell = new SwBezierShell( *this );
423
0
                rDispatcher.Push( *m_pShell );
424
0
            }
425
0
#if HAVE_FEATURE_AVMEDIA
426
0
            else if( m_nSelectionType & SelectionType::Media )
427
0
            {
428
0
                eShellMode = ShellMode::Media;
429
0
                m_pShell = new SwMediaShell( *this );
430
0
                rDispatcher.Push( *m_pShell );
431
0
            }
432
0
#endif
433
0
            if (m_nSelectionType & SelectionType::ExtrudedCustomShape)
434
0
            {
435
0
                eShellMode = ShellMode::ExtrudedCustomShape;
436
0
                m_pShell = new svx::ExtrusionBar(this);
437
0
                rDispatcher.Push( *m_pShell );
438
0
            }
439
0
            if (m_nSelectionType & SelectionType::FontWork)
440
0
            {
441
0
                eShellMode = ShellMode::FontWork;
442
0
                m_pShell = new svx::FontworkBar(this);
443
0
                rDispatcher.Push( *m_pShell );
444
0
            }
445
0
        }
446
4.02k
        else if ( m_nSelectionType & SelectionType::DbForm )
447
0
        {
448
0
            eShellMode = ShellMode::DrawForm;
449
0
            m_pShell = new SwDrawFormShell( *this );
450
451
0
            rDispatcher.Push( *m_pShell );
452
0
        }
453
4.02k
        else if ( m_nSelectionType & SelectionType::DrawObjectEditMode )
454
0
        {
455
0
            bSetExtInpCntxt = true;
456
0
            eShellMode = ShellMode::DrawText;
457
0
            rDispatcher.Push( *(new SwBaseShell( *this )) );
458
0
            m_pShell = new SwDrawTextShell( *this );
459
0
            rDispatcher.Push( *m_pShell );
460
0
        }
461
4.02k
        else if ( m_nSelectionType & SelectionType::PostIt )
462
0
        {
463
0
            eShellMode = ShellMode::PostIt;
464
0
            m_pShell = new SwAnnotationShell( *this );
465
0
            rDispatcher.Push( *m_pShell );
466
0
        }
467
4.02k
        else
468
4.02k
        {
469
4.02k
            bSetExtInpCntxt = true;
470
4.02k
            eShellMode = ShellMode::Text;
471
4.02k
            if ( m_nSelectionType & SelectionType::NumberList )
472
7
            {
473
7
                eShellMode = ShellMode::ListText;
474
7
                m_pShell = new SwListShell( *this );
475
7
                rDispatcher.Push( *m_pShell );
476
7
            }
477
4.02k
            m_pShell = new SwTextShell(*this);
478
479
4.02k
            rDispatcher.Push( *m_pShell );
480
4.02k
            if ( m_nSelectionType & SelectionType::Table )
481
16
            {
482
16
                eShellMode = eShellMode == ShellMode::ListText ? ShellMode::TableListText
483
16
                                                        : ShellMode::TableText;
484
16
                m_pShell = new SwTableShell( *this );
485
16
                rDispatcher.Push( *m_pShell );
486
16
            }
487
4.02k
        }
488
489
4.02k
        if ( m_nSelectionType & SelectionType::FormControl )
490
0
            rDispatcher.Push( *m_pFormShell );
491
492
4.02k
        m_pViewImpl->SetShellMode(eShellMode);
493
4.02k
        ImpSetVerb( m_nSelectionType );
494
495
4.02k
        if( !GetDocShell()->IsReadOnly() )
496
4.02k
        {
497
4.02k
            if( bSetExtInpCntxt && GetWrtShell().HasReadonlySel() )
498
1
                bSetExtInpCntxt = false;
499
500
4.02k
            InputContext aCntxt( GetEditWin().GetInputContext() );
501
4.02k
            aCntxt.SetOptions( bSetExtInpCntxt
502
4.02k
                                ? (aCntxt.GetOptions() |
503
4.02k
                                        ( InputContextFlags::Text |
504
4.02k
                                            InputContextFlags::ExtText ))
505
4.02k
                                : (aCntxt.GetOptions() & ~
506
1
                                        InputContextFlags( InputContextFlags::Text |
507
1
                                            InputContextFlags::ExtText )) );
508
4.02k
            GetEditWin().SetInputContext( aCntxt );
509
4.02k
        }
510
511
        // Show Mail Merge toolbar initially for documents with Database fields
512
4.02k
        if (!m_bInitOnceCompleted && GetWrtShell().IsAnyDatabaseFieldInDoc() && !comphelper::IsFuzzing())
513
0
            ShowUIElement(u"private:resource/toolbar/mailmerge"_ustr);
514
515
        // Activate the toolbar to the new selection which also was active last time.
516
        // Before a flush () must be, but does not affect the UI according to MBA and
517
        // is not a performance problem.
518
        // TODO/LATER: maybe now the Flush() command is superfluous?!
519
4.02k
        rDispatcher.Flush();
520
521
4.02k
        Point aPnt = GetEditWin().OutputToScreenPixel(GetEditWin().GetPointerPosPixel());
522
4.02k
        aPnt = GetEditWin().PixelToLogic(aPnt);
523
4.02k
        GetEditWin().UpdatePointer(aPnt);
524
525
4.02k
        SdrView* pDView = GetWrtShell().GetDrawView();
526
4.02k
        if ( bInitFormShell && pDView )
527
4.02k
            m_pFormShell->SetView(dynamic_cast<FmFormView*>( pDView) );
528
529
4.02k
    }
530
    // Opportune time for the communication with OLE objects?
531
14.9k
    if ( GetDocShell()->GetDoc()->IsOLEPrtNotifyPending() )
532
103
        GetDocShell()->GetDoc()->PrtOLENotify( false );
533
534
    // now the table-update
535
14.9k
    if(bUpdateTable)
536
16
        m_pWrtShell->UpdateTable();
537
538
14.9k
    GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
539
540
14.9k
    m_bInitOnceCompleted = true;
541
14.9k
}
542
543
// Interaction: AttrChangedNotify() and TimeoutHdl.
544
// No Update if actions are still open, since the cursor on the core side
545
// can be somewhere in no man's land.
546
// But since we can no longer supply status and we want instead lock
547
// the dispatcher.
548
549
IMPL_LINK_NOARG(SwView, AttrChangedNotify, LinkParamNone*, void)
550
11.0k
{
551
11.0k
    if ( GetEditWin().IsChainMode() )
552
0
        GetEditWin().SetChainMode( false );
553
554
11.0k
    if (!m_pWrtShell || !GetDocShell())
555
0
    {
556
0
        return;
557
0
    }
558
559
    //Opt: Not if PaintLocked. During unlock a notify will be once more triggered.
560
11.0k
    if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt &&
561
10.9k
        GetDocShell()->IsReadOnly() )
562
0
        CheckReadonlyState();
563
564
11.0k
    if( !m_pWrtShell->IsPaintLocked() && !g_bNoInterrupt )
565
10.9k
        CheckReadonlySelection();
566
567
11.0k
    if( !m_bAttrChgNotified )
568
10.9k
    {
569
10.9k
        if (m_pWrtShell->ActionPend() || g_bNoInterrupt ||
570
10.9k
             GetDispatcher().IsLocked() ||               //do not confuse the SFX
571
10.9k
             GetViewFrame().GetBindings().IsInUpdate() )//do not confuse the SFX
572
16
        {
573
16
            m_bAttrChgNotified = true;
574
16
            m_aTimer.Start();
575
576
16
            const SfxBoolItem *pItem =
577
16
                GetObjectShell()->GetMedium()->GetItemSet().
578
16
                                    GetItemIfSet( SID_HIDDEN, false );
579
16
            if ( !pItem || !pItem->GetValue() )
580
16
            {
581
16
                GetViewFrame().GetBindings().ENTERREGISTRATIONS();
582
16
                m_bAttrChgNotifiedWithRegistrations = true;
583
16
            }
584
585
16
        }
586
10.9k
        else
587
10.9k
            SelectShell();
588
589
10.9k
    }
590
591
    // change ui if cursor is at a SwPostItField
592
11.0k
    if (m_pPostItMgr)
593
11.0k
    {
594
        // only perform the code that is needed to determine, if at the
595
        // actual cursor position is a post-it field
596
11.0k
        m_pPostItMgr->SetShadowState( m_pWrtShell->GetPostItFieldAtCursor() );
597
11.0k
    }
598
11.0k
}
599
600
IMPL_LINK_NOARG(SwView, TimeoutHdl, Timer *, void)
601
0
{
602
0
    if (m_pWrtShell->ActionPend() || g_bNoInterrupt)
603
0
    {
604
0
        m_aTimer.Start();
605
0
        return;
606
0
    }
607
608
0
    if ( m_bAttrChgNotifiedWithRegistrations )
609
0
    {
610
0
        GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
611
0
        m_bAttrChgNotifiedWithRegistrations = false;
612
0
    }
613
614
0
    CheckReadonlyState();
615
0
    CheckReadonlySelection();
616
617
0
    bool bOldUndo = m_pWrtShell->DoesUndo();
618
0
    m_pWrtShell->DoUndo( false );
619
0
    SelectShell();
620
0
    m_pWrtShell->DoUndo( bOldUndo );
621
0
    m_bAttrChgNotified = false;
622
0
    GetViewImpl()->GetUNOObject_Impl()->NotifySelChanged();
623
0
}
624
625
void SwView::CheckReadonlyState()
626
0
{
627
0
    SfxDispatcher &rDis = GetDispatcher();
628
    // To be able to recognize if it is already disabled!
629
0
    SfxItemState eStateRO, eStateProtAll;
630
0
    SfxPoolItemHolder aResult;
631
    // Query the status from a slot which is only known to us.
632
    // Otherwise the slot is known from other; like the BasicIde
633
0
    eStateRO = rDis.QueryState(FN_INSERT_BOOKMARK, aResult);
634
0
    eStateProtAll = rDis.QueryState(FN_EDIT_REGION, aResult);
635
0
    bool bChgd = false;
636
637
0
    if ( !m_pWrtShell->IsCursorReadonly() )
638
0
    {
639
0
        static constexpr sal_uInt16 aROIds[] =
640
0
        {
641
0
            SID_PASTE_SPECIAL, SID_PASTE_UNFORMATTED, SID_CHARMAP_CONTROL,
642
0
            SID_REDO, SID_UNDO, SID_REPEAT,
643
0
            SID_PASTE, SID_DELETE, SID_ATTR_CHAR_FONT,
644
0
            SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, SID_ATTR_CHAR_SHADOWED,
645
0
            SID_ATTR_CHAR_WORDLINEMODE, SID_ATTR_CHAR_CONTOUR, SID_ATTR_CHAR_STRIKEOUT,
646
0
            SID_ATTR_CHAR_UNDERLINE, SID_ATTR_CHAR_FONTHEIGHT, SID_ATTR_CHAR_COLOR,
647
0
            SID_ATTR_CHAR_KERNING, SID_ATTR_CHAR_CASEMAP, SID_ATTR_CHAR_LANGUAGE,
648
0
            SID_ATTR_CHAR_ESCAPEMENT, SID_ATTR_PARA_ADJUST, SID_ATTR_PARA_ADJUST_LEFT,
649
0
            SID_ATTR_PARA_ADJUST_RIGHT, SID_ATTR_PARA_ADJUST_CENTER, SID_ATTR_PARA_ADJUST_BLOCK,
650
0
            SID_ATTR_PARA_LINESPACE, SID_ATTR_PARA_LINESPACE_10, SID_ATTR_PARA_LINESPACE_15,
651
0
            SID_ATTR_PARA_LINESPACE_20, SID_ATTR_PARA_SPLIT, SID_ATTR_PARA_ORPHANS,
652
0
            SID_ATTR_PARA_WIDOWS, SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
653
0
            SID_ATTR_CHAR_AUTOKERN, SID_BACKGROUND_COLOR, SID_CHAR_DLG,
654
0
            SID_PARA_DLG, SID_ATTR_FLASH, SID_DEC_INDENT,
655
0
            SID_INC_INDENT, SID_ATTR_CHAR_COLOR_EXT, SID_ATTR_CHAR_COLOR_BACKGROUND,
656
0
            SID_ATTR_CHAR_COLOR_BACKGROUND_EXT, SID_CHARMAP, FN_SVX_SET_NUMBER,
657
0
            FN_SVX_SET_BULLET, FN_SVX_SET_OUTLINE, SID_ATTR_CHAR_BACK_COLOR,
658
0
            SID_ULINE_VAL_SINGLE, SID_ULINE_VAL_DOUBLE, SID_ULINE_VAL_DOTTED,
659
0
            SID_ATTR_CHAR_OVERLINE, SID_ATTR_PARA_ADJUST_START, SID_ATTR_PARA_ADJUST_END,
660
0
            SID_AUTOSPELL_CHECK, SID_SBA_BRW_INSERT,
661
0
            FN_NUM_BULLET_ON, FN_NUM_NUMBERING_ON, FN_SELECT_PARA,
662
0
            FN_INSERT_BOOKMARK, FN_INSERT_BREAK, FN_INSERT_BREAK_DLG,
663
0
            FN_INSERT_COLUMN_BREAK, FN_INSERT_LINEBREAK, FN_INSERT_CONTENT_CONTROL,
664
0
            FN_INSERT_CHECKBOX_CONTENT_CONTROL, FN_INSERT_DROPDOWN_CONTENT_CONTROL, FN_INSERT_PICTURE_CONTENT_CONTROL,
665
0
            FN_INSERT_DATE_CONTENT_CONTROL, FN_INSERT_PLAIN_TEXT_CONTENT_CONTROL, FN_POSTIT,
666
0
            FN_INSERT_TABLE, FN_INSERT_COMBO_BOX_CONTENT_CONTROL, FN_INSERT_SOFT_HYPHEN,
667
0
            FN_INSERT_HARD_SPACE, FN_INSERT_NNBSP, FN_INSERT_HARDHYPHEN,
668
0
            FN_GROW_FONT_SIZE, FN_SHRINK_FONT_SIZE, FN_SET_SUPER_SCRIPT,
669
0
            FN_SET_SUB_SCRIPT, FN_FORMAT_DROPCAPS, FN_FORMAT_TABLE_DLG,
670
0
            FN_FORMAT_RESET, FN_CALCULATE, FN_EXPAND_GLOSSARY,
671
0
            FN_BACKSPACE, FN_DELETE_SENT, FN_DELETE_BACK_SENT,
672
0
            FN_DELETE_WORD, FN_DELETE_BACK_WORD, FN_DELETE_LINE,
673
0
            FN_DELETE_BACK_LINE, FN_DELETE_PARA, FN_DELETE_BACK_PARA,
674
0
            FN_DELETE_WHOLE_LINE, FN_SHIFT_BACKSPACE, FN_TXTATR_INET,
675
0
            FN_JAVAEDIT, FN_PASTE_NESTED_TABLE, FN_TABLE_PASTE_ROW_BEFORE,
676
0
            FN_TABLE_PASTE_COL_BEFORE, FN_SPELL_GRAMMAR_DIALOG };
677
678
0
        static_assert(std::is_sorted(std::begin(aROIds), std::end(aROIds)));
679
680
0
        if ( SfxItemState::DISABLED == eStateRO )
681
0
        {
682
0
            if (m_pWrtShell->GetViewOptions()->IsReadonly())
683
0
                ShowUIElement(u"private:resource/toolbar/drawtextobjectbar"_ustr);
684
685
0
            rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aROIds );
686
0
            bChgd = true;
687
0
        }
688
0
    }
689
0
    else if( m_pWrtShell->IsAllProtect() )
690
0
    {
691
0
        if ( SfxItemState::DISABLED == eStateProtAll )
692
0
        {
693
0
            static constexpr sal_uInt16 aAllProtIds[] = { SID_SAVEDOC, FN_EDIT_REGION };
694
695
0
            static_assert(std::is_sorted(std::begin(aAllProtIds), std::end(aAllProtIds)));
696
697
0
            rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aAllProtIds );
698
0
            bChgd = true;
699
0
        }
700
0
    }
701
0
    else if ( SfxItemState::DISABLED != eStateRO ||
702
0
                SfxItemState::DISABLED != eStateProtAll )
703
0
    {
704
0
        if (m_pWrtShell->GetViewOptions()->IsReadonly())
705
0
            HideUIElement(u"private:resource/toolbar/drawtextobjectbar"_ustr);
706
707
0
        bChgd = true;
708
0
        rDis.SetSlotFilter();
709
0
    }
710
0
    if ( bChgd )
711
0
        GetViewFrame().GetBindings().InvalidateAll(true);
712
0
}
713
714
void SwView::CheckReadonlySelection()
715
10.9k
{
716
10.9k
    SfxDisableFlags nDisableFlags = SfxDisableFlags::NONE;
717
10.9k
    SfxDispatcher &rDis = GetDispatcher();
718
719
10.9k
    if( m_pWrtShell->HasReadonlySel() &&
720
2
        ( !m_pWrtShell->GetDrawView() ||
721
2
            !m_pWrtShell->GetDrawView()->GetMarkedObjectList().GetMarkCount() ))
722
2
        nDisableFlags |= SfxDisableFlags::SwOnProtectedCursor;
723
724
10.9k
    if( (SfxDisableFlags::SwOnProtectedCursor & nDisableFlags ) !=
725
10.9k
        (SfxDisableFlags::SwOnProtectedCursor & rDis.GetDisableFlags() ) )
726
1
    {
727
        // Additionally move at the Window the InputContext, so that
728
        // in japanese / chinese versions the external input will be
729
        // turned on or off. This but only if the correct shell is on
730
        // the stack.
731
1
        switch( m_pViewImpl->GetShellMode() )
732
1
        {
733
1
        case ShellMode::Text:
734
1
        case ShellMode::ListText:
735
1
        case ShellMode::TableText:
736
1
        case ShellMode::TableListText:
737
1
            {
738
// Temporary solution!!! Should set the font of the current insertion point
739
//         at each cursor movement, so outside of this "if". But TH does not
740
//         evaluates the font at this time and the "purchase" appears to me
741
//         as too expensive.
742
//         Moreover, we don't have a font, but only attributes from which the
743
//         text formatting and the correct font will be build together.
744
745
1
                InputContext aCntxt( GetEditWin().GetInputContext() );
746
1
                aCntxt.SetOptions( SfxDisableFlags::SwOnProtectedCursor & nDisableFlags
747
1
                                    ? (aCntxt.GetOptions() & ~
748
1
                                            InputContextFlags( InputContextFlags::Text |
749
1
                                                InputContextFlags::ExtText ))
750
1
                                    : (aCntxt.GetOptions() |
751
0
                                            ( InputContextFlags::Text |
752
0
                                                InputContextFlags::ExtText )) );
753
1
                GetEditWin().SetInputContext( aCntxt );
754
1
            }
755
1
            break;
756
0
        default:
757
0
            ;
758
1
        }
759
760
1
    }
761
762
10.9k
    if( nDisableFlags != rDis.GetDisableFlags() )
763
1
    {
764
1
        rDis.SetDisableFlags( nDisableFlags );
765
1
        GetViewFrame().GetBindings().InvalidateAll( true );
766
1
    }
767
10.9k
}
768
769
SwView::SwView(SfxViewFrame& _rFrame, SfxViewShell* pOldSh)
770
4.02k
    : SfxViewShell(_rFrame, SWVIEWFLAGS),
771
4.02k
    m_aTimer( "sw::SwView m_aTimer" ),
772
4.02k
    m_nNewPage(USHRT_MAX),
773
4.02k
    m_nOldPageNum(0),
774
4.02k
    m_pNumRuleNodeFromDoc(nullptr),
775
4.02k
    m_pEditWin( VclPtr<SwEditWin>::Create( &_rFrame.GetWindow(), *this ) ),
776
4.02k
    m_pShell(nullptr),
777
4.02k
    m_pFormShell(nullptr),
778
4.02k
    m_pHScrollbar(nullptr),
779
4.02k
    m_pVScrollbar(nullptr),
780
4.02k
    m_pLastTableFormat(nullptr),
781
4.02k
    m_pLastFlyFormat(nullptr),
782
4.02k
    m_pFormatClipboard(new SwFormatClipboard()),
783
4.02k
    m_nSelectionType( SelectionType::All ),
784
4.02k
    m_nPageCnt(0),
785
4.02k
    m_nDrawSfxId( USHRT_MAX ),
786
4.02k
    m_nFormSfxId( USHRT_MAX ),
787
4.02k
    m_eFormObjKind(SdrObjKind::NONE),
788
4.02k
    m_nLastPasteDestination( static_cast<SotExchangeDest>(0xFFFF) ),
789
4.02k
    m_nLeftBorderDistance( 0 ),
790
4.02k
    m_nRightBorderDistance( 0 ),
791
4.02k
    m_eLastSearchCommand( static_cast<SvxSearchCmd>(0xFFFF) ),
792
4.02k
    m_bWheelScrollInProgress(false),
793
4.02k
    m_bCenterCursor(false),
794
4.02k
    m_bTopCursor(false),
795
4.02k
    m_bTabColFromDoc(false),
796
4.02k
    m_bTabRowFromDoc(false),
797
4.02k
    m_bSetTabColFromDoc(false),
798
4.02k
    m_bSetTabRowFromDoc(false),
799
4.02k
    m_bAttrChgNotified(false),
800
4.02k
    m_bAttrChgNotifiedWithRegistrations(false),
801
4.02k
    m_bVerbsActive(false),
802
4.02k
    m_bDrawRotate(false),
803
4.02k
    m_bDrawSelMode(true),
804
4.02k
    m_bShowAtResize(true),
805
4.02k
    m_bInOuterResizePixel(false),
806
4.02k
    m_bInInnerResizePixel(false),
807
4.02k
    m_bPasteState(false),
808
4.02k
    m_bPasteSpecialState(false),
809
4.02k
    m_bInMailMerge(false),
810
4.02k
    m_bInDtor(false),
811
4.02k
    m_bOldShellWasPagePreview(false),
812
4.02k
    m_bIsPreviewDoubleClick(false),
813
4.02k
    m_bMakeSelectionVisible(false),
814
4.02k
    m_bForceChangesToolbar(true),
815
4.02k
    m_nLOKPageUpDownOffset(0),
816
4.02k
    m_aBringToAttentionBlinkTimer("SwView m_aBringToAttentionBlinkTimer"),
817
4.02k
    m_nBringToAttentionBlinkTimeOutsRemaining(0)
818
4.02k
{
819
4.02k
    static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE");
820
4.02k
    if (bRequestDoubleBuffering)
821
0
        m_pEditWin->RequestDoubleBuffering(true);
822
823
    // According to discussion with MBA and further
824
    // investigations, no old SfxViewShell will be set as parameter <pOldSh>,
825
    // if function "New Window" is performed to open an additional view beside
826
    // an already existing one.
827
    // If the view is switch from one to another, the 'old' view is given by
828
    // parameter <pOldSh>.
829
830
4.02k
    bDocSzUpdated = true;
831
832
4.02k
    static bool bFuzzing = comphelper::IsFuzzing();
833
834
4.02k
    if (!bFuzzing)
835
0
    {
836
0
        CreateScrollbar( true );
837
0
        CreateScrollbar( false );
838
0
    }
839
840
4.02k
    m_pViewImpl.reset(new SwView_Impl(this));
841
4.02k
    SetName(u"View"_ustr);
842
4.02k
    SetWindow( m_pEditWin );
843
844
4.02k
    m_aTimer.SetTimeout( 120 );
845
846
4.02k
    SwDocShell& rDocSh = dynamic_cast<SwDocShell&>(*_rFrame.GetObjectShell());
847
4.02k
    bool bOldModifyFlag = rDocSh.IsEnableSetModified();
848
4.02k
    if (bOldModifyFlag)
849
4.02k
        rDocSh.EnableSetModified( false );
850
    // HACK: SwDocShell has some cached font info, VCL informs about font updates,
851
    // but loading of docs with embedded fonts happens after SwDocShell is created
852
    // but before SwEditWin (which handles the VCL event) is created. So update
853
    // manually.
854
4.02k
    if (rDocSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::EMBED_FONTS ))
855
0
        rDocSh.UpdateFontList();
856
4.02k
    bool bWebDShell = dynamic_cast<const SwWebDocShell*>(&rDocSh) !=  nullptr;
857
858
4.02k
    const SwMasterUsrPref* pUsrPref = SwModule::get()->GetUsrPref(bWebDShell);
859
4.02k
    SwViewOption aUsrPref( *pUsrPref);
860
861
    //! get lingu options without loading lingu DLL
862
4.02k
    SvtLinguOptions aLinguOpt;
863
4.02k
    SvtLinguConfig().GetOptions( aLinguOpt );
864
4.02k
    aUsrPref.SetOnlineSpell( aLinguOpt.bIsSpellAuto );
865
866
    // Inherit the per-view setting from the per-document one.
867
4.02k
    aUsrPref.SetRedlineRecordingOn(rDocSh.GetDoc()->getIDocumentRedlineAccess().IsRedlineOn());
868
869
4.02k
    bool bOldShellWasSrcView = false;
870
871
    // determine if there is an existing view for
872
    // document
873
4.02k
    SfxViewShell* pExistingSh = nullptr;
874
4.02k
    if ( pOldSh )
875
0
    {
876
0
        pExistingSh = pOldSh;
877
        // determine type of existing view
878
0
        if (SwPagePreview* pPagePreview = dynamic_cast<SwPagePreview *>(pExistingSh))
879
0
        {
880
0
            m_sSwViewData = pPagePreview->GetPrevSwViewData();
881
0
            m_sNewCursorPos = pPagePreview->GetNewCursorPos();
882
0
            m_nNewPage = pPagePreview->GetNewPage();
883
0
            m_bOldShellWasPagePreview = true;
884
0
            m_bIsPreviewDoubleClick = !m_sNewCursorPos.isEmpty() || m_nNewPage != USHRT_MAX;
885
0
        }
886
0
        else if (dynamic_cast<const SwSrcView *>(pExistingSh) != nullptr)
887
0
            bOldShellWasSrcView = true;
888
0
    }
889
890
4.02k
    SAL_INFO( "sw.ui", "before create WrtShell" );
891
4.02k
    if (SwView *pView = dynamic_cast<SwView*>(pExistingSh))
892
0
    {
893
0
        m_pWrtShell.reset(new SwWrtShell(*pView->m_pWrtShell, m_pEditWin, *this));
894
0
    }
895
4.02k
    else if (SwWrtShell *pWrtShell = dynamic_cast<SwWrtShell*>(rDocSh.GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()))
896
0
    {
897
0
        m_pWrtShell.reset(new SwWrtShell(*pWrtShell, m_pEditWin, *this));
898
0
    }
899
4.02k
    else
900
4.02k
    {
901
4.02k
        SwDoc& rDoc = *rDocSh.GetDoc();
902
903
4.02k
        if( !bOldShellWasSrcView && bWebDShell && !m_bOldShellWasPagePreview )
904
0
            aUsrPref.setBrowseMode( true );
905
4.02k
        else
906
4.02k
            aUsrPref.setBrowseMode( rDoc.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) );
907
908
4.02k
        aUsrPref.setDraftView( false );
909
910
        //For the BrowseMode we do not assume a factor.
911
4.02k
        if( aUsrPref.getBrowseMode() && aUsrPref.GetZoomType() != SvxZoomType::PERCENT )
912
0
        {
913
0
            aUsrPref.SetZoomType( SvxZoomType::PERCENT );
914
0
            aUsrPref.SetZoom( 100 );
915
0
        }
916
4.02k
        else if (rDocSh.IsPreview())
917
0
        {
918
0
            aUsrPref.SetZoomType( SvxZoomType::WHOLEPAGE );
919
0
            aUsrPref.SetViewLayoutBookMode( false );
920
0
            aUsrPref.SetViewLayoutColumns( 1 );
921
0
        }
922
4.02k
        else if (!pUsrPref->IsDefaultZoom())
923
0
        {
924
0
            aUsrPref.SetZoomType(pUsrPref->GetDefaultZoomType());
925
0
            aUsrPref.SetZoom(pUsrPref->GetDefaultZoomValue());
926
0
        }
927
4.02k
        m_pWrtShell.reset(new SwWrtShell(rDoc, m_pEditWin, *this, &aUsrPref));
928
        // creating an SwView from a SwPagePreview needs to
929
        // add the SwViewShell to the ring of the other SwViewShell(s)
930
4.02k
        if(m_bOldShellWasPagePreview)
931
0
        {
932
0
            SwViewShell& rPreviewViewShell = *static_cast<SwPagePreview*>(pExistingSh)->GetViewShell();
933
0
            m_pWrtShell->MoveTo(&rPreviewViewShell);
934
            // to update the field command et.al. if necessary
935
0
            const SwViewOption* pPreviewOpt = rPreviewViewShell.GetViewOptions();
936
0
            if( pPreviewOpt->IsFieldName() != aUsrPref.IsFieldName() ||
937
0
                    pPreviewOpt->IsShowHiddenField() != aUsrPref.IsShowHiddenField() ||
938
0
                    pPreviewOpt->IsShowHiddenPara() != aUsrPref.IsShowHiddenPara() ||
939
0
                    pPreviewOpt->IsShowHiddenChar() != aUsrPref.IsShowHiddenChar() )
940
0
                rPreviewViewShell.ApplyViewOptions(aUsrPref);
941
            // reset design mode at draw view for form
942
            // shell, if needed.
943
0
            if ( static_cast<SwPagePreview*>(pExistingSh)->ResetFormDesignMode() &&
944
0
                 m_pWrtShell->HasDrawView() )
945
0
            {
946
0
                SdrView* pDrawView = m_pWrtShell->GetDrawView();
947
0
                pDrawView->SetDesignMode( static_cast<SwPagePreview*>(pExistingSh)->FormDesignModeToReset() );
948
0
            }
949
0
        }
950
4.02k
    }
951
4.02k
    SAL_INFO( "sw.ui", "after create WrtShell" );
952
4.02k
    m_pHRuler = VclPtr<SwCommentRuler>::Create(m_pWrtShell.get(), &GetViewFrame().GetWindow(), m_pEditWin,
953
4.02k
                SvxRulerSupportFlags::TABS |
954
4.02k
                SvxRulerSupportFlags::PARAGRAPH_MARGINS |
955
4.02k
                SvxRulerSupportFlags::BORDERS |
956
4.02k
                SvxRulerSupportFlags::NEGATIVE_MARGINS|
957
4.02k
                SvxRulerSupportFlags::REDUCED_METRIC,
958
4.02k
                GetViewFrame().GetBindings(),
959
4.02k
                WB_STDRULER | WB_EXTRAFIELD | WB_BORDER);
960
961
4.02k
    m_pVRuler = VclPtr<SvxRuler>::Create(&GetViewFrame().GetWindow(), m_pEditWin,
962
4.02k
                SvxRulerSupportFlags::TABS |
963
4.02k
                SvxRulerSupportFlags::PARAGRAPH_MARGINS_VERTICAL |
964
4.02k
                SvxRulerSupportFlags::BORDERS |
965
4.02k
                SvxRulerSupportFlags::NEGATIVE_MARGINS|
966
4.02k
                SvxRulerSupportFlags::REDUCED_METRIC,
967
4.02k
                GetViewFrame().GetBindings(),
968
4.02k
                WB_VSCROLL | WB_EXTRAFIELD | WB_BORDER);
969
970
    // assure that modified state of document
971
    // isn't reset, if document is already modified.
972
4.02k
    const bool bIsDocModified = m_pWrtShell->GetDoc()->getIDocumentState().IsModified();
973
974
    // Thus among other things, the HRuler is not displayed in the read-only case.
975
4.02k
    aUsrPref.SetReadonly( m_pWrtShell->GetViewOptions()->IsReadonly() );
976
977
    // no margin for OLE!
978
4.02k
    Size aBrwsBorder;
979
4.02k
    if( SfxObjectCreateMode::EMBEDDED != rDocSh.GetCreateMode() )
980
4.02k
        aBrwsBorder = GetMargin();
981
982
4.02k
    m_pWrtShell->SetBrowseBorder( aBrwsBorder );
983
984
    // In CTOR no shell changes may take place, which must be temporarily stored
985
    // with the timer. Otherwise, the SFX removes them from the stack!
986
4.02k
    bool bOld = g_bNoInterrupt;
987
4.02k
    g_bNoInterrupt = true;
988
989
4.02k
    m_pHRuler->SetActive();
990
4.02k
    m_pVRuler->SetActive();
991
992
4.02k
    SfxViewFrame& rViewFrame = GetViewFrame();
993
994
4.02k
    StartListening(rViewFrame, DuplicateHandling::Prevent);
995
4.02k
    StartListening(rDocSh, DuplicateHandling::Prevent);
996
997
    // Set Zoom-factor from HRuler
998
4.02k
    double aZoomFract = double( aUsrPref.GetZoom() ) / 100;
999
4.02k
    m_pHRuler->SetZoom( aZoomFract );
1000
4.02k
    m_pVRuler->SetZoom( aZoomFract );
1001
4.02k
    m_pHRuler->SetDoubleClickHdl(LINK( this, SwView, ExecRulerClick ));
1002
4.02k
    FieldUnit eMetric = pUsrPref->GetHScrollMetric();
1003
4.02k
    m_pHRuler->SetUnit( eMetric );
1004
1005
4.02k
    eMetric = pUsrPref->GetVScrollMetric();
1006
4.02k
    m_pVRuler->SetUnit( eMetric );
1007
1008
4.02k
    m_pHRuler->SetCharWidth( 371 );  // default character width
1009
4.02k
    m_pVRuler->SetLineHeight( 551 );  // default line height
1010
1011
    // Set DocShell
1012
4.02k
    m_xGlueDocShell.reset(new SwViewGlueDocShell(*this, rDocSh));
1013
4.02k
    m_pPostItMgr.reset(new SwPostItMgr(this));
1014
#if ENABLE_YRS
1015
    m_pWrtShell->GetDoc()->getIDocumentState().YrsInitAcceptor();
1016
#endif
1017
1018
    // Check and process the DocSize. Via the handler, the shell could not
1019
    // be found, because the shell is not known in the SFX management
1020
    // within the CTOR phase.
1021
4.02k
    DocSzChgd( m_pWrtShell->GetDocSize() );
1022
1023
        // Set AttrChangedNotify link
1024
4.02k
    m_pWrtShell->SetChgLnk(LINK(this, SwView, AttrChangedNotify));
1025
1026
4.02k
    if (rDocSh.GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
1027
0
        !rDocSh.GetVisArea(ASPECT_CONTENT).IsEmpty())
1028
0
        SetVisArea(rDocSh.GetVisArea(ASPECT_CONTENT),false);
1029
1030
4.02k
    SAL_WARN_IF(
1031
4.02k
        officecfg::Office::Common::Undo::Steps::get() <= 0,
1032
4.02k
        "sw.ui", "/org.openoffice.Office.Common/Undo/Steps <= 0");
1033
4.02k
    if (!bFuzzing && 0 < officecfg::Office::Common::Undo::Steps::get())
1034
0
    {
1035
0
        m_pWrtShell->DoUndo();
1036
0
    }
1037
1038
4.02k
    const bool bBrowse = m_pWrtShell->GetViewOptions()->getBrowseMode();
1039
    // Disable "multiple window"
1040
4.02k
    SetNewWindowAllowed(!bBrowse);
1041
    // End of disabled multiple window
1042
1043
4.02k
    UpdateXformsViewOption(GetDrawView()->IsDesignMode());
1044
1045
4.02k
    m_bVScrollbarEnabled = aUsrPref.IsViewVScrollBar();
1046
4.02k
    m_bHScrollbarEnabled = aUsrPref.IsViewHScrollBar();
1047
4.02k
    if (m_pHScrollbar)
1048
0
        m_pHScrollbar->SetAuto(bBrowse);
1049
4.02k
    if( aUsrPref.IsViewHRuler() )
1050
0
        CreateTab();
1051
4.02k
    if( aUsrPref.IsViewVRuler() )
1052
0
        CreateVRuler();
1053
1054
4.02k
    m_pWrtShell->SetUIOptions( aUsrPref );
1055
4.02k
    m_pWrtShell->SetReadOnlyAvailable( aUsrPref.IsCursorInProtectedArea() );
1056
4.02k
#if !ENABLE_WASM_STRIP_ACCESSIBILITY
1057
4.02k
    m_pWrtShell->ApplyAccessibilityOptions();
1058
4.02k
#endif
1059
1060
4.02k
    if( m_pWrtShell->GetDoc()->getIDocumentState().IsUpdateExpField() )
1061
0
    {
1062
0
        if (m_pWrtShell->GetDoc()->GetDocumentFieldsManager().containsUpdatableFields())
1063
0
        {
1064
0
            CurrShell aCurr(m_pWrtShell.get());
1065
0
            m_pWrtShell->StartAction();
1066
0
            m_pWrtShell->CalcLayout();
1067
0
            m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().UpdateFields(false);
1068
0
            m_pWrtShell->EndAction();
1069
0
        }
1070
0
        m_pWrtShell->GetDoc()->getIDocumentState().SetUpdateExpFieldStat( false );
1071
0
    }
1072
1073
    // Update all tables if necessary:
1074
4.02k
    if( m_pWrtShell->GetDoc()->IsUpdateTOX() )
1075
0
    {
1076
0
        SfxRequest aSfxRequest( FN_UPDATE_TOX, SfxCallMode::SLOT, GetPool() );
1077
0
        Execute( aSfxRequest );
1078
0
        m_pWrtShell->GetDoc()->SetUpdateTOX( false );     // reset again
1079
0
        m_pWrtShell->SttEndDoc(true);
1080
0
    }
1081
1082
    // No ResetModified, if there is already a view to this doc.
1083
4.02k
    SfxViewFrame& rVFrame = GetViewFrame();
1084
4.02k
    SfxViewFrame* pFirst = SfxViewFrame::GetFirst(&rDocSh);
1085
    // Currently(360) the view is registered firstly after the CTOR,
1086
    // the following expression is also working if this changes.
1087
    // If the modification cannot be canceled by undo, then do NOT set
1088
    // the modify back.
1089
    // no reset of modified state, if document
1090
    // was already modified.
1091
4.02k
    if (!m_pWrtShell->GetDoc()->GetIDocumentUndoRedo().IsUndoNoResetModified() &&
1092
4.02k
         ( !pFirst || pFirst == &rVFrame ) &&
1093
4.02k
         !bIsDocModified )
1094
217
    {
1095
217
        m_pWrtShell->ResetModified();
1096
217
    }
1097
1098
4.02k
    g_bNoInterrupt = bOld;
1099
1100
    // If a new GlobalDoc will be created, the navigator will also be generated.
1101
4.02k
    if( dynamic_cast<const SwGlobalDocShell*>(&rDocSh) != nullptr &&
1102
0
        !rVFrame.GetChildWindow( SID_NAVIGATOR ))
1103
0
    {
1104
0
        SfxBoolItem aNavi(SID_NAVIGATOR, true);
1105
0
        GetDispatcher().ExecuteList(SID_NAVIGATOR, SfxCallMode::ASYNCHRON, { &aNavi });
1106
0
    }
1107
1108
4.02k
    uno::Reference< frame::XFrame >  xFrame = rVFrame.GetFrame().GetFrameInterface();
1109
1110
4.02k
    uno::Reference< frame::XFrame >  xBeamerFrame = xFrame->findFrame(
1111
4.02k
            u"_beamer"_ustr, frame::FrameSearchFlag::CHILDREN);
1112
4.02k
    if(xBeamerFrame.is())
1113
0
    {
1114
0
        SwDBData aData = m_pWrtShell->GetDBData();
1115
0
        SwModule::ShowDBObj( *this, aData );
1116
0
    }
1117
1118
    // has anybody calls the attrchanged handler in the constructor?
1119
4.02k
    if( m_bAttrChgNotifiedWithRegistrations )
1120
0
    {
1121
0
        GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1122
0
        if( m_aTimer.IsActive() )
1123
0
            m_aTimer.Stop();
1124
0
    }
1125
1126
4.02k
    m_aTimer.SetInvokeHandler(LINK(this, SwView, TimeoutHdl));
1127
4.02k
    m_bAttrChgNotified = m_bAttrChgNotifiedWithRegistrations = false;
1128
4.02k
    if (bOldModifyFlag)
1129
4.02k
        rDocSh.EnableSetModified();
1130
4.02k
    InvalidateBorder();
1131
1132
4.02k
    if (!bFuzzing)
1133
0
    {
1134
0
        if (!m_pHScrollbar->IsScrollbarVisible(true))
1135
0
            ShowHScrollbar( false );
1136
0
        if (!m_pVScrollbar->IsScrollbarVisible(true))
1137
0
            ShowVScrollbar( false );
1138
0
    }
1139
1140
4.02k
    if (m_pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton())
1141
0
        m_pWrtShell->InvalidateOutlineContentVisibility();
1142
1143
4.02k
    if (!bFuzzing)
1144
0
        GetViewFrame().GetWindow().AddChildEventListener(LINK(this, SwView, WindowChildEventListener));
1145
1146
4.02k
    m_aBringToAttentionBlinkTimer.SetInvokeHandler(
1147
4.02k
                LINK(this, SwView, BringToAttentionBlinkTimerHdl));
1148
4.02k
    m_aBringToAttentionBlinkTimer.SetTimeout(350);
1149
1150
4.02k
    if (comphelper::LibreOfficeKit::isActive())
1151
0
    {
1152
0
        SwXTextDocument* pModel = comphelper::getFromUnoTunnel<SwXTextDocument>(GetCurrentDocument());
1153
0
        SfxLokHelper::notifyViewRenderState(this, pModel);
1154
0
    }
1155
4.02k
}
1156
1157
SwViewGlueDocShell::SwViewGlueDocShell(SwView& rView, SwDocShell& rDocSh)
1158
4.02k
    : m_rView(rView)
1159
4.02k
{
1160
    // Set DocShell
1161
4.02k
    rDocSh.SetView(&m_rView);
1162
4.02k
    SwModule::get()->SetView(&m_rView);
1163
4.02k
}
1164
1165
SwViewGlueDocShell::~SwViewGlueDocShell()
1166
4.02k
{
1167
4.02k
    SwDocShell* pDocSh = m_rView.GetDocShell();
1168
4.02k
    if (pDocSh && pDocSh->GetView() == &m_rView)
1169
4.02k
        pDocSh->SetView(nullptr);
1170
4.02k
    if (SwModule* mod = SwModule::get(); mod->GetView() == &m_rView)
1171
4.02k
        mod->SetView(nullptr);
1172
4.02k
}
1173
1174
SwView::~SwView()
1175
4.02k
{
1176
    // Notify other LOK views that we are going away.
1177
4.02k
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false"_ostr);
1178
4.02k
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", ""_ostr);
1179
4.02k
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY"_ostr);
1180
1181
    // Need to remove activated field's button before disposing EditWin.
1182
4.02k
    GetWrtShell().getIDocumentMarkAccess()->ClearFieldActivation();
1183
1184
4.02k
    GetViewFrame().GetWindow().RemoveChildEventListener( LINK( this, SwView, WindowChildEventListener ) );
1185
4.02k
    m_pPostItMgr.reset();
1186
1187
4.02k
    m_bInDtor = true;
1188
4.02k
    m_pEditWin->Hide(); // prevent problems with painting
1189
1190
    // Set pointer in SwDocShell to the view again
1191
4.02k
    m_xGlueDocShell.reset();
1192
1193
4.02k
    if( m_aTimer.IsActive() && m_bAttrChgNotifiedWithRegistrations )
1194
16
        GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1195
1196
    // the last view must end the text edit
1197
4.02k
    SdrView *pSdrView = m_pWrtShell->GetDrawView();
1198
4.02k
    if( pSdrView && pSdrView->IsTextEdit() )
1199
0
        pSdrView->SdrEndTextEdit( true );
1200
4.02k
    else if (pSdrView)
1201
4.02k
    {
1202
4.02k
        pSdrView->DisposeUndoManager();
1203
4.02k
    }
1204
1205
4.02k
    SetWindow( nullptr );
1206
1207
4.02k
    m_pViewImpl->Invalidate();
1208
4.02k
    EndListening(GetViewFrame());
1209
4.02k
    EndListening(*GetDocShell());
1210
1211
    // tdf#155410 speedup shutdown, prevent unnecessary broadcasting during teardown of draw model
1212
4.02k
    auto pDrawModel = GetWrtShell().getIDocumentDrawModelAccess().GetDrawModel();
1213
4.02k
    const bool bWasLocked = pDrawModel->isLocked();
1214
4.02k
    pDrawModel->setLock(true);
1215
4.02k
    m_pWrtShell.reset(); // reset here so that it is not accessible by the following dtors.
1216
4.02k
    pDrawModel->setLock(bWasLocked);
1217
1218
4.02k
    m_pHScrollbar.disposeAndClear();
1219
4.02k
    m_pVScrollbar.disposeAndClear();
1220
4.02k
    m_pHRuler.disposeAndClear();
1221
4.02k
    m_pVRuler.disposeAndClear();
1222
4.02k
    m_pGlosHdl.reset();
1223
4.02k
    m_pViewImpl.reset();
1224
1225
    // If this was enabled in the ctor for the frame, then disable it here.
1226
4.02k
    static bool bRequestDoubleBuffering = getenv("VCL_DOUBLEBUFFERING_ENABLE");
1227
4.02k
    if (bRequestDoubleBuffering)
1228
0
        m_pEditWin->RequestDoubleBuffering(false);
1229
4.02k
    m_pEditWin.disposeAndClear();
1230
1231
4.02k
    m_pFormatClipboard.reset();
1232
4.02k
}
1233
1234
void SwView::SetDying()
1235
0
{
1236
0
    m_bDying = true;
1237
0
}
1238
1239
void SwView::afterCallbackRegistered()
1240
0
{
1241
0
    if (!comphelper::LibreOfficeKit::isActive())
1242
0
        return;
1243
1244
    // common tasks
1245
0
    SfxViewShell::afterCallbackRegistered();
1246
1247
0
    auto* pDocShell = GetDocShell();
1248
0
    if (pDocShell)
1249
0
    {
1250
0
        std::shared_ptr<model::ColorSet> pThemeColors = pDocShell->GetThemeColors();
1251
0
        std::set<Color> aDocumentColors = pDocShell->GetDocColors();
1252
0
        svx::theme::notifyLOK(pThemeColors, aDocumentColors);
1253
0
    }
1254
0
}
1255
1256
SwDocShell* SwView::GetDocShell()
1257
193k
{
1258
193k
    SfxObjectShell* pDocShell = GetViewFrame().GetObjectShell();
1259
193k
    return dynamic_cast<SwDocShell*>( pDocShell );
1260
193k
}
1261
1262
// Remember CursorPos
1263
1264
void SwView::WriteUserData( OUString &rUserData, bool bBrowse )
1265
0
{
1266
    // The browse flag will be passed from Sfx when documents are browsed
1267
    // (not to be confused with the BrowseMode).
1268
    // Then that stored data are not persistent!
1269
1270
0
    const SwRect& rRect = m_pWrtShell->GetCharRect();
1271
0
    const tools::Rectangle& rVis = GetVisArea();
1272
1273
0
    rUserData = OUString::number( rRect.Left() );
1274
0
    rUserData += ";";
1275
0
    rUserData += OUString::number( rRect.Top() );
1276
0
    rUserData += ";";
1277
0
    rUserData += OUString::number( m_pWrtShell->GetViewOptions()->GetZoom() );
1278
0
    rUserData += ";";
1279
0
    rUserData += OUString::number( rVis.Left() );
1280
0
    rUserData += ";";
1281
0
    rUserData += OUString::number( rVis.Top() );
1282
0
    rUserData += ";";
1283
0
    rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Right());
1284
0
    rUserData += ";";
1285
0
    rUserData += OUString::number( bBrowse ? SAL_MIN_INT32 : rVis.Bottom());
1286
0
    rUserData += ";";
1287
0
    rUserData += OUString::number(
1288
0
            static_cast<sal_uInt16>(m_pWrtShell->GetViewOptions()->GetZoomType()));//eZoom;
1289
0
    rUserData += ";";
1290
0
    rUserData += FrameTypeFlags::NONE == m_pWrtShell->GetSelFrameType() ? std::u16string_view(u"0") : std::u16string_view(u"1");
1291
0
}
1292
1293
// Set CursorPos
1294
1295
static bool lcl_IsOwnDocument( SwView& rView )
1296
4.01k
{
1297
4.01k
    if (::officecfg::Office::Common::Load::ViewPositionForAnyUser::get())
1298
0
    {
1299
0
        return true;
1300
0
    }
1301
4.01k
    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1302
4.01k
        rView.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
1303
4.01k
    uno::Reference<document::XDocumentProperties> xDocProps
1304
4.01k
        = xDPS->getDocumentProperties();
1305
4.01k
    OUString Created = xDocProps->getAuthor();
1306
4.01k
    OUString Changed = xDocProps->getModifiedBy();
1307
4.01k
    OUString FullName = SwModule::get()->GetUserOptions().GetFullName();
1308
4.01k
    return !FullName.isEmpty()
1309
0
           && (Changed == FullName || (Changed.isEmpty() && Created == FullName));
1310
4.01k
}
1311
1312
void SwView::ReadUserData( const OUString &rUserData, bool bBrowse )
1313
0
{
1314
0
    if ( !(rUserData.indexOf(';')>=0 && // more than one token
1315
        // For document without layout only in the onlinelayout or
1316
        // while forward/backward
1317
0
         (!m_pWrtShell->IsNewLayout() || m_pWrtShell->GetViewOptions()->getBrowseMode() || bBrowse)) )
1318
0
        return;
1319
1320
0
    bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1321
1322
0
    CurrShell aCurr(m_pWrtShell.get());
1323
1324
0
    sal_Int32 nPos = 0;
1325
1326
    // No it is *not* a good idea to call GetToken within Point constr. immediately,
1327
    // because which parameter is evaluated first?
1328
0
    tools::Long nX = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1329
0
         nY = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos ));
1330
0
    Point aCursorPos( nX, nY );
1331
1332
0
    sal_uInt16 nZoomFactor =
1333
0
        static_cast< sal_uInt16 >( o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )) );
1334
1335
0
    tools::Long nLeft  = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1336
0
         nTop   = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1337
0
         nRight = o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos )),
1338
0
         nBottom= o3tl::toInt32(o3tl::getToken(rUserData, 0, ';', nPos ));
1339
1340
0
    const tools::Long nAdd = m_pWrtShell->GetViewOptions()->getBrowseMode() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
1341
0
    if ( nBottom > (m_pWrtShell->GetDocSize().Height()+nAdd) )
1342
0
        return;
1343
1344
0
    m_pWrtShell->EnableSmooth( false );
1345
1346
0
    const tools::Rectangle aVis( nLeft, nTop, nRight, nBottom );
1347
1348
0
    sal_Int32 nOff = 0;
1349
0
    SvxZoomType eZoom;
1350
0
    if( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1351
0
        eZoom = static_cast<SvxZoomType>(o3tl::narrowing<sal_uInt16>(o3tl::toInt32(o3tl::getToken(rUserData, nOff, ';', nPos ))));
1352
0
    else
1353
0
    {
1354
0
        eZoom = SvxZoomType::PERCENT;
1355
0
        ++nOff;
1356
0
    }
1357
1358
0
    bool bSelectObj = (0 != o3tl::toInt32(o3tl::getToken(rUserData, nOff, ';', nPos )))
1359
0
                        && m_pWrtShell->IsObjSelectable( aCursorPos );
1360
1361
    // restore editing position
1362
0
    m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj);
1363
    // set flag value to avoid macro execution.
1364
0
    bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1365
0
    m_pWrtShell->SetMacroExecAllowed( false );
1366
// os: changed: The user data has to be read if the view is switched back from page preview
1367
// go to the last editing position when opening own files
1368
0
    if(m_bOldShellWasPagePreview || bIsOwnDocument)
1369
0
    {
1370
0
        m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj );
1371
0
        if( bSelectObj )
1372
0
        {
1373
0
            m_pWrtShell->SelectObj( aCursorPos );
1374
0
            m_pWrtShell->EnterSelFrameMode( &aCursorPos );
1375
0
        }
1376
0
    }
1377
1378
    // reset flag value
1379
0
    m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1380
1381
    // set visible area before applying
1382
    // information from print preview. Otherwise, the applied information
1383
    // is lost.
1384
// os: changed: The user data has to be read if the view is switched back from page preview
1385
// go to the last editing position when opening own files
1386
0
    if(m_bOldShellWasPagePreview || bIsOwnDocument )
1387
0
    {
1388
0
        if ( bBrowse )
1389
0
            SetVisArea( aVis.TopLeft() );
1390
0
        else
1391
0
            SetVisArea( aVis );
1392
0
    }
1393
1394
    //apply information from print preview - if available
1395
0
    if( !m_sNewCursorPos.isEmpty() )
1396
0
    {
1397
0
        sal_Int32 nIdx{ 0 };
1398
0
        const tools::Long nXTmp = o3tl::toInt32(o3tl::getToken(m_sNewCursorPos, 0, ';', nIdx ));
1399
0
        const tools::Long nYTmp = o3tl::toInt32(o3tl::getToken(m_sNewCursorPos, 0, ';', nIdx ));
1400
0
        Point aCursorPos2( nXTmp, nYTmp );
1401
0
        bSelectObj = m_pWrtShell->IsObjSelectable( aCursorPos2 );
1402
1403
0
        m_pWrtShell->SwCursorShell::SetCursor( aCursorPos2 );
1404
0
        if( bSelectObj )
1405
0
        {
1406
0
            m_pWrtShell->SelectObj( aCursorPos2 );
1407
0
            m_pWrtShell->EnterSelFrameMode( &aCursorPos2 );
1408
0
        }
1409
0
        m_pWrtShell->MakeSelVisible();
1410
0
        m_sNewCursorPos.clear();
1411
0
    }
1412
0
    else if(USHRT_MAX != m_nNewPage)
1413
0
    {
1414
0
        m_pWrtShell->GotoPage(m_nNewPage, true);
1415
0
        m_nNewPage = USHRT_MAX;
1416
0
    }
1417
1418
0
    SelectShell();
1419
1420
0
    m_pWrtShell->StartAction();
1421
0
    const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1422
0
    if( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom )
1423
0
        SetZoom( eZoom, nZoomFactor);
1424
1425
0
    m_pWrtShell->LockView( true );
1426
0
    m_pWrtShell->EndAction();
1427
0
    m_pWrtShell->LockView( false );
1428
0
    m_pWrtShell->EnableSmooth( true );
1429
0
}
1430
1431
void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >& rSequence )
1432
4.01k
{
1433
4.01k
    if(GetDocShell()->IsPreview()||m_bIsPreviewDoubleClick)
1434
0
        return;
1435
4.01k
    bool bIsOwnDocument = lcl_IsOwnDocument( *this );
1436
1437
4.01k
    CurrShell aCurr(m_pWrtShell.get());
1438
4.01k
    const SwRect& rRect = m_pWrtShell->GetCharRect();
1439
4.01k
    const tools::Rectangle &rVis = GetVisArea();
1440
4.01k
    const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
1441
1442
4.01k
    sal_Int64 nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top();
1443
4.01k
    sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType());
1444
4.01k
    sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom());
1445
4.01k
    bool bViewLayoutBookMode = pVOpt->IsViewLayoutBookMode();
1446
4.01k
    sal_Int16 nViewLayoutColumns = pVOpt->GetViewLayoutColumns();
1447
1448
4.01k
    bool bSelectedFrame = ( m_pWrtShell->GetSelFrameType() != FrameTypeFlags::NONE ),
1449
4.01k
             bGotVisibleLeft = false,
1450
4.01k
             bGotVisibleTop = false,
1451
4.01k
             bGotZoomType = false,
1452
4.01k
             bGotZoomFactor = false, bGotIsSelectedFrame = false,
1453
4.01k
             bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false,
1454
4.01k
             bBrowseMode = false, bGotBrowseMode = false;
1455
4.01k
    bool bKeepRatio = pVOpt->IsKeepRatio();
1456
4.01k
    bool bGotKeepRatio = false;
1457
1458
4.01k
    for (const beans::PropertyValue& rValue : rSequence)
1459
73.0k
    {
1460
73.0k
        if ( rValue.Name == "ViewLeft" )
1461
3.97k
        {
1462
3.97k
           rValue.Value >>= nX;
1463
3.97k
           nX = o3tl::convertSaturate(nX, o3tl::Length::mm100, o3tl::Length::twip);
1464
3.97k
        }
1465
69.0k
        else if ( rValue.Name == "ViewTop" )
1466
3.95k
        {
1467
3.95k
           rValue.Value >>= nY;
1468
3.95k
           nY = o3tl::convertSaturate(nY, o3tl::Length::mm100, o3tl::Length::twip);
1469
3.95k
        }
1470
65.1k
        else if ( rValue.Name == "VisibleLeft" )
1471
3.97k
        {
1472
3.97k
           rValue.Value >>= nLeft;
1473
3.97k
           nLeft = o3tl::convertSaturate(nLeft, o3tl::Length::mm100, o3tl::Length::twip);
1474
3.97k
           bGotVisibleLeft = true;
1475
3.97k
        }
1476
61.1k
        else if ( rValue.Name == "VisibleTop" )
1477
3.97k
        {
1478
3.97k
           rValue.Value >>= nTop;
1479
3.97k
           nTop = o3tl::convertSaturate(nTop, o3tl::Length::mm100, o3tl::Length::twip);
1480
3.97k
           bGotVisibleTop = true;
1481
3.97k
        }
1482
57.1k
        else if ( rValue.Name == "ZoomType" )
1483
4.00k
        {
1484
4.00k
           rValue.Value >>= nZoomType;
1485
4.00k
           bGotZoomType = true;
1486
4.00k
        }
1487
53.1k
        else if ( rValue.Name == "ZoomFactor" )
1488
4.00k
        {
1489
4.00k
           rValue.Value >>= nZoomFactor;
1490
4.00k
           bGotZoomFactor = true;
1491
4.00k
        }
1492
49.1k
        else if ( rValue.Name == "ViewLayoutColumns" )
1493
3.97k
        {
1494
3.97k
           rValue.Value >>= nViewLayoutColumns;
1495
3.97k
           bGotViewLayoutColumns = true;
1496
3.97k
        }
1497
45.2k
        else if ( rValue.Name == "ViewLayoutBookMode" )
1498
3.97k
        {
1499
3.97k
           bViewLayoutBookMode = *o3tl::doAccess<bool>(rValue.Value);
1500
3.97k
           bGotViewLayoutBookMode = true;
1501
3.97k
        }
1502
41.2k
        else if ( rValue.Name == "IsSelectedFrame" )
1503
3.97k
        {
1504
3.97k
           rValue.Value >>= bSelectedFrame;
1505
3.97k
           bGotIsSelectedFrame = true;
1506
3.97k
        }
1507
37.2k
        else if (rValue.Name == "ShowOnlineLayout")
1508
0
        {
1509
0
           rValue.Value >>= bBrowseMode;
1510
0
           bGotBrowseMode = true;
1511
0
        }
1512
37.2k
        else if (rValue.Name == "KeepRatio")
1513
3.60k
        {
1514
3.60k
            rValue.Value >>= bKeepRatio;
1515
3.60k
            bGotKeepRatio = true;
1516
3.60k
        }
1517
33.6k
        else if (rValue.Name == "WindowState")
1518
3.60k
        {
1519
            // ignored
1520
3.60k
        }
1521
        // Fallback to common SdrModel processing
1522
30.0k
        else
1523
30.0k
           GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->ReadUserDataSequenceValue(&rValue);
1524
73.0k
    }
1525
4.01k
    if (bGotBrowseMode)
1526
0
    {
1527
        // delegate further
1528
0
        GetViewImpl()->GetUNOObject_Impl()->getViewSettings()->setPropertyValue(u"ShowOnlineLayout"_ustr, uno::Any(bBrowseMode));
1529
0
    }
1530
1531
4.01k
    SelectShell();
1532
1533
4.01k
    Point aCursorPos( nX, nY );
1534
1535
4.01k
    m_pWrtShell->EnableSmooth( false );
1536
1537
4.01k
    SvxZoomType eZoom;
1538
4.01k
    if ( !m_pWrtShell->GetViewOptions()->getBrowseMode() )
1539
3.95k
        eZoom = static_cast < SvxZoomType > ( nZoomType );
1540
60
    else
1541
60
    {
1542
60
        eZoom = SvxZoomType::PERCENT;
1543
60
    }
1544
4.01k
    if (bGotIsSelectedFrame)
1545
3.97k
    {
1546
3.97k
        bool bSelectObj = bSelectedFrame && m_pWrtShell->IsObjSelectable( aCursorPos );
1547
1548
        // set flag value to avoid macro execution.
1549
3.97k
        bool bSavedFlagValue = m_pWrtShell->IsMacroExecAllowed();
1550
3.97k
        m_pWrtShell->SetMacroExecAllowed( false );
1551
// os: changed: The user data has to be read if the view is switched back from page preview
1552
// go to the last editing position when opening own files
1553
3.97k
        m_pViewImpl->SetRestorePosition(aCursorPos, bSelectObj);
1554
3.97k
        if(m_bOldShellWasPagePreview|| bIsOwnDocument)
1555
0
        {
1556
0
            m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj );
1557
1558
            // Update the shell to toggle Header/Footer edit if needed
1559
0
            bool bInHeader = true;
1560
0
            if ( m_pWrtShell->IsInHeaderFooter( &bInHeader ) )
1561
0
            {
1562
0
                if ( !bInHeader )
1563
0
                {
1564
0
                    m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, true );
1565
0
                    m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, false );
1566
0
                }
1567
0
                else
1568
0
                {
1569
0
                    m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Header, true );
1570
0
                    m_pWrtShell->SetShowHeaderFooterSeparator( FrameControlType::Footer, false );
1571
0
                }
1572
1573
                // Force repaint
1574
0
                m_pWrtShell->GetWin()->Invalidate();
1575
0
            }
1576
0
            if ( m_pWrtShell->IsInHeaderFooter() != m_pWrtShell->IsHeaderFooterEdit() )
1577
0
                m_pWrtShell->ToggleHeaderFooterEdit();
1578
1579
0
            if( bSelectObj )
1580
0
            {
1581
0
                m_pWrtShell->SelectObj( aCursorPos );
1582
0
                m_pWrtShell->EnterSelFrameMode( &aCursorPos );
1583
0
            }
1584
0
        }
1585
1586
        // reset flag value
1587
3.97k
        m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
1588
3.97k
    }
1589
1590
4.01k
    if (bGotKeepRatio && bKeepRatio != pVOpt->IsKeepRatio())
1591
0
    {
1592
        // Got a custom value, then it makes sense to trigger notifications.
1593
0
        SwViewOption aUsrPref(*pVOpt);
1594
0
        aUsrPref.SetKeepRatio(bKeepRatio);
1595
0
        SwModule::get()->ApplyUsrPref(aUsrPref, this);
1596
0
    }
1597
1598
    // Set ViewLayoutSettings
1599
4.01k
    const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
1600
3.96k
                                        ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
1601
1602
4.01k
    const bool bSetViewSettings = bGotZoomType && bGotZoomFactor &&
1603
3.98k
                                  ( pVOpt->GetZoom() != nZoomFactor || pVOpt->GetZoomType() != eZoom ) &&
1604
234
                                   SwModule::get()->GetUsrPref(pVOpt->getBrowseMode())->IsDefaultZoom();
1605
1606
    // In case we have a 'fixed' view layout of 2 or more columns,
1607
    // we have to apply the view options *before* starting the action.
1608
    // Otherwise the SetZoom function cannot work correctly, because
1609
    // the view layout hasn't been calculated.
1610
4.01k
    const bool bZoomNeedsViewLayout = bSetViewLayoutSettings &&
1611
17
                                      1 < nViewLayoutColumns &&
1612
0
                                      bSetViewSettings &&
1613
0
                                      eZoom != SvxZoomType::PERCENT;
1614
1615
4.01k
    if ( !bZoomNeedsViewLayout )
1616
4.00k
        m_pWrtShell->StartAction();
1617
1618
4.01k
    if ( bSetViewLayoutSettings )
1619
17
        SetViewLayout( nViewLayoutColumns, bViewLayoutBookMode, true );
1620
1621
4.01k
    if ( bZoomNeedsViewLayout )
1622
0
        m_pWrtShell->StartAction();
1623
1624
4.01k
    if ( bSetViewSettings )
1625
234
        SetZoom( eZoom, nZoomFactor, true );
1626
1627
// os: changed: The user data has to be read if the view is switched back from page preview
1628
// go to the last editing position when opening own files
1629
4.01k
    if(m_bOldShellWasPagePreview||bIsOwnDocument)
1630
0
    {
1631
0
        if ( bGotVisibleLeft && bGotVisibleTop )
1632
0
        {
1633
0
            Point aTopLeft(nLeft, nTop);
1634
            // make sure the document is still centered
1635
0
            const SwTwips lBorder = IsDocumentBorder() ? DOCUMENTBORDER : 2 * DOCUMENTBORDER;
1636
0
            SwTwips nEditWidth = GetEditWin().GetOutDev()->GetOutputSize().Width();
1637
0
            if(nEditWidth > (m_aDocSz.Width() + lBorder ))
1638
0
                aTopLeft.setX( ( m_aDocSz.Width() + lBorder - nEditWidth  ) / 2 );
1639
0
            else
1640
0
            {
1641
                //check if the values are possible
1642
0
                tools::Long nXMax = m_pHScrollbar->GetRangeMax() - m_pHScrollbar->GetVisibleSize();
1643
0
                if( aTopLeft.X() > nXMax )
1644
0
                    aTopLeft.setX( nXMax < 0 ? 0 : nXMax );
1645
0
            }
1646
0
            SetVisArea( aTopLeft );
1647
0
        }
1648
0
    }
1649
1650
4.01k
    m_pWrtShell->LockView( true );
1651
4.01k
    m_pWrtShell->EndAction();
1652
4.01k
    m_pWrtShell->LockView( false );
1653
4.01k
    m_pWrtShell->EnableSmooth( true );
1654
1655
4.01k
}
1656
1657
void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSequence )
1658
3.60k
{
1659
3.60k
    const SwRect& rRect = m_pWrtShell->GetCharRect();
1660
3.60k
    const tools::Rectangle& rVis = GetVisArea();
1661
1662
3.60k
    std::vector<beans::PropertyValue> aVector;
1663
1664
3.60k
    sal_uInt16 nViewID( GetViewFrame().GetCurViewId());
1665
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ViewId"_ustr, "view" + OUString::number(nViewID)));
1666
1667
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ViewLeft"_ustr, convertTwipToMm100 ( rRect.Left() )));
1668
1669
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ViewTop"_ustr, convertTwipToMm100 ( rRect.Top() )));
1670
1671
3.60k
    auto visibleLeft = convertTwipToMm100 ( rVis.Left() );
1672
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"VisibleLeft"_ustr, visibleLeft));
1673
1674
3.60k
    auto visibleTop = convertTwipToMm100 ( rVis.Top() );
1675
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"VisibleTop"_ustr, visibleTop));
1676
1677
    // We don't read VisibleRight and VisibleBottom anymore, but write them,
1678
    // because older versions rely on their presence to restore position
1679
1680
3.60k
    auto visibleRight = rVis.IsWidthEmpty() ? visibleLeft : convertTwipToMm100 ( rVis.Right() );
1681
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"VisibleRight"_ustr, visibleRight));
1682
1683
3.60k
    auto visibleBottom = rVis.IsHeightEmpty() ? visibleTop : convertTwipToMm100 ( rVis.Bottom() );
1684
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"VisibleBottom"_ustr, visibleBottom));
1685
1686
3.60k
    const sal_Int16 nZoomType = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetZoomType());
1687
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ZoomType"_ustr, nZoomType));
1688
1689
3.60k
    const sal_Int16 nViewLayoutColumns = static_cast< sal_Int16 >(m_pWrtShell->GetViewOptions()->GetViewLayoutColumns());
1690
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ViewLayoutColumns"_ustr, nViewLayoutColumns));
1691
1692
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ViewLayoutBookMode"_ustr, m_pWrtShell->GetViewOptions()->IsViewLayoutBookMode()));
1693
1694
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"ZoomFactor"_ustr, static_cast < sal_Int16 > (m_pWrtShell->GetViewOptions()->GetZoom())));
1695
1696
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"IsSelectedFrame"_ustr, FrameTypeFlags::NONE != m_pWrtShell->GetSelFrameType()));
1697
1698
3.60k
    aVector.push_back(
1699
3.60k
        comphelper::makePropertyValue(u"KeepRatio"_ustr, m_pWrtShell->GetViewOptions()->IsKeepRatio()));
1700
1701
    // get the current window state for export
1702
3.60k
    aVector.push_back(comphelper::makePropertyValue(u"WindowState"_ustr, ::framework::WindowStateHelper::GetFromWindow(GetWindow())));
1703
1704
3.60k
    rSequence = comphelper::containerToSequence(aVector);
1705
1706
    // Common SdrModel processing
1707
3.60k
    GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->WriteUserDataSequence(rSequence);
1708
3.60k
}
1709
1710
void SwView::ShowCursor( bool bOn )
1711
0
{
1712
    //don't scroll the cursor into the visible area
1713
0
    bool bUnlockView = !m_pWrtShell->IsViewLocked();
1714
0
    m_pWrtShell->LockView( true );    //lock visible section
1715
1716
0
    if( !bOn )
1717
0
        m_pWrtShell->HideCursor();
1718
0
    else if( !m_pWrtShell->IsFrameSelected() && !m_pWrtShell->GetSelectedObjCount() )
1719
0
        m_pWrtShell->ShowCursor();
1720
1721
0
    if( bUnlockView )
1722
0
        m_pWrtShell->LockView( false );
1723
0
}
1724
1725
ErrCode SwView::DoVerb(sal_Int32 nVerb)
1726
0
{
1727
0
    if ( !GetViewFrame().GetFrame().IsInPlace() )
1728
0
    {
1729
0
        SwWrtShell &rSh = GetWrtShell();
1730
0
        const SelectionType nSel = rSh.GetSelectionType();
1731
0
        if ( nSel & SelectionType::Ole )
1732
0
            rSh.LaunchOLEObj( nVerb );
1733
0
    }
1734
0
    return ERRCODE_NONE;
1735
0
}
1736
1737
//   only return true for a text selection
1738
1739
bool SwView::HasSelection( bool  bText ) const
1740
4.02k
{
1741
4.02k
    return bText ? GetWrtShell().SwCursorShell::HasSelection()
1742
4.02k
                 : GetWrtShell().HasSelection();
1743
4.02k
}
1744
1745
OUString SwView::GetSelectionText( bool bCompleteWrds, bool /*bOnlyASample*/ )
1746
0
{
1747
0
    return GetSelectionTextParam( bCompleteWrds, true );
1748
0
}
1749
1750
OUString SwView::GetSelectionTextParam( bool bCompleteWrds, bool bEraseTrail )
1751
0
{
1752
0
    OUString sReturn;
1753
0
    if( bCompleteWrds && !GetWrtShell().HasSelection() )
1754
0
        GetWrtShell().SelWrd();
1755
1756
0
    GetWrtShell().GetSelectedText( sReturn );
1757
0
    if( bEraseTrail )
1758
0
        sReturn = comphelper::string::stripEnd(sReturn, ' ');
1759
0
    return sReturn;
1760
0
}
1761
1762
SwGlossaryHdl* SwView::GetGlosHdl()
1763
0
{
1764
0
    if(!m_pGlosHdl)
1765
0
        m_pGlosHdl.reset(new SwGlossaryHdl(GetViewFrame(), m_pWrtShell.get()));
1766
0
    return m_pGlosHdl.get();
1767
0
}
1768
1769
void SwView::UpdateXformsViewOption(bool bDesignMode)
1770
8.04k
{
1771
    // Set suitable view options when in/out of design mode in XForm documents
1772
8.04k
    if( GetDocShell()->GetDoc()->isXForms() )
1773
0
    {
1774
0
        SwViewOption aViewOption = *GetWrtShellPtr()->GetViewOptions();
1775
0
        aViewOption.SetFormView(!bDesignMode);
1776
0
        GetWrtShellPtr()->ApplyViewOptions(aViewOption);
1777
0
    }
1778
8.04k
}
1779
1780
void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1781
97.3k
{
1782
97.3k
    bool bCallBase = true;
1783
97.3k
    SfxHintId nId = rHint.GetId();
1784
97.3k
    switch ( nId )
1785
97.3k
    {
1786
4.02k
        case SfxHintId::FmDesignModeChanged:
1787
4.02k
        {
1788
4.02k
            auto pChangedHint = static_cast<const FmDesignModeChangedHint*>(&rHint);
1789
4.02k
            bool bDesignMode = pChangedHint->GetDesignMode();
1790
1791
4.02k
            UpdateXformsViewOption(bDesignMode);
1792
1793
4.02k
            if (!bDesignMode && GetDrawFuncPtr())
1794
0
            {
1795
0
                GetDrawFuncPtr()->Deactivate();
1796
0
                SetDrawFuncPtr(nullptr);
1797
0
                LeaveDrawCreate();
1798
0
                AttrChangedNotify(nullptr);
1799
0
            }
1800
4.02k
            break;
1801
0
        }
1802
        // sub shells will be destroyed by the
1803
        // dispatcher, if the view frame is dying. Thus, reset member <pShell>.
1804
8.04k
        case SfxHintId::Dying:
1805
8.04k
            {
1806
8.04k
                if ( &rBC == &GetViewFrame() )
1807
4.02k
                {
1808
4.02k
                    ResetSubShell();
1809
4.02k
                }
1810
8.04k
            }
1811
8.04k
            break;
1812
0
        case SfxHintId::ModeChanged:
1813
0
            {
1814
                // Modal mode change-over?
1815
0
                bool bModal = GetDocShell()->IsInModalMode();
1816
0
                m_pHRuler->SetActive( !bModal );
1817
0
                m_pVRuler->SetActive( !bModal );
1818
0
            }
1819
1820
0
            [[fallthrough]];
1821
1822
8.04k
        case SfxHintId::TitleChanged:
1823
8.04k
            if ( GetDocShell()->IsReadOnly() != GetWrtShell().GetViewOptions()->IsReadonly() )
1824
0
            {
1825
0
                SwWrtShell &rSh = GetWrtShell();
1826
0
                rSh.SetReadonlyOption( GetDocShell()->IsReadOnly() );
1827
1828
0
                if ( rSh.GetViewOptions()->IsViewVRuler() )
1829
0
                    CreateVRuler();
1830
0
                else
1831
0
                    KillVRuler();
1832
0
                if ( rSh.GetViewOptions()->IsViewHRuler() )
1833
0
                    CreateTab();
1834
0
                else
1835
0
                    KillTab();
1836
0
                bool bReadonly = GetDocShell()->IsReadOnly();
1837
                // if document is to be opened in alive-mode then this has to be
1838
                // regarded while switching from readonly-mode to edit-mode
1839
0
                if( !bReadonly )
1840
0
                {
1841
0
                    SwDrawModel * pDrawDoc = GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
1842
0
                    if (pDrawDoc)
1843
0
                    {
1844
0
                        if( !pDrawDoc->GetOpenInDesignMode() )
1845
0
                            break;// don't touch the design mode
1846
0
                    }
1847
0
                }
1848
0
                SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadonly);
1849
0
                GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
1850
0
                        SfxCallMode::ASYNCHRON, { &aItem });
1851
0
            }
1852
8.04k
            break;
1853
1854
8.04k
        case SfxHintId::SwDrawViewsCreated:
1855
0
            {
1856
0
                bCallBase = false;
1857
0
                if ( GetFormShell() )
1858
0
                {
1859
0
                    GetFormShell()->SetView(dynamic_cast<FmFormView*>(GetWrtShell().GetDrawView()));
1860
0
                    SfxBoolItem aItem( SID_FM_DESIGN_MODE, !GetDocShell()->IsReadOnly());
1861
0
                    GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
1862
0
                            SfxCallMode::SYNCHRON, { &aItem });
1863
0
                }
1864
0
            }
1865
0
            break;
1866
0
        case SfxHintId::RedlineChanged:
1867
0
            {
1868
0
                static sal_uInt16 const aSlotRedLine[] = {
1869
0
                    FN_REDLINE_ACCEPT_DIRECT,
1870
0
                    FN_REDLINE_REJECT_DIRECT,
1871
0
                    FN_REDLINE_NEXT_CHANGE,
1872
0
                    FN_REDLINE_PREV_CHANGE,
1873
0
                    FN_REDLINE_ACCEPT_ALL,
1874
0
                    FN_REDLINE_REJECT_ALL,
1875
0
                    0
1876
0
                };
1877
0
                GetViewFrame().GetBindings().Invalidate(aSlotRedLine);
1878
0
            }
1879
0
            break;
1880
0
        case SfxHintId::StylesSpotlightModified:
1881
0
            {
1882
                // we need to Invalidate to render with the new set of
1883
                // spotlighted styles
1884
0
                if (vcl::Window *pMyWin = GetWrtShell().GetWin())
1885
0
                    pMyWin->Invalidate();
1886
0
            }
1887
0
            break;
1888
77.2k
        default: break;
1889
97.3k
    }
1890
1891
97.3k
    if ( bCallBase )
1892
97.3k
        SfxViewShell::Notify(rBC, rHint);
1893
97.3k
}
1894
1895
#if defined(_WIN32) || defined UNX
1896
1897
void SwView::ScannerEventHdl()
1898
0
{
1899
0
    if (uno::Reference<XScannerManager2> xScanMgr = SwModule::get()->GetScannerManager())
1900
0
    {
1901
0
        const ScannerContext    aContext( xScanMgr->getAvailableScanners().getConstArray()[ 0 ] );
1902
0
        const ScanError         eError = xScanMgr->getError( aContext );
1903
1904
0
        if( ScanError_ScanErrorNone == eError )
1905
0
        {
1906
0
            const uno::Reference< awt::XBitmap > xBitmap( xScanMgr->getBitmap( aContext ) );
1907
1908
0
            if( xBitmap.is() )
1909
0
            {
1910
0
                const Bitmap aScanBmp( VCLUnoHelper::GetBitmap( xBitmap ) );
1911
1912
0
                if( !aScanBmp.IsEmpty() )
1913
0
                {
1914
0
                    Graphic aGrf(aScanBmp);
1915
0
                    m_pWrtShell->InsertGraphic( OUString(), OUString(), aGrf );
1916
0
                }
1917
0
            }
1918
0
        }
1919
0
    }
1920
0
    SfxBindings& rBind = GetViewFrame().GetBindings();
1921
0
    rBind.Invalidate( SID_TWAIN_SELECT );
1922
0
    rBind.Invalidate( SID_TWAIN_TRANSFER );
1923
0
}
1924
#endif
1925
1926
void    SwView::StopShellTimer()
1927
0
{
1928
0
    if(m_aTimer.IsActive())
1929
0
    {
1930
0
        m_aTimer.Stop();
1931
0
        if ( m_bAttrChgNotifiedWithRegistrations )
1932
0
        {
1933
0
            GetViewFrame().GetBindings().LEAVEREGISTRATIONS();
1934
0
            m_bAttrChgNotifiedWithRegistrations = false;
1935
0
        }
1936
0
        SelectShell();
1937
0
        m_bAttrChgNotified = false;
1938
0
    }
1939
0
}
1940
1941
bool SwView::PrepareClose( bool bUI )
1942
8.04k
{
1943
8.04k
    SfxViewFrame& rVFrame = GetViewFrame();
1944
8.04k
    rVFrame.SetChildWindow( SwInputChild::GetChildWindowId(), false );
1945
8.04k
    if( rVFrame.GetDispatcher()->IsLocked() )
1946
0
        rVFrame.GetDispatcher()->Lock(false);
1947
1948
8.04k
    if ( m_pFormShell && !m_pFormShell->PrepareClose( bUI ) )
1949
0
    {
1950
0
        return false;
1951
0
    }
1952
8.04k
    return SfxViewShell::PrepareClose( bUI );
1953
8.04k
}
1954
1955
// status methods for clipboard.
1956
// Status changes now notified from the clipboard.
1957
bool SwView::IsPasteAllowed()
1958
0
{
1959
0
    SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1960
0
    if( m_nLastPasteDestination != nPasteDestination )
1961
0
    {
1962
0
        TransferableDataHelper aDataHelper(
1963
0
                        TransferableDataHelper::CreateFromSystemClipboard(
1964
0
                                                        &GetEditWin()) );
1965
0
        if( aDataHelper.GetXTransferable().is() )
1966
0
        {
1967
0
            m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1968
0
            m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1969
0
                                                    *m_pWrtShell, aDataHelper );
1970
0
        }
1971
0
        else
1972
0
            m_bPasteState = m_bPasteSpecialState = false;
1973
1974
0
        if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination )  // the init value
1975
0
            m_pViewImpl->AddClipboardListener();
1976
0
        m_nLastPasteDestination = nPasteDestination;
1977
0
    }
1978
0
    return m_bPasteState;
1979
0
}
1980
1981
bool SwView::IsPasteSpecialAllowed()
1982
0
{
1983
0
    if ( m_pFormShell && m_pFormShell->IsActiveControl() )
1984
0
        return false;
1985
1986
0
    SotExchangeDest nPasteDestination = SwTransferable::GetSotDestination( *m_pWrtShell );
1987
0
    if( m_nLastPasteDestination != nPasteDestination )
1988
0
    {
1989
0
        TransferableDataHelper aDataHelper(
1990
0
                        TransferableDataHelper::CreateFromSystemClipboard(
1991
0
                                                        &GetEditWin()) );
1992
0
        if( aDataHelper.GetXTransferable().is() )
1993
0
        {
1994
0
            m_bPasteState = SwTransferable::IsPaste( *m_pWrtShell, aDataHelper );
1995
0
            m_bPasteSpecialState = SwTransferable::IsPasteSpecial(
1996
0
                                                    *m_pWrtShell, aDataHelper );
1997
0
        }
1998
0
        else
1999
0
            m_bPasteState = m_bPasteSpecialState = false;
2000
2001
0
        if( static_cast<SotExchangeDest>(0xFFFF) == m_nLastPasteDestination )  // the init value
2002
0
            m_pViewImpl->AddClipboardListener();
2003
0
    }
2004
0
    return m_bPasteSpecialState;
2005
0
}
2006
2007
bool SwView::IsPasteSpreadsheet(bool bHasOwnTableCopied)
2008
0
{
2009
0
    TransferableDataHelper aDataHelper(
2010
0
                        TransferableDataHelper::CreateFromSystemClipboard(
2011
0
                                                        &GetEditWin()) );
2012
0
    if( aDataHelper.GetXTransferable().is() )
2013
0
    {
2014
0
        if (bHasOwnTableCopied && SwTransferable::IsPasteOwnFormat( aDataHelper ))
2015
0
            return true;
2016
0
        return aDataHelper.HasFormat( SotClipboardFormatId::SYLK ) || aDataHelper.HasFormat( SotClipboardFormatId::SYLK_BIGCAPS );
2017
0
    }
2018
0
    return false;
2019
0
}
2020
2021
void SwView::NotifyDBChanged()
2022
0
{
2023
0
    GetViewImpl()->GetUNOObject_Impl()->NotifyDBChanged();
2024
0
}
2025
2026
// Printing
2027
2028
SfxObjectShellLock SwView::CreateTmpSelectionDoc()
2029
0
{
2030
0
    SwXTextView *const pTempImpl = GetViewImpl()->GetUNOObject_Impl();
2031
0
    return pTempImpl->BuildTmpSelectionDoc();
2032
0
}
2033
2034
void SwView::AddTransferable(SwTransferable& rTransferable)
2035
0
{
2036
0
    GetViewImpl()->AddTransferable(rTransferable);
2037
0
}
2038
2039
tools::Rectangle SwView::getLOKVisibleArea() const
2040
0
{
2041
0
    if (SwViewShell* pVwSh = GetWrtShellPtr())
2042
0
        return pVwSh->getLOKVisibleArea();
2043
0
    else
2044
0
        return tools::Rectangle();
2045
0
}
2046
2047
void SwView::flushPendingLOKInvalidateTiles()
2048
0
{
2049
0
    if (SwWrtShell* pSh = GetWrtShellPtr())
2050
0
        pSh->FlushPendingLOKInvalidateTiles();
2051
0
}
2052
2053
std::optional<OString> SwView::getLOKPayload(int nType, int nViewId) const
2054
0
{
2055
0
    if (SwWrtShell* pSh = GetWrtShellPtr())
2056
0
        return pSh->getLOKPayload(nType, nViewId);
2057
0
    else
2058
0
        return std::nullopt;
2059
0
}
2060
2061
int SwView::getEditMode() const
2062
0
{
2063
0
    SwWrtShell* pWrtShell = GetWrtShellPtr();
2064
0
    if (!pWrtShell)
2065
0
    {
2066
0
        return 0;
2067
0
    }
2068
2069
0
    return static_cast<int>(pWrtShell->GetViewOptions()->GetRedlineRenderMode());
2070
0
}
2071
2072
OUString SwView::GetDataSourceName() const
2073
0
{
2074
0
    uno::Reference<lang::XMultiServiceFactory> xFactory(GetDocShell()->GetModel(), uno::UNO_QUERY);
2075
0
    uno::Reference<beans::XPropertySet> xSettings(
2076
0
        xFactory->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
2077
0
    OUString sDataSourceName = u""_ustr;
2078
0
    xSettings->getPropertyValue(u"CurrentDatabaseDataSource"_ustr) >>= sDataSourceName;
2079
2080
0
    return sDataSourceName;
2081
0
}
2082
2083
bool SwView::IsDataSourceAvailable(const OUString& sDataSourceName)
2084
0
{
2085
0
    const uno::Reference< uno::XComponentContext >& xContext( ::comphelper::getProcessComponentContext() );
2086
0
    Reference< XDatabaseContext> xDatabaseContext = DatabaseContext::create(xContext);
2087
2088
0
    return xDatabaseContext->hasByName(sDataSourceName);
2089
0
}
2090
2091
void SwView::BringToAttention(std::vector<basegfx::B2DRange>&& aRanges)
2092
0
{
2093
0
    m_nBringToAttentionBlinkTimeOutsRemaining = 0;
2094
0
    m_aBringToAttentionBlinkTimer.Stop();
2095
0
    if (aRanges.empty())
2096
0
        m_xBringToAttentionOverlayObject.reset();
2097
0
    else
2098
0
    {
2099
0
        m_xBringToAttentionOverlayObject.reset(
2100
0
                    new sdr::overlay::OverlaySelection(sdr::overlay::OverlayType::Invert,
2101
0
                                                       Color(), std::move(aRanges),
2102
0
                                                       true /*unused for Invert type*/));
2103
0
        m_nBringToAttentionBlinkTimeOutsRemaining = 4;
2104
0
        m_aBringToAttentionBlinkTimer.Start();
2105
0
    }
2106
0
}
2107
2108
void SwView::BringToAttention(const tools::Rectangle& rRect)
2109
0
{
2110
0
    std::vector<basegfx::B2DRange> aRanges{ basegfx::B2DRange(rRect.Left(), rRect.Top(),
2111
0
                                                              rRect.Right(), rRect.Bottom()) };
2112
0
    BringToAttention(std::move(aRanges));
2113
0
}
2114
2115
void SwView::BringToAttention(const SwNode* pNode)
2116
0
{
2117
0
    if (!pNode)
2118
0
        return;
2119
2120
0
    std::vector<basegfx::B2DRange> aRanges;
2121
0
    const SwFrame* pFrame;
2122
0
    if (pNode->IsContentNode())
2123
0
    {
2124
0
        pFrame = pNode->GetContentNode()->getLayoutFrame(GetWrtShell().GetLayout());
2125
0
    }
2126
0
    else
2127
0
    {
2128
        // section and table nodes
2129
0
        SwNode2Layout aTmp(*pNode, pNode->GetIndex() - 1);
2130
0
        pFrame = aTmp.NextFrame();
2131
0
    }
2132
0
    while (pFrame)
2133
0
    {
2134
0
        const SwRect& rFrameRect = pFrame->getFrameArea();
2135
0
        if (!rFrameRect.IsEmpty())
2136
0
            aRanges.emplace_back(rFrameRect.Left(), rFrameRect.Top() + pFrame->GetTopMargin(),
2137
0
                                 rFrameRect.Right(), rFrameRect.Bottom());
2138
0
        if (!pFrame->IsFlowFrame())
2139
0
            break;
2140
0
        const SwFlowFrame* pFollow = SwFlowFrame::CastFlowFrame(pFrame)->GetFollow();
2141
0
        if (!pFollow)
2142
0
            break;
2143
0
        pFrame = &pFollow->GetFrame();
2144
0
    }
2145
0
    BringToAttention(std::move(aRanges));
2146
0
}
2147
2148
IMPL_LINK_NOARG(SwView, BringToAttentionBlinkTimerHdl, Timer*, void)
2149
0
{
2150
0
    if (GetDrawView() && m_xBringToAttentionOverlayObject)
2151
0
    {
2152
0
        if (SdrView* pView = GetDrawView())
2153
0
        {
2154
0
            if (SdrPaintWindow* pPaintWindow = pView->GetPaintWindow(0))
2155
0
            {
2156
0
                const rtl::Reference<sdr::overlay::OverlayManager>& xOverlayManager
2157
0
                    = pPaintWindow->GetOverlayManager();
2158
0
                if (m_nBringToAttentionBlinkTimeOutsRemaining % 2 == 0)
2159
0
                    xOverlayManager->add(*m_xBringToAttentionOverlayObject);
2160
0
                else
2161
0
                    xOverlayManager->remove(*m_xBringToAttentionOverlayObject);
2162
0
                --m_nBringToAttentionBlinkTimeOutsRemaining;
2163
0
            }
2164
0
            else
2165
0
                m_nBringToAttentionBlinkTimeOutsRemaining = 0;
2166
0
        }
2167
0
        else
2168
0
            m_nBringToAttentionBlinkTimeOutsRemaining = 0;
2169
0
    }
2170
0
    else
2171
0
        m_nBringToAttentionBlinkTimeOutsRemaining = 0;
2172
0
    if (m_nBringToAttentionBlinkTimeOutsRemaining == 0)
2173
0
    {
2174
0
        m_xBringToAttentionOverlayObject.reset();
2175
0
        m_aBringToAttentionBlinkTimer.Stop();
2176
0
    }
2177
0
}
2178
2179
void SwView::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart,
2180
                                                       int nMode) const
2181
0
{
2182
0
    SfxViewShell::libreOfficeKitViewInvalidateTilesCallback(pRect, nPart, nMode);
2183
0
    if (static_cast<SwRedlineRenderMode>(nMode) == SwRedlineRenderMode::OmitDeletes)
2184
0
    {
2185
        // If an "omit deletes" mode is invalidated, also invalidate the matching "omit inserts"
2186
        // mode.
2187
0
        SfxViewShell::libreOfficeKitViewInvalidateTilesCallback(
2188
0
            pRect, nPart, static_cast<int>(SwRedlineRenderMode::OmitInserts));
2189
0
    }
2190
0
}
2191
2192
namespace sw {
2193
2194
void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)
2195
4.02k
{
2196
4.02k
    o_rData = *SwModule::get()->GetPrtOptions(bWeb);
2197
4.02k
}
2198
2199
} // namespace sw
2200
2201
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */