Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sw/source/uibase/uiview/view1.cxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <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
8.47k
{
40
    // fdo#40438 Update the layout to make sure everything is correct before showing the content
41
8.47k
    m_pWrtShell->StartAction();
42
8.47k
    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
8.47k
    SwDocShell* pDocSh = GetDocShell();
48
8.47k
    if(pDocSh)
49
8.47k
        pDocSh->SetView(this);
50
8.47k
    SwModule::get()->SetView(this);
51
52
    // Document size has changed.
53
8.47k
    if(!bDocSzUpdated)
54
8.47k
        DocSzChgd(m_aDocSz);
55
56
    // make selection visible
57
8.47k
    if(m_bMakeSelectionVisible)
58
0
    {
59
0
        m_pWrtShell->MakeSelVisible();
60
0
        m_bMakeSelectionVisible = false;
61
0
    }
62
8.47k
    m_pHRuler->SetActive();
63
8.47k
    m_pVRuler->SetActive();
64
65
8.47k
    if ( bMDIActivate )
66
8.47k
    {
67
8.47k
        if ( m_pShell )
68
0
        {
69
0
            SfxDispatcher &rDispatcher = GetDispatcher();
70
0
            SfxShell *pTopShell = rDispatcher.GetShell( 0 );
71
72
            // this SwView is the top-most shell on the stack
73
0
            if ( pTopShell == this )
74
0
            {
75
0
                for ( sal_uInt16 i = 1; true; ++i )
76
0
                {
77
0
                    SfxShell *pSfxShell = rDispatcher.GetShell( i );
78
                    // does the stack contain any shells spawned by this SwView already?
79
0
                    if  ( ( dynamic_cast< const SwBaseShell *>( pSfxShell ) !=  nullptr
80
0
                         || dynamic_cast< const FmFormShell  *>( pSfxShell ) !=  nullptr )
81
0
                         && ( pSfxShell->GetViewShell() == this ) )
82
0
                    {
83
                        // it shouldn't b/c we haven't been activated yet
84
                        // so assert that 'cause it'll crash during dispose at the latest
85
0
                        assert( pSfxShell && "Corrupted shell stack: dependent shell positioned below its view");
86
0
                    }
87
0
                    else
88
0
                        break;
89
0
                }
90
0
            }
91
0
        }
92
93
8.47k
        m_pWrtShell->ShellGetFocus();     // Selections visible
94
95
8.47k
        if( !m_sSwViewData.isEmpty() )
96
0
        {
97
0
            ReadUserData(m_sSwViewData);
98
0
            m_sSwViewData.clear();
99
0
        }
100
101
8.47k
        AttrChangedNotify(nullptr);
102
103
        // Initialize Fielddlg newly if necessary (e.g. for TYP_SETVAR)
104
8.47k
        sal_uInt16 nId = SwFieldDlgWrapper::GetChildWindowId();
105
8.47k
        SfxViewFrame& rVFrame = GetViewFrame();
106
8.47k
        SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(rVFrame.GetChildWindow(nId));
107
8.47k
        if (pWrp)
108
0
            pWrp->ReInitDlg();
109
110
        // Initialize RedlineDlg newly if necessary
111
8.47k
        nId = SwRedlineAcceptChild::GetChildWindowId();
112
8.47k
        SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(rVFrame.GetChildWindow(nId));
113
8.47k
        if (pRed)
114
0
            pRed->ReInitDlg();
115
116
        // reinit IdxMarkDlg
117
8.47k
        nId = SwInsertIdxMarkWrapper::GetChildWindowId();
118
8.47k
        SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(rVFrame.GetChildWindow(nId));
119
8.47k
        if (pIdxMrk)
120
0
            pIdxMrk->ReInitDlg(*m_pWrtShell);
121
122
        // reinit AuthMarkDlg
123
8.47k
        nId = SwInsertAuthMarkWrapper::GetChildWindowId();
124
8.47k
        SwInsertAuthMarkWrapper *pAuthMrk = static_cast<SwInsertAuthMarkWrapper*>(rVFrame.
125
8.47k
                                                                GetChildWindow(nId));
126
8.47k
        if (pAuthMrk)
127
0
            pAuthMrk->ReInitDlg(*m_pWrtShell);
128
8.47k
    }
129
0
    else
130
        // At least call the Notify (as a precaution because of the SlotFilter).
131
0
        AttrChangedNotify(nullptr);
132
133
8.47k
    SfxViewShell::Activate(bMDIActivate);
134
8.47k
}
135
136
void SwView::Deactivate(bool bMDIActivate)
137
8.47k
{
138
8.47k
    GetEditWin().FlushInBuffer(); // Flush characters still in the input buffer.
139
140
8.47k
    if( bMDIActivate )
141
8.47k
    {
142
8.47k
        m_pWrtShell->ShellLoseFocus();    // Selections invisible
143
144
8.47k
        m_pHRuler->SetActive( false );
145
8.47k
        m_pVRuler->SetActive( false );
146
8.47k
    }
147
8.47k
    SfxViewShell::Deactivate(bMDIActivate);
148
8.47k
}
149
150
void SwView::MarginChanged()
151
0
{
152
0
    GetWrtShell().SetBrowseBorder( GetMargin() );
153
0
}
154
155
void SwView::ExecFormatPaintbrush(SfxRequest const & rReq)
156
0
{
157
0
    if(!m_pFormatClipboard)
158
0
        return;
159
160
0
    if( m_pFormatClipboard->HasContent() )
161
0
    {
162
0
        m_pFormatClipboard->Erase();
163
164
0
        SwApplyTemplate aTemplate;
165
0
        GetEditWin().SetApplyTemplate(aTemplate);
166
0
    }
167
0
    else
168
0
    {
169
0
        bool bPersistentCopy = false;
170
0
        const SfxItemSet *pArgs = rReq.GetArgs();
171
0
        if( pArgs && pArgs->Count() >= 1 )
172
0
        {
173
0
            bPersistentCopy = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
174
0
        }
175
176
0
        m_pFormatClipboard->Copy( GetWrtShell(), GetPool(), bPersistentCopy );
177
178
0
        SwApplyTemplate aTemplate;
179
0
        aTemplate.m_pFormatClipboard = m_pFormatClipboard.get();
180
0
        GetEditWin().SetApplyTemplate(aTemplate);
181
0
    }
182
0
    GetViewFrame().GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
183
0
}
184
185
void SwView::StateFormatPaintbrush(SfxItemSet &rSet)
186
0
{
187
0
    if(!m_pFormatClipboard)
188
0
        return;
189
190
0
    const bool bHasContent = m_pFormatClipboard->HasContent();
191
0
    if( !bHasContent &&
192
0
        !SwFormatClipboard::CanCopyThisType( GetWrtShell().GetSelectionType())
193
0
      )
194
0
    {
195
0
        rSet.DisableItem( SID_FORMATPAINTBRUSH );
196
0
    }
197
0
    else
198
0
        rSet.Put(SfxBoolItem(SID_FORMATPAINTBRUSH, bHasContent));
199
0
}
200
201
void SwView::UpdateWordCount(SfxShell* pShell, sal_uInt16 nSlot)
202
0
{
203
0
    SfxViewFrame& rVFrame = GetViewFrame();
204
0
    rVFrame.ToggleChildWindow(FN_WORDCOUNT_DIALOG);
205
0
    pShell->Invalidate(nSlot);
206
207
0
    SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(rVFrame.GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
208
0
    if (pWrdCnt)
209
0
        pWrdCnt->UpdateCounts();
210
0
}
211
212
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */