1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include <tools/gen.hxx> 28 29 #include <postithelper.hxx> 30 #include <PostItMgr.hxx> 31 #include <AnnotationWin.hxx> 32 33 #include <fmtfld.hxx> 34 #include <txtfld.hxx> 35 #include <docufld.hxx> 36 #include <ndtxt.hxx> 37 #include <cntfrm.hxx> 38 #include <pagefrm.hxx> 39 #include <rootfrm.hxx> 40 #include <txtfrm.hxx> 41 #include <tabfrm.hxx> 42 #include <IDocumentRedlineAccess.hxx> 43 #include <redline.hxx> 44 #include <scriptinfo.hxx> 45 #include <editeng/charhiddenitem.hxx> 46 #include <switerator.hxx> 47 48 namespace { 49 50 struct LayoutInfoOrder 51 { 52 bool operator()( const SwLayoutInfo& rLayoutInfo, 53 const SwLayoutInfo& rNewLayoutInfo ) 54 { 55 if ( rLayoutInfo.mnPageNumber != rNewLayoutInfo.mnPageNumber ) 56 { 57 // corresponding <SwFrm> instances are on different pages 58 return rLayoutInfo.mnPageNumber < rNewLayoutInfo.mnPageNumber; 59 } 60 else 61 { 62 // corresponding <SwFrm> instances are in different repeating table header rows 63 ASSERT( rLayoutInfo.mpAnchorFrm->FindTabFrm(), 64 "<LayoutInfoOrder::operator()> - table frame not found" ); 65 ASSERT( rNewLayoutInfo.mpAnchorFrm->FindTabFrm(), 66 "<LayoutInfoOrder::operator()> - table frame not found" ); 67 const SwTabFrm* pLayoutInfoTabFrm( rLayoutInfo.mpAnchorFrm->FindTabFrm() ); 68 const SwTabFrm* pNewLayoutInfoTabFrm( rNewLayoutInfo.mpAnchorFrm->FindTabFrm() ); 69 const SwTabFrm* pTmpTabFrm( pNewLayoutInfoTabFrm ); 70 while ( pTmpTabFrm && pTmpTabFrm->GetFollow() ) 71 { 72 pTmpTabFrm = static_cast<const SwTabFrm*>(pTmpTabFrm->GetFollow()->GetFrm()); 73 if ( pTmpTabFrm == pLayoutInfoTabFrm ) 74 { 75 return false; 76 } 77 } 78 return true; 79 } 80 } 81 }; 82 83 } // eof anonymous namespace 84 85 SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos( std::vector< SwLayoutInfo >& rInfo, SwPosition& rPos ) 86 { 87 SwLayoutStatus aRet = INVISIBLE; 88 const SwTxtNode* pTxtNode = rPos.nNode.GetNode().GetTxtNode(); 89 SwCntntNode* pNode = rPos.nNode.GetNode().GetCntntNode(); // getfirstcontentnode // getnext... 90 if( !pNode ) 91 return aRet; 92 SwIterator<SwTxtFrm,SwCntntNode> aIter( *pNode ); 93 for( SwTxtFrm* pTxtFrm = aIter.First(); pTxtFrm; pTxtFrm = aIter.Next() ) 94 { 95 if( !pTxtFrm->IsFollow() ) 96 { 97 pTxtFrm = ((SwTxtFrm*)pTxtFrm)->GetFrmAtPos( rPos ); 98 SwPageFrm *pPage = pTxtFrm ? pTxtFrm->FindPageFrm() : 0; 99 // #i103490# 100 if ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() ) 101 { 102 SwLayoutInfo aInfo; 103 pTxtFrm->GetCharRect( aInfo.mPosition, rPos, 0 ); 104 aInfo.mpAnchorFrm = pTxtFrm; 105 aInfo.mPageFrame = pPage->Frm(); 106 aInfo.mPagePrtArea = pPage->Prt(); 107 aInfo.mPagePrtArea.Pos() += aInfo.mPageFrame.Pos(); 108 aInfo.mnPageNumber = pPage->GetPhyPageNum(); 109 aInfo.meSidebarPosition = pPage->SidebarPosition(); 110 aInfo.mRedlineAuthor = 0; 111 112 if( aRet == INVISIBLE ) 113 { 114 aRet = VISIBLE; 115 const IDocumentRedlineAccess* pIDRA = pNode->getIDocumentRedlineAccess(); 116 if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) ) 117 { 118 const SwRedline* pRedline = pIDRA->GetRedline( rPos, 0 ); 119 if( pRedline ) 120 { 121 if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() ) 122 aRet = INSERTED; 123 else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() ) 124 aRet = DELETED; 125 aInfo.mRedlineAuthor = pRedline->GetAuthor(); 126 } 127 } 128 } 129 130 { 131 std::vector< SwLayoutInfo >::iterator aInsPosIter = 132 std::lower_bound( rInfo.begin(), rInfo.end(), 133 aInfo, LayoutInfoOrder() ); 134 135 rInfo.insert( aInsPosIter, aInfo ); 136 } 137 } 138 } 139 } 140 return ((aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTxtNode , rPos.nContent.GetIndex()) ) ? HIDDEN : aRet; 141 } 142 143 long SwPostItHelper::getLayoutHeight( const SwRootFrm* pRoot ) 144 { 145 long nRet = pRoot ? pRoot->Frm().Height() : 0; 146 return nRet; 147 } 148 149 void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode ) 150 { 151 if( pRoot ) 152 { 153 pRoot->SetSidebarChanged(); 154 if( bBrowseMode ) 155 pRoot->InvalidateBrowseWidth(); 156 } 157 } 158 159 unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrm, const SwRootFrm* pRoot, const Point& rPoint ) 160 { 161 unsigned long nRet = 0; 162 const SwFrm* pPage = pRoot->GetPageAtPos( rPoint, 0, true ); 163 if( pPage ) 164 { 165 nRet = pPage->GetPhyPageNum(); 166 rPageFrm = pPage->Frm(); 167 } 168 return nRet; 169 } 170 171 SwPosition SwAnnotationItem::GetAnchorPosition() const 172 { 173 SwTxtFld* pFld = pFmtFld->GetTxtFld(); 174 //if( pFld ) 175 //{ 176 SwTxtNode* pTNd = pFld->GetpTxtNode(); 177 // if( pTNd ) 178 // { 179 SwPosition aPos( *pTNd ); 180 aPos.nContent.Assign( pTNd, *pFld->GetStart() ); 181 return aPos; 182 // } 183 //} 184 } 185 186 bool SwAnnotationItem::UseElement() 187 { 188 return pFmtFld->IsFldInDoc(); 189 } 190 191 sw::sidebarwindows::SwSidebarWin* SwAnnotationItem::GetSidebarWindow( 192 SwEditWin& rEditWin, 193 WinBits nBits, 194 SwPostItMgr& aMgr, 195 SwPostItBits aBits) 196 { 197 return new sw::annotation::SwAnnotationWin( rEditWin, nBits, 198 aMgr, aBits, 199 *this, 200 pFmtFld ); 201 } 202 203 /* 204 SwPosition SwRedCommentItem::GetAnchorPosition() 205 { 206 return *pRedline->Start(); 207 } 208 209 SwSidebarWin* SwRedCommentItem::GetSidebarWindow(Window* pParent, WinBits nBits,SwPostItMgr* aMgr,SwPostItBits aBits) 210 { 211 return new SwRedComment(pParent,nBits,aMgr,aBits,pRedline); 212 } 213 214 bool SwRedCommentItem::UseElement() 215 { 216 return true; 217 } 218 */ 219