1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 // MARKER(update_precomp.py): autogen include statement, do not remove 24 #include "precompiled_sw.hxx" 25 26 #include <annotationmark.hxx> 27 28 #include <doc.hxx> 29 #include <IDocumentMarkAccess.hxx> 30 #include <fldbas.hxx> 31 #include <switerator.hxx> 32 #include <fmtfld.hxx> 33 #include <docufld.hxx> 34 #include <IDocumentUndoRedo.hxx> 35 #include <UndoBookmark.hxx> 36 #include <ndtxt.hxx> 37 #include <txtfld.hxx> 38 39 namespace sw { namespace mark 40 { 41 AnnotationMark::AnnotationMark( 42 const SwPaM& rPaM, 43 const ::rtl::OUString& rName ) 44 : MarkBase( rPaM, rName ) 45 { 46 if ( rName.getLength() == 0 ) 47 { 48 SetName( MarkBase::GenerateNewName( ::rtl::OUString::createFromAscii("__Annotation__") ) ); 49 } 50 } 51 52 53 AnnotationMark::~AnnotationMark() 54 { 55 } 56 57 58 void AnnotationMark::InitDoc(SwDoc* const io_pDoc) 59 { 60 SwTxtFld* pTxtFld = 61 GetMarkEnd().nNode.GetNode().GetTxtNode()->GetFldTxtAttrAt( 62 GetMarkEnd().nContent.GetIndex()-1, true ); 63 if ( pTxtFld != NULL ) 64 { 65 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtFld->GetFmtFld().GetField()); 66 ASSERT( pPostItField != NULL, "<AnnotationMark::InitDoc(..)> - annotation field missing!" ); 67 if ( pPostItField != NULL ) 68 { 69 // use the annotation mark's name as the annotation name, if 70 // - the annotation field has an empty annotation name or 71 // - the annotation mark's name differs (on mark creation a name clash had been detected) 72 if ( pPostItField->GetName().Len() == 0 73 || rtl::OUString( pPostItField->GetName() ) != GetName() ) 74 { 75 const_cast<SwPostItField*>(pPostItField)->SetName( GetName() ); 76 } 77 } 78 } 79 80 if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) 81 { 82 io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) ); 83 } 84 io_pDoc->SetModified(); 85 } 86 87 88 const SwFmtFld* AnnotationMark::GetAnnotationFmtFld() const 89 { 90 SwDoc* pDoc = GetMarkPos().GetDoc(); 91 if ( pDoc == NULL ) 92 { 93 ASSERT( false, "<AnnotationMark::GetAnnotationFmtFld()> - missing document at annotation mark" ); 94 return NULL; 95 } 96 97 SwFmtFld* pAnnotationFmtFld = NULL; 98 99 SwFieldType* pType = pDoc->GetFldType( RES_POSTITFLD, String(), false ); 100 SwIterator<SwFmtFld,SwFieldType> aIter( *pType ); 101 for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld != NULL; pFmtFld = aIter.Next() ) 102 { 103 if ( pFmtFld->IsFldInDoc() ) 104 { 105 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pFmtFld->GetField()); 106 if ( pPostItField != NULL 107 && rtl::OUString( pPostItField->GetName() ) == GetName() ) 108 { 109 pAnnotationFmtFld = pFmtFld; 110 break; 111 } 112 } 113 } 114 115 return pAnnotationFmtFld; 116 } 117 }} 118 119