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