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  : m_rShell( rSh )
36 {
37  // remember SPoint-values of current cursor
39  SwNode& rNd = pCursor->GetPoint()->nNode.GetNode();
40  m_nNode = rNd.GetIndex();
41  m_nContent = pCursor->GetPoint()->nContent.GetIndex();
42  m_nNodeType = rNd.GetNodeType();
43  m_bHasSelection = ( *pCursor->GetPoint() != *pCursor->GetMark() );
44 
45  if( rNd.IsTextNode() )
47  !m_rShell.ActionPend() );
48  else
49  {
50  m_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  m_nNodeType = SwNodeType::NONE;
59  }
60 }
61 
62 static void lcl_notifyRow(const SwContentNode* pNode, SwCursorShell & 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 
79  if (rShell.IsTableMode() || (rShell.StartsWithTable() && rShell.ExtendedSelectedAll()))
80  {
81  // If we have a table selection, then avoid the notification: it's not necessary (the text
82  // cursor needs no updating) and the notification may kill the selection overlay, leading to
83  // flicker.
84  // Same for whole-document selection when it starts with a table.
85  return;
86  }
87 
88  SwFormatFrameSize aSize = pLine->GetFrameFormat()->GetFrameSize();
89  pRow->ModifyNotification(nullptr, &aSize);
90 }
91 
92 SwCallLink::~SwCallLink() COVERITY_NOEXCEPT_FALSE
93 {
94  if( m_nNodeType == SwNodeType::NONE || !m_rShell.m_bCallChgLnk ) // see ctor
95  return ;
96 
97  // If travelling over Nodes check formats and register them anew at the
98  // new Node.
99  SwPaM* pCurrentCursor = m_rShell.IsTableMode() ? m_rShell.GetTableCrs() : m_rShell.GetCursor();
100  SwContentNode * pCNd = pCurrentCursor->GetContentNode();
101  if( !pCNd )
102  return;
103 
104  lcl_notifyRow(pCNd, m_rShell);
105 
106  const SwDoc *pDoc=m_rShell.GetDoc();
107  const SwContentNode *pNode = nullptr;
108  if ( pDoc && m_nNode < pDoc->GetNodes( ).Count( ) )
109  {
110  pNode = pDoc->GetNodes()[m_nNode]->GetContentNode();
111  }
112  lcl_notifyRow(pNode, m_rShell);
113 
114  sal_Int32 nCmp, nCurrentContent = pCurrentCursor->GetPoint()->nContent.GetIndex();
115  SwNodeType nNdWhich = pCNd->GetNodeType();
116  sal_uLong nCurrentNode = pCurrentCursor->GetPoint()->nNode.GetIndex();
117 
118  // Register the Shell as dependent at the current Node. By doing this all
119  // attribute changes can be signaled over the link.
120  pCNd->Add( &m_rShell );
121 
122  const bool bCurrentHasSelection = (*pCurrentCursor->GetPoint() != *pCurrentCursor->GetMark());
123 
124  if( m_nNodeType != nNdWhich || m_nNode != nCurrentNode )
125  {
126  // Every time a switch between nodes occurs, there is a chance that
127  // new attributes do apply - meaning text-attributes.
128  // So the currently applying attributes would have to be determined.
129  // That can be done in one go by the handler.
131  }
132  else if (m_bHasSelection != bCurrentHasSelection)
133  {
134  // always call change link when selection changes
136  }
137  else if( m_rShell.m_aChgLnk.IsSet() && SwNodeType::Text == nNdWhich &&
138  m_nContent != nCurrentContent )
139  {
140  // If travelling with left/right only and the frame is
141  // unchanged (columns!) then check text hints.
142  if( m_nLeftFramePos == SwCallLink::getLayoutFrame( m_rShell.GetLayout(), *pCNd->GetTextNode(), nCurrentContent,
143  !m_rShell.ActionPend() ) &&
144  (( nCmp = m_nContent ) + 1 == nCurrentContent || // Right
145  m_nContent -1 == ( nCmp = nCurrentContent )) ) // Left
146  {
147  if( nCmp == nCurrentContent && pCurrentCursor->HasMark() ) // left & select
148  ++nCmp;
149 
150  if ( pCNd->GetTextNode()->HasHints() )
151  {
152  const SwpHints &rHts = pCNd->GetTextNode()->GetSwpHints();
153 
154  for( size_t n = 0; n < rHts.Count(); ++n )
155  {
156  const SwTextAttr* pHt = rHts.Get( n );
157  const sal_Int32 *pEnd = pHt->End();
158  const sal_Int32 nStart = pHt->GetStart();
159 
160  // If "only start" or "start and end equal" then call on
161  // every overflow of start.
162  if( ( !pEnd || ( nStart == *pEnd ) ) &&
163  ( nStart == m_nContent || nStart == nCurrentContent) )
164  {
166  return;
167  }
168 
169  // If the attribute has an area and that area is not empty ...
170  else if( pEnd && nStart < *pEnd &&
171  // ... then test if travelling occurred via start/end.
172  ( nStart == nCmp ||
173  ( pHt->DontExpand() ? nCmp == *pEnd-1
174  : nCmp == *pEnd ) ))
175  {
177  return;
178  }
179  }
180  }
181 
183  const OUString rText = pCNd->GetTextNode()->GetText();
184  if( !nCmp ||
185  g_pBreakIt->GetBreakIter()->getScriptType( rText, m_nContent )
186  != g_pBreakIt->GetBreakIter()->getScriptType(rText, nCurrentContent))
187  {
189  return;
190  }
191  }
192  else
193  // If travelling more than one character with home/end/.. then
194  // always call ChgLnk, because it can not be determined here what
195  // has changed. Something may have changed.
197  }
198 
199  const SwFrame* pFrame;
200  const SwFlyFrame *pFlyFrame;
201  if (m_rShell.ActionPend())
202  return;
203  pFrame = pCNd->getLayoutFrame(m_rShell.GetLayout(), nullptr, nullptr);
204  if (!pFrame)
205  return;
206  pFlyFrame = pFrame->FindFlyFrame();
207  if ( !pFlyFrame || m_rShell.IsTableMode() )
208  return;
209 
210  const SwNodeIndex* pIndex = pFlyFrame->GetFormat()->GetContent().GetContentIdx();
211  OSL_ENSURE( pIndex, "Fly without Content" );
212 
213  if (!pIndex)
214  return;
215 
216  const SwNode& rStNd = pIndex->GetNode();
217 
218  if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > m_nNode ||
219  m_nNode > rStNd.EndOfSectionIndex() )
220  m_rShell.GetFlyMacroLnk().Call( pFlyFrame->GetFormat() );
221 }
222 
224  SwTextNode const & rNd, sal_Int32 nCntPos, bool /*bCalcFrame*/)
225 {
226  SwTextFrame* pFrame = static_cast<SwTextFrame*>(rNd.getLayoutFrame(pRoot, nullptr, nullptr));
227  SwTextFrame* pNext;
228  if ( pFrame && !pFrame->IsHiddenNow() )
229  {
230  if( pFrame->HasFollow() )
231  {
232  TextFrameIndex const nPos(pFrame->MapModelToView(&rNd, nCntPos));
233  for (;;)
234  {
235  pNext = pFrame->GetFollow();
236  if(!pNext || nPos < pNext->GetOffset())
237  break;
238  pFrame = pNext;
239  }
240  }
241 
242  return pFrame->getFrameArea().Left();
243  }
244  return 0;
245 }
246 
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:690
Base class of the Writer layout elements.
Definition: frame.hxx:297
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
sal_uLong GetIndex() const
Definition: node.hxx:290
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
virtual const SwFlyFrameFormat * GetFormat() const override
Definition: fly.cxx:2852
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:189
sal_uLong StartOfSectionIndex() const
Definition: node.hxx:681
const OUString & GetText() const
Definition: ndtxt.hxx:211
void Left(const tools::Long nLeft)
Definition: swrect.hxx:195
SwNodeIndex nNode
Definition: pam.hxx:37
bool IsTableMode() const
Definition: crsrsh.hxx:643
sal_uIntPtr sal_uLong
long Long
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:1192
sal_Int64 n
Definition: doc.hxx:184
bool HasFollow() const
Definition: flowfrm.hxx:165
SwTableLine is one table row in the document model.
Definition: swtable.hxx:350
SwNode & GetNode() const
Definition: ndindex.hxx:119
The root element of a Writer document layout.
Definition: rootfrm.hxx:80
SwContentNode * GetContentNode(bool bPoint=true) const
Definition: pam.hxx:229
bool IsHiddenNow() const
Hidden.
Definition: txtfrm.cxx:1350
SwNodeType GetNodeType() const
Definition: node.hxx:144
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:177
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
SwRowFrame * FindRowFrame()
Definition: findfrm.cxx:538
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1089
bool m_bCallChgLnk
flag for derived classes
Definition: crsrsh.hxx:213
const Link< const SwFlyFrameFormat *, void > & GetFlyMacroLnk() const
Definition: crsrsh.hxx:480
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:846
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:156
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool ExtendedSelectedAll()
If ExtendedSelectAll() was called and selection didn't change since then.
Definition: crsrsh.cxx:605
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:904
const SwPosition * GetPoint() const
Definition: pam.hxx:207
Count
bool ActionPend() const
Definition: viewsh.hxx:196
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:372
Marks a node in the document model.
Definition: ndindex.hxx:31
SwpHints & GetSwpHints()
getters for SwpHints
Definition: ndtxt.hxx:810
const SwNodeIndex * GetContentIdx() const
Definition: fmtcntnt.hxx:46
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:62
void CallChgLnk()
Definition: crsrsh.cxx:2510
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:685
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
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:1244
sal_Int32 GetIndex() const
Definition: index.hxx:91
bool StartsWithTable()
If document body starts with a table.
Definition: crsrsh.cxx:624
SwNodes & GetNodes()
Definition: doc.hxx:403
const sal_Int32 * End() const
Definition: txatbase.hxx:148
const SwFormatFrameSize & GetFrameSize(bool=true) const
Definition: fmtfsize.hxx:104
const SwFormatContent & GetContent(bool=true) const
Definition: fmtcntnt.hxx:55
bool DontExpand() const
Definition: txatbase.hxx:92
Link< LinkParamNone *, void > m_aChgLnk
link will be called by every attribute/ format changes at cursor position.
Definition: crsrsh.hxx:171
const SwTableLine * GetTabLine() const
Definition: rowfrm.hxx:69
static void lcl_notifyRow(const SwContentNode *pNode, SwCursorShell &rShell)
Definition: callnk.cxx:62
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2073
bool IsTextNode() const
Definition: node.hxx:644
sal_uInt16 nPos
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:844
bool HasHints() const
Definition: ndtxt.hxx:221
SwRowFrame is one table row in the document layout.
Definition: rowfrm.hxx:28
Base class of the Writer document model elements.
Definition: node.hxx:79