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( 86 SwLayoutInfo& o_rInfo, 87 const SwPosition& rAnchorPos, 88 const SwPosition* pAnnotationStartPos ) 89 { 90 SwLayoutStatus aRet = INVISIBLE; 91 SwTxtNode* pTxtNode = rAnchorPos.nNode.GetNode().GetTxtNode(); 92 if ( pTxtNode == NULL ) 93 return aRet; 94 95 SwIterator<SwTxtFrm,SwCntntNode> aIter( *pTxtNode ); 96 for( SwTxtFrm* pTxtFrm = aIter.First(); pTxtFrm != NULL; pTxtFrm = aIter.Next() ) 97 { 98 if( !pTxtFrm->IsFollow() ) 99 { 100 pTxtFrm = pTxtFrm->GetFrmAtPos( rAnchorPos ); 101 SwPageFrm *pPage = pTxtFrm ? pTxtFrm->FindPageFrm() : 0; 102 if ( pPage != NULL && !pPage->IsInvalid() && !pPage->IsInvalidFly() ) 103 { 104 aRet = VISIBLE; 105 106 o_rInfo.mpAnchorFrm = pTxtFrm; 107 pTxtFrm->GetCharRect( o_rInfo.mPosition, rAnchorPos, 0 ); 108 if ( pAnnotationStartPos != NULL ) 109 { 110 o_rInfo.mnStartNodeIdx = pAnnotationStartPos->nNode.GetIndex(); 111 o_rInfo.mnStartContent = pAnnotationStartPos->nContent.GetIndex(); 112 } 113 else 114 { 115 o_rInfo.mnStartNodeIdx = 0; 116 o_rInfo.mnStartContent = STRING_NOTFOUND; 117 } 118 o_rInfo.mPageFrame = pPage->Frm(); 119 o_rInfo.mPagePrtArea = pPage->Prt(); 120 o_rInfo.mPagePrtArea.Pos() += o_rInfo.mPageFrame.Pos(); 121 o_rInfo.mnPageNumber = pPage->GetPhyPageNum(); 122 o_rInfo.meSidebarPosition = pPage->SidebarPosition(); 123 o_rInfo.mRedlineAuthor = 0; 124 125 const IDocumentRedlineAccess* pIDRA = pTxtNode->getIDocumentRedlineAccess(); 126 if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) ) 127 { 128 const SwRedline* pRedline = pIDRA->GetRedline( rAnchorPos, 0 ); 129 if( pRedline ) 130 { 131 if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() ) 132 aRet = INSERTED; 133 else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() ) 134 aRet = DELETED; 135 o_rInfo.mRedlineAuthor = pRedline->GetAuthor(); 136 } 137 } 138 } 139 } 140 } 141 142 return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTxtNode , rAnchorPos.nContent.GetIndex()) ) 143 ? HIDDEN 144 : 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* pTxtFld = mrFmtFld.GetTxtFld(); 178 //if( pTxtFld ) 179 //{ 180 SwTxtNode* pTxtNode = pTxtFld->GetpTxtNode(); 181 //if( pTxtNode ) 182 //{ 183 SwPosition aPos( *pTxtNode ); 184 aPos.nContent.Assign( pTxtNode, *(pTxtFld->GetStart()) ); 185 return aPos; 186 //} 187 //} 188 } 189 190 bool SwAnnotationItem::UseElement() 191 { 192 return mrFmtFld.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 &mrFmtFld ); 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