1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <tools/gen.hxx>
32 
33 #include <postithelper.hxx>
34 #include <PostItMgr.hxx>
35 #include <AnnotationWin.hxx>
36 
37 #include <fmtfld.hxx>
38 #include <txtfld.hxx>
39 #include <docufld.hxx>
40 #include <ndtxt.hxx>
41 #include <cntfrm.hxx>
42 #include <pagefrm.hxx>
43 #include <rootfrm.hxx>
44 #include <txtfrm.hxx>
45 #include <tabfrm.hxx>
46 #include <IDocumentRedlineAccess.hxx>
47 #include <redline.hxx>
48 #include <scriptinfo.hxx>
49 #include <editeng/charhiddenitem.hxx>
50 #include <switerator.hxx>
51 
52 namespace {
53 
54 struct LayoutInfoOrder
55 {
56     bool operator()( const SwLayoutInfo& rLayoutInfo,
57                      const SwLayoutInfo& rNewLayoutInfo )
58     {
59         if ( rLayoutInfo.mnPageNumber != rNewLayoutInfo.mnPageNumber )
60         {
61             // corresponding <SwFrm> instances are on different pages
62             return rLayoutInfo.mnPageNumber < rNewLayoutInfo.mnPageNumber;
63         }
64         else
65         {
66             // corresponding <SwFrm> instances are in different repeating table header rows
67             ASSERT( rLayoutInfo.mpAnchorFrm->FindTabFrm(),
68                     "<LayoutInfoOrder::operator()> - table frame not found" );
69             ASSERT( rNewLayoutInfo.mpAnchorFrm->FindTabFrm(),
70                     "<LayoutInfoOrder::operator()> - table frame not found" );
71             const SwTabFrm* pLayoutInfoTabFrm( rLayoutInfo.mpAnchorFrm->FindTabFrm() );
72             const SwTabFrm* pNewLayoutInfoTabFrm( rNewLayoutInfo.mpAnchorFrm->FindTabFrm() );
73             const SwTabFrm* pTmpTabFrm( pNewLayoutInfoTabFrm );
74             while ( pTmpTabFrm && pTmpTabFrm->GetFollow() )
75             {
76                 pTmpTabFrm = static_cast<const SwTabFrm*>(pTmpTabFrm->GetFollow()->GetFrm());
77                 if ( pTmpTabFrm == pLayoutInfoTabFrm )
78                 {
79                     return false;
80                 }
81             }
82             return true;
83         }
84     }
85 };
86 
87 } // eof anonymous namespace
88 
89 SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos( std::vector< SwLayoutInfo >& rInfo, SwPosition& rPos )
90 {
91     SwLayoutStatus aRet = INVISIBLE;
92 	const SwTxtNode* pTxtNode = rPos.nNode.GetNode().GetTxtNode();
93     SwCntntNode* pNode = rPos.nNode.GetNode().GetCntntNode();	// getfirstcontentnode // getnext...
94     if( !pNode )
95         return aRet;
96 	SwIterator<SwTxtFrm,SwCntntNode> aIter( *pNode );
97     for( SwTxtFrm* pTxtFrm = aIter.First(); pTxtFrm; pTxtFrm = aIter.Next() )
98     {
99         if( !pTxtFrm->IsFollow() )
100         {
101             pTxtFrm = ((SwTxtFrm*)pTxtFrm)->GetFrmAtPos( rPos );
102 	    SwPageFrm *pPage = pTxtFrm ? pTxtFrm->FindPageFrm() : 0;
103 	    // #i103490#
104             if ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
105             {
106                 SwLayoutInfo aInfo;
107                 pTxtFrm->GetCharRect( aInfo.mPosition, rPos, 0 );
108                 aInfo.mpAnchorFrm = pTxtFrm;
109                 aInfo.mPageFrame = pPage->Frm();
110                 aInfo.mPagePrtArea = pPage->Prt();
111                 aInfo.mPagePrtArea.Pos() += aInfo.mPageFrame.Pos();
112                 aInfo.mnPageNumber = pPage->GetPhyPageNum();
113                 aInfo.meSidebarPosition = pPage->SidebarPosition();
114 				aInfo.mRedlineAuthor = 0;
115 
116                 if( aRet == INVISIBLE )
117                 {
118                     aRet = VISIBLE;
119                     const IDocumentRedlineAccess* pIDRA = pNode->getIDocumentRedlineAccess();
120                     if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) )
121                     {
122                         const SwRedline* pRedline = pIDRA->GetRedline( rPos, 0 );
123                         if( pRedline )
124                         {
125                             if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() )
126                                 aRet = INSERTED;
127                             else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() )
128                                 aRet = DELETED;
129 							aInfo.mRedlineAuthor = pRedline->GetAuthor();
130                         }
131                     }
132                 }
133 
134                 {
135                     std::vector< SwLayoutInfo >::iterator aInsPosIter =
136                                 std::lower_bound( rInfo.begin(), rInfo.end(),
137                                                   aInfo, LayoutInfoOrder() );
138 
139                     rInfo.insert( aInsPosIter, aInfo );
140                 }
141             }
142         }
143     }
144 	return ((aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTxtNode , rPos.nContent.GetIndex()) ) ? HIDDEN : aRet;
145 }
146 
147 long SwPostItHelper::getLayoutHeight( const SwRootFrm* pRoot )
148 {
149     long nRet = pRoot ? pRoot->Frm().Height() : 0;
150     return nRet;
151 }
152 
153 void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode )
154 {
155     if( pRoot )
156     {
157 		pRoot->SetSidebarChanged();
158         if( bBrowseMode )
159             pRoot->InvalidateBrowseWidth();
160     }
161 }
162 
163 unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrm, const SwRootFrm* pRoot, const Point& rPoint )
164 {
165     unsigned long nRet = 0;
166     const SwFrm* pPage = pRoot->GetPageAtPos( rPoint, 0, true );
167     if( pPage )
168     {
169         nRet = pPage->GetPhyPageNum();
170         rPageFrm = pPage->Frm();
171     }
172     return nRet;
173 }
174 
175 SwPosition SwAnnotationItem::GetAnchorPosition() const
176 {
177 	SwTxtFld* pFld = pFmtFld->GetTxtFld();
178 	//if( pFld )
179 	//{
180 		SwTxtNode* pTNd = pFld->GetpTxtNode();
181 	//	if( pTNd )
182 	//	{
183 			SwPosition aPos( *pTNd );
184 			aPos.nContent.Assign( pTNd, *pFld->GetStart() );
185 			return aPos;
186 	//	}
187 	//}
188 }
189 
190 bool SwAnnotationItem::UseElement()
191 {
192 	return pFmtFld->IsFldInDoc();
193 }
194 
195 sw::sidebarwindows::SwSidebarWin* SwAnnotationItem::GetSidebarWindow(
196                                                             SwEditWin& rEditWin,
197                                                             WinBits nBits,
198                                                             SwPostItMgr& aMgr,
199                                                             SwPostItBits aBits)
200 {
201     return new sw::annotation::SwAnnotationWin( rEditWin, nBits,
202                                                 aMgr, aBits,
203                                                 *this,
204                                                 pFmtFld );
205 }
206 
207 /*
208 SwPosition SwRedCommentItem::GetAnchorPosition()
209 {
210 	return *pRedline->Start();
211 }
212 
213 SwSidebarWin* SwRedCommentItem::GetSidebarWindow(Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits)
214 {
215 	return new SwRedComment(pParent,nBits,aMgr,aBits,pRedline);
216 }
217 
218 bool SwRedCommentItem::UseElement()
219 {
220 	return true;
221 }
222 */
223