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 <annotationmark.hxx>
21 :
22 : #include <doc.hxx>
23 : #include <IDocumentMarkAccess.hxx>
24 : #include <fldbas.hxx>
25 : #include <switerator.hxx>
26 : #include <fmtfld.hxx>
27 : #include <docufld.hxx>
28 : #include <IDocumentUndoRedo.hxx>
29 : #include <UndoBookmark.hxx>
30 : #include <ndtxt.hxx>
31 : #include <txtfld.hxx>
32 :
33 : namespace sw { namespace mark
34 : {
35 0 : AnnotationMark::AnnotationMark(
36 : const SwPaM& rPaM,
37 : const ::rtl::OUString& rName )
38 0 : : MarkBase( rPaM, rName )
39 : {
40 0 : if ( rName.getLength() == 0 )
41 : {
42 0 : SetName( MarkBase::GenerateNewName( ::rtl::OUString::createFromAscii("__Annotation__") ) );
43 : }
44 0 : }
45 :
46 0 : AnnotationMark::~AnnotationMark()
47 : {
48 0 : }
49 :
50 0 : void AnnotationMark::InitDoc(SwDoc* const io_pDoc)
51 : {
52 : SwTxtFld* pTxtFld =
53 0 : GetMarkEnd().nNode.GetNode().GetTxtNode()->GetFldTxtAttrAt(
54 0 : GetMarkEnd().nContent.GetIndex()-1, true );
55 : OSL_ENSURE( pTxtFld != NULL, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" );
56 0 : if ( pTxtFld != NULL )
57 : {
58 0 : const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtFld->GetFmtFld().GetField());
59 : OSL_ENSURE( pPostItField != NULL, "<AnnotationMark::InitDoc(..)> - annotation field missing!" );
60 0 : if ( pPostItField != NULL )
61 : {
62 : // use the annotation mark's name as the annotation name, if
63 : // - the annotation field has an empty annotation name or
64 : // - the annotation mark's name differs (on mark creation a name clash had been detected)
65 0 : if ( pPostItField->GetName().isEmpty()
66 0 : || rtl::OUString( pPostItField->GetName() ) != GetName() )
67 : {
68 0 : const_cast<SwPostItField*>(pPostItField)->SetName( GetName() );
69 : }
70 : }
71 : }
72 :
73 0 : if (io_pDoc->GetIDocumentUndoRedo().DoesUndo())
74 : {
75 0 : io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) );
76 : }
77 0 : io_pDoc->SetModified();
78 0 : }
79 :
80 0 : const SwFmtFld* AnnotationMark::GetAnnotationFmtFld() const
81 : {
82 0 : SwDoc* pDoc = GetMarkPos().GetDoc();
83 0 : if ( pDoc == NULL )
84 : {
85 : OSL_ENSURE( false, "<AnnotationMark::GetAnnotationFmtFld()> - missing document at annotation mark" );
86 0 : return NULL;
87 : }
88 :
89 0 : SwFmtFld* pAnnotationFmtFld = NULL;
90 :
91 0 : SwFieldType* pType = pDoc->GetFldType( RES_POSTITFLD, OUString(), false );
92 0 : SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
93 0 : for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld != NULL; pFmtFld = aIter.Next() )
94 : {
95 0 : if ( pFmtFld->IsFldInDoc() )
96 : {
97 0 : const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pFmtFld->GetField());
98 0 : if ( pPostItField != NULL
99 0 : && rtl::OUString( pPostItField->GetName() ) == GetName() )
100 : {
101 0 : pAnnotationFmtFld = pFmtFld;
102 0 : break;
103 : }
104 : }
105 : }
106 :
107 0 : return pAnnotationFmtFld;
108 : }
109 : }}
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|