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 nAktCntnt,
40 : sal_uInt8 nAktNdTyp, long nLRPos, bool bAktSelection )
41 : : rShell( rSh ), nNode( nAktNode ), nCntnt( nAktCntnt ),
42 : nNdTyp( nAktNdTyp ), nLeftFrmPos( nLRPos ),
43 0 : bHasSelection( bAktSelection )
44 : {
45 0 : }
46 :
47 0 : SwCallLink::SwCallLink( SwCrsrShell & rSh )
48 0 : : rShell( rSh )
49 : {
50 : // remember SPoint-values of current cursor
51 0 : SwPaM* pCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
52 0 : SwNode& rNd = pCrsr->GetPoint()->nNode.GetNode();
53 0 : nNode = rNd.GetIndex();
54 0 : nCntnt = pCrsr->GetPoint()->nContent.GetIndex();
55 0 : nNdTyp = rNd.GetNodeType();
56 0 : bHasSelection = ( *pCrsr->GetPoint() != *pCrsr->GetMark() );
57 :
58 0 : if( rNd.IsTxtNode() )
59 0 : nLeftFrmPos = SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)rNd, nCntnt,
60 0 : !rShell.ActionPend() );
61 : else
62 : {
63 0 : 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 CntntNode (ContentNode) this fact gets
69 : // saved in NdType.
70 0 : if( ND_CONTENTNODE & nNdTyp )
71 0 : nNdTyp = 0;
72 : }
73 0 : }
74 :
75 0 : static void lcl_notifyRow(const SwCntntNode* pNode, SwCrsrShell& rShell)
76 : {
77 0 : if ( !pNode )
78 0 : return;
79 :
80 0 : SwFrm *const pMyFrm = pNode->getLayoutFrm( rShell.GetLayout() );
81 0 : if ( !pMyFrm )
82 0 : return;
83 :
84 : // We need to emulated a change of the row height in order
85 : // to have the complete row redrawn
86 0 : SwRowFrm *const pRow = pMyFrm->FindRowFrm();
87 0 : if ( !pRow )
88 0 : return;
89 :
90 0 : const SwTableLine* pLine = pRow->GetTabLine( );
91 : // Avoid redrawing the complete row if there are no nested tables
92 0 : for (SwFrm *pCell = pRow->GetLower(); pCell; pCell = pCell->GetNext())
93 : {
94 0 : for (SwFrm *pContent = pCell->GetLower(); pContent; pContent = pContent->GetNext())
95 : {
96 0 : if (pContent->GetType() == FRM_TAB)
97 : {
98 0 : SwFmtFrmSize pSize = pLine->GetFrmFmt()->GetFrmSize();
99 0 : pRow->ModifyNotification(NULL, &pSize);
100 0 : return;
101 : }
102 : }
103 : }
104 : }
105 :
106 0 : SwCallLink::~SwCallLink()
107 : {
108 0 : 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 0 : SwPaM* pCurCrsr = rShell.IsTableMode() ? rShell.GetTblCrs() : rShell.GetCrsr();
114 0 : SwCntntNode * pCNd = pCurCrsr->GetCntntNode();
115 0 : if( !pCNd )
116 0 : return;
117 :
118 0 : lcl_notifyRow(pCNd, rShell);
119 :
120 0 : const SwDoc *pDoc=rShell.GetDoc();
121 0 : const SwCntntNode *pNode = NULL;
122 0 : if ( ( pDoc != NULL && nNode < pDoc->GetNodes( ).Count( ) ) )
123 : {
124 0 : pNode = pDoc->GetNodes()[nNode]->GetCntntNode();
125 : }
126 0 : lcl_notifyRow(pNode, rShell);
127 :
128 0 : sal_Int32 nCmp, nAktCntnt = pCurCrsr->GetPoint()->nContent.GetIndex();
129 0 : sal_uInt16 nNdWhich = pCNd->GetNodeType();
130 0 : 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 0 : pCNd->Add( &rShell );
135 :
136 0 : 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 0 : rShell.CallChgLnk();
143 : }
144 0 : else if( !bHasSelection != !(*pCurCrsr->GetPoint() != *pCurCrsr->GetMark()) )
145 : {
146 : // always call change link when selection changes
147 0 : rShell.CallChgLnk();
148 : }
149 0 : else if( rShell.m_aChgLnk.IsSet() && ND_TEXTNODE == nNdWhich &&
150 0 : nCntnt != nAktCntnt )
151 : {
152 : // If travelling with left/right only and the frame is
153 : // unchanged (columns!) then check text hints.
154 0 : if( nLeftFrmPos == SwCallLink::getLayoutFrm( rShell.GetLayout(), (SwTxtNode&)*pCNd, nAktCntnt,
155 0 : !rShell.ActionPend() ) &&
156 0 : (( nCmp = nCntnt ) + 1 == nAktCntnt || // Right
157 0 : nCntnt -1 == ( nCmp = nAktCntnt )) ) // Left
158 : {
159 0 : if( nCmp == nAktCntnt && pCurCrsr->HasMark() ) // left & select
160 0 : ++nCmp;
161 :
162 0 : if ( ((SwTxtNode*)pCNd)->HasHints() )
163 : {
164 0 : const SwpHints &rHts = ((SwTxtNode*)pCNd)->GetSwpHints();
165 :
166 0 : for( sal_uInt16 n = 0; n < rHts.Count(); n++ )
167 : {
168 0 : const SwTxtAttr* pHt = rHts[ n ];
169 0 : const sal_Int32 *pEnd = pHt->End();
170 0 : 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 0 : if( ( !pEnd || ( nStart == *pEnd ) ) &&
175 0 : ( nStart == nCntnt || nStart == nAktCntnt) )
176 : {
177 0 : rShell.CallChgLnk();
178 0 : return;
179 : }
180 :
181 : // If the attribute has an area and that area is not empty ...
182 0 : else if( pEnd && nStart < *pEnd &&
183 : // ... then test if travelling occurred via start/end.
184 0 : ( nStart == nCmp ||
185 0 : ( pHt->DontExpand() ? nCmp == *pEnd-1
186 0 : : nCmp == *pEnd ) ))
187 : {
188 0 : rShell.CallChgLnk();
189 0 : return;
190 : }
191 : }
192 : }
193 :
194 0 : if( g_pBreakIt->GetBreakIter().is() )
195 : {
196 0 : const OUString rTxt = ((SwTxtNode*)pCNd)->GetTxt();
197 0 : if( !nCmp ||
198 0 : g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp )
199 0 : != g_pBreakIt->GetBreakIter()->getScriptType( rTxt, nCmp - 1 ))
200 : {
201 0 : rShell.CallChgLnk();
202 0 : return;
203 0 : }
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 0 : rShell.CallChgLnk();
211 : }
212 :
213 : const SwFrm* pFrm;
214 : const SwFlyFrm *pFlyFrm;
215 0 : if( !rShell.ActionPend() && 0 != ( pFrm = pCNd->getLayoutFrm(rShell.GetLayout(), 0, 0, false) ) &&
216 0 : 0 != ( pFlyFrm = pFrm->FindFlyFrm() ) && !rShell.IsTableMode() )
217 : {
218 0 : const SwNodeIndex* pIndex = pFlyFrm->GetFmt()->GetCntnt().GetCntntIdx();
219 : OSL_ENSURE( pIndex, "Fly without Cntnt" );
220 :
221 0 : if (!pIndex)
222 0 : return;
223 :
224 0 : const SwNode& rStNd = pIndex->GetNode();
225 :
226 0 : if( rStNd.EndOfSectionNode()->StartOfSectionIndex() > nNode ||
227 0 : nNode > rStNd.EndOfSectionIndex() )
228 0 : rShell.GetFlyMacroLnk().Call( (void*)pFlyFrm->GetFmt() );
229 : }
230 0 : }
231 :
232 0 : long SwCallLink::getLayoutFrm( const SwRootFrm* pRoot, SwTxtNode& rNd, sal_Int32 nCntPos, bool bCalcFrm )
233 : {
234 0 : SwTxtFrm* pFrm = (SwTxtFrm*)rNd.getLayoutFrm(pRoot,0,0,bCalcFrm), *pNext = pFrm;
235 0 : if ( pFrm && !pFrm->IsHiddenNow() )
236 : {
237 0 : if( pFrm->HasFollow() )
238 0 : while( 0 != ( pNext = (SwTxtFrm*)pFrm->GetFollow() ) &&
239 0 : nCntPos >= pNext->GetOfst() )
240 0 : pFrm = pNext;
241 :
242 0 : return pFrm->Frm().Left();
243 : }
244 0 : return 0;
245 : }
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|