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 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  SwFormatFrameSize aSize = pLine->GetFrameFormat()->GetFrameSize();
79  pRow->ModifyNotification(nullptr, &aSize);
80 }
81 
82 SwCallLink::~SwCallLink() COVERITY_NOEXCEPT_FALSE
83 {
84  if( m_nNodeType == SwNodeType::NONE || !m_rShell.m_bCallChgLnk ) // see ctor
85  return ;
86 
87  // If travelling over Nodes check formats and register them anew at the
88  // new Node.
89  SwPaM* pCurrentCursor = m_rShell.IsTableMode() ? m_rShell.GetTableCrs() : m_rShell.GetCursor();
90  SwContentNode * pCNd = pCurrentCursor->GetContentNode();
91  if( !pCNd )
92  return;
93 
94  lcl_notifyRow(pCNd, m_rShell);
95 
96  const SwDoc *pDoc=m_rShell.GetDoc();
97  const SwContentNode *pNode = nullptr;
98  if ( pDoc && m_nNode < pDoc->GetNodes( ).Count( ) )
99  {
100  pNode = pDoc->GetNodes()[m_nNode]->GetContentNode();
101  }
102  lcl_notifyRow(pNode, m_rShell);
103 
104  sal_Int32 nCmp, nCurrentContent = pCurrentCursor->GetPoint()->nContent.GetIndex();
105  SwNodeType nNdWhich = pCNd->GetNodeType();
106  sal_uLong nCurrentNode = pCurrentCursor->GetPoint()->nNode.GetIndex();
107 
108  // Register the Shell as dependent at the current Node. By doing this all
109  // attribute changes can be signaled over the link.
110  pCNd->Add( &m_rShell );
111 
112  const bool bCurrentHasSelection = (*pCurrentCursor->GetPoint() != *pCurrentCursor->GetMark());
113 
114  if( m_nNodeType != nNdWhich || m_nNode != nCurrentNode )
115  {
116  // Every time a switch between nodes occurs, there is a chance that
117  // new attributes do apply - meaning text-attributes.
118  // So the currently applying attributes would have to be determined.
119  // That can be done in one go by the handler.
121  }
122  else if (m_bHasSelection != bCurrentHasSelection)
123  {
124  // always call change link when selection changes
126  }
127  else if( m_rShell.m_aChgLnk.IsSet() && SwNodeType::Text == nNdWhich &&
128  m_nContent != nCurrentContent )
129  {
130  // If travelling with left/right only and the frame is
131  // unchanged (columns!) then check text hints.
132  if( m_nLeftFramePos == SwCallLink::getLayoutFrame( m_rShell.GetLayout(), *pCNd->GetTextNode(), nCurrentContent,
133  !m_rShell.ActionPend() ) &&
134  (( nCmp = m_nContent ) + 1 == nCurrentContent || // Right
135  m_nContent -1 == ( nCmp = nCurrentContent )) ) // Left
136  {
137  if( nCmp == nCurrentContent && pCurrentCursor->HasMark() ) // left & select
138  ++nCmp;
139 
140  if ( pCNd->GetTextNode()->HasHints() )
141  {
142  const SwpHints &rHts = pCNd->GetTextNode()->GetSwpHints();
143 
144  for( size_t n = 0; n < rHts.Count(); ++n )
145  {
146  const SwTextAttr* pHt = rHts.Get( n );
147  const sal_Int32 *pEnd = pHt->End();
148  const sal_Int32 nStart = pHt->GetStart();
149 
150  // If "only start" or "start and end equal" then call on
151  // every overflow of start.
152  if( ( !pEnd || ( nStart == *pEnd ) ) &&
153  ( nStart == m_nContent || nStart == nCurrentContent) )
154  {
156  return;
157  }
158 
159  // If the attribute has an area and that area is not empty ...
160  else if( pEnd && nStart < *pEnd &&
161  // ... then test if travelling occurred via start/end.
162  ( nStart == nCmp ||
163  ( pHt->DontExpand() ? nCmp == *pEnd-1
164  : nCmp == *pEnd ) ))
165  {
167  return;
168  }
169  }
170  }
171 
172  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
173  const OUString rText = pCNd->GetTextNode()->GetText();
174  if( !nCmp ||
175  g_pBreakIt->GetBreakIter()->getScriptType( rText, m_nContent )
176  != g_pBreakIt->GetBreakIter()->getScriptType(rText, nCurrentContent))
177  {
179  return;
180  }
181  }
182  else
183  // If travelling more than one character with home/end/.. then
184  // always call ChgLnk, because it can not be determined here what
185  // has changed. Something may have changed.
187  }
188 
189  const SwFrame* pFrame;
190  const SwFlyFrame *pFlyFrame;
191  if (!m_rShell.ActionPend() && nullptr != (pFrame = pCNd->getLayoutFrame(m_rShell.GetLayout(), nullptr, nullptr)) &&
192  nullptr != ( pFlyFrame = pFrame->FindFlyFrame() ) && !m_rShell.IsTableMode() )
193  {
194  const SwNodeIndex* pIndex = pFlyFrame->GetFormat()->GetContent().GetContentIdx();
195  OSL_ENSURE( pIndex, "Fly without Content" );
196 
197  if (!pIndex)
198  return;
199 
200  const SwNode& rStNd = pIndex->GetNode();
201 
202  if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > m_nNode ||
203  m_nNode > rStNd.EndOfSectionIndex() )
204  m_rShell.GetFlyMacroLnk().Call( pFlyFrame->GetFormat() );
205  }
206 }
207 
209  SwTextNode const & rNd, sal_Int32 nCntPos, bool /*bCalcFrame*/)
210 {
211  SwTextFrame* pFrame = static_cast<SwTextFrame*>(rNd.getLayoutFrame(pRoot, nullptr, nullptr));
212  SwTextFrame* pNext;
213  if ( pFrame && !pFrame->IsHiddenNow() )
214  {
215  if( pFrame->HasFollow() )
216  {
217  TextFrameIndex const nPos(pFrame->MapModelToView(&rNd, nCntPos));
218  while( nullptr != ( pNext = pFrame->GetFollow() ) &&
219  nPos >= pNext->GetOfst())
220  pFrame = pNext;
221  }
222 
223  return pFrame->getFrameArea().Left();
224  }
225  return 0;
226 }
227 
228 /* 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:2810
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:210
SwNodeIndex nNode
Definition: pam.hxx:37
bool IsTableMode() const
Definition: crsrsh.hxx:647
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:1147
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:119
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
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:284
SwFlyFrame * FindFlyFrame()
Definition: frame.hxx:1087
bool m_bCallChgLnk
flag for derived classes
Definition: crsrsh.hxx:217
const Link< const SwFlyFrameFormat *, void > & GetFlyMacroLnk() const
Definition: crsrsh.hxx:484
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:908
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:808
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: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
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:175
const SwTableLine * GetTabLine() const
Definition: rowfrm.hxx:68
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
sal_Int32 nPos
bool IsTextNode() const
Definition: node.hxx:636
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
bool HasHints() const
Definition: ndtxt.hxx:220
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