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