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 "richstringcontext.hxx"
27 using namespace ::oox::core
;
29 CommentsFragment::CommentsFragment( const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
30 WorksheetFragmentBase( rHelper
, rFragmentPath
)
34 ContextHandlerRef
CommentsFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
36 switch( getCurrentElement() )
38 case XML_ROOT_CONTEXT
:
39 if( nElement
== XLS_TOKEN( comments
) ) return this;
41 case XLS_TOKEN( comments
):
42 if( nElement
== XLS_TOKEN( authors
) ) return this;
43 if( nElement
== XLS_TOKEN( commentList
) ) return this;
45 case XLS_TOKEN( authors
):
46 if( nElement
== XLS_TOKEN( author
) ) return this; // collect author in onCharacters()
48 case XLS_TOKEN( commentList
):
49 if( nElement
== XLS_TOKEN( comment
) ) { importComment( rAttribs
); return this; }
51 case XLS_TOKEN( commentPr
):
52 if( nElement
== XLS_TOKEN( anchor
) )
55 case XLS_TOKEN( anchor
):
56 if( nElement
== XDR_TOKEN( from
) || nElement
== XDR_TOKEN( to
) )
59 case XDR_TOKEN( from
):
62 case XLS_TOKEN( comment
):
63 if( (nElement
== XLS_TOKEN( text
)) && mxComment
.get() )
64 return new RichStringContext( *this, mxComment
->createText() );
65 if( nElement
== XLS_TOKEN( commentPr
) ) { mxComment
->importCommentPr( rAttribs
); return this; }
71 void CommentsFragment::onCharacters( const OUString
& rChars
)
73 if( isCurrentElement( XLS_TOKEN( author
) ) )
74 getComments().appendAuthor( rChars
);
77 void CommentsFragment::onEndElement()
79 if( isCurrentElement( XLS_TOKEN( comment
) ) )
83 ContextHandlerRef
CommentsFragment::onCreateRecordContext( sal_Int32 nRecId
, SequenceInputStream
& rStrm
)
85 switch( getCurrentElement() )
87 case XML_ROOT_CONTEXT
:
88 if( nRecId
== BIFF12_ID_COMMENTS
) return this;
90 case BIFF12_ID_COMMENTS
:
91 if( nRecId
== BIFF12_ID_COMMENTAUTHORS
) return this;
92 if( nRecId
== BIFF12_ID_COMMENTLIST
) return this;
94 case BIFF12_ID_COMMENTAUTHORS
:
95 if( nRecId
== BIFF12_ID_COMMENTAUTHOR
) getComments().appendAuthor( BiffHelper::readString( rStrm
) );
97 case BIFF12_ID_COMMENTLIST
:
98 if( nRecId
== BIFF12_ID_COMMENT
) { importComment( rStrm
); return this; }
100 case BIFF12_ID_COMMENT
:
101 if( (nRecId
== BIFF12_ID_COMMENTTEXT
) && mxComment
.get() )
102 mxComment
->createText()->importString( rStrm
, true );
108 void CommentsFragment::onEndRecord()
110 if( isCurrentElement( BIFF12_ID_COMMENT
) )
114 const RecordInfo
* CommentsFragment::getRecordInfos() const
116 static const RecordInfo spRecInfos
[] =
118 { BIFF12_ID_COMMENT
, BIFF12_ID_COMMENT
+ 1 },
119 { BIFF12_ID_COMMENTAUTHORS
, BIFF12_ID_COMMENTAUTHORS
+ 1 },
120 { BIFF12_ID_COMMENTLIST
, BIFF12_ID_COMMENTLIST
+ 1 },
121 { BIFF12_ID_COMMENTS
, BIFF12_ID_COMMENTS
+ 1 },
127 // private --------------------------------------------------------------------
129 void CommentsFragment::importComment( const AttributeList
& rAttribs
)
131 mxComment
= getComments().createComment();
132 mxComment
->importComment( rAttribs
);
135 void CommentsFragment::importComment( SequenceInputStream
& rStrm
)
137 mxComment
= getComments().createComment();
138 mxComment
->importComment( rStrm
);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */