1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablebuffer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/commentsbuffer.hxx"
32 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
33 #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
34 #include <com/sun/star/sheet/XSheetAnnotations.hpp>
35 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
36 #include "oox/helper/attributelist.hxx"
37 #include "oox/helper/recordinputstream.hxx"
38 #include "oox/vml/vmlshape.hxx"
39 #include "oox/xls/addressconverter.hxx"
40 #include "oox/xls/drawingfragment.hxx"
42 using ::rtl::OUString
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::Exception
;
45 using ::com::sun::star::uno::UNO_QUERY_THROW
;
46 using ::com::sun::star::uno::UNO_SET_THROW
;
47 using ::com::sun::star::drawing::XShape
;
48 using ::com::sun::star::table::CellAddress
;
49 using ::com::sun::star::sheet::XSheetAnnotation
;
50 using ::com::sun::star::sheet::XSheetAnnotationAnchor
;
51 using ::com::sun::star::sheet::XSheetAnnotationShapeSupplier
;
52 using ::com::sun::star::sheet::XSheetAnnotations
;
53 using ::com::sun::star::sheet::XSheetAnnotationsSupplier
;
58 // ============================================================================
60 CommentModel::CommentModel() :
65 // ----------------------------------------------------------------------------
67 Comment::Comment( const WorksheetHelper
& rHelper
) :
68 WorksheetHelper( rHelper
)
72 void Comment::importComment( const AttributeList
& rAttribs
)
74 maModel
.mnAuthorId
= rAttribs
.getInteger( XML_authorId
, -1 );
75 // cell range will be checked while inserting the comment into the document
76 getAddressConverter().convertToCellRangeUnchecked( maModel
.maRange
, rAttribs
.getString( XML_ref
, OUString() ), getSheetIndex() );
79 void Comment::importComment( RecordInputStream
& rStrm
)
82 rStrm
>> maModel
.mnAuthorId
>> aBinRange
;
83 // cell range will be checked while inserting the comment into the document
84 getAddressConverter().convertToCellRangeUnchecked( maModel
.maRange
, aBinRange
, getSheetIndex() );
87 RichStringRef
Comment::createText()
89 maModel
.mxText
.reset( new RichString( *this ) );
90 return maModel
.mxText
;
93 void Comment::finalizeImport()
95 // OOBIN format stores cell range instead of cell address, use first cell of this range
96 OSL_ENSURE( (maModel
.maRange
.StartColumn
== maModel
.maRange
.EndColumn
) &&
97 (maModel
.maRange
.StartRow
== maModel
.maRange
.EndRow
),
98 "Comment::finalizeImport - comment anchor should be a single cell" );
99 CellAddress
aNotePos( maModel
.maRange
.Sheet
, maModel
.maRange
.StartColumn
, maModel
.maRange
.StartRow
);
100 if( getAddressConverter().checkCellAddress( aNotePos
, true ) && maModel
.mxText
.get() ) try
102 maModel
.mxText
->finalizeImport();
103 OUString aNoteText
= maModel
.mxText
->getPlainText();
104 // non-empty string required by note implementation
105 if( aNoteText
.getLength() > 0 )
107 Reference
< XSheetAnnotationsSupplier
> xAnnosSupp( getSheet(), UNO_QUERY_THROW
);
108 Reference
< XSheetAnnotations
> xAnnos( xAnnosSupp
->getAnnotations(), UNO_SET_THROW
);
109 xAnnos
->insertNew( aNotePos
, aNoteText
);
110 // receive craeted note from cell (insertNew does not return the note)
111 Reference
< XSheetAnnotationAnchor
> xAnnoAnchor( getCell( aNotePos
), UNO_QUERY_THROW
);
112 Reference
< XSheetAnnotation
> xAnno( xAnnoAnchor
->getAnnotation(), UNO_SET_THROW
);
113 Reference
< XSheetAnnotationShapeSupplier
> xAnnoShapeSupp( xAnno
, UNO_QUERY_THROW
);
114 Reference
< XShape
> xAnnoShape( xAnnoShapeSupp
->getAnnotationShape(), UNO_SET_THROW
);
115 // convert shape formatting
116 if( const ::oox::vml::ShapeBase
* pNoteShape
= getVmlDrawing().getNoteShape( aNotePos
) )
118 // position and formatting
119 pNoteShape
->convertFormatting( xAnnoShape
);
121 const ::oox::vml::ShapeModel::ShapeClientDataPtr
& rxClientData
= pNoteShape
->getShapeModel().mxClientData
;
122 bool bVisible
= rxClientData
.get() && rxClientData
->mbVisible
;
123 xAnno
->setIsVisible( bVisible
);
132 // ============================================================================
134 CommentsBuffer::CommentsBuffer( const WorksheetHelper
& rHelper
) :
135 WorksheetHelper( rHelper
)
139 void CommentsBuffer::appendAuthor( const OUString
& rAuthor
)
141 maAuthors
.push_back( rAuthor
);
144 CommentRef
CommentsBuffer::createComment()
146 CommentRef
xComment( new Comment( *this ) );
147 maComments
.push_back( xComment
);
151 void CommentsBuffer::finalizeImport()
153 maComments
.forEachMem( &Comment::finalizeImport
);
156 // ============================================================================