1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: postithelper.cxx,v $
10 * $Revision: 1.2.118.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <tools/gen.hxx>
36 #include <postithelper.hxx>
37 #include <PostItMgr.hxx>
41 #include <docufld.hxx>
44 #include <pagefrm.hxx>
45 #include <rootfrm.hxx>
47 #include <IDocumentRedlineAccess.hxx>
48 #include <redline.hxx>
49 #include <scriptinfo.hxx>
50 #include <svx/charhiddenitem.hxx>
53 SwPostItHelper::SwLayoutStatus
SwPostItHelper::getLayoutInfos( std::vector
< SwLayoutInfo
>& rInfo
, SwPosition
& rPos
)
55 SwLayoutStatus aRet
= INVISIBLE
;
56 const SwTxtNode
* pTxtNode
= rPos
.nNode
.GetNode().GetTxtNode();
57 SwCntntNode
* pNode
= rPos
.nNode
.GetNode().GetCntntNode(); // getfirstcontentnode // getnext...
60 SwClientIter
aIter( *pNode
);
62 for( pTxtFrm
= (SwTxtFrm
*)aIter
.First( TYPE( SwTxtFrm
)); pTxtFrm
; pTxtFrm
= (SwTxtFrm
*)aIter
.Next() )
64 if( !pTxtFrm
->IsFollow() )
66 pTxtFrm
= ((SwTxtFrm
*)pTxtFrm
)->GetFrmAtPos( rPos
);
67 SwPageFrm
*pPage
= pTxtFrm
? pTxtFrm
->FindPageFrm() : 0;
69 if ( pPage
&& !pPage
->IsInvalid() && !pPage
->IsInvalidFly() )
72 pTxtFrm
->GetCharRect( aInfo
.mPosition
, rPos
, 0 );
73 aInfo
.mPageFrame
= pPage
->Frm();
74 aInfo
.mPagePrtArea
= pPage
->Prt();
75 aInfo
.mPagePrtArea
.Pos() += aInfo
.mPageFrame
.Pos();
76 aInfo
.mnPageNumber
= pPage
->GetPhyPageNum();
77 aInfo
.mbMarginSide
= pPage
->MarginSide();
78 aInfo
.mRedlineAuthor
= 0;
80 if( aRet
== INVISIBLE
)
83 const IDocumentRedlineAccess
* pIDRA
= pNode
->getIDocumentRedlineAccess();
84 if( IDocumentRedlineAccess::IsShowChanges( pIDRA
->GetRedlineMode() ) )
86 const SwRedline
* pRedline
= pIDRA
->GetRedline( rPos
, 0 );
89 if( nsRedlineType_t::REDLINE_INSERT
== pRedline
->GetType() )
91 else if( nsRedlineType_t::REDLINE_DELETE
== pRedline
->GetType() )
93 aInfo
.mRedlineAuthor
= pRedline
->GetAuthor();
97 rInfo
.push_back( aInfo
);
101 return ((aRet
==VISIBLE
) && SwScriptInfo::IsInHiddenRange( *pTxtNode
, rPos
.nContent
.GetIndex()) ) ? HIDDEN
: aRet
;
104 long SwPostItHelper::getLayoutHeight( const SwRootFrm
* pRoot
)
106 long nRet
= pRoot
? pRoot
->Frm().Height() : 0;
110 void SwPostItHelper::setSidebarChanged( SwRootFrm
* pRoot
, bool bBrowseMode
)
114 pRoot
->SetSidebarChanged();
116 pRoot
->InvalidateBrowseWidth();
120 unsigned long SwPostItHelper::getPageInfo( SwRect
& rPageFrm
, const SwRootFrm
* pRoot
, const Point
& rPoint
)
122 unsigned long nRet
= 0;
123 const SwFrm
* pPage
= pRoot
->GetPageAtPos( rPoint
, 0, true );
126 nRet
= pPage
->GetPhyPageNum();
127 rPageFrm
= pPage
->Frm();
132 SwPostItHelper::SwLayoutStatus
SwPostItHelper::getLayoutInfos( std::vector
< SwLayoutInfo
>& rInfo
, SwTxtFld
* pFld
)
134 SwLayoutStatus aRet
= SwPostItHelper::INVISIBLE
;
137 SwTxtNode
* pTNd
= pFld
->GetpTxtNode();
140 SwPosition
aPos( *pTNd
);
141 aPos
.nContent
.Assign( pTNd
, *pFld
->GetStart() );
142 aRet
= getLayoutInfos( rInfo
, aPos
);
148 SwPosition
SwPostItItem::GetPosition()
150 SwTxtFld
* pFld
= pFmtFld
->GetTxtFld();
153 SwTxtNode
* pTNd
= pFld
->GetpTxtNode();
156 SwPosition
aPos( *pTNd
);
157 aPos
.nContent
.Assign( pTNd
, *pFld
->GetStart() );
163 bool SwPostItItem::UseElement()
165 return pFmtFld
->IsFldInDoc();
168 SwMarginWin
* SwPostItItem::GetMarginWindow(Window
* pParent
, WinBits nBits
,SwPostItMgr
* aMgr
,SwPostItBits aBits
)
170 return new SwPostIt(pParent
,nBits
,pFmtFld
,aMgr
,aBits
);
174 SwPosition SwRedCommentItem::GetPosition()
176 return *pRedline->Start();
179 SwMarginWin* SwRedCommentItem::GetMarginWindow(Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits)
181 return new SwRedComment(pParent,nBits,aMgr,aBits,pRedline);
184 bool SwRedCommentItem::UseElement()