Coverage Report

Created: 2026-04-09 11:41

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