Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/uiview/view1.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 <svl/eitem.hxx>
21
#include <svx/ruler.hxx>
22
#include <idxmrk.hxx>
23
#include <view.hxx>
24
#include <basesh.hxx>
25
#include <wrtsh.hxx>
26
#include <swmodule.hxx>
27
#include <docsh.hxx>
28
#include <fldwrap.hxx>
29
#include <redlndlg.hxx>
30
#include <edtwin.hxx>
31
#include <formatclipboard.hxx>
32
#include <cmdid.h>
33
#include <sfx2/dispatch.hxx>
34
#include <sfx2/request.hxx>
35
#include <sfx2/viewfrm.hxx>
36
#include <wordcountdialog.hxx>
37
38
void SwView::Activate(bool bMDIActivate)
39
6.21k
{
40
    // fdo#40438 Update the layout to make sure everything is correct before showing the content
41
6.21k
    m_pWrtShell->StartAction();
42
6.21k
    m_pWrtShell->EndAction( true );
43
44
    // Register the current View at the DocShell.
45
    // The view remains active at the DocShell until it will
46
    // be destroyed or by Activate a new one will be set.
47
6.21k
    SwDocShell* pDocSh = GetDocShell();
48
6.21k
    if(pDocSh)
49
6.21k
    {
50
6.21k
        pDocSh->SetView(this);
51
6.21k
        pDocSh->CheckPendingLinkUpdateInfobar();
52
6.21k
    }
53
6.21k
    SwModule::get()->SetView(this);
54
55
    // Document size has changed.
56
6.21k
    if(!bDocSzUpdated)
57
6.21k
        DocSzChgd(m_aDocSz);
58
59
    // make selection visible
60
6.21k
    if(m_bMakeSelectionVisible)
61
0
    {
62
0
        m_pWrtShell->MakeSelVisible();
63
0
        m_bMakeSelectionVisible = false;
64
0
    }
65
6.21k
    m_pHRuler->SetActive();
66
6.21k
    m_pVRuler->SetActive();
67
68
6.21k
    if ( bMDIActivate )
69
6.21k
    {
70
6.21k
        if ( m_pShell )
71
1
        {
72
1
            SfxDispatcher &rDispatcher = GetDispatcher();
73
1
            SfxShell *pTopShell = rDispatcher.GetShell( 0 );
74
75
            // this SwView is the top-most shell on the stack
76
1
            if ( pTopShell == this )
77
0
            {
78
0
                for ( sal_uInt16 i = 1; true; ++i )
79
0
                {
80
0
                    SfxShell *pSfxShell = rDispatcher.GetShell( i );
81
                    // does the stack contain any shells spawned by this SwView already?
82
0
                    if  ( ( dynamic_cast< const SwBaseShell *>( pSfxShell ) !=  nullptr
83
0
                         || dynamic_cast< const FmFormShell  *>( pSfxShell ) !=  nullptr )
84
0
                         && ( pSfxShell->GetViewShell() == this ) )
85
0
                    {
86
                        // it shouldn't b/c we haven't been activated yet
87
                        // so assert that 'cause it'll crash during dispose at the latest
88
0
                        assert( pSfxShell && "Corrupted shell stack: dependent shell positioned below its view");
89
0
                    }
90
0
                    else
91
0
                        break;
92
0
                }
93
0
            }
94
1
        }
95
96
6.21k
        m_pWrtShell->ShellGetFocus();     // Selections visible
97
98
6.21k
        if( !m_sSwViewData.isEmpty() )
99
0
        {
100
0
            ReadUserData(m_sSwViewData);
101
0
            m_sSwViewData.clear();
102
0
        }
103
104
6.21k
        AttrChangedNotify(nullptr);
105
106
        // Initialize Fielddlg newly if necessary (e.g. for TYP_SETVAR)
107
6.21k
        sal_uInt16 nId = SwFieldDlgWrapper::GetChildWindowId();
108
6.21k
        SfxViewFrame& rVFrame = GetViewFrame();
109
6.21k
        SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(rVFrame.GetChildWindow(nId));
110
6.21k
        if (pWrp)
111
0
            pWrp->ReInitDlg();
112
113
        // Initialize RedlineDlg newly if necessary
114
6.21k
        nId = SwRedlineAcceptChild::GetChildWindowId();
115
6.21k
        SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(rVFrame.GetChildWindow(nId));
116
6.21k
        if (pRed)
117
0
            pRed->ReInitDlg();
118
119
        // reinit IdxMarkDlg
120
6.21k
        nId = SwInsertIdxMarkWrapper::GetChildWindowId();
121
6.21k
        SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(rVFrame.GetChildWindow(nId));
122
6.21k
        if (pIdxMrk)
123
0
            pIdxMrk->ReInitDlg(*m_pWrtShell);
124
125
        // reinit AuthMarkDlg
126
6.21k
        nId = SwInsertAuthMarkWrapper::GetChildWindowId();
127
6.21k
        SwInsertAuthMarkWrapper *pAuthMrk = static_cast<SwInsertAuthMarkWrapper*>(rVFrame.
128
6.21k
                                                                GetChildWindow(nId));
129
6.21k
        if (pAuthMrk)
130
0
            pAuthMrk->ReInitDlg(*m_pWrtShell);
131
6.21k
    }
132
0
    else
133
        // At least call the Notify (as a precaution because of the SlotFilter).
134
0
        AttrChangedNotify(nullptr);
135
136
6.21k
    SfxViewShell::Activate(bMDIActivate);
137
6.21k
}
138
139
void SwView::Deactivate(bool bMDIActivate)
140
6.21k
{
141
6.21k
    GetEditWin().FlushInBuffer(); // Flush characters still in the input buffer.
142
143
6.21k
    if( bMDIActivate )
144
6.21k
    {
145
6.21k
        m_pWrtShell->ShellLoseFocus();    // Selections invisible
146
147
6.21k
        m_pHRuler->SetActive( false );
148
6.21k
        m_pVRuler->SetActive( false );
149
6.21k
    }
150
6.21k
    SfxViewShell::Deactivate(bMDIActivate);
151
6.21k
}
152
153
void SwView::MarginChanged()
154
0
{
155
0
    GetWrtShell().SetBrowseBorder( GetMargin() );
156
0
}
157
158
void SwView::ExecFormatPaintbrush(SfxRequest const & rReq)
159
0
{
160
0
    if(!m_pFormatClipboard)
161
0
        return;
162
163
0
    if( m_pFormatClipboard->HasContent() )
164
0
    {
165
0
        m_pFormatClipboard->Erase();
166
167
0
        SwApplyTemplate aTemplate;
168
0
        GetEditWin().SetApplyTemplate(aTemplate);
169
0
    }
170
0
    else
171
0
    {
172
0
        bool bPersistentCopy = false;
173
0
        const SfxItemSet *pArgs = rReq.GetArgs();
174
0
        if( pArgs && pArgs->Count() >= 1 )
175
0
        {
176
0
            bPersistentCopy = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
177
0
        }
178
179
0
        m_pFormatClipboard->Copy( GetWrtShell(), GetPool(), bPersistentCopy );
180
181
0
        SwApplyTemplate aTemplate;
182
0
        aTemplate.m_pFormatClipboard = m_pFormatClipboard.get();
183
0
        GetEditWin().SetApplyTemplate(aTemplate);
184
0
    }
185
0
    GetViewFrame().GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
186
0
}
187
188
void SwView::StateFormatPaintbrush(SfxItemSet &rSet)
189
0
{
190
0
    if(!m_pFormatClipboard)
191
0
        return;
192
193
0
    const bool bHasContent = m_pFormatClipboard->HasContent();
194
0
    if( !bHasContent &&
195
0
        !SwFormatClipboard::CanCopyThisType( GetWrtShell().GetSelectionType())
196
0
      )
197
0
    {
198
0
        rSet.DisableItem( SID_FORMATPAINTBRUSH );
199
0
    }
200
0
    else
201
0
        rSet.Put(SfxBoolItem(SID_FORMATPAINTBRUSH, bHasContent));
202
0
}
203
204
void SwView::UpdateWordCount(SfxShell* pShell, sal_uInt16 nSlot)
205
0
{
206
0
    SfxViewFrame& rVFrame = GetViewFrame();
207
0
    rVFrame.ToggleChildWindow(FN_WORDCOUNT_DIALOG);
208
0
    pShell->Invalidate(nSlot);
209
210
0
    SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(rVFrame.GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
211
0
    if (pWrdCnt)
212
0
        pWrdCnt->UpdateCounts();
213
0
}
214
215
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */