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