LibreOffice Module sc (master)  1
commentsfragment.cxx
Go to the documentation of this file.
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 <biffhelper.hxx>
23 #include <richstringcontext.hxx>
24 #include <oox/token/namespaces.hxx>
25 
26 namespace oox::xls {
27 
28 using namespace ::oox::core;
29 
30 CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
31  WorksheetFragmentBase( rHelper, rFragmentPath )
32 {
33 }
34 
36 {
37  switch( getCurrentElement() )
38  {
39  case XML_ROOT_CONTEXT:
40  if( nElement == XLS_TOKEN( comments ) ) return this;
41  break;
42  case XLS_TOKEN( comments ):
43  if( nElement == XLS_TOKEN( authors ) ) return this;
44  if( nElement == XLS_TOKEN( commentList ) ) return this;
45  break;
46  case XLS_TOKEN( authors ):
47  if( nElement == XLS_TOKEN( author ) ) return this; // collect author in onCharacters()
48  break;
49  case XLS_TOKEN( commentList ):
50  if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
51  break;
52  case XLS_TOKEN( commentPr ):
53  if( nElement == XLS_TOKEN( anchor ) )
54  return this;
55  break;
56  case XLS_TOKEN( anchor ):
57  if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
58  return this;
59  break;
60  case XDR_TOKEN( from ):
61  case XDR_TOKEN( to ):
62  return this;
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; }
67  break;
68  }
69  return nullptr;
70 }
71 
72 void CommentsFragment::onCharacters( const OUString& rChars )
73 {
74  if( isCurrentElement( XLS_TOKEN( author ) ) )
75  getComments().appendAuthor( rChars );
76 }
77 
79 {
80  if( isCurrentElement( XLS_TOKEN( comment ) ) )
81  mxComment.reset();
82 }
83 
85 {
86  switch( getCurrentElement() )
87  {
88  case XML_ROOT_CONTEXT:
89  if( nRecId == BIFF12_ID_COMMENTS ) return this;
90  break;
91  case BIFF12_ID_COMMENTS:
92  if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
93  if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
94  break;
97  break;
99  if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
100  break;
101  case BIFF12_ID_COMMENT:
102  if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment )
103  mxComment->createText()->importString( rStrm, true );
104  break;
105  }
106  return nullptr;
107 }
108 
110 {
112  mxComment.reset();
113 }
114 
115 const RecordInfo* CommentsFragment::getRecordInfos() const
116 {
117  static const RecordInfo spRecInfos[] =
118  {
123  { -1, -1 }
124  };
125  return spRecInfos;
126 }
127 
128 // private --------------------------------------------------------------------
129 
131 {
133  mxComment->importComment( rAttribs );
134 }
135 
137 {
139  mxComment->importComment( rStrm );
140 }
141 
142 } // namespace oox::xls
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 BIFF12_ID_COMMENT
Definition: biffhelper.hxx:67
anchor
const sal_Int32 BIFF12_ID_COMMENTAUTHOR
Definition: biffhelper.hxx:68
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
const sal_Int32 BIFF12_ID_COMMENTLIST
Definition: biffhelper.hxx:70
const sal_Int32 BIFF12_ID_COMMENTTEXT
Definition: biffhelper.hxx:72
void appendAuthor(const OUString &rAuthor)
Appends a new author to the list of comment authors.
bool isCurrentElement(sal_Int32 nElement) const
const sal_Int32 BIFF12_ID_COMMENTS
Definition: biffhelper.hxx:71
const sal_Int32 BIFF12_ID_COMMENTAUTHORS
Definition: biffhelper.hxx:69
UBlockCode from
UBlockCode to
CommentsBuffer & getComments() const
Returns the buffer for all cell comments in this sheet.
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
exports com.sun.star. text
CommentRef createComment()
Creates and returns a new comment.
virtual void onCharacters(const OUString &rChars) override
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
Definition: biffhelper.cxx:78
sal_Int32 getCurrentElement() const
CommentsFragment(const WorksheetHelper &rHelper, const OUString &rFragmentPath)
Fragment handler derived from the WorksheetHelper helper class.
virtual void onEndElement() override
virtual void onEndRecord() override
const sal_Int32 XML_ROOT_CONTEXT
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
void importComment(const AttributeList &rAttribs)
Imports comment data from the comment element.