1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <commentsfragment.hxx>
22 #include <biffhelper.hxx>
23 #include <richstringcontext.hxx>
24 #include <oox/token/namespaces.hxx>
29 using namespace ::oox::core
;
31 CommentsFragment::CommentsFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
32 WorksheetFragmentBase( rHelper
, rFragmentPath
)
36 ContextHandlerRef
CommentsFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
38 switch( getCurrentElement() )
40 case XML_ROOT_CONTEXT
:
41 if( nElement
== XLS_TOKEN( comments
) ) return this;
43 case XLS_TOKEN( comments
):
44 if( nElement
== XLS_TOKEN( authors
) ) return this;
45 if( nElement
== XLS_TOKEN( commentList
) ) return this;
47 case XLS_TOKEN( authors
):
48 if( nElement
== XLS_TOKEN( author
) ) return this; // collect author in onCharacters()
50 case XLS_TOKEN( commentList
):
51 if( nElement
== XLS_TOKEN( comment
) ) { importComment( rAttribs
); return this; }
53 case XLS_TOKEN( commentPr
):
54 if( nElement
== XLS_TOKEN( anchor
) )
57 case XLS_TOKEN( anchor
):
58 if( nElement
== XDR_TOKEN( from
) || nElement
== XDR_TOKEN( to
) )
61 case XDR_TOKEN( from
):
64 case XLS_TOKEN( comment
):
65 if( (nElement
== XLS_TOKEN( text
)) && mxComment
.get() )
66 return new RichStringContext( *this, mxComment
->createText() );
67 if( nElement
== XLS_TOKEN( commentPr
) ) { mxComment
->importCommentPr( rAttribs
); return this; }
73 void CommentsFragment::onCharacters( const OUString
& rChars
)
75 if( isCurrentElement( XLS_TOKEN( author
) ) )
76 getComments().appendAuthor( rChars
);
79 void CommentsFragment::onEndElement()
81 if( isCurrentElement( XLS_TOKEN( comment
) ) )
85 ContextHandlerRef
CommentsFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
87 switch( getCurrentElement() )
89 case XML_ROOT_CONTEXT
:
90 if( nRecId
== BIFF12_ID_COMMENTS
) return this;
92 case BIFF12_ID_COMMENTS
:
93 if( nRecId
== BIFF12_ID_COMMENTAUTHORS
) return this;
94 if( nRecId
== BIFF12_ID_COMMENTLIST
) return this;
96 case BIFF12_ID_COMMENTAUTHORS
:
97 if( nRecId
== BIFF12_ID_COMMENTAUTHOR
) getComments().appendAuthor( BiffHelper::readString( rStrm
) );
99 case BIFF12_ID_COMMENTLIST
:
100 if( nRecId
== BIFF12_ID_COMMENT
) { importComment( rStrm
); return this; }
102 case BIFF12_ID_COMMENT
:
103 if( (nRecId
== BIFF12_ID_COMMENTTEXT
) && mxComment
.get() )
104 mxComment
->createText()->importString( rStrm
, true );
110 void CommentsFragment::onEndRecord()
112 if( isCurrentElement( BIFF12_ID_COMMENT
) )
116 const RecordInfo
* CommentsFragment::getRecordInfos() const
118 static const RecordInfo spRecInfos
[] =
120 { BIFF12_ID_COMMENT
, BIFF12_ID_COMMENT
+ 1 },
121 { BIFF12_ID_COMMENTAUTHORS
, BIFF12_ID_COMMENTAUTHORS
+ 1 },
122 { BIFF12_ID_COMMENTLIST
, BIFF12_ID_COMMENTLIST
+ 1 },
123 { BIFF12_ID_COMMENTS
, BIFF12_ID_COMMENTS
+ 1 },
129 // private --------------------------------------------------------------------
131 void CommentsFragment::importComment( const AttributeList
& rAttribs
)
133 mxComment
= getComments().createComment();
134 mxComment
->importComment( rAttribs
);
137 void CommentsFragment::importComment( SequenceInputStream
& rStrm
)
139 mxComment
= getComments().createComment();
140 mxComment
->importComment( rStrm
);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */