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