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