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>
33#include <redline.hxx>
34#include <scriptinfo.hxx>
35#include <calbck.hxx>
36#include <IMark.hxx>
37#include <sortedobjs.hxx>
38#include <anchoredobject.hxx>
39#include <fmtanchr.hxx>
40
41class Point;
42
43namespace
44{
46bool AnnotationMarkCoversCommentAnchor(const sw::mark::IMark* pAnnotationMark,
47 const SwPosition& rAnchorPos)
48{
49 if (!pAnnotationMark)
50 {
51 return false;
52 }
53
54 const SwPosition& rMarkStart = pAnnotationMark->GetMarkStart();
55 const SwPosition& rMarkEnd = pAnnotationMark->GetMarkEnd();
56
57 if (rMarkStart != rAnchorPos)
58 {
59 // This can be the as-char case: the comment placeholder character is exactly between the
60 // annotation mark start and end.
61 SwPosition aPosition(rMarkStart);
62 ++aPosition.nContent;
63 if (aPosition != rAnchorPos)
64 {
65 return false;
66 }
67
68 ++aPosition.nContent;
69 if (aPosition != rMarkEnd)
70 {
71 return false;
72 }
73
74 return true;
75 }
76
77 if (rMarkStart.nNode != rMarkEnd.nNode)
78 {
79 return false;
80 }
81
82 return rMarkEnd.GetContentIndex() == rMarkStart.GetContentIndex() + 1;
83}
84
89SwAnchoredObject* GetAnchoredObjectOfAnnotationMark(const sw::mark::IMark& rAnnotationMark,
90 const SwTextFrame& rTextFrame)
91{
92 const SwSortedObjs* pAnchored = rTextFrame.GetDrawObjs();
93 if (!pAnchored)
94 {
95 return nullptr;
96 }
97
98 for (SwAnchoredObject* pObject : *pAnchored)
99 {
100 SwFrameFormat& rFrameFormat = pObject->GetFrameFormat();
101 const SwPosition* pFrameAnchor = rFrameFormat.GetAnchor().GetContentAnchor();
102 if (!pFrameAnchor)
103 {
104 continue;
105 }
106
107 if (rAnnotationMark.GetMarkStart() == *pFrameAnchor)
108 {
109 return pObject;
110 }
111 }
112
113 return nullptr;
114}
115}
116
118 : mpPostIt(nullptr)
119 , mbShow(true)
120 , mbFocus(aFocus)
121 , mbPendingLayout(false)
122 , mLayoutStatus(SwPostItHelper::INVISIBLE)
123{
124}
125
127
129 SwLayoutInfo& o_rInfo,
130 const SwPosition& rAnchorPos,
131 const sw::mark::IMark* pAnnotationMark )
132{
134 SwTextNode* pTextNode = rAnchorPos.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.GetNodeIndex();
173 o_rInfo.mnStartContent = rAnnotationStartPos.GetContentIndex();
174 }
175 else
176 {
177 o_rInfo.mnStartNodeIdx = SwNodeOffset(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 {
197 bool bDeleted = pAnnotationMark == nullptr;
198 if( !bDeleted )
199 {
201 IDocumentMarkAccess::const_iterator_t pAnnotationBookmark =
202 rDMA.findAnnotationBookmark(pAnnotationMark->GetName());
203 // tdf#140980 only really deleted, if there is no helper bookmark
204 // in ChangesInMargin mode
205 if ( pAnnotationBookmark == rDMA.getBookmarksEnd() )
206 bDeleted = true;
207 }
208 if ( bDeleted )
209 aRet = DELETED;
210 }
211 o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
212 }
213 }
214 }
215 }
216 }
217
218 return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTextNode , rAnchorPos.GetContentIndex()) )
219 ? HIDDEN
220 : aRet;
221}
222
224{
225 tools::Long nRet = pRoot ? pRoot->getFrameArea().Height() : 0;
226 return nRet;
227}
228
229void SwPostItHelper::setSidebarChanged( SwRootFrame* pRoot, bool bBrowseMode )
230{
231 if( pRoot )
232 {
233 pRoot->SetSidebarChanged();
234 if( bBrowseMode )
235 pRoot->InvalidateBrowseWidth();
236 }
237}
238
239tools::ULong SwPostItHelper::getPageInfo( SwRect& rPageFrame, const SwRootFrame* pRoot, const Point& rPoint )
240{
241 tools::ULong nRet = 0;
242 const SwFrame* pPage = pRoot->GetPageAtPos( rPoint, nullptr, true );
243 if( pPage )
244 {
245 nRet = pPage->GetPhyPageNum();
246 rPageFrame = pPage->getFrameArea();
247 }
248 return nRet;
249}
250
252{
253 SwTextField* pTextField = mrFormatField.GetTextField();
254 SwTextNode* pTextNode = pTextField->GetpTextNode();
255
256 SwPosition aPos( *pTextNode );
257 aPos.nContent.Assign( pTextNode, pTextField->GetStart() );
258 return aPos;
259}
260
262 IDocumentRedlineAccess const& rIDRA)
263{
265 && (!rLayout.IsHideRedlines()
267}
268
270 SwEditWin& rEditWin,
271 SwPostItMgr& aMgr)
272{
274 aMgr,
275 *this,
276 &mrFormatField );
277}
278
279/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
helper class to disable creation of an action by a callback event in particular, change event from a ...
Definition: rootfrm.hxx:451
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual const_iterator_t findAnnotationBookmark(const OUString &rName) const =0
virtual const_iterator_t getBookmarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
static bool IsShowChanges(const RedlineFlags eM)
virtual const SwRangeRedline * GetRedline(const SwPosition &rPos, SwRedlineTable::size_type *pFndPos) const =0
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
wrapper class for the positioning of Writer fly frames and drawing objects
virtual SwRect GetObjRect() const =0
virtual VclPtr< sw::annotation::SwAnnotationWin > GetSidebarWindow(SwEditWin &rEditWin, SwPostItMgr &aMgr) override
SwFormatField & mrFormatField
virtual SwPosition GetAnchorPosition() const override
virtual bool UseElement(SwRootFrame const &, IDocumentRedlineAccess const &) override
SwContentIndex & Assign(const SwContentNode *, sal_Int32)
Definition: index.cxx:206
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1793
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:69
bool IsFieldInDoc() const
Definition: atrfld.cxx:435
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:148
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:83
const SwRect & getFrameArea() const
Definition: frame.hxx:179
const SwRect & getFramePrintArea() const
Definition: frame.hxx:180
Style of a layout element.
Definition: frmfmt.hxx:62
Base class of the Writer layout elements.
Definition: frame.hxx:315
const SwSortedObjs * GetDrawObjs() const
Definition: frame.hxx:564
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
sal_uInt16 GetPhyPageNum() const
Definition: trvlfrm.cxx:1705
TElementType * Next()
Definition: calbck.hxx:364
TElementType * First()
Definition: calbck.hxx:356
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: node.cxx:2140
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:876
SwDoc & GetDoc()
Definition: node.hxx:217
A page of the document layout.
Definition: pagefrm.hxx:58
bool IsInvalid() const
Definition: pagefrm.hxx:439
sal_uInt16 GetPhyPageNum() const
Definition: pagefrm.hxx:204
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:1452
bool IsInvalidFly() const
Definition: pagefrm.hxx:443
std::size_t GetAuthor(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1919
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1934
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
void Pos(const Point &rNew)
Definition: swrect.hxx:171
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
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:627
void InvalidateBrowseWidth()
Definition: rootfrm.hxx:437
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding).
Definition: rootfrm.hxx:421
void SetSidebarChanged()
Definition: rootfrm.hxx:410
static bool IsInHiddenRange(const SwTextNode &rNode, sal_Int32 nPos)
Definition: porlay.cxx:2149
virtual ~SwSidebarItem()
SwSidebarItem(const bool aFocus)
class for collecting anchored objects
Definition: sortedobjs.hxx:49
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:165
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:86
static VclPtr< reference_type > Create(Arg &&... arg)
virtual const SwPosition & GetMarkEnd() const =0
virtual const SwPosition & GetMarkStart() const =0
virtual const OUString & GetName() const =0
EmbeddedObjectRef * pObject
uno_Any a
tools::Long getLayoutHeight(const SwRootFrame *pRoot)
tools::ULong getPageInfo(SwRect &rPageFrame, const SwRootFrame *, const Point &)
SwLayoutStatus getLayoutInfos(SwLayoutInfo &o_rInfo, const SwPosition &rAnchorPos, const sw::mark::IMark *pAnnotationMark=nullptr)
void setSidebarChanged(SwRootFrame *pRoot, bool bBrowseMode)
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
unsigned long ULong
long Long
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
std::size_t mRedlineAuthor
sal_Int32 mnStartContent
SwNodeOffset mnStartNodeIdx
tools::ULong mnPageNumber
sw::sidebarwindows::SidebarPosition meSidebarPosition
SwRect mPageFrame
SwRect mPosition
const SwFrame * mpAnchorFrame
bool mPositionFromCommentAnchor
If true, the overlay arrow points to the comment anchor, otherwise it points to the commented frame.
SwRect mPagePrtArea
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
SwNodeIndex nNode
Definition: pam.hxx:38
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:77
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
SwContentIndex nContent
Definition: pam.hxx:39