Update ooo320-m1
[ooovba.git] / sw / source / core / fields / postithelper.cxx
blob9a4542b6287203b9493dedbe4ad30c9d35ae8cd5
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 // #i103490#
69 if ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
71 SwLayoutInfo aInfo;
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 )
82 aRet = VISIBLE;
83 const IDocumentRedlineAccess* pIDRA = pNode->getIDocumentRedlineAccess();
84 if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) )
86 const SwRedline* pRedline = pIDRA->GetRedline( rPos, 0 );
87 if( pRedline )
89 if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() )
90 aRet = INSERTED;
91 else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() )
92 aRet = DELETED;
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;
107 return nRet;
110 void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode )
112 if( pRoot )
114 pRoot->SetSidebarChanged();
115 if( bBrowseMode )
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 );
124 if( pPage )
126 nRet = pPage->GetPhyPageNum();
127 rPageFrm = pPage->Frm();
129 return nRet;
132 SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos( std::vector< SwLayoutInfo >& rInfo, SwTxtFld* pFld )
134 SwLayoutStatus aRet = SwPostItHelper::INVISIBLE;
135 if( pFld )
137 SwTxtNode* pTNd = pFld->GetpTxtNode();
138 if( pTNd )
140 SwPosition aPos( *pTNd );
141 aPos.nContent.Assign( pTNd, *pFld->GetStart() );
142 aRet = getLayoutInfos( rInfo, aPos );
145 return aRet;
148 SwPosition SwPostItItem::GetPosition()
150 SwTxtFld* pFld = pFmtFld->GetTxtFld();
151 //if( pFld )
153 SwTxtNode* pTNd = pFld->GetpTxtNode();
154 // if( pTNd )
155 // {
156 SwPosition aPos( *pTNd );
157 aPos.nContent.Assign( pTNd, *pFld->GetStart() );
158 return aPos;
159 // }
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()
186 return true;