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 { AnnotationMark(const SwPaM & rPaM,const::rtl::OUString & rName)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 ~AnnotationMark()53 AnnotationMark::~AnnotationMark() 54 { 55 } 56 57 InitDoc(SwDoc * const io_pDoc)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 ASSERT( pTxtFld != NULL, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" ); 64 if ( pTxtFld != NULL ) 65 { 66 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtFld->GetFmtFld().GetField()); 67 ASSERT( pPostItField != NULL, "<AnnotationMark::InitDoc(..)> - annotation field missing!" ); 68 if ( pPostItField != NULL ) 69 { 70 // use the annotation mark's name as the annotation name, if 71 // - the annotation field has an empty annotation name or 72 // - the annotation mark's name differs (on mark creation a name clash had been detected) 73 if ( pPostItField->GetName().Len() == 0 74 || rtl::OUString( pPostItField->GetName() ) != GetName() ) 75 { 76 const_cast<SwPostItField*>(pPostItField)->SetName( GetName() ); 77 } 78 } 79 } 80 81 if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) 82 { 83 io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) ); 84 } 85 io_pDoc->SetModified(); 86 } 87 88 GetAnnotationFmtFld() const89 const SwFmtFld* AnnotationMark::GetAnnotationFmtFld() const 90 { 91 SwDoc* pDoc = GetMarkPos().GetDoc(); 92 if ( pDoc == NULL ) 93 { 94 ASSERT( false, "<AnnotationMark::GetAnnotationFmtFld()> - missing document at annotation mark" ); 95 return NULL; 96 } 97 98 SwFmtFld* pAnnotationFmtFld = NULL; 99 100 SwFieldType* pType = pDoc->GetFldType( RES_POSTITFLD, String(), false ); 101 SwIterator<SwFmtFld,SwFieldType> aIter( *pType ); 102 for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld != NULL; pFmtFld = aIter.Next() ) 103 { 104 if ( pFmtFld->IsFldInDoc() ) 105 { 106 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pFmtFld->GetField()); 107 if ( pPostItField != NULL 108 && rtl::OUString( pPostItField->GetName() ) == GetName() ) 109 { 110 pAnnotationFmtFld = pFmtFld; 111 break; 112 } 113 } 114 } 115 116 return pAnnotationFmtFld; 117 } 118 }} 119 120