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 <ndtxt.hxx>
27 #include <pagefrm.hxx>
28 #include <rootfrm.hxx>
29 #include <txtfrm.hxx>
32 #include <redline.hxx>
33 #include <scriptinfo.hxx>
34 #include <calbck.hxx>
35 #include <IMark.hxx>
36 #include <sortedobjs.hxx>
37 #include <anchoredobject.hxx>
38 #include <fmtanchr.hxx>
39 
40 class Point;
41 
42 namespace
43 {
45 bool AnnotationMarkCoversCommentAnchor(const sw::mark::IMark* pAnnotationMark,
46  const SwPosition& rAnchorPos)
47 {
48  if (!pAnnotationMark)
49  {
50  return false;
51  }
52 
53  const SwPosition& rMarkStart = pAnnotationMark->GetMarkStart();
54  const SwPosition& rMarkEnd = pAnnotationMark->GetMarkEnd();
55 
56  if (rMarkStart != rAnchorPos)
57  {
58  // This can be the as-char case: the comment placeholder character is exactly between the
59  // annotation mark start and end.
60  SwPosition aPosition(rMarkStart);
61  ++aPosition.nContent;
62  if (aPosition != rAnchorPos)
63  {
64  return false;
65  }
66 
67  ++aPosition.nContent;
68  if (aPosition != rMarkEnd)
69  {
70  return false;
71  }
72 
73  return true;
74  }
75 
76  if (rMarkStart.nNode != rMarkEnd.nNode)
77  {
78  return false;
79  }
80 
81  return rMarkEnd.nContent.GetIndex() == rMarkStart.nContent.GetIndex() + 1;
82 }
83 
88 SwAnchoredObject* GetAnchoredObjectOfAnnotationMark(const sw::mark::IMark& rAnnotationMark,
89  const SwTextFrame& rTextFrame)
90 {
91  const SwSortedObjs* pAnchored = rTextFrame.GetDrawObjs();
92  if (!pAnchored)
93  {
94  return nullptr;
95  }
96 
97  for (SwAnchoredObject* pObject : *pAnchored)
98  {
99  SwFrameFormat& rFrameFormat = pObject->GetFrameFormat();
100  const SwPosition* pFrameAnchor = rFrameFormat.GetAnchor().GetContentAnchor();
101  if (!pFrameAnchor)
102  {
103  continue;
104  }
105 
106  if (rAnnotationMark.GetMarkStart() == *pFrameAnchor)
107  {
108  return pObject;
109  }
110  }
111 
112  return nullptr;
113 }
114 }
115 
117  : pPostIt(nullptr)
118  , bShow(true)
119  , bFocus(aFocus)
120  , bPendingLayout(false)
121  , mLayoutStatus(SwPostItHelper::INVISIBLE)
122  , maLayoutInfo()
123 {
124 }
125 
127 
129  SwLayoutInfo& o_rInfo,
130  const SwPosition& rAnchorPos,
131  const sw::mark::IMark* pAnnotationMark )
132 {
133  SwLayoutStatus aRet = INVISIBLE;
134  SwTextNode* pTextNode = rAnchorPos.nNode.GetNode().GetTextNode();
135  if ( pTextNode == nullptr )
136  return aRet;
137 
139  for( SwTextFrame* pTextFrame = aIter.First(); pTextFrame != nullptr; pTextFrame = aIter.Next() )
140  {
141  if( !pTextFrame->IsFollow() )
142  {
143  pTextFrame = pTextFrame->GetFrameAtPos( rAnchorPos );
144  SwPageFrame *pPage = pTextFrame ? pTextFrame->FindPageFrame() : nullptr;
145  if ( pPage != nullptr && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
146  {
147  aRet = VISIBLE;
148 
149  o_rInfo.mpAnchorFrame = pTextFrame;
150  {
151  DisableCallbackAction a(*pTextFrame->getRootFrame());
152  bool bPositionFromCommentAnchor = true;
153  if (AnnotationMarkCoversCommentAnchor(pAnnotationMark, rAnchorPos))
154  {
155  SwAnchoredObject* pFrame
156  = GetAnchoredObjectOfAnnotationMark(*pAnnotationMark, *pTextFrame);
157  if (pFrame)
158  {
159  o_rInfo.mPosition = pFrame->GetObjRect();
160  bPositionFromCommentAnchor = false;
161  }
162  }
163  if (bPositionFromCommentAnchor)
164  {
165  pTextFrame->GetCharRect(o_rInfo.mPosition, rAnchorPos, nullptr, false);
166  }
167  o_rInfo.mPositionFromCommentAnchor = bPositionFromCommentAnchor;
168  }
169  if (pAnnotationMark != nullptr)
170  {
171  const SwPosition& rAnnotationStartPos = pAnnotationMark->GetMarkStart();
172  o_rInfo.mnStartNodeIdx = rAnnotationStartPos.nNode.GetIndex();
173  o_rInfo.mnStartContent = rAnnotationStartPos.nContent.GetIndex();
174  }
175  else
176  {
177  o_rInfo.mnStartNodeIdx = 0;
178  o_rInfo.mnStartContent = -1;
179  }
180  o_rInfo.mPageFrame = pPage->getFrameArea();
181  o_rInfo.mPagePrtArea = pPage->getFramePrintArea();
182  o_rInfo.mPagePrtArea.Pos() += o_rInfo.mPageFrame.Pos();
183  o_rInfo.mnPageNumber = pPage->GetPhyPageNum();
184  o_rInfo.meSidebarPosition = pPage->SidebarPosition();
185  o_rInfo.mRedlineAuthor = 0;
186 
187  const IDocumentRedlineAccess& rIDRA = pTextNode->getIDocumentRedlineAccess();
189  {
190  const SwRangeRedline* pRedline = rIDRA.GetRedline( rAnchorPos, nullptr );
191  if( pRedline )
192  {
193  if( RedlineType::Insert == pRedline->GetType() )
194  aRet = INSERTED;
195  else if( RedlineType::Delete == pRedline->GetType() )
196  aRet = DELETED;
197  o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
198  }
199  }
200  }
201  }
202  }
203 
204  return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTextNode , rAnchorPos.nContent.GetIndex()) )
205  ? HIDDEN
206  : aRet;
207 }
208 
210 {
211  long nRet = pRoot ? pRoot->getFrameArea().Height() : 0;
212  return nRet;
213 }
214 
215 void SwPostItHelper::setSidebarChanged( SwRootFrame* pRoot, bool bBrowseMode )
216 {
217  if( pRoot )
218  {
219  pRoot->SetSidebarChanged();
220  if( bBrowseMode )
221  pRoot->InvalidateBrowseWidth();
222  }
223 }
224 
225 unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrame, const SwRootFrame* pRoot, const Point& rPoint )
226 {
227  unsigned long nRet = 0;
228  const SwFrame* pPage = pRoot->GetPageAtPos( rPoint, nullptr, true );
229  if( pPage )
230  {
231  nRet = pPage->GetPhyPageNum();
232  rPageFrame = pPage->getFrameArea();
233  }
234  return nRet;
235 }
236 
238 {
239  SwTextField* pTextField = mrFormatField.GetTextField();
240  SwTextNode* pTextNode = pTextField->GetpTextNode();
241 
242  SwPosition aPos( *pTextNode );
243  aPos.nContent.Assign( pTextNode, pTextField->GetStart() );
244  return aPos;
245 }
246 
248  IDocumentRedlineAccess const& rIDRA)
249 {
250  return mrFormatField.IsFieldInDoc()
251  && (!rLayout.IsHideRedlines()
253 }
254 
256  SwEditWin& rEditWin,
257  SwPostItMgr& aMgr)
258 {
260  aMgr,
261  *this,
262  &mrFormatField );
263 }
264 
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer layout elements.
Definition: frame.hxx:297
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
virtual SwRect GetObjRect() const =0
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:545
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:178
std::size_t mRedlineAuthor
TElementType * Next()
Definition: calbck.hxx:351
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:191
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:1373
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
void Pos(const Point &rNew)
Definition: swrect.hxx:169
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:35
EmbeddedObjectRef * pObject
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
virtual SwPosition GetAnchorPosition() const override
static bool IsShowChanges(const RedlineFlags eM)
virtual ~SwSidebarItem()
SwFormatField & mrFormatField
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:191
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:177
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:129
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
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
bool IsInvalidFly() const
Definition: pagefrm.hxx:430
Style of a layout element.
Definition: frmfmt.hxx:57
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: node.cxx:2110
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
uno_Any a
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:206
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
SwPageFrame * FindPageFrame()
Definition: frame.hxx:660
SwRect mPagePrtArea
TElementType * First()
Definition: calbck.hxx:343
long getLayoutHeight(const SwRootFrame *pRoot)
sal_uLong mnStartNodeIdx
unsigned long mnPageNumber
A page of the document layout.
Definition: pagefrm.hxx:41
virtual const SwRangeRedline * GetRedline(const SwPosition &rPos, SwRedlineTable::size_type *pFndPos) const =0
bool IsFieldInDoc() const
Definition: atrfld.cxx:394
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
SwSidebarItem(const bool aFocus)
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
std::size_t GetAuthor(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1719
sw::sidebarwindows::SidebarPosition meSidebarPosition
sal_uInt16 GetPhyPageNum() const
Definition: trvlfrm.cxx:1694
sal_Int32 GetIndex() const
Definition: index.hxx:91
static VclPtr< reference_type > Create(Arg &&...arg)
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1734
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:1877
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:426
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:844