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 "commentsfragment.hxx"
21 :
22 : #include "richstringcontext.hxx"
23 :
24 : namespace oox {
25 : namespace xls {
26 :
27 : using namespace ::oox::core;
28 :
29 :
30 1 : CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
31 1 : WorksheetFragmentBase( rHelper, rFragmentPath )
32 : {
33 1 : }
34 :
35 18 : ContextHandlerRef CommentsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
36 : {
37 18 : switch( getCurrentElement() )
38 : {
39 : case XML_ROOT_CONTEXT:
40 1 : if( nElement == XLS_TOKEN( comments ) ) return this;
41 0 : break;
42 : case XLS_TOKEN( comments ):
43 2 : if( nElement == XLS_TOKEN( authors ) ) return this;
44 1 : if( nElement == XLS_TOKEN( commentList ) ) return this;
45 0 : break;
46 : case XLS_TOKEN( authors ):
47 1 : if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
48 0 : break;
49 : case XLS_TOKEN( commentList ):
50 1 : if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
51 0 : break;
52 : case XLS_TOKEN( commentPr ):
53 1 : if( nElement == XLS_TOKEN( anchor ) )
54 1 : return this;
55 0 : break;
56 : case XLS_TOKEN( anchor ):
57 2 : if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
58 2 : return this;
59 0 : break;
60 : case XDR_TOKEN( from ):
61 : case XDR_TOKEN( to ):
62 8 : return this;
63 : case XLS_TOKEN( comment ):
64 2 : if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
65 1 : return new RichStringContext( *this, mxComment->createText() );
66 1 : if( nElement == XLS_TOKEN( commentPr ) ) { mxComment->importCommentPr( rAttribs ); return this; }
67 0 : break;
68 : }
69 0 : return 0;
70 : }
71 :
72 8 : void CommentsFragment::onCharacters( const OUString& rChars )
73 : {
74 8 : if( isCurrentElement( XLS_TOKEN( author ) ) )
75 0 : getComments().appendAuthor( rChars );
76 8 : }
77 :
78 19 : void CommentsFragment::onEndElement()
79 : {
80 19 : if( isCurrentElement( XLS_TOKEN( comment ) ) )
81 3 : mxComment.reset();
82 19 : }
83 :
84 0 : ContextHandlerRef CommentsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
85 : {
86 0 : switch( getCurrentElement() )
87 : {
88 : case XML_ROOT_CONTEXT:
89 0 : if( nRecId == BIFF12_ID_COMMENTS ) return this;
90 0 : break;
91 : case BIFF12_ID_COMMENTS:
92 0 : if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
93 0 : if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
94 0 : break;
95 : case BIFF12_ID_COMMENTAUTHORS:
96 0 : if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
97 0 : break;
98 : case BIFF12_ID_COMMENTLIST:
99 0 : if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
100 0 : break;
101 : case BIFF12_ID_COMMENT:
102 0 : if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
103 0 : mxComment->createText()->importString( rStrm, true );
104 0 : break;
105 : }
106 0 : return 0;
107 : }
108 :
109 0 : void CommentsFragment::onEndRecord()
110 : {
111 0 : if( isCurrentElement( BIFF12_ID_COMMENT ) )
112 0 : mxComment.reset();
113 0 : }
114 :
115 0 : const RecordInfo* CommentsFragment::getRecordInfos() const
116 : {
117 : static const RecordInfo spRecInfos[] =
118 : {
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 },
123 : { -1, -1 }
124 : };
125 0 : return spRecInfos;
126 : }
127 :
128 : // private --------------------------------------------------------------------
129 :
130 1 : void CommentsFragment::importComment( const AttributeList& rAttribs )
131 : {
132 1 : mxComment = getComments().createComment();
133 1 : mxComment->importComment( rAttribs );
134 1 : }
135 :
136 0 : void CommentsFragment::importComment( SequenceInputStream& rStrm )
137 : {
138 0 : mxComment = getComments().createComment();
139 0 : mxComment->importComment( rStrm );
140 0 : }
141 :
142 : } // namespace xls
143 18 : } // namespace oox
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|