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 <hintids.hxx>
21 : #include <com/sun/star/i18n/ScriptType.hpp>
22 : #include <fmtcntnt.hxx>
23 : #include <txatbase.hxx>
24 : #include <frmatr.hxx>
25 : #include <viscrs.hxx>
26 : #include <callnk.hxx>
27 : #include <crsrsh.hxx>
28 : #include <doc.hxx>
29 : #include <frmfmt.hxx>
30 : #include <txtfrm.hxx>
31 : #include <tabfrm.hxx>
32 : #include <rowfrm.hxx>
33 : #include <fmtfsize.hxx>
34 : #include <ndtxt.hxx>
35 : #include <flyfrm.hxx>
36 : #include <breakit.hxx>
37 : #include <vcl/window.hxx>
38 :
39 0 : SwCallLink::SwCallLink( SwCrsrShell & rSh, sal_uLong nAktNode, sal_Int32 nAktContent,
40 : sal_uInt8 nAktNdTyp, long nLRPos, bool bAktSelection )
41 : : rShell( rSh ), nNode( nAktNode ), nContent( nAktContent ),
42 : nNdTyp( nAktNdTyp ), nLeftFrmPos( nLRPos ),
43 0 : bHasSelection( bAktSelection )
44 : {
45 0 : }
46 :
47 41802 : SwCallLink::SwCallLink( SwCrsrShell & rSh )
48 41802 : : rShell( rSh )
49 : {
50 : // remember SPoint-values of current cursor
51 41802 : SwPaM* pCrsr = rShell.IsTableMode() ? rShell.GetTableCrs() : rShell.GetCrsr();
52 41802 : SwNode& rNd = pCrsr->GetPoint()->nNode.GetNode();
53 41802 : nNode = rNd.GetIndex();
54 41802 : nContent = pCrsr->GetPoint()->nContent.GetIndex();
55 41802 : nNdTyp = rNd.GetNodeType();
56 41802 : bHasSelection = ( *pCrsr->GetPoint() != *pCrsr->GetMark() );
57 :
58 41802 : if( rNd.IsTextNode() )
59 41758 : nLeftFrmPos = SwCallLink::getLayoutFrm( rShell.GetLayout(), *rNd.GetTextNode(), nContent,
60 83516 : !rShell.ActionPend() );
61 : else
62 : {
63 44 : nLeftFrmPos = 0;
64 :
65 : // A special treatment for SwFeShell:
66 : // When deleting the header/footer, footnotes SwFeShell sets the
67 : // Cursor to NULL (Node + Content).
68 : // If the Cursor is not on a ContentNode (ContentNode) this fact gets
69 : // saved in NdType.
70 44 : if( ND_CONTENTNODE & nNdTyp )
71 0 : nNdTyp = 0;
72 : }
73 41802 : }
74 :
75 83604 : static void lcl_notifyRow(const SwContentNode* pNode, SwCrsrShell& rShell)
76 : {
77 83604 : if ( !pNode )
78 187 : return;
79 :
80 83417 : SwFrm *const pMyFrm = pNode->getLayoutFrm( rShell.GetLayout() );
81 83417 : if ( !pMyFrm )
82 1 : return;
83 :
84 : // We need to emulated a change of the row height in order
85 : // to have the complete row redrawn
86 83416 : SwRowFrm *const pRow = pMyFrm->FindRowFrm();
87 83416 : if ( !pRow )
88 78728 : return;
89 :
90 4688 : const SwTableLine* pLine = pRow->GetTabLine( );
91 : // Avoid redrawing the complete row if there are no nested tables
92 14207 : for (SwFrm *pCell = pRow->GetLower(); pCell; pCell = pCell->GetNext())
93 : {
94 21615 : for (SwFrm *pContent = pCell->GetLower(); pContent; pContent = pContent->GetNext())
95 : {
96 12096 : if (pContent->GetType() == FRM_TAB)
97 : {
98 90 : SwFormatFrmSize pSize = pLine->GetFrameFormat()->GetFrmSize();
99 90 : pRow->ModifyNotification(NULL, &pSize);
100 90 : return;
101 : }
102 : }
103 : }
104 : }
105 :
106 41802 : SwCallLink::~SwCallLink()
107 : {
108 41802 : if( !nNdTyp || !rShell.m_bCallChgLnk ) // see ctor
109 : return ;
110 :
111 : // If travelling over Nodes check formats and register them anew at the
112 : // new Node.
113 41802 : SwPaM* pCurCrsr = rShell.IsTableMode() ? rShell.GetTableCrs() : rShell.GetCrsr();
114 41802 : SwContentNode * pCNd = pCurCrsr->GetContentNode();
115 41802 : if( !pCNd )
116 0 : return;
117 :
118 41802 : lcl_notifyRow(pCNd, rShell);
119 :
120 41802 : const SwDoc *pDoc=rShell.GetDoc();
121 41802 : const SwContentNode *pNode = NULL;
122 41802 : if ( ( pDoc != NULL && nNode < pDoc->GetNodes( ).Count( ) ) )
123 : {
124 41787 : pNode = pDoc->GetNodes()[nNode]->GetContentNode();
125 : }
126 41802 : lcl_notifyRow(pNode, rShell);
127 :
128 41802 : sal_Int32 nCmp, nAktContent = pCurCrsr->GetPoint()->nContent.GetIndex();
129 41802 : sal_uInt16 nNdWhich = pCNd->GetNodeType();
130 41802 : sal_uLong nAktNode = pCurCrsr->GetPoint()->nNode.GetIndex();
131 :
132 : // Register the Shell as dependent at the current Node. By doing this all
133 : // attribute changes can be signaled over the link.
134 41802 : pCNd->Add( &rShell );
135 :
136 41802 : if( nNdTyp != nNdWhich || nNode != nAktNode )
137 : {
138 : // Every time a switch between nodes occurs, there is a chance that
139 : // new attributes do apply - meaning text-attributes.
140 : // So the currently applying attributes would have to be determined.
141 : // That can be done in one go by the handler.
142 536 : rShell.CallChgLnk();
143 : }
144 41266 : else if( !bHasSelection != !(*pCurCrsr->GetPoint() != *pCurCrsr->GetMark()) )
145 : {
146 : // always call change link when selection changes
147 31 : rShell.CallChgLnk();
148 : }
149 82419 : else if( rShell.m_aChgLnk.IsSet() && ND_TEXTNODE == nNdWhich &&
150 41184 : nContent != nAktContent )
151 : {
152 : // If travelling with left/right only and the frame is
153 : // unchanged (columns!) then check text hints.
154 5301 : if( nLeftFrmPos == SwCallLink::getLayoutFrm( rShell.GetLayout(), *pCNd->GetTextNode(), nAktContent,
155 5790 : !rShell.ActionPend() ) &&
156 3048 : (( nCmp = nContent ) + 1 == nAktContent || // Right
157 1288 : nContent -1 == ( nCmp = nAktContent )) ) // Left
158 : {
159 496 : if( nCmp == nAktContent && pCurCrsr->HasMark() ) // left & select
160 4 : ++nCmp;
161 :
162 496 : if ( pCNd->GetTextNode()->HasHints() )
163 : {
164 359 : const SwpHints &rHts = pCNd->GetTextNode()->GetSwpHints();
165 :
166 711 : for( size_t n = 0; n < rHts.Count(); ++n )
167 : {
168 625 : const SwTextAttr* pHt = rHts[ n ];
169 625 : const sal_Int32 *pEnd = pHt->End();
170 625 : const sal_Int32 nStart = pHt->GetStart();
171 :
172 : // If "only start" or "start and end equal" then call on
173 : // every overflow of start.
174 1069 : if( ( !pEnd || ( nStart == *pEnd ) ) &&
175 634 : ( nStart == nContent || nStart == nAktContent) )
176 : {
177 255 : rShell.CallChgLnk();
178 255 : return;
179 : }
180 :
181 : // If the attribute has an area and that area is not empty ...
182 565 : else if( pEnd && nStart < *pEnd &&
183 : // ... then test if travelling occurred via start/end.
184 177 : ( nStart == nCmp ||
185 354 : ( pHt->DontExpand() ? nCmp == *pEnd-1
186 0 : : nCmp == *pEnd ) ))
187 : {
188 18 : rShell.CallChgLnk();
189 18 : return;
190 : }
191 : }
192 : }
193 :
194 223 : if( g_pBreakIt->GetBreakIter().is() )
195 : {
196 223 : const OUString rText = pCNd->GetTextNode()->GetText();
197 1093 : if( !nCmp ||
198 859 : g_pBreakIt->GetBreakIter()->getScriptType( rText, nCmp )
199 647 : != g_pBreakIt->GetBreakIter()->getScriptType( rText, nCmp - 1 ))
200 : {
201 29 : rShell.CallChgLnk();
202 29 : return;
203 194 : }
204 : }
205 : }
206 : else
207 : // If travelling more than one character with home/end/.. then
208 : // always call ChgLnk, because it can not be determined here what
209 : // has changed. Something may have changed.
210 1271 : rShell.CallChgLnk();
211 : }
212 :
213 : const SwFrm* pFrm;
214 : const SwFlyFrm *pFlyFrm;
215 124264 : if( !rShell.ActionPend() && 0 != ( pFrm = pCNd->getLayoutFrm(rShell.GetLayout(), 0, 0, false) ) &&
216 41506 : 0 != ( pFlyFrm = pFrm->FindFlyFrm() ) && !rShell.IsTableMode() )
217 : {
218 6 : const SwNodeIndex* pIndex = pFlyFrm->GetFormat()->GetContent().GetContentIdx();
219 : OSL_ENSURE( pIndex, "Fly without Content" );
220 :
221 6 : if (!pIndex)
222 0 : return;
223 :
224 6 : const SwNode& rStNd = pIndex->GetNode();
225 :
226 12 : if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > nNode ||
227 6 : nNode > rStNd.EndOfSectionIndex() )
228 2 : rShell.GetFlyMacroLnk().Call( const_cast<SwFlyFrameFormat *>(pFlyFrm->GetFormat()) );
229 : }
230 41802 : }
231 :
232 83774 : long SwCallLink::getLayoutFrm( const SwRootFrm* pRoot, SwTextNode& rNd, sal_Int32 nCntPos, bool bCalcFrm )
233 : {
234 83774 : SwTextFrm* pFrm = static_cast<SwTextFrm*>(rNd.getLayoutFrm(pRoot,0,0,bCalcFrm));
235 : SwTextFrm* pNext;
236 83774 : if ( pFrm && !pFrm->IsHiddenNow() )
237 : {
238 83746 : if( pFrm->HasFollow() )
239 62008 : while( 0 != ( pNext = pFrm->GetFollow() ) &&
240 19598 : nCntPos >= pNext->GetOfst() )
241 19536 : pFrm = pNext;
242 :
243 83746 : return pFrm->Frm().Left();
244 : }
245 28 : return 0;
246 177 : }
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|