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 <oox/token/properties.hxx>
21 : #include <oox/token/tokens.hxx>
22 :
23 : #include "commentsbuffer.hxx"
24 :
25 : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
26 : #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
27 : #include <com/sun/star/sheet/XSheetAnnotations.hpp>
28 : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
29 : #include <oox/helper/attributelist.hxx>
30 : #include <oox/vml/vmlshape.hxx>
31 : #include "addressconverter.hxx"
32 : #include "biffinputstream.hxx"
33 : #include "drawingfragment.hxx"
34 : #include <svx/sdtaitm.hxx>
35 : #include "unitconverter.hxx"
36 : #include "drawingmanager.hxx"
37 :
38 : #include <com/sun/star/text/XText.hpp>
39 : #include <com/sun/star/text/XTextRange.hpp>
40 :
41 : using ::com::sun::star::text::XText;
42 : using ::com::sun::star::text::XTextRange;
43 :
44 : namespace oox {
45 : namespace xls {
46 :
47 : using namespace ::com::sun::star::drawing;
48 : using namespace ::com::sun::star::sheet;
49 : using namespace ::com::sun::star::table;
50 : using namespace ::com::sun::star::text;
51 : using namespace ::com::sun::star::uno;
52 :
53 4 : static sal_Int32 lcl_ToHorizAlign( sal_Int32 nAlign )
54 : {
55 4 : switch( nAlign )
56 : {
57 : case XML_left:
58 2 : return SDRTEXTHORZADJUST_LEFT;
59 : case XML_right:
60 0 : return SDRTEXTHORZADJUST_RIGHT;
61 : case XML_center:
62 0 : return SDRTEXTHORZADJUST_CENTER;
63 : default:
64 2 : return SDRTEXTHORZADJUST_BLOCK;
65 : }
66 : }
67 :
68 4 : static sal_Int32 lcl_ToVertAlign( sal_Int32 nAlign )
69 : {
70 4 : switch( nAlign )
71 : {
72 : case XML_top:
73 2 : return SDRTEXTVERTADJUST_TOP;
74 : case XML_center:
75 0 : return SDRTEXTVERTADJUST_CENTER;
76 : case XML_bottom:
77 0 : return SDRTEXTVERTADJUST_BOTTOM;
78 : default:
79 2 : return SDRTEXTVERTADJUST_BLOCK;
80 : }
81 : }
82 :
83 4 : CommentModel::CommentModel()
84 : : mnAuthorId(-1)
85 : , mnObjId(BIFF_OBJ_INVALID_ID)
86 : , mbAutoFill(false)
87 : , mbAutoScale(false)
88 : , mbColHidden(false)
89 : , mbLocked(false)
90 : , mbRowHidden(false)
91 : , mnTHA(0)
92 : , mnTVA(0)
93 4 : , mbVisible( false )
94 : {
95 4 : }
96 :
97 4 : Comment::Comment( const WorksheetHelper& rHelper ) :
98 4 : WorksheetHelper( rHelper )
99 : {
100 4 : }
101 :
102 4 : void Comment::importComment( const AttributeList& rAttribs )
103 : {
104 4 : maModel.mnAuthorId = rAttribs.getInteger( XML_authorId, -1 );
105 : // cell range will be checked while inserting the comment into the document
106 4 : getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex() );
107 4 : }
108 :
109 2 : void Comment::importCommentPr( const AttributeList& rAttribs )
110 : {
111 2 : maModel.mbAutoFill = rAttribs.getBool( XML_autoFill, true );
112 2 : maModel.mbAutoScale = rAttribs.getBool( XML_autoScale, false );
113 2 : maModel.mbColHidden = rAttribs.getBool( XML_colHidden, false );
114 2 : maModel.mbLocked = rAttribs.getBool( XML_locked, false );
115 2 : maModel.mbRowHidden = rAttribs.getBool( XML_rowHidden, false );
116 2 : maModel.mnTHA = rAttribs.getToken( XML_textHAlign, XML_left );
117 2 : maModel.mnTVA = rAttribs.getToken( XML_textVAlign, XML_top );
118 2 : }
119 :
120 0 : void Comment::importComment( SequenceInputStream& rStrm )
121 : {
122 0 : BinRange aBinRange;
123 0 : rStrm >> maModel.mnAuthorId >> aBinRange;
124 : // cell range will be checked while inserting the comment into the document
125 0 : getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, aBinRange, getSheetIndex() );
126 0 : }
127 :
128 4 : RichStringRef Comment::createText()
129 : {
130 4 : maModel.mxText.reset( new RichString( *this ) );
131 4 : return maModel.mxText;
132 : }
133 :
134 4 : void Comment::finalizeImport()
135 : {
136 : // BIFF12 stores cell range instead of cell address, use first cell of this range
137 : OSL_ENSURE( (maModel.maRange.StartColumn == maModel.maRange.EndColumn) &&
138 : (maModel.maRange.StartRow == maModel.maRange.EndRow),
139 : "Comment::finalizeImport - comment anchor should be a single cell" );
140 4 : CellAddress aNotePos( maModel.maRange.Sheet, maModel.maRange.StartColumn, maModel.maRange.StartRow );
141 4 : if( getAddressConverter().checkCellAddress( aNotePos, true ) && maModel.mxText.get() ) try
142 : {
143 4 : Reference< XSheetAnnotationsSupplier > xAnnosSupp( getSheet(), UNO_QUERY_THROW );
144 8 : Reference< XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), UNO_SET_THROW );
145 : // non-empty string required by note implementation (real text will be added below)
146 4 : xAnnos->insertNew( aNotePos, OUString( ' ' ) );
147 :
148 : // receive created note from cell (insertNew does not return the note)
149 8 : Reference< XSheetAnnotationAnchor > xAnnoAnchor( getCell( aNotePos ), UNO_QUERY_THROW );
150 8 : Reference< XSheetAnnotation > xAnno( xAnnoAnchor->getAnnotation(), UNO_SET_THROW );
151 8 : Reference< XSheetAnnotationShapeSupplier > xAnnoShapeSupp( xAnno, UNO_QUERY_THROW );
152 8 : Reference< XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), UNO_SET_THROW );
153 :
154 : // convert shape formatting and visibility
155 4 : bool bVisible = true;
156 4 : switch( getFilterType() )
157 : {
158 : case FILTER_OOXML:
159 : {
160 : // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped)
161 4 : PropertySet aCommentPr( xAnnoShape );
162 4 : aCommentPr.setProperty( PROP_TextFitToSize, maModel.mbAutoScale );
163 4 : aCommentPr.setProperty( PROP_MoveProtect, maModel.mbLocked );
164 4 : aCommentPr.setProperty( PROP_TextHorizontalAdjust, lcl_ToHorizAlign( maModel.mnTHA ) );
165 4 : aCommentPr.setProperty( PROP_TextVerticalAdjust, lcl_ToVertAlign( maModel.mnTVA ) );
166 4 : if( maModel.maAnchor.Width > 0 && maModel.maAnchor.Height > 0 )
167 : {
168 0 : xAnnoShape->setPosition( css::awt::Point( maModel.maAnchor.X, maModel.maAnchor.Y ) );
169 0 : xAnnoShape->setSize( css::awt::Size( maModel.maAnchor.Width, maModel.maAnchor.Height ) );
170 : }
171 :
172 : // convert shape formatting and visibility
173 4 : if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
174 : {
175 : // position and formatting
176 2 : pNoteShape->convertFormatting( xAnnoShape );
177 : // visibility
178 2 : bVisible = pNoteShape->getTypeModel().mbVisible;
179 4 : }
180 : }
181 4 : break;
182 : case FILTER_BIFF:
183 0 : bVisible = maModel.mbVisible;
184 0 : break;
185 : case FILTER_UNKNOWN:
186 0 : break;
187 : }
188 4 : xAnno->setIsVisible( bVisible );
189 :
190 : // insert text and convert text formatting
191 4 : maModel.mxText->finalizeImport();
192 4 : Reference< XText > xAnnoText( xAnnoShape, UNO_QUERY_THROW );
193 8 : maModel.mxText->convert( xAnnoText, true );
194 : }
195 0 : catch( Exception& )
196 : {
197 : }
198 4 : }
199 :
200 : // private --------------------------------------------------------------------
201 :
202 260 : CommentsBuffer::CommentsBuffer( const WorksheetHelper& rHelper ) :
203 260 : WorksheetHelper( rHelper )
204 : {
205 260 : }
206 :
207 0 : void CommentsBuffer::appendAuthor( const OUString& rAuthor )
208 : {
209 0 : maAuthors.push_back( rAuthor );
210 0 : }
211 :
212 4 : CommentRef CommentsBuffer::createComment()
213 : {
214 4 : CommentRef xComment( new Comment( *this ) );
215 4 : maComments.push_back( xComment );
216 4 : return xComment;
217 : }
218 :
219 260 : void CommentsBuffer::finalizeImport()
220 : {
221 260 : maComments.forEachMem( &Comment::finalizeImport );
222 260 : }
223 :
224 : } // namespace xls
225 48 : } // namespace oox
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|