Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / view1.cxx
blobca51ceba98c70444689ba87e7a239856101e2f99
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
38 void SwView::Activate(bool bMDIActivate)
40 // fdo#40438 Update the layout to make sure everything is correct before showing the content
41 m_pWrtShell->StartAction();
42 m_pWrtShell->EndAction( true );
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 SwDocShell* pDocSh = GetDocShell();
48 if(pDocSh)
49 pDocSh->SetView(this);
50 SwModule* pSwMod = SW_MOD();
51 pSwMod->SetView(this);
53 // Document size has changed.
54 if(!bDocSzUpdated)
55 DocSzChgd(m_aDocSz);
57 // make selection visible
58 if(m_bMakeSelectionVisible)
60 m_pWrtShell->MakeSelVisible();
61 m_bMakeSelectionVisible = false;
63 m_pHRuler->SetActive();
64 m_pVRuler->SetActive();
66 if ( bMDIActivate )
68 if ( m_pShell )
70 SfxDispatcher &rDispatcher = GetDispatcher();
71 SfxShell *pTopShell = rDispatcher.GetShell( 0 );
73 // this SwView is the top-most shell on the stack
74 if ( pTopShell == this )
76 for ( sal_uInt16 i = 1; true; ++i )
78 SfxShell *pSfxShell = rDispatcher.GetShell( i );
79 // does the stack contain any shells spawned by this SwView already?
80 if ( ( dynamic_cast< const SwBaseShell *>( pSfxShell ) != nullptr
81 || dynamic_cast< const FmFormShell *>( pSfxShell ) != nullptr )
82 && ( pSfxShell->GetViewShell() == this ) )
84 // it shouldn't b/c we haven't been activated yet
85 // so assert that 'cause it'll crash during dispose at the latest
86 assert( pSfxShell && "Corrupted shell stack: dependent shell positioned below its view");
88 else
89 break;
94 m_pWrtShell->ShellGetFocus(); // Selections visible
96 if( !m_sSwViewData.isEmpty() )
98 ReadUserData(m_sSwViewData);
99 m_sSwViewData.clear();
102 AttrChangedNotify(nullptr);
104 // Initialize Fielddlg newly if necessary (e.g. for TYP_SETVAR)
105 sal_uInt16 nId = SwFieldDlgWrapper::GetChildWindowId();
106 SfxViewFrame& rVFrame = GetViewFrame();
107 SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(rVFrame.GetChildWindow(nId));
108 if (pWrp)
109 pWrp->ReInitDlg(GetDocShell());
111 // Initialize RedlineDlg newly if necessary
112 nId = SwRedlineAcceptChild::GetChildWindowId();
113 SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(rVFrame.GetChildWindow(nId));
114 if (pRed)
115 pRed->ReInitDlg(GetDocShell());
117 // reinit IdxMarkDlg
118 nId = SwInsertIdxMarkWrapper::GetChildWindowId();
119 SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(rVFrame.GetChildWindow(nId));
120 if (pIdxMrk)
121 pIdxMrk->ReInitDlg(*m_pWrtShell);
123 // reinit AuthMarkDlg
124 nId = SwInsertAuthMarkWrapper::GetChildWindowId();
125 SwInsertAuthMarkWrapper *pAuthMrk = static_cast<SwInsertAuthMarkWrapper*>(rVFrame.
126 GetChildWindow(nId));
127 if (pAuthMrk)
128 pAuthMrk->ReInitDlg(*m_pWrtShell);
130 else
131 // At least call the Notify (as a precaution because of the SlotFilter).
132 AttrChangedNotify(nullptr);
134 SfxViewShell::Activate(bMDIActivate);
137 void SwView::Deactivate(bool bMDIActivate)
139 GetEditWin().FlushInBuffer(); // Flush characters still in the input buffer.
141 if( bMDIActivate )
143 m_pWrtShell->ShellLoseFocus(); // Selections invisible
145 m_pHRuler->SetActive( false );
146 m_pVRuler->SetActive( false );
148 SfxViewShell::Deactivate(bMDIActivate);
151 void SwView::MarginChanged()
153 GetWrtShell().SetBrowseBorder( GetMargin() );
156 void SwView::ExecFormatPaintbrush(SfxRequest const & rReq)
158 if(!m_pFormatClipboard)
159 return;
161 if( m_pFormatClipboard->HasContent() )
163 m_pFormatClipboard->Erase();
165 SwApplyTemplate aTemplate;
166 GetEditWin().SetApplyTemplate(aTemplate);
168 else
170 bool bPersistentCopy = false;
171 const SfxItemSet *pArgs = rReq.GetArgs();
172 if( pArgs && pArgs->Count() >= 1 )
174 bPersistentCopy = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
177 m_pFormatClipboard->Copy( GetWrtShell(), GetPool(), bPersistentCopy );
179 SwApplyTemplate aTemplate;
180 aTemplate.m_pFormatClipboard = m_pFormatClipboard.get();
181 GetEditWin().SetApplyTemplate(aTemplate);
183 GetViewFrame().GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
186 void SwView::StateFormatPaintbrush(SfxItemSet &rSet)
188 if(!m_pFormatClipboard)
189 return;
191 const bool bHasContent = m_pFormatClipboard->HasContent();
192 if( !bHasContent &&
193 !SwFormatClipboard::CanCopyThisType( GetWrtShell().GetSelectionType())
196 rSet.DisableItem( SID_FORMATPAINTBRUSH );
198 else
199 rSet.Put(SfxBoolItem(SID_FORMATPAINTBRUSH, bHasContent));
202 void SwView::UpdateWordCount(SfxShell* pShell, sal_uInt16 nSlot)
204 SfxViewFrame& rVFrame = GetViewFrame();
205 rVFrame.ToggleChildWindow(FN_WORDCOUNT_DIALOG);
206 pShell->Invalidate(nSlot);
208 SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(rVFrame.GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
209 if (pWrdCnt)
210 pWrdCnt->UpdateCounts();
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */