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>
28 using namespace ::oox::core
;
30 CommentsFragment::CommentsFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
31 WorksheetFragmentBase( rHelper
, rFragmentPath
)
35 ContextHandlerRef
CommentsFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
37 switch( getCurrentElement() )
39 case XML_ROOT_CONTEXT
:
40 if( nElement
== XLS_TOKEN( comments
) ) return this;
42 case XLS_TOKEN( comments
):
43 if( nElement
== XLS_TOKEN( authors
) ) return this;
44 if( nElement
== XLS_TOKEN( commentList
) ) return this;
46 case XLS_TOKEN( authors
):
47 if( nElement
== XLS_TOKEN( author
) ) return this; // collect author in onCharacters()
49 case XLS_TOKEN( commentList
):
50 if( nElement
== XLS_TOKEN( comment
) ) { importComment( rAttribs
); return this; }
52 case XLS_TOKEN( commentPr
):
53 if( nElement
== XLS_TOKEN( anchor
) )
56 case XLS_TOKEN( anchor
):
57 if( nElement
== XDR_TOKEN( from
) || nElement
== XDR_TOKEN( to
) )
60 case XDR_TOKEN( from
):
63 case XLS_TOKEN( comment
):
64 if( (nElement
== XLS_TOKEN( text
)) && mxComment
)
65 return new RichStringContext( *this, mxComment
->createText() );
66 if( nElement
== XLS_TOKEN( commentPr
) ) { mxComment
->importCommentPr( rAttribs
); return this; }
72 void CommentsFragment::onCharacters( const OUString
& rChars
)
74 if( isCurrentElement( XLS_TOKEN( author
) ) )
75 getComments().appendAuthor( rChars
);
78 void CommentsFragment::onEndElement()
80 if( isCurrentElement( XLS_TOKEN( comment
) ) )
84 ContextHandlerRef
CommentsFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
86 switch( getCurrentElement() )
88 case XML_ROOT_CONTEXT
:
89 if( nRecId
== BIFF12_ID_COMMENTS
) return this;
91 case BIFF12_ID_COMMENTS
:
92 if( nRecId
== BIFF12_ID_COMMENTAUTHORS
) return this;
93 if( nRecId
== BIFF12_ID_COMMENTLIST
) return this;
95 case BIFF12_ID_COMMENTAUTHORS
:
96 if( nRecId
== BIFF12_ID_COMMENTAUTHOR
) getComments().appendAuthor( BiffHelper::readString( rStrm
) );
98 case BIFF12_ID_COMMENTLIST
:
99 if( nRecId
== BIFF12_ID_COMMENT
) { importComment( rStrm
); return this; }
101 case BIFF12_ID_COMMENT
:
102 if( (nRecId
== BIFF12_ID_COMMENTTEXT
) && mxComment
)
103 mxComment
->createText()->importString( rStrm
, true, *this );
109 void CommentsFragment::onEndRecord()
111 if( isCurrentElement( BIFF12_ID_COMMENT
) )
115 const RecordInfo
* CommentsFragment::getRecordInfos() const
117 static const RecordInfo spRecInfos
[] =
119 { BIFF12_ID_COMMENT
, BIFF12_ID_COMMENT
+ 1 },
120 { BIFF12_ID_COMMENTAUTHORS
, BIFF12_ID_COMMENTAUTHORS
+ 1 },
121 { BIFF12_ID_COMMENTLIST
, BIFF12_ID_COMMENTLIST
+ 1 },
122 { BIFF12_ID_COMMENTS
, BIFF12_ID_COMMENTS
+ 1 },
128 // private --------------------------------------------------------------------
130 void CommentsFragment::importComment( const AttributeList
& rAttribs
)
132 mxComment
= getComments().createComment();
133 mxComment
->importComment( rAttribs
);
136 void CommentsFragment::importComment( SequenceInputStream
& rStrm
)
138 mxComment
= getComments().createComment();
139 mxComment
->importComment( rStrm
);
142 } // namespace oox::xls
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */