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 <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 {
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 );
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  SwDocShell* pDocSh = GetDocShell();
48  if(pDocSh)
49  pDocSh->SetView(this);
50  SwModule* pSwMod = SW_MOD();
51  pSwMod->SetView(this);
52 
53  // Document size has changed.
54  if(!bDocSzUpdated)
56 
57  // make selection visible
59  {
60  m_pWrtShell->MakeSelVisible();
62  }
65 
66  if ( bMDIActivate )
67  {
68  if ( m_pShell )
69  {
70  SfxDispatcher &rDispatcher = GetDispatcher();
71  SfxShell *pTopShell = rDispatcher.GetShell( 0 );
72 
73  // this SwView is the top-most shell on the stack
74  if ( pTopShell == this )
75  {
76  for ( sal_uInt16 i = 1; true; ++i )
77  {
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 ) )
83  {
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");
87  }
88  else
89  break;
90  }
91  }
92  }
93 
94  m_pWrtShell->ShellGetFocus(); // Selections visible
95 
96  if( !m_sSwViewData.isEmpty() )
97  {
99  m_sSwViewData.clear();
100  }
101 
102  AttrChangedNotify(nullptr);
103 
104  // Initialize Fielddlg newly if necessary (e.g. for TYP_SETVAR)
105  sal_uInt16 nId = SwFieldDlgWrapper::GetChildWindowId();
106  SfxViewFrame* pVFrame = GetViewFrame();
107  SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(pVFrame->GetChildWindow(nId));
108  if (pWrp)
109  pWrp->ReInitDlg(GetDocShell());
110 
111  // Initialize RedlineDlg newly if necessary
112  nId = SwRedlineAcceptChild::GetChildWindowId();
113  SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(pVFrame->GetChildWindow(nId));
114  if (pRed)
115  pRed->ReInitDlg(GetDocShell());
116 
117  // reinit IdxMarkDlg
118  nId = SwInsertIdxMarkWrapper::GetChildWindowId();
119  SwInsertIdxMarkWrapper *pIdxMrk = static_cast<SwInsertIdxMarkWrapper*>(pVFrame->GetChildWindow(nId));
120  if (pIdxMrk)
121  pIdxMrk->ReInitDlg(*m_pWrtShell);
122 
123  // reinit AuthMarkDlg
124  nId = SwInsertAuthMarkWrapper::GetChildWindowId();
125  SwInsertAuthMarkWrapper *pAuthMrk = static_cast<SwInsertAuthMarkWrapper*>(pVFrame->
126  GetChildWindow(nId));
127  if (pAuthMrk)
128  pAuthMrk->ReInitDlg(*m_pWrtShell);
129  }
130  else
131  // At least call the Notify (as a precaution because of the SlotFilter).
132  AttrChangedNotify(nullptr);
133 
134  SfxViewShell::Activate(bMDIActivate);
135 }
136 
137 void SwView::Deactivate(bool bMDIActivate)
138 {
139  if( g_bFlushCharBuffer ) // Are Characters still in the input buffer?
141 
142  if( bMDIActivate )
143  {
144  m_pWrtShell->ShellLoseFocus(); // Selections invisible
145 
146  m_pHRuler->SetActive( false );
147  m_pVRuler->SetActive( false );
148  }
149  SfxViewShell::Deactivate(bMDIActivate);
150 }
151 
153 {
155 }
156 
158 {
159  if(!m_pFormatClipboard)
160  return;
161 
162  if( m_pFormatClipboard->HasContent() )
163  {
164  m_pFormatClipboard->Erase();
165 
166  SwApplyTemplate aTemplate;
167  GetEditWin().SetApplyTemplate(aTemplate);
168  }
169  else
170  {
171  bool bPersistentCopy = false;
172  const SfxItemSet *pArgs = rReq.GetArgs();
173  if( pArgs && pArgs->Count() >= 1 )
174  {
175  bPersistentCopy = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
176  }
177 
178  m_pFormatClipboard->Copy( GetWrtShell(), GetPool(), bPersistentCopy );
179 
180  SwApplyTemplate aTemplate;
181  aTemplate.m_pFormatClipboard = m_pFormatClipboard.get();
182  GetEditWin().SetApplyTemplate(aTemplate);
183  }
184  GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
185 }
186 
188 {
189  if(!m_pFormatClipboard)
190  return;
191 
192  const bool bHasContent = m_pFormatClipboard->HasContent();
193  if( !bHasContent &&
195  )
196  {
197  rSet.DisableItem( SID_FORMATPAINTBRUSH );
198  }
199  else
200  rSet.Put(SfxBoolItem(SID_FORMATPAINTBRUSH, bHasContent));
201 }
202 
203 void SwView::UpdateWordCount(SfxShell* pShell, sal_uInt16 nSlot)
204 {
205  SfxViewFrame* pVFrame = GetViewFrame();
206  if (pVFrame != nullptr)
207  {
209  pShell->Invalidate(nSlot);
210 
211  SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(pVFrame->GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
212  if (pWrdCnt)
213  pWrdCnt->UpdateCounts();
214  }
215 }
216 
217 /* 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:157
sal_Int16 nId
void ReInitDlg(SwWrtShell &rWrtShell)
Definition: idxmrk.cxx:44
Size m_aDocSz
Definition: view.hxx:179
SwEditWin & GetEditWin()
Definition: view.hxx:403
virtual bool ReInitDlg(SwDocShell *pDocSh) override
Definition: fldwrap.cxx:78
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
bool g_bFlushCharBuffer
Definition: edtwin.cxx:161
void FlushInBuffer()
Character buffer is inserted into the document.
Definition: edtwin.cxx:837
void SetApplyTemplate(const SwApplyTemplate &)
Apply template.
Definition: edtwin.cxx:4919
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
void ToggleChildWindow(sal_uInt16)
void UpdateWordCount(SfxShell *, sal_uInt16)
Definition: view1.cxx:203
SwFormatClipboard * m_pFormatClipboard
Definition: view.hxx:120
SfxShell * GetShell(sal_uInt16 nIdx) const
bool bDocSzUpdated
Definition: view.cxx:112
virtual void MarginChanged() override
Definition: view1.cxx:152
static bool CanCopyThisType(SelectionType nSelectionType)
void StateFormatPaintbrush(SfxItemSet &)
Definition: view1.cxx:187
void DocSzChgd(const Size &rNewSize)
Definition: viewport.cxx:151
void SetBrowseBorder(const Size &rNew)
Definition: viewsh.cxx:1976
SfxItemPool & GetPool() const
SfxDispatcher & GetDispatcher()
Definition: view.cxx:123
virtual void ReadUserData(const OUString &, bool bBrowse=false) override
Definition: view.cxx:1160
void ReInitDlg(SwWrtShell &rWrtShell)
Definition: idxmrk.cxx:68
void SetView(SwView *pVw)
Set View for actions via Shell.
Definition: docsh.cxx:1133
#define SW_MOD()
Definition: swmodule.hxx:256
virtual void Activate(bool) override
Definition: view1.cxx:38
SfxBindings & GetBindings()
int i
sal_uInt16 Count() const
#define FN_WORDCOUNT_DIALOG
Definition: cmdid.h:586
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:1107
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:69
virtual void Deactivate(bool) override
Definition: view1.cxx:137
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