LibreOffice Module sw (master)  1
postithelper.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 <postithelper.hxx>
21 #include <PostItMgr.hxx>
22 #include <AnnotationWin.hxx>
23 
24 #include <fmtfld.hxx>
25 #include <txtfld.hxx>
26 #include <docufld.hxx>
27 #include <ndtxt.hxx>
28 #include <cntfrm.hxx>
29 #include <pagefrm.hxx>
30 #include <rootfrm.hxx>
31 #include <txtfrm.hxx>
32 #include <tabfrm.hxx>
35 #include <redline.hxx>
36 #include <scriptinfo.hxx>
38 #include <calbck.hxx>
39 #include <IMark.hxx>
40 #include <sortedobjs.hxx>
41 #include <anchoredobject.hxx>
42 #include <fmtanchr.hxx>
43 #include <tools/solar.h>
44 
45 class Point;
46 
47 namespace
48 {
50 bool AnnotationMarkCoversCommentAnchor(const sw::mark::IMark* pAnnotationMark,
51  const SwPosition& rAnchorPos)
52 {
53  if (!pAnnotationMark)
54  {
55  return false;
56  }
57 
58  const SwPosition& rMarkStart = pAnnotationMark->GetMarkStart();
59  const SwPosition& rMarkEnd = pAnnotationMark->GetMarkEnd();
60 
61  if (rMarkStart != rAnchorPos)
62  {
63  // This can be the as-char case: the comment placeholder character is exactly between the
64  // annotation mark start and end.
65  SwPosition aPosition(rMarkStart);
66  ++aPosition.nContent;
67  if (aPosition != rAnchorPos)
68  {
69  return false;
70  }
71 
72  ++aPosition.nContent;
73  if (aPosition != rMarkEnd)
74  {
75  return false;
76  }
77 
78  return true;
79  }
80 
81  if (rMarkStart.nNode != rMarkEnd.nNode)
82  {
83  return false;
84  }
85 
86  return rMarkEnd.nContent.GetIndex() == rMarkStart.nContent.GetIndex() + 1;
87 }
88 
93 SwAnchoredObject* GetAnchoredObjectOfAnnotationMark(const sw::mark::IMark& rAnnotationMark,
94  const SwTextFrame& rTextFrame)
95 {
96  const SwSortedObjs* pAnchored = rTextFrame.GetDrawObjs();
97  if (!pAnchored)
98  {
99  return nullptr;
100  }
101 
102  for (SwAnchoredObject* pObject : *pAnchored)
103  {
104  SwFrameFormat& rFrameFormat = pObject->GetFrameFormat();
105  const SwPosition* pFrameAnchor = rFrameFormat.GetAnchor().GetContentAnchor();
106  if (!pFrameAnchor)
107  {
108  continue;
109  }
110 
111  if (rAnnotationMark.GetMarkStart() == *pFrameAnchor)
112  {
113  return pObject;
114  }
115  }
116 
117  return nullptr;
118 }
119 }
120 
122  SwLayoutInfo& o_rInfo,
123  const SwPosition& rAnchorPos,
124  const sw::mark::IMark* pAnnotationMark )
125 {
126  SwLayoutStatus aRet = INVISIBLE;
127  SwTextNode* pTextNode = rAnchorPos.nNode.GetNode().GetTextNode();
128  if ( pTextNode == nullptr )
129  return aRet;
130 
132  for( SwTextFrame* pTextFrame = aIter.First(); pTextFrame != nullptr; pTextFrame = aIter.Next() )
133  {
134  if( !pTextFrame->IsFollow() )
135  {
136  pTextFrame = pTextFrame->GetFrameAtPos( rAnchorPos );
137  SwPageFrame *pPage = pTextFrame ? pTextFrame->FindPageFrame() : nullptr;
138  if ( pPage != nullptr && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
139  {
140  aRet = VISIBLE;
141 
142  o_rInfo.mpAnchorFrame = pTextFrame;
143  {
144  DisableCallbackAction a(*pTextFrame->getRootFrame());
145  bool bPositionFromCommentAnchor = true;
146  if (AnnotationMarkCoversCommentAnchor(pAnnotationMark, rAnchorPos))
147  {
148  SwAnchoredObject* pFrame
149  = GetAnchoredObjectOfAnnotationMark(*pAnnotationMark, *pTextFrame);
150  if (pFrame)
151  {
152  o_rInfo.mPosition = pFrame->GetObjRect();
153  bPositionFromCommentAnchor = false;
154  }
155  }
156  if (bPositionFromCommentAnchor)
157  {
158  pTextFrame->GetCharRect(o_rInfo.mPosition, rAnchorPos, nullptr, false);
159  }
160  o_rInfo.mPositionFromCommentAnchor = bPositionFromCommentAnchor;
161  }
162  if (pAnnotationMark != nullptr)
163  {
164  const SwPosition& rAnnotationStartPos = pAnnotationMark->GetMarkStart();
165  o_rInfo.mnStartNodeIdx = rAnnotationStartPos.nNode.GetIndex();
166  o_rInfo.mnStartContent = rAnnotationStartPos.nContent.GetIndex();
167  }
168  else
169  {
170  o_rInfo.mnStartNodeIdx = 0;
171  o_rInfo.mnStartContent = -1;
172  }
173  o_rInfo.mPageFrame = pPage->getFrameArea();
174  o_rInfo.mPagePrtArea = pPage->getFramePrintArea();
175  o_rInfo.mPagePrtArea.Pos() += o_rInfo.mPageFrame.Pos();
176  o_rInfo.mnPageNumber = pPage->GetPhyPageNum();
177  o_rInfo.meSidebarPosition = pPage->SidebarPosition();
178  o_rInfo.mRedlineAuthor = 0;
179 
180  const IDocumentRedlineAccess& rIDRA = pTextNode->getIDocumentRedlineAccess();
182  {
183  const SwRangeRedline* pRedline = rIDRA.GetRedline( rAnchorPos, nullptr );
184  if( pRedline )
185  {
186  if( RedlineType::Insert == pRedline->GetType() )
187  aRet = INSERTED;
188  else if( RedlineType::Delete == pRedline->GetType() )
189  aRet = DELETED;
190  o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
191  }
192  }
193  }
194  }
195  }
196 
197  return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTextNode , rAnchorPos.nContent.GetIndex()) )
198  ? HIDDEN
199  : aRet;
200 }
201 
203 {
204  long nRet = pRoot ? pRoot->getFrameArea().Height() : 0;
205  return nRet;
206 }
207 
208 void SwPostItHelper::setSidebarChanged( SwRootFrame* pRoot, bool bBrowseMode )
209 {
210  if( pRoot )
211  {
212  pRoot->SetSidebarChanged();
213  if( bBrowseMode )
214  pRoot->InvalidateBrowseWidth();
215  }
216 }
217 
218 unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrame, const SwRootFrame* pRoot, const Point& rPoint )
219 {
220  unsigned long nRet = 0;
221  const SwFrame* pPage = pRoot->GetPageAtPos( rPoint, nullptr, true );
222  if( pPage )
223  {
224  nRet = pPage->GetPhyPageNum();
225  rPageFrame = pPage->getFrameArea();
226  }
227  return nRet;
228 }
229 
231 {
232  SwTextField* pTextField = mrFormatField.GetTextField();
233  SwTextNode* pTextNode = pTextField->GetpTextNode();
234 
235  SwPosition aPos( *pTextNode );
236  aPos.nContent.Assign( pTextNode, pTextField->GetStart() );
237  return aPos;
238 }
239 
241  IDocumentRedlineAccess const& rIDRA)
242 {
243  return mrFormatField.IsFieldInDoc()
244  && (!rLayout.IsHideRedlines()
246 }
247 
249  SwEditWin& rEditWin,
250  SwPostItMgr& aMgr)
251 {
253  aMgr,
254  *this,
255  &mrFormatField );
256 }
257 
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:295
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:543
Marks a position in the document model.
Definition: pam.hxx:35
const SwPageFrame * GetPageAtPos(const Point &rPt, const Size *pSize=nullptr, bool bExtend=false) const
Point rPt: The point that should be used to find the page Size pSize: If given, we return the (first)...
Definition: findfrm.cxx:572
const SwFrame * mpAnchorFrame
SwNodeIndex nNode
Definition: pam.hxx:37
const SwRect & getFramePrintArea() const
Definition: frame.hxx:176
std::size_t mRedlineAuthor
TElementType * Next()
Definition: calbck.hxx:376
helper class to disable creation of an action by a callback event in particular, change event from a ...
Definition: rootfrm.hxx:440
void Height(long nNew)
Definition: swrect.hxx:189
sw::sidebarwindows::SidebarPosition SidebarPosition() const
asks the page on which side a margin should be shown, e.g for notes returns true for left side...
Definition: pagechg.cxx:1374
SwNode & GetNode() const
Definition: ndindex.hxx:118
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
void Pos(const Point &rNew)
Definition: swrect.hxx:167
bool mPositionFromCommentAnchor
If true, the overlay arrow points to the comment anchor, otherwise it points to the commented frame...
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
virtual SwPosition GetAnchorPosition() const override
static bool IsShowChanges(const RedlineFlags eM)
SwFormatField & mrFormatField
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:190
wrapper class for the positioning of Writer fly frames and drawing objects
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:175
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:89
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
void SetSidebarChanged()
Definition: rootfrm.hxx:405
void InvalidateBrowseWidth()
Definition: rootfrm.hxx:427
virtual bool UseElement(SwRootFrame const &, IDocumentRedlineAccess const &) override
virtual const SwRect GetObjRect() const =0
bool IsInvalidFly() const
Definition: pagefrm.hxx:426
Style of a layout element.
Definition: frmfmt.hxx:57
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: node.cxx:2057
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
SwRect mPageFrame
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
SwPageFrame * FindPageFrame()
Definition: frame.hxx:658
SwRect mPagePrtArea
TElementType * First()
Definition: calbck.hxx:345
long getLayoutHeight(const SwRootFrame *pRoot)
sal_uLong mnStartNodeIdx
unsigned long mnPageNumber
A page of the document layout.
Definition: pagefrm.hxx:40
virtual const SwRangeRedline * GetRedline(const SwPosition &rPos, SwRedlineTable::size_type *pFndPos) const =0
bool IsFieldInDoc() const
Definition: atrfld.cxx:329
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
std::size_t GetAuthor(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1699
sw::sidebarwindows::SidebarPosition meSidebarPosition
sal_uInt16 GetPhyPageNum() const
Definition: trvlfrm.cxx:1689
sal_Int32 GetIndex() const
Definition: index.hxx:95
static VclPtr< reference_type > Create(Arg &&...arg)
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1714
virtual VclPtr< sw::annotation::SwAnnotationWin > GetSidebarWindow(SwEditWin &rEditWin, SwPostItMgr &aMgr) override
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:416
void setSidebarChanged(SwRootFrame *pRoot, bool bBrowseMode)
virtual const SwPosition & GetMarkEnd() const =0
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:1660
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
sal_Int32 mnStartContent
virtual const SwPosition & GetMarkStart() const =0
bool IsInvalid() const
Definition: pagefrm.hxx:422
class for collecting anchored objects
Definition: sortedobjs.hxx:48
SwLayoutStatus getLayoutInfos(SwLayoutInfo &o_rInfo, const SwPosition &rAnchorPos, const sw::mark::IMark *pAnnotationMark=nullptr)
unsigned long getPageInfo(SwRect &rPageFrame, const SwRootFrame *, const Point &)
SwRect mPosition
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843