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 : #include <postithelper.hxx>
21 : #include <PostItMgr.hxx>
22 : #include <AnnotationWin.hxx>
23 :
24 : #include <fmtfld.hxx>
25 : #include <txtfld.hxx>
26 : #include <docufld.hxx>
27 : #include <ndtxt.hxx>
28 : #include <cntfrm.hxx>
29 : #include <pagefrm.hxx>
30 : #include <rootfrm.hxx>
31 : #include <txtfrm.hxx>
32 : #include <tabfrm.hxx>
33 : #include <IDocumentRedlineAccess.hxx>
34 : #include <redline.hxx>
35 : #include <scriptinfo.hxx>
36 : #include <editeng/charhiddenitem.hxx>
37 : #include <calbck.hxx>
38 :
39 : class Point;
40 :
41 967 : SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos(
42 : SwLayoutInfo& o_rInfo,
43 : const SwPosition& rAnchorPos,
44 : const SwPosition* pAnnotationStartPos )
45 : {
46 967 : SwLayoutStatus aRet = INVISIBLE;
47 967 : SwTextNode* pTextNode = rAnchorPos.nNode.GetNode().GetTextNode();
48 967 : if ( pTextNode == NULL )
49 0 : return aRet;
50 :
51 967 : SwIterator<SwTextFrm,SwContentNode> aIter( *pTextNode );
52 1934 : for( SwTextFrm* pTextFrm = aIter.First(); pTextFrm != NULL; pTextFrm = aIter.Next() )
53 : {
54 967 : if( !pTextFrm->IsFollow() )
55 : {
56 967 : pTextFrm = pTextFrm->GetFrmAtPos( rAnchorPos );
57 967 : SwPageFrm *pPage = pTextFrm ? pTextFrm->FindPageFrm() : 0;
58 967 : if ( pPage != NULL && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
59 : {
60 883 : aRet = VISIBLE;
61 :
62 883 : o_rInfo.mpAnchorFrm = pTextFrm;
63 883 : pTextFrm->GetCharRect( o_rInfo.mPosition, rAnchorPos, 0 );
64 883 : if ( pAnnotationStartPos != NULL )
65 : {
66 605 : o_rInfo.mnStartNodeIdx = pAnnotationStartPos->nNode.GetIndex();
67 605 : o_rInfo.mnStartContent = pAnnotationStartPos->nContent.GetIndex();
68 : }
69 : else
70 : {
71 278 : o_rInfo.mnStartNodeIdx = 0;
72 278 : o_rInfo.mnStartContent = -1;
73 : }
74 883 : o_rInfo.mPageFrame = pPage->Frm();
75 883 : o_rInfo.mPagePrtArea = pPage->Prt();
76 883 : o_rInfo.mPagePrtArea.Pos() += o_rInfo.mPageFrame.Pos();
77 883 : o_rInfo.mnPageNumber = pPage->GetPhyPageNum();
78 883 : o_rInfo.meSidebarPosition = pPage->SidebarPosition();
79 883 : o_rInfo.mRedlineAuthor = 0;
80 :
81 883 : const IDocumentRedlineAccess* pIDRA = pTextNode->getIDocumentRedlineAccess();
82 883 : if( IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() ) )
83 : {
84 883 : const SwRangeRedline* pRedline = pIDRA->GetRedline( rAnchorPos, 0 );
85 883 : if( pRedline )
86 : {
87 0 : if( nsRedlineType_t::REDLINE_INSERT == pRedline->GetType() )
88 0 : aRet = INSERTED;
89 0 : else if( nsRedlineType_t::REDLINE_DELETE == pRedline->GetType() )
90 0 : aRet = DELETED;
91 0 : o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
92 : }
93 : }
94 : }
95 : }
96 : }
97 :
98 883 : return ( (aRet==VISIBLE) && SwScriptInfo::IsInHiddenRange( *pTextNode , rAnchorPos.nContent.GetIndex()) )
99 : ? HIDDEN
100 1814 : : aRet;
101 : }
102 :
103 26586 : long SwPostItHelper::getLayoutHeight( const SwRootFrm* pRoot )
104 : {
105 26586 : long nRet = pRoot ? pRoot->Frm().Height() : 0;
106 26586 : return nRet;
107 : }
108 :
109 167 : void SwPostItHelper::setSidebarChanged( SwRootFrm* pRoot, bool bBrowseMode )
110 : {
111 167 : if( pRoot )
112 : {
113 167 : pRoot->SetSidebarChanged();
114 167 : if( bBrowseMode )
115 78 : pRoot->InvalidateBrowseWidth();
116 : }
117 167 : }
118 :
119 0 : unsigned long SwPostItHelper::getPageInfo( SwRect& rPageFrm, const SwRootFrm* pRoot, const Point& rPoint )
120 : {
121 0 : unsigned long nRet = 0;
122 0 : const SwFrm* pPage = pRoot->GetPageAtPos( rPoint, 0, true );
123 0 : if( pPage )
124 : {
125 0 : nRet = pPage->GetPhyPageNum();
126 0 : rPageFrm = pPage->Frm();
127 : }
128 0 : return nRet;
129 : }
130 :
131 2423 : SwPosition SwAnnotationItem::GetAnchorPosition() const
132 : {
133 2423 : SwTextField* pTextField = mrFormatField.GetTextField();
134 2423 : SwTextNode* pTextNode = pTextField->GetpTextNode();
135 :
136 2423 : SwPosition aPos( *pTextNode );
137 2423 : aPos.nContent.Assign( pTextNode, pTextField->GetStart() );
138 2423 : return aPos;
139 : }
140 :
141 967 : bool SwAnnotationItem::UseElement()
142 : {
143 967 : return mrFormatField.IsFieldInDoc();
144 : }
145 :
146 84 : VclPtr<sw::sidebarwindows::SwSidebarWin> SwAnnotationItem::GetSidebarWindow(
147 : SwEditWin& rEditWin,
148 : WinBits nBits,
149 : SwPostItMgr& aMgr,
150 : SwPostItBits aBits)
151 : {
152 : return VclPtr<sw::annotation::SwAnnotationWin>::Create( rEditWin, nBits,
153 : aMgr, aBits,
154 : *this,
155 84 : &mrFormatField );
156 177 : }
157 :
158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|