Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / oox / commentsfragment.cxx
blob8a4fe854b9b120ea3aaefe02dddde68c2a812413
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 namespace oox {
27 namespace xls {
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;
42 break;
43 case XLS_TOKEN( comments ):
44 if( nElement == XLS_TOKEN( authors ) ) return this;
45 if( nElement == XLS_TOKEN( commentList ) ) return this;
46 break;
47 case XLS_TOKEN( authors ):
48 if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
49 break;
50 case XLS_TOKEN( commentList ):
51 if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
52 break;
53 case XLS_TOKEN( commentPr ):
54 if( nElement == XLS_TOKEN( anchor ) )
55 return this;
56 break;
57 case XLS_TOKEN( anchor ):
58 if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
59 return this;
60 break;
61 case XDR_TOKEN( from ):
62 case XDR_TOKEN( to ):
63 return this;
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; }
68 break;
70 return nullptr;
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 ) ) )
82 mxComment.reset();
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;
91 break;
92 case BIFF12_ID_COMMENTS:
93 if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
94 if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
95 break;
96 case BIFF12_ID_COMMENTAUTHORS:
97 if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
98 break;
99 case BIFF12_ID_COMMENTLIST:
100 if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
101 break;
102 case BIFF12_ID_COMMENT:
103 if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
104 mxComment->createText()->importString( rStrm, true );
105 break;
107 return nullptr;
110 void CommentsFragment::onEndRecord()
112 if( isCurrentElement( BIFF12_ID_COMMENT ) )
113 mxComment.reset();
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 },
124 { -1, -1 }
126 return spRecInfos;
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 );
143 } // namespace xls
144 } // namespace oox
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */