LibreOffice Module sw (master)  1
callnk.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 <com/sun/star/i18n/XBreakIterator.hpp>
21 #include <fmtcntnt.hxx>
22 #include <txatbase.hxx>
23 #include "callnk.hxx"
24 #include <crsrsh.hxx>
25 #include <doc.hxx>
26 #include <frmfmt.hxx>
27 #include <txtfrm.hxx>
28 #include <rowfrm.hxx>
29 #include <fmtfsize.hxx>
30 #include <ndtxt.hxx>
31 #include <flyfrm.hxx>
32 #include <breakit.hxx>
33 
35  : rShell( rSh )
36 {
37  // remember SPoint-values of current cursor
39  SwNode& rNd = pCursor->GetPoint()->nNode.GetNode();
40  nNode = rNd.GetIndex();
41  nContent = pCursor->GetPoint()->nContent.GetIndex();
42  nNdTyp = rNd.GetNodeType();
43  bHasSelection = ( *pCursor->GetPoint() != *pCursor->GetMark() );
44 
45  if( rNd.IsTextNode() )
47  !rShell.ActionPend() );
48  else
49  {
50  nLeftFramePos = 0;
51 
52  // A special treatment for SwFeShell:
53  // When deleting the header/footer, footnotes SwFeShell sets the
54  // Cursor to NULL (Node + Content).
55  // If the Cursor is not on a ContentNode (ContentNode) this fact gets
56  // saved in nNdType.
58  nNdTyp = SwNodeType::NONE;
59  }
60 }
61 
62 static void lcl_notifyRow(const SwContentNode* pNode, SwCursorShell const & rShell)
63 {
64  if ( !pNode )
65  return;
66 
67  SwFrame *const pMyFrame = pNode->getLayoutFrame( rShell.GetLayout() );
68  if ( !pMyFrame )
69  return;
70 
71  // We need to emulated a change of the row height in order
72  // to have the complete row redrawn
73  SwRowFrame *const pRow = pMyFrame->FindRowFrame();
74  if ( !pRow )
75  return;
76 
77  const SwTableLine* pLine = pRow->GetTabLine( );
78  // Avoid redrawing the complete row if there are no nested tables
79  for (SwFrame *pCell = pRow->GetLower(); pCell; pCell = pCell->GetNext())
80  {
81  for (SwFrame *pContent = pCell->GetLower(); pContent; pContent = pContent->GetNext())
82  {
83  if (pContent->GetType() == SwFrameType::Tab)
84  {
85  SwFormatFrameSize aSize = pLine->GetFrameFormat()->GetFrameSize();
86  pRow->ModifyNotification(nullptr, &aSize);
87  return;
88  }
89  }
90  }
91 }
92 
93 SwCallLink::~SwCallLink() COVERITY_NOEXCEPT_FALSE
94 {
95  if( nNdTyp == SwNodeType::NONE || !rShell.m_bCallChgLnk ) // see ctor
96  return ;
97 
98  // If travelling over Nodes check formats and register them anew at the
99  // new Node.
100  SwPaM* pCurrentCursor = rShell.IsTableMode() ? rShell.GetTableCrs() : rShell.GetCursor();
101  SwContentNode * pCNd = pCurrentCursor->GetContentNode();
102  if( !pCNd )
103  return;
104 
105  lcl_notifyRow(pCNd, rShell);
106 
107  const SwDoc *pDoc=rShell.GetDoc();
108  const SwContentNode *pNode = nullptr;
109  if ( pDoc && nNode < pDoc->GetNodes( ).Count( ) )
110  {
111  pNode = pDoc->GetNodes()[nNode]->GetContentNode();
112  }
113  lcl_notifyRow(pNode, rShell);
114 
115  sal_Int32 nCmp, nCurrentContent = pCurrentCursor->GetPoint()->nContent.GetIndex();
116  SwNodeType nNdWhich = pCNd->GetNodeType();
117  sal_uLong nCurrentNode = pCurrentCursor->GetPoint()->nNode.GetIndex();
118 
119  // Register the Shell as dependent at the current Node. By doing this all
120  // attribute changes can be signaled over the link.
121  pCNd->Add( &rShell );
122 
123  const bool bCurrentHasSelection = (*pCurrentCursor->GetPoint() != *pCurrentCursor->GetMark());
124 
125  if( nNdTyp != nNdWhich || nNode != nCurrentNode )
126  {
127  // Every time a switch between nodes occurs, there is a chance that
128  // new attributes do apply - meaning text-attributes.
129  // So the currently applying attributes would have to be determined.
130  // That can be done in one go by the handler.
131  rShell.CallChgLnk();
132  }
133  else if (bHasSelection != bCurrentHasSelection)
134  {
135  // always call change link when selection changes
136  rShell.CallChgLnk();
137  }
138  else if( rShell.m_aChgLnk.IsSet() && SwNodeType::Text == nNdWhich &&
139  nContent != nCurrentContent )
140  {
141  // If travelling with left/right only and the frame is
142  // unchanged (columns!) then check text hints.
143  if( nLeftFramePos == SwCallLink::getLayoutFrame( rShell.GetLayout(), *pCNd->GetTextNode(), nCurrentContent,
144  !rShell.ActionPend() ) &&
145  (( nCmp = nContent ) + 1 == nCurrentContent || // Right
146  nContent -1 == ( nCmp = nCurrentContent )) ) // Left
147  {
148  if( nCmp == nCurrentContent && pCurrentCursor->HasMark() ) // left & select
149  ++nCmp;
150 
151  if ( pCNd->GetTextNode()->HasHints() )
152  {
153  const SwpHints &rHts = pCNd->GetTextNode()->GetSwpHints();
154 
155  for( size_t n = 0; n < rHts.Count(); ++n )
156  {
157  const SwTextAttr* pHt = rHts.Get( n );
158  const sal_Int32 *pEnd = pHt->End();
159  const sal_Int32 nStart = pHt->GetStart();
160 
161  // If "only start" or "start and end equal" then call on
162  // every overflow of start.
163  if( ( !pEnd || ( nStart == *pEnd ) ) &&
164  ( nStart == nContent || nStart == nCurrentContent) )
165  {
166  rShell.CallChgLnk();
167  return;
168  }
169 
170  // If the attribute has an area and that area is not empty ...
171  else if( pEnd && nStart < *pEnd &&
172  // ... then test if travelling occurred via start/end.
173  ( nStart == nCmp ||
174  ( pHt->DontExpand() ? nCmp == *pEnd-1
175  : nCmp == *pEnd ) ))
176  {
177  rShell.CallChgLnk();
178  return;
179  }
180  }
181  }
182 
183  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
184  const OUString rText = pCNd->GetTextNode()->GetText();
185  if( !nCmp ||
186  g_pBreakIt->GetBreakIter()->getScriptType( rText, nContent )
187  != g_pBreakIt->GetBreakIter()->getScriptType(rText, nCurrentContent))
188  {
189  rShell.CallChgLnk();
190  return;
191  }
192  }
193  else
194  // If travelling more than one character with home/end/.. then
195  // always call ChgLnk, because it can not be determined here what
196  // has changed. Something may have changed.
197  rShell.CallChgLnk();
198  }
199 
200  const SwFrame* pFrame;
201  const SwFlyFrame *pFlyFrame;
202  if (!rShell.ActionPend() && nullptr != (pFrame = pCNd->getLayoutFrame(rShell.GetLayout(), nullptr, nullptr)) &&
203  nullptr != ( pFlyFrame = pFrame->FindFlyFrame() ) && !rShell.IsTableMode() )
204  {
205  const SwNodeIndex* pIndex = pFlyFrame->GetFormat()->GetContent().GetContentIdx();
206  OSL_ENSURE( pIndex, "Fly without Content" );
207 
208  if (!pIndex)
209  return;
210 
211  const SwNode& rStNd = pIndex->GetNode();
212 
213  if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > nNode ||
214  nNode > rStNd.EndOfSectionIndex() )
215  rShell.GetFlyMacroLnk().Call( pFlyFrame->GetFormat() );
216  }
217 }
218 
220  SwTextNode const & rNd, sal_Int32 nCntPos, bool /*bCalcFrame*/)
221 {
222  SwTextFrame* pFrame = static_cast<SwTextFrame*>(rNd.getLayoutFrame(pRoot, nullptr, nullptr));
223  SwTextFrame* pNext;
224  if ( pFrame && !pFrame->IsHiddenNow() )
225  {
226  if( pFrame->HasFollow() )
227  {
228  TextFrameIndex const nPos(pFrame->MapModelToView(&rNd, nCntPos));
229  while( nullptr != ( pNext = pFrame->GetFollow() ) &&
230  nPos >= pNext->GetOfst())
231  pFrame = pNext;
232  }
233 
234  return pFrame->getFrameArea().Left();
235  }
236  return 0;
237 }
238 
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
sal_uLong GetIndex() const
Definition: node.hxx:282
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2816
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:184
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:673
const OUString & GetText() const
Definition: ndtxt.hxx:211
SwNodeIndex nNode
Definition: pam.hxx:37
bool IsTableMode() const
Definition: crsrsh.hxx:646
sal_uIntPtr sal_uLong
const SwPosition * GetMark() const
Definition: pam.hxx:209
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
Definition: doc.hxx:185
bool HasFollow() const
Definition: flowfrm.hxx:165
TextFrameIndex GetOfst() const
Definition: txtfrm.hxx:426
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
SwNode & GetNode() const
Definition: ndindex.hxx:118
static void lcl_notifyRow(const SwContentNode *pNode, SwCursorShell const &rShell)
Definition: callnk.cxx:62
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
bool IsHiddenNow() const
Hidden.
Definition: txtfrm.cxx:1357
SwNodeType GetNodeType() const
Definition: node.hxx:144
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:175
Link< SwCursorShell *, void > m_aChgLnk
link will be called by every attribute/ format changes at cursor position.
Definition: crsrsh.hxx:175
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
SwRowFrame * FindRowFrame()
Definition: findfrm.cxx:538
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1087
bool m_bCallChgLnk
flag for derived classes
Definition: crsrsh.hxx:216
const Link< const SwFlyFrameFormat *, void > & GetFlyMacroLnk() const
Definition: crsrsh.hxx:483
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:844
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:154
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
size_t Count() const
Definition: ndhints.hxx:142
SwNodeType
Definition: ndtyp.hxx:28
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
const SwPaM * GetTableCrs() const
Definition: crsrsh.hxx:903
const SwPosition * GetPoint() const
Definition: pam.hxx:207
Count
bool ActionPend() const
Definition: viewsh.hxx:199
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:366
Marks a node in the document model.
Definition: ndindex.hxx:31
SwpHints & GetSwpHints()
getters for SwpHints
Definition: ndtxt.hxx:809
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
void CallChgLnk()
Definition: crsrsh.cxx:2492
void Left(const long nLeft)
Definition: swrect.hxx:193
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
TextFrameIndex MapModelToView(SwTextNode const *pNode, sal_Int32 nIndex) const
Definition: txtfrm.cxx:1251
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwNodes & GetNodes()
Definition: doc.hxx:402
const sal_Int32 * End() const
Definition: txatbase.hxx:148
SwFrame * GetLower()
Definition: findfrm.cxx:169
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
Definition: breakit.hxx:62
bool DontExpand() const
Definition: txatbase.hxx:92
const SwTableLine * GetTabLine() const
Definition: rowfrm.hxx:68
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
sal_Int32 nPos
bool IsTextNode() const
Definition: node.hxx:636
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843
bool HasHints() const
Definition: ndtxt.hxx:221
SwRowFrame is one table row in the document layout.
Definition: rowfrm.hxx:28
SwFrame * GetNext()
Definition: frame.hxx:654
Base class of the Writer document model elements.
Definition: node.hxx:79