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 <stdlib.h>
22 : #include <hintids.hxx>
23 : #include <svl/intitem.hxx>
24 : #include <svl/stritem.hxx>
25 : #include <sfx2/docfile.hxx>
26 : #include <sfx2/docfilt.hxx>
27 : #include <editeng/protitem.hxx>
28 : #include <sfx2/linkmgr.hxx>
29 : #include <tools/urlobj.hxx>
30 : #include <sfx2/sfxsids.hrc>
31 : #include <sfx2/fcontnr.hxx>
32 : #include <docary.hxx>
33 : #include <fmtcntnt.hxx>
34 : #include <fmtpdsc.hxx>
35 : #include <doc.hxx>
36 : #include <IDocumentUndoRedo.hxx>
37 : #include <node.hxx>
38 : #include <pam.hxx>
39 : #include <frmtool.hxx>
40 : #include <editsh.hxx>
41 : #include <hints.hxx>
42 : #include <docsh.hxx>
43 : #include <ndtxt.hxx>
44 : #include <section.hxx>
45 : #include <swserv.hxx>
46 : #include <shellio.hxx>
47 : #include <poolfmt.hxx>
48 : #include <expfld.hxx>
49 : #include <swbaslnk.hxx>
50 : #include <mvsave.hxx>
51 : #include <sectfrm.hxx>
52 : #include <fmtftntx.hxx>
53 : #include <ftnidx.hxx>
54 : #include <doctxm.hxx>
55 : #include <fmteiro.hxx>
56 : #include <swerror.h>
57 : #include <unosection.hxx>
58 : #include <switerator.hxx>
59 : #include <svl/smplhint.hxx>
60 : #include <algorithm>
61 :
62 : using namespace ::com::sun::star;
63 :
64 :
65 0 : SV_IMPL_REF( SwServerObject )
66 :
67 : #define sSectionFmtNm aEmptyStr
68 :
69 0 : class SwIntrnlSectRefLink : public SwBaseLink
70 : {
71 : SwSectionFmt& rSectFmt;
72 : public:
73 0 : SwIntrnlSectRefLink( SwSectionFmt& rFmt, sal_uInt16 nUpdateType, sal_uInt16 nFmt )
74 : : SwBaseLink( nUpdateType, nFmt ),
75 0 : rSectFmt( rFmt )
76 0 : {}
77 :
78 : virtual void Closed();
79 : virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
80 : const String& rMimeType, const ::com::sun::star::uno::Any & rValue );
81 :
82 : virtual const SwNode* GetAnchor() const;
83 : virtual sal_Bool IsInRange( sal_uLong nSttNd, sal_uLong nEndNd, xub_StrLen nStt = 0,
84 : xub_StrLen nEnd = STRING_NOTFOUND ) const;
85 :
86 0 : inline SwSectionNode* GetSectNode()
87 : {
88 0 : const SwNode* pSectNd( const_cast<SwIntrnlSectRefLink*>(this)->GetAnchor() );
89 0 : return const_cast<SwSectionNode*>( dynamic_cast<const SwSectionNode*>( pSectNd ) );
90 : }
91 : };
92 :
93 :
94 540 : TYPEINIT1(SwSectionFmt,SwFrmFmt );
95 1146 : TYPEINIT1(SwSection,SwClient );
96 :
97 :
98 152 : SwSectionData::SwSectionData(SectionType const eType, String const& rName)
99 : : m_eType(eType)
100 : , m_sSectionName(rName)
101 : , m_bHiddenFlag(false)
102 : , m_bProtectFlag(false)
103 : , m_bEditInReadonlyFlag(false) // edit in readonly sections
104 : , m_bHidden(false)
105 : , m_bCondHiddenFlag(true)
106 152 : , m_bConnectFlag(true)
107 : {
108 152 : }
109 :
110 : // this must have the same semantics as operator=()
111 0 : SwSectionData::SwSectionData(SwSection const& rSection)
112 0 : : m_eType(rSection.GetType())
113 0 : , m_sSectionName(rSection.GetSectionName())
114 0 : , m_sCondition(rSection.GetCondition())
115 0 : , m_sLinkFileName(rSection.GetLinkFileName())
116 0 : , m_sLinkFilePassword(rSection.GetLinkFilePassword())
117 0 : , m_Password(rSection.GetPassword())
118 0 : , m_bHiddenFlag(rSection.IsHiddenFlag())
119 0 : , m_bProtectFlag(rSection.IsProtect())
120 : // edit in readonly sections
121 0 : , m_bEditInReadonlyFlag(rSection.IsEditInReadonly())
122 0 : , m_bHidden(rSection.IsHidden())
123 : , m_bCondHiddenFlag(true)
124 0 : , m_bConnectFlag(rSection.IsConnectFlag())
125 : {
126 0 : }
127 :
128 : // this must have the same semantics as operator=()
129 0 : SwSectionData::SwSectionData(SwSectionData const& rOther)
130 : : m_eType(rOther.m_eType)
131 : , m_sSectionName(rOther.m_sSectionName)
132 : , m_sCondition(rOther.m_sCondition)
133 : , m_sLinkFileName(rOther.m_sLinkFileName)
134 : , m_sLinkFilePassword(rOther.m_sLinkFilePassword)
135 : , m_Password(rOther.m_Password)
136 : , m_bHiddenFlag(rOther.m_bHiddenFlag)
137 : , m_bProtectFlag(rOther.m_bProtectFlag)
138 : // edit in readonly sections
139 : , m_bEditInReadonlyFlag(rOther.m_bEditInReadonlyFlag)
140 : , m_bHidden(rOther.m_bHidden)
141 : , m_bCondHiddenFlag(true)
142 0 : , m_bConnectFlag(rOther.m_bConnectFlag)
143 : {
144 0 : }
145 :
146 : // the semantics here are weird for reasons of backward compatibility
147 76 : SwSectionData & SwSectionData::operator= (SwSectionData const& rOther)
148 : {
149 76 : m_eType = rOther.m_eType;
150 76 : m_sSectionName = rOther.m_sSectionName;
151 76 : m_sCondition = rOther.m_sCondition;
152 76 : m_sLinkFileName = rOther.m_sLinkFileName;
153 76 : m_sLinkFilePassword = rOther.m_sLinkFilePassword;
154 76 : m_bConnectFlag = rOther.m_bConnectFlag;
155 76 : m_Password = rOther.m_Password;
156 :
157 76 : m_bEditInReadonlyFlag = rOther.m_bEditInReadonlyFlag;
158 76 : m_bProtectFlag = rOther.m_bProtectFlag;
159 :
160 76 : m_bHidden = rOther.m_bHidden;
161 : // FIXME: old code did not assign m_bHiddenFlag ?
162 : // FIXME: why should m_bCondHiddenFlag always default to true?
163 76 : m_bCondHiddenFlag = true;
164 :
165 76 : return *this;
166 : }
167 :
168 : // the semantics here are weird for reasons of backward compatibility
169 0 : bool SwSectionData::operator==(SwSectionData const& rOther) const
170 : {
171 : return (m_eType == rOther.m_eType)
172 0 : && (m_sSectionName == rOther.m_sSectionName)
173 0 : && (m_sCondition == rOther.m_sCondition)
174 : && (m_bHidden == rOther.m_bHidden)
175 : && (m_bProtectFlag == rOther.m_bProtectFlag)
176 : && (m_bEditInReadonlyFlag == rOther.m_bEditInReadonlyFlag)
177 0 : && (m_sLinkFileName == rOther.m_sLinkFileName)
178 0 : && (m_sLinkFilePassword == rOther.m_sLinkFilePassword)
179 0 : && (m_Password == rOther.m_Password);
180 : // FIXME: old code ignored m_bCondHiddenFlag m_bHiddenFlag m_bConnectFlag
181 : }
182 :
183 : // SwSection ===========================================================
184 :
185 76 : SwSection::SwSection(
186 : SectionType const eType, String const& rName, SwSectionFmt & rFormat)
187 : : SwClient(& rFormat)
188 76 : , m_Data(eType, rName)
189 : {
190 76 : SwSection *const pParentSect = GetParent();
191 76 : if( pParentSect )
192 : {
193 0 : if( pParentSect->IsHiddenFlag() )
194 : {
195 0 : SetHidden( true );
196 : }
197 :
198 0 : m_Data.SetProtectFlag( pParentSect->IsProtectFlag() );
199 : // edit in readonly sections
200 0 : m_Data.SetEditInReadonlyFlag( pParentSect->IsEditInReadonlyFlag() );
201 : }
202 :
203 76 : if (!m_Data.IsProtectFlag())
204 : {
205 76 : m_Data.SetProtectFlag( rFormat.GetProtect().IsCntntProtected() );
206 : }
207 :
208 76 : if (!m_Data.IsEditInReadonlyFlag()) // edit in readonly sections
209 : {
210 76 : m_Data.SetEditInReadonlyFlag( rFormat.GetEditInReadonly().GetValue() );
211 : }
212 76 : }
213 :
214 :
215 6 : SwSection::~SwSection()
216 : {
217 2 : SwSectionFmt* pFmt = GetFmt();
218 2 : if( !pFmt )
219 : return;
220 :
221 2 : SwDoc* pDoc = pFmt->GetDoc();
222 2 : if( pDoc->IsInDtor() )
223 : {
224 : // We reattach our Format to the default FrameFmt
225 : // to not get any dependencies
226 2 : if( pFmt->DerivedFrom() != pDoc->GetDfltFrmFmt() )
227 0 : pFmt->RegisterToFormat( *pDoc->GetDfltFrmFmt() );
228 : }
229 : else
230 : {
231 0 : pFmt->Remove( this ); // remove
232 :
233 0 : if (CONTENT_SECTION != m_Data.GetType())
234 : {
235 0 : pDoc->GetLinkManager().Remove( m_RefLink );
236 : }
237 :
238 0 : if (m_RefObj.Is())
239 : {
240 0 : pDoc->GetLinkManager().RemoveServer( &m_RefObj );
241 : }
242 :
243 : // If the Section is the last Client in the Format we can delete it
244 0 : SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT, pFmt );
245 0 : pFmt->ModifyNotification( &aMsgHint, &aMsgHint );
246 0 : if( !pFmt->GetDepends() )
247 : {
248 : // Do not add to the Undo. This should've happened earlier.
249 0 : ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
250 0 : pDoc->DelSectionFmt( pFmt );
251 0 : }
252 : }
253 2 : if (m_RefObj.Is())
254 : {
255 0 : m_RefObj->Closed();
256 : }
257 4 : }
258 :
259 76 : void SwSection::SetSectionData(SwSectionData const& rData)
260 : {
261 76 : bool const bOldHidden( m_Data.IsHidden() );
262 76 : m_Data = rData;
263 : // The next two may actually overwrite the m_Data.m_bProtect or EditInReadonly Flag
264 : // in Modify, which should result in same flag value as the old code!
265 76 : SetProtect(m_Data.IsProtectFlag());
266 76 : SetEditInReadonly(m_Data.IsEditInReadonlyFlag());
267 76 : if (bOldHidden != m_Data.IsHidden()) // check if changed...
268 : {
269 2 : ImplSetHiddenFlag(m_Data.IsHidden(), m_Data.IsCondHidden());
270 : }
271 76 : }
272 :
273 0 : bool SwSection::DataEquals(SwSectionData const& rCmp) const
274 : {
275 : // note that the old code compared the flags of the parameter with the
276 : // format attributes of this; the following mess should do the same...
277 0 : (void) GetLinkFileName(); // updates m_sLinkFileName
278 0 : bool const bProtect(m_Data.IsProtectFlag());
279 0 : bool const bEditInReadonly(m_Data.IsEditInReadonlyFlag());
280 0 : const_cast<SwSection*>(this)->m_Data.SetProtectFlag(IsProtect());
281 : const_cast<SwSection*>(this)->m_Data
282 0 : .SetEditInReadonlyFlag(IsEditInReadonly());
283 0 : bool const bResult( m_Data == rCmp );
284 0 : const_cast<SwSection*>(this)->m_Data.SetProtectFlag(bProtect);
285 0 : const_cast<SwSection*>(this)->m_Data.SetEditInReadonlyFlag(bEditInReadonly);
286 0 : return bResult;
287 : }
288 :
289 :
290 4 : void SwSection::ImplSetHiddenFlag(bool const bTmpHidden, bool const bCondition)
291 : {
292 4 : SwSectionFmt* pFmt = GetFmt();
293 : OSL_ENSURE(pFmt, "ImplSetHiddenFlag: no format?");
294 4 : if( pFmt )
295 : {
296 4 : const bool bHide = bTmpHidden && bCondition;
297 :
298 4 : if (bHide) // should be hidden
299 : {
300 2 : if (!m_Data.IsHiddenFlag()) // is not hidden
301 : {
302 : // Is the Parent hidden?
303 : // This should be shown by the bHiddenFlag.
304 :
305 : // Tell all Children that they are hidden
306 2 : SwMsgPoolItem aMsgItem( RES_SECTION_HIDDEN );
307 2 : pFmt->ModifyNotification( &aMsgItem, &aMsgItem );
308 :
309 : // Delete all Frames
310 2 : pFmt->DelFrms();
311 : }
312 : }
313 2 : else if (m_Data.IsHiddenFlag()) // show Nodes again
314 : {
315 : // Show all Frames (Child Sections are accounted for by MakeFrms)
316 : // Only if the Parent Section is not restricting us!
317 2 : SwSection* pParentSect = pFmt->GetParentSection();
318 2 : if( !pParentSect || !pParentSect->IsHiddenFlag() )
319 : {
320 : // Tell all Children that the Parent is not hidden anymore
321 2 : SwMsgPoolItem aMsgItem( RES_SECTION_NOT_HIDDEN );
322 2 : pFmt->ModifyNotification( &aMsgItem, &aMsgItem );
323 :
324 2 : pFmt->MakeFrms();
325 : }
326 : }
327 : }
328 4 : }
329 :
330 76 : sal_Bool SwSection::CalcHiddenFlag() const
331 : {
332 76 : const SwSection* pSect = this;
333 76 : do {
334 76 : if( pSect->IsHidden() && pSect->IsCondHidden() )
335 0 : return sal_True;
336 : } while( 0 != ( pSect = pSect->GetParent()) );
337 :
338 76 : return sal_False;
339 : }
340 :
341 76 : bool SwSection::IsProtect() const
342 : {
343 76 : SwSectionFmt *const pFmt( GetFmt() );
344 : OSL_ENSURE(pFmt, "SwSection::IsProtect: no format?");
345 : return (pFmt)
346 76 : ? pFmt->GetProtect().IsCntntProtected()
347 152 : : IsProtectFlag();
348 : }
349 :
350 : // edit in readonly sections
351 0 : bool SwSection::IsEditInReadonly() const
352 : {
353 0 : SwSectionFmt *const pFmt( GetFmt() );
354 : OSL_ENSURE(pFmt, "SwSection::IsEditInReadonly: no format?");
355 : return (pFmt)
356 0 : ? pFmt->GetEditInReadonly().GetValue()
357 0 : : IsEditInReadonlyFlag();
358 : }
359 :
360 0 : void SwSection::SetHidden(bool const bFlag)
361 : {
362 0 : if (!m_Data.IsHidden() == !bFlag)
363 0 : return;
364 :
365 0 : m_Data.SetHidden(bFlag);
366 0 : ImplSetHiddenFlag(bFlag, m_Data.IsCondHidden());
367 : }
368 :
369 :
370 76 : void SwSection::SetProtect(bool const bFlag)
371 : {
372 76 : SwSectionFmt *const pFormat( GetFmt() );
373 : OSL_ENSURE(pFormat, "SwSection::SetProtect: no format?");
374 76 : if (pFormat)
375 : {
376 76 : SvxProtectItem aItem( RES_PROTECT );
377 76 : aItem.SetCntntProtect( (sal_Bool)bFlag );
378 76 : pFormat->SetFmtAttr( aItem );
379 : // note: this will call m_Data.SetProtectFlag via Modify!
380 : }
381 : else
382 : {
383 0 : m_Data.SetProtectFlag(bFlag);
384 : }
385 76 : }
386 :
387 : // edit in readonly sections
388 76 : void SwSection::SetEditInReadonly(bool const bFlag)
389 : {
390 76 : SwSectionFmt *const pFormat( GetFmt() );
391 : OSL_ENSURE(pFormat, "SwSection::SetEditInReadonly: no format?");
392 76 : if (pFormat)
393 : {
394 76 : SwFmtEditInReadonly aItem;
395 76 : aItem.SetValue( (sal_Bool)bFlag );
396 76 : pFormat->SetFmtAttr( aItem );
397 : // note: this will call m_Data.SetEditInReadonlyFlag via Modify!
398 : }
399 : else
400 : {
401 0 : m_Data.SetEditInReadonlyFlag(bFlag);
402 : }
403 76 : }
404 :
405 156 : void SwSection::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
406 : {
407 156 : bool bRemake = false;
408 156 : bool bUpdateFtn = false;
409 156 : switch( pOld ? pOld->Which() : pNew ? pNew->Which() : 0 )
410 : {
411 : case RES_ATTRSET_CHG:
412 : {
413 0 : SfxItemSet* pNewSet = ((SwAttrSetChg*)pNew)->GetChgSet();
414 0 : SfxItemSet* pOldSet = ((SwAttrSetChg*)pOld)->GetChgSet();
415 : const SfxPoolItem* pItem;
416 :
417 0 : if( SFX_ITEM_SET == pNewSet->GetItemState(
418 0 : RES_PROTECT, sal_False, &pItem ) )
419 : {
420 : m_Data.SetProtectFlag( static_cast<SvxProtectItem const*>(pItem)
421 0 : ->IsCntntProtected() );
422 0 : pNewSet->ClearItem( RES_PROTECT );
423 0 : pOldSet->ClearItem( RES_PROTECT );
424 : }
425 :
426 : // --> edit in readonly sections
427 0 : if( SFX_ITEM_SET == pNewSet->GetItemState(
428 0 : RES_EDIT_IN_READONLY, sal_False, &pItem ) )
429 : {
430 : m_Data.SetEditInReadonlyFlag(
431 0 : static_cast<SwFmtEditInReadonly const*>(pItem)->GetValue());
432 0 : pNewSet->ClearItem( RES_EDIT_IN_READONLY );
433 0 : pOldSet->ClearItem( RES_EDIT_IN_READONLY );
434 : }
435 :
436 0 : if( SFX_ITEM_SET == pNewSet->GetItemState(
437 0 : RES_FTN_AT_TXTEND, sal_False, &pItem ) ||
438 : SFX_ITEM_SET == pNewSet->GetItemState(
439 0 : RES_END_AT_TXTEND, sal_False, &pItem ))
440 : {
441 0 : bUpdateFtn = true;
442 : }
443 :
444 0 : if( !pNewSet->Count() )
445 : return;
446 : }
447 0 : break;
448 :
449 : case RES_PROTECT:
450 76 : if( pNew )
451 : {
452 : bool bNewFlag =
453 76 : static_cast<const SvxProtectItem*>(pNew)->IsCntntProtected();
454 76 : if( !bNewFlag )
455 : {
456 : // Switching off: See if there is protection transferred
457 : // by the Parents
458 76 : const SwSection* pSect = this;
459 76 : do {
460 76 : if( pSect->IsProtect() )
461 : {
462 0 : bNewFlag = true;
463 0 : break;
464 : }
465 76 : pSect = pSect->GetParent();
466 : } while (pSect);
467 : }
468 :
469 76 : m_Data.SetProtectFlag( bNewFlag );
470 : }
471 76 : return;
472 : // edit in readonly sections
473 : case RES_EDIT_IN_READONLY:
474 76 : if( pNew )
475 : {
476 : const bool bNewFlag =
477 76 : static_cast<const SwFmtEditInReadonly*>(pNew)->GetValue();
478 76 : m_Data.SetEditInReadonlyFlag( bNewFlag );
479 : }
480 76 : return;
481 :
482 : case RES_SECTION_HIDDEN:
483 2 : m_Data.SetHiddenFlag(true);
484 2 : return;
485 :
486 : case RES_SECTION_NOT_HIDDEN:
487 : case RES_SECTION_RESETHIDDENFLAG:
488 2 : m_Data.SetHiddenFlag( m_Data.IsHidden() && m_Data.IsCondHidden() );
489 2 : return;
490 :
491 : case RES_COL:
492 : // Is handeled by the Layout, if appropriate
493 0 : break;
494 :
495 : case RES_FTN_AT_TXTEND:
496 0 : if( pNew && pOld )
497 : {
498 0 : bUpdateFtn = true;
499 : }
500 0 : break;
501 :
502 : case RES_END_AT_TXTEND:
503 0 : if( pNew && pOld )
504 : {
505 0 : bUpdateFtn = true;
506 : }
507 0 : break;
508 :
509 : default:
510 0 : CheckRegistration( pOld, pNew );
511 0 : break;
512 : }
513 :
514 0 : if( bRemake )
515 : {
516 0 : GetFmt()->DelFrms();
517 0 : GetFmt()->MakeFrms();
518 : }
519 :
520 0 : if( bUpdateFtn )
521 : {
522 0 : SwSectionNode* pSectNd = GetFmt()->GetSectionNode( sal_False );
523 0 : if( pSectNd )
524 0 : pSectNd->GetDoc()->GetFtnIdxs().UpdateFtn(SwNodeIndex( *pSectNd ));
525 : }
526 : }
527 :
528 0 : void SwSection::SetRefObject( SwServerObject* pObj )
529 : {
530 0 : m_RefObj = pObj;
531 0 : }
532 :
533 :
534 8 : void SwSection::SetCondHidden(bool const bFlag)
535 : {
536 8 : if (!m_Data.IsCondHidden() == !bFlag)
537 14 : return;
538 :
539 2 : m_Data.SetCondHidden(bFlag);
540 2 : ImplSetHiddenFlag(m_Data.IsHidden(), bFlag);
541 : }
542 :
543 :
544 : // Set/remove the linked FileName
545 0 : const String& SwSection::GetLinkFileName() const
546 : {
547 0 : if (m_RefLink.Is())
548 : {
549 0 : String sTmp;
550 0 : switch (m_Data.GetType())
551 : {
552 : case DDE_LINK_SECTION:
553 0 : sTmp = m_RefLink->GetLinkSourceName();
554 0 : break;
555 :
556 : case FILE_LINK_SECTION:
557 : {
558 0 : String sRange, sFilter;
559 0 : if (m_RefLink->GetLinkManager() &&
560 : m_RefLink->GetLinkManager()->GetDisplayNames(
561 0 : m_RefLink, 0, &sTmp, &sRange, &sFilter ))
562 : {
563 0 : ( sTmp += sfx2::cTokenSeperator ) += sFilter;
564 0 : ( sTmp += sfx2::cTokenSeperator ) += sRange;
565 : }
566 0 : else if( GetFmt() && !GetFmt()->GetSectionNode() )
567 : {
568 : // If the Section is in the UndoNodesArray, the LinkManager
569 : // does not contain the Link, thus it cannot be queried for it.
570 : // Thus return the current Name.
571 0 : return m_Data.GetLinkFileName();
572 0 : }
573 : }
574 0 : break;
575 0 : default: break;
576 : }
577 0 : const_cast<SwSection*>(this)->m_Data.SetLinkFileName(sTmp);
578 : }
579 0 : return m_Data.GetLinkFileName();
580 : }
581 :
582 :
583 0 : void SwSection::SetLinkFileName(const String& rNew, String const*const pPassWd)
584 : {
585 0 : if (m_RefLink.Is())
586 : {
587 0 : m_RefLink->SetLinkSourceName( rNew );
588 : }
589 0 : m_Data.SetLinkFileName(rNew);
590 0 : if( pPassWd )
591 : {
592 0 : SetLinkFilePassword( *pPassWd );
593 : }
594 0 : }
595 :
596 : // If it was a Linked Section, we need to make all Child Links visible
597 0 : void SwSection::MakeChildLinksVisible( const SwSectionNode& rSectNd )
598 : {
599 : const SwNode* pNd;
600 0 : const ::sfx2::SvBaseLinks& rLnks = rSectNd.GetDoc()->GetLinkManager().GetLinks();
601 0 : for( sal_uInt16 n = rLnks.size(); n; )
602 : {
603 0 : ::sfx2::SvBaseLink* pBLnk = &(*rLnks[ --n ]);
604 0 : if( pBLnk && !pBLnk->IsVisible() &&
605 0 : pBLnk->ISA( SwBaseLink ) &&
606 0 : 0 != ( pNd = ((SwBaseLink*)pBLnk)->GetAnchor() ) )
607 : {
608 0 : pNd = pNd->StartOfSectionNode(); // If it's a SectionNode
609 : const SwSectionNode* pParent;
610 0 : while( 0 != ( pParent = pNd->FindSectionNode() ) &&
611 0 : ( CONTENT_SECTION == pParent->GetSection().GetType()
612 : || pNd == &rSectNd ))
613 0 : pNd = pParent->StartOfSectionNode();
614 :
615 : // It's within a normal Section, so show again
616 0 : if( !pParent )
617 0 : pBLnk->SetVisible( sal_True );
618 : }
619 : }
620 0 : }
621 :
622 0 : const SwTOXBase* SwSection::GetTOXBase() const
623 : {
624 0 : const SwTOXBase* pRet = 0;
625 0 : if( TOX_CONTENT_SECTION == GetType() )
626 0 : pRet = PTR_CAST( SwTOXBaseSection, this );
627 0 : return pRet;
628 : }
629 :
630 : // SwSectionFmt ========================================================
631 :
632 76 : SwSectionFmt::SwSectionFmt( SwSectionFmt* pDrvdFrm, SwDoc *pDoc )
633 76 : : SwFrmFmt( pDoc->GetAttrPool(), sSectionFmtNm, pDrvdFrm )
634 : {
635 76 : LockModify();
636 76 : SetFmtAttr( *GetDfltAttr( RES_COL ) );
637 76 : UnlockModify();
638 76 : }
639 :
640 6 : SwSectionFmt::~SwSectionFmt()
641 : {
642 2 : if( !GetDoc()->IsInDtor() )
643 : {
644 : SwSectionNode* pSectNd;
645 0 : const SwNodeIndex* pIdx = GetCntnt( sal_False ).GetCntntIdx();
646 0 : if( pIdx && &GetDoc()->GetNodes() == &pIdx->GetNodes() &&
647 0 : 0 != (pSectNd = pIdx->GetNode().GetSectionNode() ))
648 : {
649 0 : SwSection& rSect = pSectNd->GetSection();
650 : // If it was a linked Section, we need to make all Child Links
651 : // visible again
652 0 : if( rSect.IsConnected() )
653 0 : rSect.MakeChildLinksVisible( *pSectNd );
654 :
655 : // Check whether we need to be visible, before deleting the Nodes
656 0 : if( rSect.IsHiddenFlag() )
657 : {
658 0 : SwSection* pParentSect = rSect.GetParent();
659 0 : if( !pParentSect || !pParentSect->IsHiddenFlag() )
660 : {
661 : // Make Nodes visible again
662 0 : rSect.SetHidden(false);
663 : }
664 : }
665 : // mba: test iteration; objects are removed while iterating
666 : // use hint which allows to specify, if the content shall be saved or not
667 0 : CallSwClientNotify( SwSectionFrmMoveAndDeleteHint( sal_True ) );
668 :
669 : // Raise the Section up
670 0 : SwNodeRange aRg( *pSectNd, 0, *pSectNd->EndOfSectionNode() );
671 0 : GetDoc()->GetNodes().SectionUp( &aRg );
672 : }
673 0 : LockModify();
674 0 : ResetFmtAttr( RES_CNTNT );
675 0 : UnlockModify();
676 : }
677 4 : }
678 :
679 :
680 84 : SwSection * SwSectionFmt::GetSection() const
681 : {
682 84 : return SwIterator<SwSection,SwSectionFmt>::FirstElement( *this );
683 : }
684 :
685 : extern void sw_DeleteFtn( SwSectionNode *pNd, sal_uLong nStt, sal_uLong nEnd );
686 :
687 : // Do not destroy all Frms in aDepend (Frms are recognized with a PTR_CAST).
688 2 : void SwSectionFmt::DelFrms()
689 : {
690 : SwSectionNode* pSectNd;
691 2 : const SwNodeIndex* pIdx = GetCntnt(sal_False).GetCntntIdx();
692 4 : if( pIdx && &GetDoc()->GetNodes() == &pIdx->GetNodes() &&
693 2 : 0 != (pSectNd = pIdx->GetNode().GetSectionNode() ))
694 : {
695 : // First delete the <SwSectionFrm> of the <SwSectionFmt> instance
696 : // mba: test iteration as objects are removed in iteration
697 : // use hint which allows to specify, if the content shall be saved or not
698 2 : CallSwClientNotify( SwSectionFrmMoveAndDeleteHint( sal_False ) );
699 :
700 : // Then delete frames of the nested <SwSectionFmt> instances
701 2 : SwIterator<SwSectionFmt,SwSectionFmt> aIter( *this );
702 2 : SwSectionFmt *pLast = aIter.First();
703 4 : while ( pLast )
704 : {
705 0 : pLast->DelFrms();
706 0 : pLast = aIter.Next();
707 : }
708 :
709 2 : sal_uLong nEnde = pSectNd->EndOfSectionIndex();
710 2 : sal_uLong nStart = pSectNd->GetIndex()+1;
711 2 : sw_DeleteFtn( pSectNd, nStart, nEnde );
712 : }
713 2 : if( pIdx )
714 : {
715 : // Send Hint for PageDesc. Actually the Layout contained in the
716 : // Paste of the Framei tself would need to do this. But that leads
717 : // to subsequent errors, which we'd need to solve at run-time.
718 2 : SwNodeIndex aNextNd( *pIdx );
719 2 : SwCntntNode* pCNd = GetDoc()->GetNodes().GoNextSection( &aNextNd, sal_True, sal_False );
720 2 : if( pCNd )
721 : {
722 2 : const SfxPoolItem& rItem = pCNd->GetSwAttrSet().Get( RES_PAGEDESC );
723 2 : pCNd->ModifyNotification( (SfxPoolItem*)&rItem, (SfxPoolItem*)&rItem );
724 2 : }
725 : }
726 2 : }
727 :
728 :
729 : // Create the Views
730 2 : void SwSectionFmt::MakeFrms()
731 : {
732 : SwSectionNode* pSectNd;
733 2 : const SwNodeIndex* pIdx = GetCntnt(sal_False).GetCntntIdx();
734 :
735 4 : if( pIdx && &GetDoc()->GetNodes() == &pIdx->GetNodes() &&
736 2 : 0 != (pSectNd = pIdx->GetNode().GetSectionNode() ))
737 : {
738 2 : SwNodeIndex aIdx( *pIdx );
739 2 : pSectNd->MakeFrms( &aIdx );
740 : }
741 2 : }
742 :
743 158 : void SwSectionFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
744 : {
745 158 : bool bClients = false;
746 158 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
747 158 : switch( nWhich )
748 : {
749 : case RES_ATTRSET_CHG:
750 154 : if( GetDepends() )
751 : {
752 152 : SfxItemSet* pNewSet = ((SwAttrSetChg*)pNew)->GetChgSet();
753 152 : SfxItemSet* pOldSet = ((SwAttrSetChg*)pOld)->GetChgSet();
754 : const SfxPoolItem *pItem;
755 152 : if( SFX_ITEM_SET == pNewSet->GetItemState(
756 152 : RES_PROTECT, sal_False, &pItem ))
757 : {
758 76 : ModifyBroadcast( (SfxPoolItem*)pItem, (SfxPoolItem*)pItem );
759 76 : pNewSet->ClearItem( RES_PROTECT );
760 76 : pOldSet->ClearItem( RES_PROTECT );
761 : }
762 :
763 : // --> edit in readonly sections
764 152 : if( SFX_ITEM_SET == pNewSet->GetItemState(
765 152 : RES_EDIT_IN_READONLY, sal_False, &pItem ) )
766 : {
767 76 : ModifyBroadcast( (SfxPoolItem*)pItem, (SfxPoolItem*)pItem );
768 76 : pNewSet->ClearItem( RES_EDIT_IN_READONLY );
769 76 : pOldSet->ClearItem( RES_EDIT_IN_READONLY );
770 : }
771 :
772 152 : if( SFX_ITEM_SET == pNewSet->GetItemState(
773 152 : RES_FTN_AT_TXTEND, sal_False, &pItem ))
774 : {
775 0 : ModifyBroadcast( (SfxPoolItem*)&pOldSet->Get( RES_FTN_AT_TXTEND ), (SfxPoolItem*)pItem );
776 0 : pNewSet->ClearItem( RES_FTN_AT_TXTEND );
777 0 : pOldSet->ClearItem( RES_FTN_AT_TXTEND );
778 : }
779 152 : if( SFX_ITEM_SET == pNewSet->GetItemState(
780 152 : RES_END_AT_TXTEND, sal_False, &pItem ))
781 : {
782 0 : ModifyBroadcast( (SfxPoolItem*)&pOldSet->Get( RES_END_AT_TXTEND ), (SfxPoolItem*)pItem );
783 0 : pNewSet->ClearItem( RES_END_AT_TXTEND );
784 0 : pOldSet->ClearItem( RES_END_AT_TXTEND );
785 : }
786 152 : if( !((SwAttrSetChg*)pOld)->GetChgSet()->Count() )
787 : return;
788 : }
789 2 : break;
790 :
791 : case RES_SECTION_RESETHIDDENFLAG:
792 : case RES_FTN_AT_TXTEND:
793 0 : case RES_END_AT_TXTEND : bClients = true;
794 : // no break !!
795 : case RES_SECTION_HIDDEN:
796 : case RES_SECTION_NOT_HIDDEN:
797 : {
798 4 : SwSection* pSect = GetSection();
799 8 : if( pSect && ( bClients || ( RES_SECTION_HIDDEN == nWhich ?
800 4 : !pSect->IsHiddenFlag() : pSect->IsHiddenFlag() ) ) )
801 : {
802 4 : ModifyBroadcast( pOld, pNew );
803 : }
804 : }
805 4 : return ;
806 :
807 :
808 : case RES_PROTECT:
809 : case RES_EDIT_IN_READONLY: // edit in readonly sections
810 : // Pass through these Messages until the End of the tree!
811 0 : if( GetDepends() )
812 : {
813 0 : ModifyBroadcast( pOld, pNew );
814 : }
815 0 : return; // That's it!
816 :
817 : case RES_OBJECTDYING:
818 0 : if( !GetDoc()->IsInDtor() &&
819 0 : ((SwPtrMsgPoolItem *)pOld)->pObject == (void*)GetRegisteredIn() )
820 : {
821 : // My Parents will be destroyed, so get the Parent's Parent
822 : // and update
823 0 : SwFrmFmt::Modify( pOld, pNew ); // Rewire first!
824 0 : UpdateParent();
825 0 : return;
826 : }
827 0 : break;
828 :
829 : case RES_FMT_CHG:
830 0 : if( !GetDoc()->IsInDtor() &&
831 0 : ((SwFmtChg*)pNew)->pChangedFmt == (void*)GetRegisteredIn() &&
832 0 : ((SwFmtChg*)pNew)->pChangedFmt->IsA( TYPE( SwSectionFmt )) )
833 : {
834 : // My Parent will be changed, thus I need to update
835 0 : SwFrmFmt::Modify( pOld, pNew ); // Rewire first!
836 0 : UpdateParent();
837 0 : return;
838 : }
839 0 : break;
840 : }
841 2 : SwFrmFmt::Modify( pOld, pNew );
842 :
843 2 : if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
844 : { // invalidate cached uno object
845 0 : SetXTextSection(uno::Reference<text::XTextSection>(0));
846 : }
847 : }
848 :
849 : // Get info from the Format
850 0 : bool SwSectionFmt::GetInfo( SfxPoolItem& rInfo ) const
851 : {
852 0 : switch( rInfo.Which() )
853 : {
854 : case RES_FINDNEARESTNODE:
855 0 : if( ((SwFmtPageDesc&)GetFmtAttr( RES_PAGEDESC )).GetPageDesc() )
856 : {
857 0 : const SwSectionNode* pNd = GetSectionNode();
858 0 : if( pNd )
859 0 : ((SwFindNearestNode&)rInfo).CheckNode( *pNd );
860 : }
861 0 : return true;
862 :
863 : case RES_CONTENT_VISIBLE:
864 : {
865 0 : SwFrm* pFrm = SwIterator<SwFrm,SwFmt>::FirstElement(*this);
866 : // if the current section has no own frame search for the children
867 0 : if(!pFrm)
868 : {
869 0 : SwIterator<SwSectionFmt,SwSectionFmt> aFormatIter(*this);
870 0 : SwSectionFmt* pChild = aFormatIter.First();
871 0 : while(pChild && !pFrm)
872 : {
873 0 : pFrm = SwIterator<SwFrm,SwFmt>::FirstElement(*pChild);
874 0 : pChild = aFormatIter.Next();
875 0 : }
876 : }
877 0 : ((SwPtrMsgPoolItem&)rInfo).pObject = pFrm;
878 : }
879 0 : return false;
880 : }
881 0 : return SwModify::GetInfo( rInfo );
882 : }
883 :
884 0 : static bool lcl_SectionCmpPos( const SwSection *pFirst, const SwSection *pSecond)
885 : {
886 0 : const SwSectionFmt* pFSectFmt = pFirst->GetFmt();
887 0 : const SwSectionFmt* pSSectFmt = pSecond->GetFmt();
888 : OSL_ENSURE( pFSectFmt && pSSectFmt &&
889 : pFSectFmt->GetCntnt(sal_False).GetCntntIdx() &&
890 : pSSectFmt->GetCntnt(sal_False).GetCntntIdx(),
891 : "ungueltige Sections" );
892 0 : return pFSectFmt->GetCntnt(sal_False).GetCntntIdx()->GetIndex() <
893 0 : pSSectFmt->GetCntnt(sal_False).GetCntntIdx()->GetIndex();
894 : }
895 :
896 0 : static bool lcl_SectionCmpNm( const SwSection *pFSect, const SwSection *pSSect)
897 : {
898 : OSL_ENSURE( pFSect && pSSect, "Invalid Sections" );
899 : StringCompare const eCmp =
900 0 : pFSect->GetSectionName().CompareTo( pSSect->GetSectionName() );
901 0 : return eCmp == COMPARE_LESS;
902 : }
903 :
904 : // Alle Sections which have been derived from this one
905 0 : sal_uInt16 SwSectionFmt::GetChildSections( SwSections& rArr,
906 : SectionSort eSort,
907 : sal_Bool bAllSections ) const
908 : {
909 0 : rArr.clear();
910 :
911 0 : if( GetDepends() )
912 : {
913 0 : SwIterator<SwSectionFmt,SwSectionFmt> aIter(*this);
914 : const SwNodeIndex* pIdx;
915 0 : for( SwSectionFmt* pLast = aIter.First(); pLast; pLast = aIter.Next() )
916 0 : if( bAllSections ||
917 0 : ( 0 != ( pIdx = pLast->GetCntnt(sal_False).
918 0 : GetCntntIdx()) && &pIdx->GetNodes() == &GetDoc()->GetNodes() ))
919 : {
920 0 : SwSection* pDummy = pLast->GetSection();
921 0 : rArr.push_back( pDummy );
922 : }
923 :
924 : // Do we need any sorting?
925 0 : if( 1 < rArr.size() )
926 0 : switch( eSort )
927 : {
928 : case SORTSECT_NAME:
929 0 : std::sort( rArr.begin(), rArr.end(), lcl_SectionCmpNm );
930 0 : break;
931 :
932 : case SORTSECT_POS:
933 0 : std::sort( rArr.begin(), rArr.end(), lcl_SectionCmpPos );
934 0 : break;
935 0 : case SORTSECT_NOT: break;
936 0 : }
937 : }
938 0 : return rArr.size();
939 : }
940 :
941 : // See whether the Section is within the Nodes or the UndoNodes array
942 0 : sal_Bool SwSectionFmt::IsInNodesArr() const
943 : {
944 0 : const SwNodeIndex* pIdx = GetCntnt(sal_False).GetCntntIdx();
945 0 : return pIdx && &pIdx->GetNodes() == &GetDoc()->GetNodes();
946 : }
947 :
948 : // Parent was changed
949 0 : void SwSectionFmt::UpdateParent()
950 : {
951 0 : if( !GetDepends() )
952 0 : return;
953 :
954 0 : SwSection* pSection = 0;
955 0 : const SvxProtectItem* pProtect(0);
956 : // edit in readonly sections
957 0 : const SwFmtEditInReadonly* pEditInReadonly = 0;
958 0 : bool bIsHidden = false;
959 :
960 0 : SwClientIter aIter( *this ); // TODO
961 0 : ::SwClient * pLast = aIter.GoStart();
962 0 : if( pLast ) // Could we jump to the beginning?
963 0 : do {
964 0 : if( pLast->IsA( TYPE(SwSectionFmt) ) )
965 : {
966 0 : if( !pSection )
967 : {
968 0 : pSection = GetSection();
969 0 : if( GetRegisteredIn() )
970 : {
971 0 : const SwSection* pPS = GetParentSection();
972 0 : pProtect = &pPS->GetFmt()->GetProtect();
973 : // edit in readonly sections
974 0 : pEditInReadonly = &pPS->GetFmt()->GetEditInReadonly();
975 0 : bIsHidden = pPS->IsHiddenFlag();
976 : }
977 : else
978 : {
979 0 : pProtect = &GetProtect();
980 : // edit in readonly sections
981 0 : pEditInReadonly = &GetEditInReadonly();
982 0 : bIsHidden = pSection->IsHidden();
983 : }
984 : }
985 0 : if (!pProtect->IsCntntProtected() !=
986 0 : !pSection->IsProtectFlag())
987 : {
988 : pLast->ModifyNotification( (SfxPoolItem*)pProtect,
989 0 : (SfxPoolItem*)pProtect );
990 : }
991 :
992 : // edit in readonly sections
993 0 : if (!pEditInReadonly->GetValue() !=
994 0 : !pSection->IsEditInReadonlyFlag())
995 : {
996 : pLast->ModifyNotification( (SfxPoolItem*)pEditInReadonly,
997 0 : (SfxPoolItem*)pEditInReadonly );
998 : }
999 :
1000 0 : if( bIsHidden == pSection->IsHiddenFlag() )
1001 : {
1002 : SwMsgPoolItem aMsgItem( static_cast<sal_uInt16>(bIsHidden
1003 : ? RES_SECTION_HIDDEN
1004 0 : : RES_SECTION_NOT_HIDDEN ) );
1005 0 : pLast->ModifyNotification( &aMsgItem, &aMsgItem );
1006 : }
1007 : }
1008 0 : else if( !pSection &&
1009 0 : pLast->IsA( TYPE(SwSection) ) )
1010 : {
1011 0 : pSection = (SwSection*)pLast;
1012 0 : if( GetRegisteredIn() )
1013 : {
1014 0 : const SwSection* pPS = GetParentSection();
1015 0 : pProtect = &pPS->GetFmt()->GetProtect();
1016 : // edit in readonly sections
1017 0 : pEditInReadonly = &pPS->GetFmt()->GetEditInReadonly();
1018 0 : bIsHidden = pPS->IsHiddenFlag();
1019 : }
1020 : else
1021 : {
1022 0 : pProtect = &GetProtect();
1023 : // edit in readonly sections
1024 0 : pEditInReadonly = &GetEditInReadonly();
1025 0 : bIsHidden = pSection->IsHidden();
1026 : }
1027 : }
1028 0 : } while( 0 != ( pLast = ++aIter ));
1029 : }
1030 :
1031 :
1032 4 : SwSectionNode* SwSectionFmt::GetSectionNode(bool const bAlways)
1033 : {
1034 4 : const SwNodeIndex* pIdx = GetCntnt(sal_False).GetCntntIdx();
1035 4 : if( pIdx && ( bAlways || &pIdx->GetNodes() == &GetDoc()->GetNodes() ))
1036 4 : return pIdx->GetNode().GetSectionNode();
1037 0 : return 0;
1038 : }
1039 :
1040 : // Is this Section valid for the GlobalDocument?
1041 0 : const SwSection* SwSectionFmt::GetGlobalDocSection() const
1042 : {
1043 0 : const SwSectionNode* pNd = GetSectionNode();
1044 0 : if( pNd &&
1045 0 : ( FILE_LINK_SECTION == pNd->GetSection().GetType() ||
1046 0 : TOX_CONTENT_SECTION == pNd->GetSection().GetType() ) &&
1047 0 : pNd->GetIndex() > pNd->GetNodes().GetEndOfExtras().GetIndex() &&
1048 0 : !pNd->StartOfSectionNode()->IsSectionNode() &&
1049 0 : !pNd->StartOfSectionNode()->FindSectionNode() )
1050 0 : return &pNd->GetSection();
1051 0 : return 0;
1052 : }
1053 :
1054 : // sw::Metadatable
1055 0 : ::sfx2::IXmlIdRegistry& SwSectionFmt::GetRegistry()
1056 : {
1057 0 : return GetDoc()->GetXmlIdRegistry();
1058 : }
1059 :
1060 0 : bool SwSectionFmt::IsInClipboard() const
1061 : {
1062 0 : return GetDoc()->IsClipBoard();
1063 : }
1064 :
1065 0 : bool SwSectionFmt::IsInUndo() const
1066 : {
1067 0 : return !IsInNodesArr();
1068 : }
1069 :
1070 0 : bool SwSectionFmt::IsInContent() const
1071 : {
1072 0 : SwNodeIndex const*const pIdx = GetCntnt(sal_False).GetCntntIdx();
1073 : OSL_ENSURE(pIdx, "SwSectionFmt::IsInContent: no index?");
1074 0 : return (pIdx) ? !GetDoc()->IsInHeaderFooter(*pIdx) : true;
1075 : }
1076 :
1077 : // n.b.: if the section format represents an index, then there is both a
1078 : // SwXDocumentIndex and a SwXTextSection instance for this single core object.
1079 : // these two can both implement XMetadatable and forward to the same core
1080 : // section format. but here only one UNO object can be returned,
1081 : // so always return the text section.
1082 : uno::Reference< rdf::XMetadatable >
1083 0 : SwSectionFmt::MakeUnoObject()
1084 : {
1085 0 : uno::Reference<rdf::XMetadatable> xMeta;
1086 0 : SwSection *const pSection( GetSection() );
1087 0 : if (pSection)
1088 : {
1089 : xMeta.set( SwXTextSection::CreateXTextSection(this,
1090 0 : TOX_HEADER_SECTION == pSection->GetType()),
1091 0 : uno::UNO_QUERY );
1092 : }
1093 0 : return xMeta;
1094 : }
1095 :
1096 :
1097 : // Method to break section links inside a linked section
1098 0 : static void lcl_BreakSectionLinksInSect( const SwSectionNode& rSectNd )
1099 : {
1100 0 : if ( !rSectNd.GetDoc() )
1101 : {
1102 : OSL_FAIL( "method <lcl_RemoveSectionLinksInSect(..)> - no Doc at SectionNode" );
1103 0 : return;
1104 : }
1105 :
1106 0 : if ( !rSectNd.GetSection().IsConnected() )
1107 : {
1108 : OSL_FAIL( "method <lcl_RemoveSectionLinksInSect(..)> - no Link at Section of SectionNode" );
1109 0 : return;
1110 : }
1111 0 : const ::sfx2::SvBaseLink* pOwnLink( &(rSectNd.GetSection().GetBaseLink() ) );
1112 0 : const ::sfx2::SvBaseLinks& rLnks = rSectNd.GetDoc()->GetLinkManager().GetLinks();
1113 0 : for ( sal_uInt16 n = rLnks.size(); n > 0; )
1114 : {
1115 0 : SwIntrnlSectRefLink* pSectLnk = dynamic_cast<SwIntrnlSectRefLink*>(&(*rLnks[ --n ]));
1116 0 : if ( pSectLnk && pSectLnk != pOwnLink &&
1117 0 : pSectLnk->IsInRange( rSectNd.GetIndex(), rSectNd.EndOfSectionIndex() ) )
1118 : {
1119 : // break the link of the corresponding section.
1120 : // the link is also removed from the link manager
1121 0 : pSectLnk->GetSectNode()->GetSection().BreakLink();
1122 :
1123 : // for robustness, because link is removed from the link manager
1124 0 : if ( n > rLnks.size() )
1125 : {
1126 0 : n = rLnks.size();
1127 : }
1128 : }
1129 : }
1130 : }
1131 :
1132 0 : static void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd )
1133 : {
1134 0 : SwDoc* pDoc = rSectNd.GetDoc();
1135 0 : SwDocShell* pDShell = pDoc->GetDocShell();
1136 0 : if( !pDShell || !pDShell->GetMedium() )
1137 0 : return ;
1138 :
1139 0 : String sName( pDShell->GetMedium()->GetName() );
1140 : SwBaseLink* pBLink;
1141 0 : String sMimeType( SotExchange::GetFormatMimeType( FORMAT_FILE ));
1142 0 : uno::Any aValue;
1143 0 : aValue <<= ::rtl::OUString( sName ); // Arbitrary name
1144 :
1145 0 : const ::sfx2::SvBaseLinks& rLnks = pDoc->GetLinkManager().GetLinks();
1146 0 : for( sal_uInt16 n = rLnks.size(); n; )
1147 : {
1148 0 : ::sfx2::SvBaseLink* pLnk = &(*rLnks[ --n ]);
1149 0 : if( pLnk && pLnk != &rUpdLnk &&
1150 0 : OBJECT_CLIENT_FILE == pLnk->GetObjType() &&
1151 0 : pLnk->ISA( SwBaseLink ) &&
1152 : ( pBLink = (SwBaseLink*)pLnk )->IsInRange( rSectNd.GetIndex(),
1153 0 : rSectNd.EndOfSectionIndex() ) )
1154 : {
1155 : // It's in the Section, so update. But only if it's not in the same File!
1156 0 : String sFName;
1157 0 : pDoc->GetLinkManager().GetDisplayNames( pBLink, 0, &sFName, 0, 0 );
1158 0 : if( sFName != sName )
1159 : {
1160 0 : pBLink->DataChanged( sMimeType, aValue );
1161 :
1162 : // If needed find the Link pointer to avoid skipping one or calling one twice
1163 0 : if( n >= rLnks.size() && 0 != ( n = rLnks.size() ))
1164 0 : --n;
1165 :
1166 0 : if( n && pLnk != &(*rLnks[ n ]) )
1167 : {
1168 : // Find - it can only precede it!
1169 0 : while( n )
1170 0 : if( pLnk == &(*rLnks[ --n ] ) )
1171 0 : break;
1172 : }
1173 0 : }
1174 : }
1175 0 : }
1176 : }
1177 :
1178 :
1179 : // Find the right DocShell and create a new one:
1180 : // The return value specifies what should happen to the Shell
1181 : // 0 - Error, could not find the DocShell
1182 : // 1 - DocShell is an existing Document
1183 : // 2 - DocShell was created anew, thus it needs to be closed again
1184 : // (will be assigned to xLockRef additionally)
1185 0 : int sw_FindDocShell( SfxObjectShellRef& xDocSh,
1186 : SfxObjectShellLock& xLockRef,
1187 : const String& rFileName,
1188 : const String& rPasswd,
1189 : String& rFilter,
1190 : sal_Int16 nVersion,
1191 : SwDocShell* pDestSh )
1192 : {
1193 0 : if( !rFileName.Len() )
1194 0 : return 0;
1195 :
1196 : // 1. Does the file already exist in the list of all Documents?
1197 0 : INetURLObject aTmpObj( rFileName );
1198 0 : aTmpObj.SetMark( aEmptyStr );
1199 :
1200 : // Iterate over the DocShell and get the ones with the name
1201 0 : TypeId aType( TYPE(SwDocShell) );
1202 :
1203 0 : SfxObjectShell* pShell = pDestSh;
1204 0 : bool bFirst = 0 != pShell;
1205 :
1206 0 : if( !bFirst )
1207 : // No DocShell passed, starting with the first from the DocShell list
1208 0 : pShell = SfxObjectShell::GetFirst( &aType );
1209 :
1210 0 : while( pShell )
1211 : {
1212 : // We want this one
1213 0 : SfxMedium* pMed = pShell->GetMedium();
1214 0 : if( pMed && pMed->GetURLObject() == aTmpObj )
1215 : {
1216 : const SfxPoolItem* pItem;
1217 0 : if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState(
1218 0 : SID_VERSION, sal_False, &pItem ) )
1219 0 : ? (nVersion == ((SfxInt16Item*)pItem)->GetValue())
1220 : : !nVersion )
1221 : {
1222 : // Found, thus return
1223 0 : xDocSh = pShell;
1224 0 : return 1;
1225 : }
1226 : }
1227 :
1228 0 : if( bFirst )
1229 : {
1230 0 : bFirst = false;
1231 0 : pShell = SfxObjectShell::GetFirst( &aType );
1232 : }
1233 : else
1234 0 : pShell = SfxObjectShell::GetNext( *pShell, &aType );
1235 : }
1236 :
1237 : // 2. Open the file ourselves
1238 : SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL(
1239 0 : INetURLObject::NO_DECODE ), STREAM_READ );
1240 0 : if( INET_PROT_FILE == aTmpObj.GetProtocol() )
1241 0 : pMed->DownLoad(); // Touch the medium (download it)
1242 :
1243 0 : const SfxFilter* pSfxFlt = 0;
1244 0 : if( !pMed->GetError() )
1245 : {
1246 0 : String sFactory(rtl::OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
1247 0 : SfxFilterMatcher aMatcher( sFactory );
1248 :
1249 : // No Filter, so search for it. Else test if the one passed is a valid one
1250 0 : if( rFilter.Len() )
1251 : {
1252 0 : pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
1253 : }
1254 :
1255 0 : if( nVersion )
1256 0 : pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
1257 :
1258 0 : if( rPasswd.Len() )
1259 0 : pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
1260 :
1261 0 : if( !pSfxFlt )
1262 0 : aMatcher.DetectFilter( *pMed, &pSfxFlt, sal_False, sal_False );
1263 :
1264 0 : if( pSfxFlt )
1265 : {
1266 : // We cannot do anything without a Filter
1267 0 : pMed->SetFilter( pSfxFlt );
1268 :
1269 : // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
1270 0 : xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
1271 0 : xDocSh = (SfxObjectShell*)xLockRef;
1272 0 : if( xDocSh->DoLoad( pMed ) )
1273 0 : return 2;
1274 0 : }
1275 : }
1276 :
1277 0 : if( !xDocSh.Is() ) // Medium still needs to be deleted
1278 0 : delete pMed;
1279 :
1280 0 : return 0;
1281 : }
1282 :
1283 :
1284 :
1285 0 : ::sfx2::SvBaseLink::UpdateResult SwIntrnlSectRefLink::DataChanged(
1286 : const String& rMimeType, const uno::Any & rValue )
1287 : {
1288 0 : SwSectionNode* pSectNd = rSectFmt.GetSectionNode( sal_False );
1289 0 : SwDoc* pDoc = rSectFmt.GetDoc();
1290 :
1291 0 : sal_uLong nDataFormat = SotExchange::GetFormatIdFromMimeType( rMimeType );
1292 :
1293 0 : if( !pSectNd || !pDoc || pDoc->IsInDtor() || ChkNoDataFlag() ||
1294 0 : sfx2::LinkManager::RegisterStatusInfoId() == nDataFormat )
1295 : {
1296 : // Should we be in the Undo already?
1297 0 : return SUCCESS;
1298 : }
1299 :
1300 : // #i38810# - Due to possible existing signatures, the
1301 : // document has to be modified after updating a link.
1302 0 : pDoc->SetModified();
1303 : // set additional flag that links have been updated, in order to check this
1304 : // during load.
1305 0 : pDoc->SetLinksUpdated( sal_True );
1306 :
1307 : // Always switch off Undo
1308 0 : bool const bWasUndo = pDoc->GetIDocumentUndoRedo().DoesUndo();
1309 0 : pDoc->GetIDocumentUndoRedo().DoUndo(false);
1310 0 : sal_Bool bWasVisibleLinks = pDoc->IsVisibleLinks();
1311 0 : pDoc->SetVisibleLinks( sal_False );
1312 :
1313 : SwPaM* pPam;
1314 0 : ViewShell* pVSh = 0;
1315 0 : SwEditShell* pESh = pDoc->GetEditShell( &pVSh );
1316 0 : pDoc->LockExpFlds();
1317 : {
1318 : // Insert an empty TextNode at the Section's start
1319 0 : SwNodeIndex aIdx( *pSectNd, +1 );
1320 0 : SwNodeIndex aEndIdx( *pSectNd->EndOfSectionNode() );
1321 0 : SwTxtNode* pNewNd = pDoc->GetNodes().MakeTxtNode( aIdx,
1322 0 : pDoc->GetTxtCollFromPool( RES_POOLCOLL_TEXT ) );
1323 :
1324 0 : if( pESh )
1325 0 : pESh->StartAllAction();
1326 0 : else if( pVSh )
1327 0 : pVSh->StartAction();
1328 :
1329 0 : SwPosition aPos( aIdx, SwIndex( pNewNd, 0 ));
1330 0 : aPos.nNode--;
1331 0 : pDoc->CorrAbs( aIdx, aEndIdx, aPos, sal_True );
1332 :
1333 0 : pPam = new SwPaM( aPos );
1334 :
1335 : // Delete everything succeeding it
1336 0 : aIdx--;
1337 0 : DelFlyInRange( aIdx, aEndIdx );
1338 0 : _DelBookmarks(aIdx, aEndIdx);
1339 0 : ++aIdx;
1340 :
1341 0 : pDoc->GetNodes().Delete( aIdx, aEndIdx.GetIndex() - aIdx.GetIndex() );
1342 : }
1343 :
1344 0 : SwSection& rSection = pSectNd->GetSection();
1345 0 : rSection.SetConnectFlag(false);
1346 :
1347 0 : ::rtl::OUString sNewFileName;
1348 0 : Reader* pRead = 0;
1349 0 : switch( nDataFormat )
1350 : {
1351 : case FORMAT_STRING:
1352 0 : pRead = ReadAscii;
1353 0 : break;
1354 :
1355 : case FORMAT_RTF:
1356 0 : pRead = SwReaderWriter::GetReader( READER_WRITER_RTF );
1357 0 : break;
1358 :
1359 : case FORMAT_FILE:
1360 0 : if( rValue.hasValue() && ( rValue >>= sNewFileName ) )
1361 : {
1362 0 : String sFilter, sRange, sFileName( sNewFileName );
1363 0 : pDoc->GetLinkManager().GetDisplayNames( this, 0, &sFileName,
1364 0 : &sRange, &sFilter );
1365 :
1366 0 : RedlineMode_t eOldRedlineMode = nsRedlineMode_t::REDLINE_NONE;
1367 0 : SfxObjectShellRef xDocSh;
1368 0 : SfxObjectShellLock xLockRef;
1369 : int nRet;
1370 0 : if( !sFileName.Len() )
1371 : {
1372 0 : xDocSh = pDoc->GetDocShell();
1373 0 : nRet = 1;
1374 : }
1375 : else
1376 : {
1377 : nRet = sw_FindDocShell( xDocSh, xLockRef, sFileName,
1378 0 : rSection.GetLinkFilePassword(),
1379 0 : sFilter, 0, pDoc->GetDocShell() );
1380 0 : if( nRet )
1381 : {
1382 0 : SwDoc* pSrcDoc = ((SwDocShell*)&xDocSh)->GetDoc();
1383 0 : eOldRedlineMode = pSrcDoc->GetRedlineMode();
1384 0 : pSrcDoc->SetRedlineMode( nsRedlineMode_t::REDLINE_SHOW_INSERT );
1385 : }
1386 : }
1387 :
1388 0 : if( nRet )
1389 : {
1390 0 : rSection.SetConnectFlag(true);
1391 :
1392 0 : SwNodeIndex aSave( pPam->GetPoint()->nNode, -1 );
1393 0 : SwNodeRange* pCpyRg = 0;
1394 :
1395 0 : if( xDocSh->GetMedium() &&
1396 0 : !rSection.GetLinkFilePassword().Len() )
1397 : {
1398 : const SfxPoolItem* pItem;
1399 0 : if( SFX_ITEM_SET == xDocSh->GetMedium()->GetItemSet()->
1400 0 : GetItemState( SID_PASSWORD, sal_False, &pItem ) )
1401 : rSection.SetLinkFilePassword(
1402 0 : ((SfxStringItem*)pItem)->GetValue() );
1403 : }
1404 :
1405 0 : SwDoc* pSrcDoc = ((SwDocShell*)&xDocSh)->GetDoc();
1406 :
1407 0 : if( sRange.Len() )
1408 : {
1409 : // Catch recursion
1410 0 : bool bRecursion = false;
1411 0 : if( pSrcDoc == pDoc )
1412 : {
1413 : SwServerObjectRef refObj( (SwServerObject*)
1414 0 : pDoc->CreateLinkSource( sRange ));
1415 0 : if( refObj.Is() )
1416 : {
1417 0 : bRecursion = refObj->IsLinkInServer( this ) ||
1418 0 : ChkNoDataFlag();
1419 0 : }
1420 : }
1421 :
1422 0 : SwNodeIndex& rInsPos = pPam->GetPoint()->nNode;
1423 :
1424 0 : SwPaM* pCpyPam = 0;
1425 0 : if( !bRecursion &&
1426 0 : pSrcDoc->SelectServerObj( sRange, pCpyPam, pCpyRg )
1427 : && pCpyPam )
1428 : {
1429 0 : if( pSrcDoc != pDoc ||
1430 0 : pCpyPam->Start()->nNode > rInsPos ||
1431 0 : rInsPos >= pCpyPam->End()->nNode )
1432 : {
1433 0 : pSrcDoc->CopyRange( *pCpyPam, *pPam->GetPoint(),
1434 0 : false );
1435 : }
1436 0 : delete pCpyPam;
1437 : }
1438 0 : if( pCpyRg && pSrcDoc == pDoc &&
1439 0 : pCpyRg->aStart < rInsPos && rInsPos < pCpyRg->aEnd )
1440 0 : delete pCpyRg, pCpyRg = 0;
1441 : }
1442 0 : else if( pSrcDoc != pDoc )
1443 0 : pCpyRg = new SwNodeRange( pSrcDoc->GetNodes().GetEndOfExtras(), 2,
1444 0 : pSrcDoc->GetNodes().GetEndOfContent() );
1445 :
1446 : // #i81653#
1447 : // Update links of extern linked document or extern linked
1448 : // document section, if section is protected.
1449 0 : if ( pSrcDoc != pDoc &&
1450 0 : rSection.IsProtectFlag() )
1451 : {
1452 0 : pSrcDoc->GetLinkManager().UpdateAllLinks( false, true, false, 0 );
1453 : }
1454 :
1455 0 : if( pCpyRg )
1456 : {
1457 0 : SwNodeIndex& rInsPos = pPam->GetPoint()->nNode;
1458 0 : sal_Bool bCreateFrm = rInsPos.GetIndex() <=
1459 0 : pDoc->GetNodes().GetEndOfExtras().GetIndex() ||
1460 0 : rInsPos.GetNode().FindTableNode();
1461 :
1462 0 : SwTblNumFmtMerge aTNFM( *pSrcDoc, *pDoc );
1463 :
1464 0 : pSrcDoc->CopyWithFlyInFly( *pCpyRg, 0, rInsPos, bCreateFrm );
1465 0 : ++aSave;
1466 :
1467 0 : if( !bCreateFrm )
1468 0 : ::MakeFrms( pDoc, aSave, rInsPos );
1469 :
1470 : // Delete last Node, only if it was copied successfully
1471 : // (the Section contains more than one Node)
1472 0 : if( 2 < pSectNd->EndOfSectionIndex() - pSectNd->GetIndex() )
1473 : {
1474 0 : aSave = rInsPos;
1475 0 : pPam->Move( fnMoveBackward, fnGoNode );
1476 0 : pPam->SetMark(); // Rewire both SwPositions
1477 :
1478 0 : pDoc->CorrAbs( aSave, *pPam->GetPoint(), 0, sal_True );
1479 0 : pDoc->GetNodes().Delete( aSave, 1 );
1480 : }
1481 0 : delete pCpyRg;
1482 : }
1483 :
1484 0 : lcl_BreakSectionLinksInSect( *pSectNd );
1485 :
1486 : // Update all Links in this Section
1487 0 : lcl_UpdateLinksInSect( *this, *pSectNd );
1488 : }
1489 0 : if( xDocSh.Is() )
1490 : {
1491 0 : if( 2 == nRet )
1492 0 : xDocSh->DoClose();
1493 0 : else if( ((SwDocShell*)&xDocSh)->GetDoc() )
1494 0 : ((SwDocShell*)&xDocSh)->GetDoc()->SetRedlineMode(
1495 0 : eOldRedlineMode );
1496 0 : }
1497 : }
1498 0 : break;
1499 : }
1500 :
1501 : // Only create DDE if Shell is available!
1502 0 : uno::Sequence< sal_Int8 > aSeq;
1503 0 : if( pRead && rValue.hasValue() && ( rValue >>= aSeq ) )
1504 : {
1505 0 : if( pESh )
1506 : {
1507 0 : pESh->Push();
1508 0 : SwPaM* pCrsr = pESh->GetCrsr();
1509 0 : *pCrsr->GetPoint() = *pPam->GetPoint();
1510 0 : delete pPam;
1511 0 : pPam = pCrsr;
1512 : }
1513 :
1514 0 : SvMemoryStream aStrm( (void*)aSeq.getConstArray(), aSeq.getLength(),
1515 0 : STREAM_READ );
1516 0 : aStrm.Seek( 0 );
1517 :
1518 : // TODO/MBA: it's impossible to set a BaseURL here!
1519 0 : SwReader aTmpReader( aStrm, aEmptyStr, pDoc->GetDocShell()->GetMedium()->GetBaseURL(), *pPam );
1520 :
1521 0 : if( !IsError( aTmpReader.Read( *pRead ) ))
1522 : {
1523 0 : rSection.SetConnectFlag(true);
1524 : }
1525 :
1526 0 : if( pESh )
1527 : {
1528 0 : pESh->Pop( sal_False );
1529 0 : pPam = 0; // pam was deleted earlier
1530 0 : }
1531 : }
1532 :
1533 :
1534 : // remove all undo actions and turn undo on again
1535 0 : pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
1536 0 : pDoc->GetIDocumentUndoRedo().DoUndo(bWasUndo);
1537 0 : pDoc->SetVisibleLinks( bWasVisibleLinks );
1538 :
1539 0 : pDoc->UnlockExpFlds();
1540 0 : if( !pDoc->IsExpFldsLocked() )
1541 0 : pDoc->UpdateExpFlds(NULL, true);
1542 :
1543 0 : if( pESh )
1544 0 : pESh->EndAllAction();
1545 0 : else if( pVSh )
1546 0 : pVSh->EndAction();
1547 0 : delete pPam; // Was created at the start
1548 :
1549 0 : return SUCCESS;
1550 : }
1551 :
1552 :
1553 0 : void SwIntrnlSectRefLink::Closed()
1554 : {
1555 0 : SwDoc* pDoc = rSectFmt.GetDoc();
1556 0 : if( pDoc && !pDoc->IsInDtor() )
1557 : {
1558 : // Advise says goodbye: mark the Section as not protected
1559 : // and change the Flag
1560 0 : const SwSectionFmts& rFmts = pDoc->GetSections();
1561 0 : for( sal_uInt16 n = rFmts.size(); n; )
1562 0 : if( rFmts[ --n ] == &rSectFmt )
1563 : {
1564 : ViewShell* pSh;
1565 0 : SwEditShell* pESh = pDoc->GetEditShell( &pSh );
1566 :
1567 0 : if( pESh )
1568 0 : pESh->StartAllAction();
1569 : else
1570 0 : pSh->StartAction();
1571 :
1572 0 : SwSectionData aSectionData(*rSectFmt.GetSection());
1573 0 : aSectionData.SetType( CONTENT_SECTION );
1574 0 : aSectionData.SetLinkFileName( aEmptyStr );
1575 0 : aSectionData.SetHidden( false );
1576 0 : aSectionData.SetProtectFlag( false );
1577 : // edit in readonly sections
1578 0 : aSectionData.SetEditInReadonlyFlag( false );
1579 :
1580 0 : aSectionData.SetConnectFlag( false );
1581 :
1582 0 : pDoc->UpdateSection( n, aSectionData );
1583 :
1584 : // Make all Links within the Section visible again
1585 0 : SwSectionNode* pSectNd = rSectFmt.GetSectionNode( sal_False );
1586 0 : if( pSectNd )
1587 0 : pSectNd->GetSection().MakeChildLinksVisible( *pSectNd );
1588 :
1589 0 : if( pESh )
1590 0 : pESh->EndAllAction();
1591 : else
1592 0 : pSh->EndAction();
1593 0 : break;
1594 : }
1595 : }
1596 0 : SvBaseLink::Closed();
1597 0 : }
1598 :
1599 :
1600 0 : void SwSection::CreateLink( LinkCreateType eCreateType )
1601 : {
1602 0 : SwSectionFmt* pFmt = GetFmt();
1603 : OSL_ENSURE(pFmt, "SwSection::CreateLink: no format?");
1604 0 : if (!pFmt || (CONTENT_SECTION == m_Data.GetType()))
1605 0 : return ;
1606 :
1607 0 : sal_uInt16 nUpdateType = sfx2::LINKUPDATE_ALWAYS;
1608 :
1609 0 : if (!m_RefLink.Is())
1610 : {
1611 : // create BaseLink
1612 0 : m_RefLink = new SwIntrnlSectRefLink( *pFmt, nUpdateType, FORMAT_RTF );
1613 : }
1614 : else
1615 : {
1616 0 : pFmt->GetDoc()->GetLinkManager().Remove( m_RefLink );
1617 : }
1618 :
1619 : SwIntrnlSectRefLink *const pLnk =
1620 0 : static_cast<SwIntrnlSectRefLink*>(& m_RefLink);
1621 :
1622 0 : String sCmd( m_Data.GetLinkFileName() );
1623 : xub_StrLen nPos;
1624 0 : while( STRING_NOTFOUND != (nPos = sCmd.SearchAscii( " " )) )
1625 0 : sCmd.Erase( nPos, 1 );
1626 :
1627 0 : pLnk->SetUpdateMode( nUpdateType );
1628 0 : pLnk->SetVisible( pFmt->GetDoc()->IsVisibleLinks() );
1629 :
1630 0 : switch (m_Data.GetType())
1631 : {
1632 : case DDE_LINK_SECTION:
1633 0 : pLnk->SetLinkSourceName( sCmd );
1634 0 : pFmt->GetDoc()->GetLinkManager().InsertDDELink( pLnk );
1635 0 : break;
1636 : case FILE_LINK_SECTION:
1637 : {
1638 0 : pLnk->SetContentType( FORMAT_FILE );
1639 0 : String sFltr( sCmd.GetToken( 1, sfx2::cTokenSeperator ) );
1640 0 : String sRange( sCmd.GetToken( 2, sfx2::cTokenSeperator ) );
1641 0 : pFmt->GetDoc()->GetLinkManager().InsertFileLink( *pLnk,
1642 0 : static_cast<sal_uInt16>(m_Data.GetType()),
1643 : sCmd.GetToken( 0, sfx2::cTokenSeperator ),
1644 0 : ( sFltr.Len() ? &sFltr : 0 ),
1645 0 : ( sRange.Len() ? &sRange : 0 ) );
1646 : }
1647 0 : break;
1648 : default:
1649 : OSL_ENSURE( !this, "What kind of Link is this?" );
1650 : }
1651 :
1652 0 : switch( eCreateType )
1653 : {
1654 : case CREATE_CONNECT: // Connect Link right away
1655 0 : pLnk->Connect();
1656 0 : break;
1657 :
1658 : case CREATE_UPDATE: // Connect Link and update
1659 0 : pLnk->Update();
1660 0 : break;
1661 0 : case CREATE_NONE: break;
1662 0 : }
1663 : }
1664 :
1665 0 : void SwSection::BreakLink()
1666 : {
1667 0 : const SectionType eCurrentType( GetType() );
1668 0 : if ( eCurrentType == CONTENT_SECTION ||
1669 : eCurrentType == TOX_HEADER_SECTION ||
1670 : eCurrentType == TOX_CONTENT_SECTION )
1671 : {
1672 : // nothing to do
1673 0 : return;
1674 : }
1675 :
1676 : // Release link, if it exists
1677 0 : if (m_RefLink.Is())
1678 : {
1679 0 : SwSectionFmt *const pFormat( GetFmt() );
1680 : OSL_ENSURE(pFormat, "SwSection::BreakLink: no format?");
1681 0 : if (pFormat)
1682 : {
1683 0 : pFormat->GetDoc()->GetLinkManager().Remove( m_RefLink );
1684 : }
1685 0 : m_RefLink.Clear();
1686 : }
1687 : // change type
1688 0 : SetType( CONTENT_SECTION );
1689 : // reset linked file data
1690 0 : SetLinkFileName( aEmptyStr );
1691 0 : SetLinkFilePassword( aEmptyStr );
1692 : }
1693 :
1694 0 : const SwNode* SwIntrnlSectRefLink::GetAnchor() const
1695 : {
1696 0 : return rSectFmt.GetSectionNode( sal_False );
1697 : }
1698 :
1699 :
1700 0 : sal_Bool SwIntrnlSectRefLink::IsInRange( sal_uLong nSttNd, sal_uLong nEndNd,
1701 : xub_StrLen , xub_StrLen ) const
1702 : {
1703 0 : SwStartNode* pSttNd = rSectFmt.GetSectionNode( sal_False );
1704 : return pSttNd &&
1705 0 : nSttNd < pSttNd->GetIndex() &&
1706 0 : pSttNd->EndOfSectionIndex() < nEndNd;
1707 : }
1708 :
1709 0 : sal_uInt16 SwSectionFmts::GetPos(const SwSectionFmt* p) const
1710 : {
1711 0 : const_iterator it = std::find(begin(), end(), p);
1712 0 : return it == end() ? USHRT_MAX : it - begin();
1713 : }
1714 :
1715 0 : bool SwSectionFmts::Contains(const SwSectionFmt* p) const
1716 : {
1717 0 : return std::find(begin(), end(), p) != end();
1718 : }
1719 :
1720 450 : SwSectionFmts::~SwSectionFmts()
1721 : {
1722 152 : for(const_iterator it = begin(); it != end(); ++it)
1723 2 : delete *it;
1724 300 : }
1725 :
1726 :
1727 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|