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
26namespace oox::xls {
27
28using namespace ::oox::core;
29
30CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
31 WorksheetFragmentBase( rHelper, rFragmentPath )
32{
33}
34
36{
37 switch( getCurrentElement() )
38 {
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
72void 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 {
89 if( nRecId == BIFF12_ID_COMMENTS ) return this;
90 break;
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;
102 if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment )
103 mxComment->createText()->importString( rStrm, true, *this );
104 break;
105 }
106 return nullptr;
107}
108
110{
111 if( isCurrentElement( BIFF12_ID_COMMENT ) )
112 mxComment.reset();
113}
114
115const 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: */
UBlockCode from
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
Definition: biffhelper.cxx:79
void appendAuthor(const OUString &rAuthor)
Appends a new author to the list of comment authors.
CommentRef createComment()
Creates and returns a new comment.
virtual void onEndElement() override
void importComment(const AttributeList &rAttribs)
Imports comment data from the comment element.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onCharacters(const OUString &rChars) override
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
CommentsFragment(const WorksheetHelper &rHelper, const OUString &rFragmentPath)
virtual void onEndRecord() override
Fragment handler derived from the WorksheetHelper helper class.
CommentsBuffer & getComments() const
Returns the buffer for all cell comments in this sheet.
anchor
def text(shape, orig_st)
void SvStream & rStrm
const sal_Int32 XML_ROOT_CONTEXT
const sal_Int32 BIFF12_ID_COMMENTLIST
Definition: biffhelper.hxx:69
const sal_Int32 BIFF12_ID_COMMENTS
Definition: biffhelper.hxx:70
const sal_Int32 BIFF12_ID_COMMENTAUTHOR
Definition: biffhelper.hxx:67
const sal_Int32 BIFF12_ID_COMMENTAUTHORS
Definition: biffhelper.hxx:68
const sal_Int32 BIFF12_ID_COMMENTTEXT
Definition: biffhelper.hxx:71
const sal_Int32 BIFF12_ID_COMMENT
Definition: biffhelper.hxx:66
static N to(double f)
Definition: xltools.cxx:275