update dev300-m58
[ooovba.git] / sw / source / core / fields / postithelper.cxx
blobde3fc1f8a90467f9195d5a801ebaf32ca8184fa2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
38 #include <postit.hxx>
39 #include <fmtfld.hxx>
40 #include <txtfld.hxx>
41 #include <docufld.hxx>
42 #include <ndtxt.hxx>
43 #include <cntfrm.hxx>
44 #include <pagefrm.hxx>
45 #include <rootfrm.hxx>
46 #include <txtfrm.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...
58 if( !pNode )
59 return aRet;
60 SwClientIter aIter( *pNode );
61 SwTxtFrm *pTxtFrm;
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;
68 if( pPage )
70 SwLayoutInfo aInfo;
71 pTxtFrm->GetCharRect( aInfo.mPosition, rPos, 0 );
72 aInfo.mPageFrame = pPage->Frm();
73 aInfo.mPagePrtArea = pPage->Prt();
74 aInfo.mPagePrtArea.Pos() += aInfo.mPageFrame.Pos();
75 aInfo.mnPageNumber = pPage->GetPhyPageNum();
76 aInfo.mbMarginSide = pPage->MarginSide();
77 aInfo.mRedlineAuthor = 0;
79 if( aRet == INVISIBLE )
81 aRet = VISIBLE;
82 const IDocumentRedlineAccess* pIDRA = pNode->getIDocumentRedlineAccess();
83 if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) )
85 const SwRedline* pRedline = pIDRA->GetRedline( rPos, 0 );
86 if( pRedline )
88 if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() )
89 aRet = INSERTED;
90 else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() )
91 aRet = DELETED;
92 aInfo.mRedlineAuthor = pRedline->GetAuthor();
96 rInfo.push_back( aInfo );
100 return ((aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTxtNode , rPos.nContent.GetIndex()) ) ? HIDDEN : aRet;
103 long SwPostItHelper::getLayoutHeight( const SwRootFrm* pRoot )
105 long nRet = pRoot ? pRoot->Frm().Height() : 0;
106 return nRet;
109 void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode )
111 if( pRoot )
113 pRoot->SetSidebarChanged();
114 if( bBrowseMode )
115 pRoot->InvalidateBrowseWidth();
119 unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrm, const SwRootFrm* pRoot, const Point& rPoint )
121 unsigned long nRet = 0;
122 const SwFrm* pPage = pRoot->GetPageAtPos( rPoint, 0, true );
123 if( pPage )
125 nRet = pPage->GetPhyPageNum();
126 rPageFrm = pPage->Frm();
128 return nRet;
131 SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos( std::vector< SwLayoutInfo >& rInfo, SwTxtFld* pFld )
133 SwLayoutStatus aRet = SwPostItHelper::INVISIBLE;
134 if( pFld )
136 SwTxtNode* pTNd = pFld->GetpTxtNode();
137 if( pTNd )
139 SwPosition aPos( *pTNd );
140 aPos.nContent.Assign( pTNd, *pFld->GetStart() );
141 aRet = getLayoutInfos( rInfo, aPos );
144 return aRet;
147 SwPosition SwPostItItem::GetPosition()
149 SwTxtFld* pFld = pFmtFld->GetTxtFld();
150 //if( pFld )
152 SwTxtNode* pTNd = pFld->GetpTxtNode();
153 // if( pTNd )
154 // {
155 SwPosition aPos( *pTNd );
156 aPos.nContent.Assign( pTNd, *pFld->GetStart() );
157 return aPos;
158 // }
162 bool SwPostItItem::UseElement()
164 return pFmtFld->IsFldInDoc();
167 SwMarginWin* SwPostItItem::GetMarginWindow(Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits)
169 return new SwPostIt(pParent,nBits,pFmtFld,aMgr,aBits);
173 SwPosition SwRedCommentItem::GetPosition()
175 return *pRedline->Start();
178 SwMarginWin* SwRedCommentItem::GetMarginWindow(Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits)
180 return new SwRedComment(pParent,nBits,aMgr,aBits,pRedline);
183 bool SwRedCommentItem::UseElement()
185 return true;