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