fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / commentsbuffer.cxx
blobd126cf02098aa04b9f13cc943955e79e9fbd4d04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <oox/token/properties.hxx>
21 #include <oox/token/tokens.hxx>
23 #include "commentsbuffer.hxx"
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 <osl/diagnose.h>
30 #include <oox/helper/attributelist.hxx>
31 #include <oox/vml/vmlshape.hxx>
32 #include "addressconverter.hxx"
33 #include "biffinputstream.hxx"
34 #include "drawingfragment.hxx"
35 #include <svx/sdtaitm.hxx>
36 #include "unitconverter.hxx"
37 #include "drawingmanager.hxx"
39 #include <com/sun/star/text/XText.hpp>
40 #include <com/sun/star/text/XTextRange.hpp>
42 using ::com::sun::star::text::XText;
43 using ::com::sun::star::text::XTextRange;
45 namespace oox {
46 namespace xls {
48 using namespace ::com::sun::star::drawing;
49 using namespace ::com::sun::star::sheet;
50 using namespace ::com::sun::star::table;
51 using namespace ::com::sun::star::text;
52 using namespace ::com::sun::star::uno;
54 static sal_Int32 lcl_ToHorizAlign( sal_Int32 nAlign )
56 switch( nAlign )
58 case XML_left:
59 return SDRTEXTHORZADJUST_LEFT;
60 case XML_right:
61 return SDRTEXTHORZADJUST_RIGHT;
62 case XML_center:
63 return SDRTEXTHORZADJUST_CENTER;
64 default:
65 return SDRTEXTHORZADJUST_BLOCK;
69 static sal_Int32 lcl_ToVertAlign( sal_Int32 nAlign )
71 switch( nAlign )
73 case XML_top:
74 return SDRTEXTVERTADJUST_TOP;
75 case XML_center:
76 return SDRTEXTVERTADJUST_CENTER;
77 case XML_bottom:
78 return SDRTEXTVERTADJUST_BOTTOM;
79 default:
80 return SDRTEXTVERTADJUST_BLOCK;
84 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 , mbVisible( false )
98 Comment::Comment( const WorksheetHelper& rHelper ) :
99 WorksheetHelper( rHelper )
103 void Comment::importComment( const AttributeList& rAttribs )
105 maModel.mnAuthorId = rAttribs.getInteger( XML_authorId, -1 );
106 // cell range will be checked while inserting the comment into the document
107 AddressConverter::convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex() );
110 void Comment::importCommentPr( const AttributeList& rAttribs )
112 maModel.mbAutoFill = rAttribs.getBool( XML_autoFill, true );
113 maModel.mbAutoScale = rAttribs.getBool( XML_autoScale, false );
114 maModel.mbColHidden = rAttribs.getBool( XML_colHidden, false );
115 maModel.mbLocked = rAttribs.getBool( XML_locked, false );
116 maModel.mbRowHidden = rAttribs.getBool( XML_rowHidden, false );
117 maModel.mnTHA = rAttribs.getToken( XML_textHAlign, XML_left );
118 maModel.mnTVA = rAttribs.getToken( XML_textVAlign, XML_top );
121 void Comment::importComment( SequenceInputStream& rStrm )
123 BinRange aBinRange;
124 maModel.mnAuthorId = rStrm.readInt32();
125 rStrm >> aBinRange;
126 // cell range will be checked while inserting the comment into the document
127 AddressConverter::convertToCellRangeUnchecked( maModel.maRange, aBinRange, getSheetIndex() );
130 RichStringRef Comment::createText()
132 maModel.mxText.reset( new RichString( *this ) );
133 return maModel.mxText;
136 void Comment::finalizeImport()
138 // BIFF12 stores cell range instead of cell address, use first cell of this range
139 OSL_ENSURE( (maModel.maRange.StartColumn == maModel.maRange.EndColumn) &&
140 (maModel.maRange.StartRow == maModel.maRange.EndRow),
141 "Comment::finalizeImport - comment anchor should be a single cell" );
142 CellAddress aNotePos( maModel.maRange.Sheet, maModel.maRange.StartColumn, maModel.maRange.StartRow );
143 if( getAddressConverter().checkCellAddress( aNotePos, true ) && maModel.mxText.get() ) try
145 Reference< XSheetAnnotationsSupplier > xAnnosSupp( getSheet(), UNO_QUERY_THROW );
146 Reference< XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), UNO_SET_THROW );
147 // non-empty string required by note implementation (real text will be added below)
148 xAnnos->insertNew( aNotePos, OUString( ' ' ) );
150 // receive created note from cell (insertNew does not return the note)
151 Reference< XSheetAnnotationAnchor > xAnnoAnchor( getCell( aNotePos ), UNO_QUERY_THROW );
152 Reference< XSheetAnnotation > xAnno( xAnnoAnchor->getAnnotation(), UNO_SET_THROW );
153 Reference< XSheetAnnotationShapeSupplier > xAnnoShapeSupp( xAnno, UNO_QUERY_THROW );
154 Reference< XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), UNO_SET_THROW );
156 // convert shape formatting and visibility
157 bool bVisible = true;
158 switch( getFilterType() )
160 case FILTER_OOXML:
162 // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped)
163 PropertySet aCommentPr( xAnnoShape );
164 aCommentPr.setProperty( PROP_TextFitToSize, maModel.mbAutoScale );
165 aCommentPr.setProperty( PROP_MoveProtect, maModel.mbLocked );
166 aCommentPr.setProperty( PROP_TextHorizontalAdjust, lcl_ToHorizAlign( maModel.mnTHA ) );
167 aCommentPr.setProperty( PROP_TextVerticalAdjust, lcl_ToVertAlign( maModel.mnTVA ) );
168 if( maModel.maAnchor.Width > 0 && maModel.maAnchor.Height > 0 )
170 xAnnoShape->setPosition( css::awt::Point( maModel.maAnchor.X, maModel.maAnchor.Y ) );
171 xAnnoShape->setSize( css::awt::Size( maModel.maAnchor.Width, maModel.maAnchor.Height ) );
174 // convert shape formatting and visibility
175 if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
177 // position and formatting
178 pNoteShape->convertFormatting( xAnnoShape );
179 // visibility
180 bVisible = pNoteShape->getTypeModel().mbVisible;
183 break;
184 case FILTER_BIFF:
185 bVisible = maModel.mbVisible;
186 break;
187 case FILTER_UNKNOWN:
188 break;
190 xAnno->setIsVisible( bVisible );
192 // insert text and convert text formatting
193 maModel.mxText->finalizeImport();
194 Reference< XText > xAnnoText( xAnnoShape, UNO_QUERY_THROW );
195 maModel.mxText->convert( xAnnoText, true );
197 catch( Exception& )
202 // private --------------------------------------------------------------------
204 CommentsBuffer::CommentsBuffer( const WorksheetHelper& rHelper ) :
205 WorksheetHelper( rHelper )
209 void CommentsBuffer::appendAuthor( const OUString& rAuthor )
211 maAuthors.push_back( rAuthor );
214 CommentRef CommentsBuffer::createComment()
216 CommentRef xComment( new Comment( *this ) );
217 maComments.push_back( xComment );
218 return xComment;
221 void CommentsBuffer::finalizeImport()
223 maComments.forEachMem( &Comment::finalizeImport );
226 } // namespace xls
227 } // namespace oox
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */