LCOV - code coverage report
Current view: top level - sc/source/filter/oox - commentsbuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 68 87 78.2 %
Date: 2012-08-25 Functions: 13 15 86.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 53 136 39.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <oox/token/properties.hxx>
      30                 :            : #include <oox/token/tokens.hxx>
      31                 :            : 
      32                 :            : #include "commentsbuffer.hxx"
      33                 :            : 
      34                 :            : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
      35                 :            : #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
      36                 :            : #include <com/sun/star/sheet/XSheetAnnotations.hpp>
      37                 :            : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
      38                 :            : #include "oox/helper/attributelist.hxx"
      39                 :            : #include "oox/vml/vmlshape.hxx"
      40                 :            : #include "addressconverter.hxx"
      41                 :            : #include "biffinputstream.hxx"
      42                 :            : #include "drawingfragment.hxx"
      43                 :            : #include "svx/sdtaitm.hxx"
      44                 :            : #include "unitconverter.hxx"
      45                 :            : #include "drawingmanager.hxx"
      46                 :            : 
      47                 :            : #include <com/sun/star/text/XText.hpp>
      48                 :            : #include <com/sun/star/text/XTextRange.hpp>
      49                 :            : 
      50                 :            : using ::com::sun::star::text::XText;
      51                 :            : using ::com::sun::star::text::XTextRange;
      52                 :            : using ::com::sun::star::awt::Size;
      53                 :            : using ::com::sun::star::awt::Point;
      54                 :            : 
      55                 :            : namespace oox {
      56                 :            : namespace xls {
      57                 :            : 
      58                 :            : // ============================================================================
      59                 :            : 
      60                 :            : using namespace ::com::sun::star::drawing;
      61                 :            : using namespace ::com::sun::star::sheet;
      62                 :            : using namespace ::com::sun::star::table;
      63                 :            : using namespace ::com::sun::star::text;
      64                 :            : using namespace ::com::sun::star::uno;
      65                 :            : 
      66                 :            : using ::rtl::OUString;
      67                 :            : 
      68                 :          3 : static sal_Int32 lcl_ToHorizAlign( sal_Int32 nAlign )
      69                 :            : {
      70   [ -  -  -  + ]:          3 :     switch( nAlign )
      71                 :            :     {
      72                 :            :         case XML_left:
      73                 :          0 :             return SDRTEXTHORZADJUST_LEFT;
      74                 :            :         case XML_right:
      75                 :          0 :             return SDRTEXTHORZADJUST_RIGHT;
      76                 :            :         case XML_center:
      77                 :          0 :             return SDRTEXTHORZADJUST_CENTER;
      78                 :            :         default:
      79                 :          3 :             return SDRTEXTHORZADJUST_BLOCK;
      80                 :            :     }
      81                 :            : }
      82                 :            : 
      83                 :          3 : static sal_Int32 lcl_ToVertAlign( sal_Int32 nAlign )
      84                 :            : {
      85   [ +  -  -  - ]:          3 :     switch( nAlign )
      86                 :            :     {
      87                 :            :         case XML_top:
      88                 :          3 :             return SDRTEXTVERTADJUST_TOP;
      89                 :            :         case XML_center:
      90                 :          0 :             return SDRTEXTVERTADJUST_CENTER;
      91                 :            :         case XML_bottom:
      92                 :          0 :             return SDRTEXTVERTADJUST_BOTTOM;
      93                 :            :         default:
      94                 :          3 :             return SDRTEXTVERTADJUST_BLOCK;
      95                 :            :     }
      96                 :            : }
      97                 :            : 
      98                 :            : // ============================================================================
      99                 :            : 
     100                 :            : namespace {
     101                 :            : 
     102                 :            : const sal_uInt16 BIFF_NOTE_VISIBLE          = 0x0002;
     103                 :            : 
     104                 :            : } // namespace
     105                 :            : 
     106                 :            : // ============================================================================
     107                 :            : 
     108                 :          3 : CommentModel::CommentModel() :
     109                 :            :     mnAuthorId( -1 ),
     110                 :            :     mnObjId( BIFF_OBJ_INVALID_ID ),
     111                 :          3 :     mbVisible( false )
     112                 :            : {
     113                 :          3 : }
     114                 :            : 
     115                 :            : // ----------------------------------------------------------------------------
     116                 :            : 
     117                 :          3 : Comment::Comment( const WorksheetHelper& rHelper ) :
     118         [ +  - ]:          3 :     WorksheetHelper( rHelper )
     119                 :            : {
     120                 :          3 : }
     121                 :            : 
     122                 :          3 : void Comment::importComment( const AttributeList& rAttribs )
     123                 :            : {
     124                 :          3 :     maModel.mnAuthorId = rAttribs.getInteger( XML_authorId, -1 );
     125                 :            :     // cell range will be checked while inserting the comment into the document
     126 [ +  - ][ +  - ]:          3 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex() );
                 [ +  - ]
     127                 :          3 : }
     128                 :            : 
     129                 :          3 : void Comment::importCommentPr( const AttributeList& rAttribs )
     130                 :            : {
     131                 :          3 :     maModel.mbAutoFill  = rAttribs.getBool( XML_autoFill, true );
     132                 :          3 :     maModel.mbAutoScale = rAttribs.getBool( XML_autoScale, false );
     133                 :          3 :     maModel.mbColHidden = rAttribs.getBool( XML_colHidden, false );
     134                 :          3 :     maModel.mbLocked    = rAttribs.getBool( XML_locked, false );
     135                 :          3 :     maModel.mbRowHidden = rAttribs.getBool( XML_rowHidden, false );
     136                 :          3 :     maModel.mnTHA       = rAttribs.getToken( XML_textHAlign, XML_left );
     137                 :          3 :     maModel.mnTVA       = rAttribs.getToken( XML_textVAlign, XML_top );
     138                 :          3 : }
     139                 :            : 
     140                 :          0 : void Comment::importComment( SequenceInputStream& rStrm )
     141                 :            : {
     142                 :          0 :     BinRange aBinRange;
     143 [ #  # ][ #  # ]:          0 :     rStrm >> maModel.mnAuthorId >> aBinRange;
     144                 :            :     // cell range will be checked while inserting the comment into the document
     145 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellRangeUnchecked( maModel.maRange, aBinRange, getSheetIndex() );
                 [ #  # ]
     146                 :          0 : }
     147                 :            : 
     148                 :          3 : RichStringRef Comment::createText()
     149                 :            : {
     150         [ +  - ]:          3 :     maModel.mxText.reset( new RichString( *this ) );
     151                 :          3 :     return maModel.mxText;
     152                 :            : }
     153                 :            : 
     154                 :          3 : void Comment::finalizeImport()
     155                 :            : {
     156                 :            :     // BIFF12 stores cell range instead of cell address, use first cell of this range
     157                 :            :     OSL_ENSURE( (maModel.maRange.StartColumn == maModel.maRange.EndColumn) &&
     158                 :            :         (maModel.maRange.StartRow == maModel.maRange.EndRow),
     159                 :            :         "Comment::finalizeImport - comment anchor should be a single cell" );
     160                 :          3 :     CellAddress aNotePos( maModel.maRange.Sheet, maModel.maRange.StartColumn, maModel.maRange.StartRow );
     161 [ +  - ][ +  - ]:          3 :     if( getAddressConverter().checkCellAddress( aNotePos, true ) && maModel.mxText.get() ) try
         [ +  - ][ +  - ]
                 [ +  - ]
     162                 :            :     {
     163 [ +  - ][ +  - ]:          3 :         Reference< XSheetAnnotationsSupplier > xAnnosSupp( getSheet(), UNO_QUERY_THROW );
     164 [ +  - ][ +  - ]:          3 :         Reference< XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), UNO_SET_THROW );
                 [ +  - ]
     165                 :            :         // non-empty string required by note implementation (real text will be added below)
     166 [ +  - ][ +  - ]:          3 :         xAnnos->insertNew( aNotePos, OUString( sal_Unicode( ' ' ) ) );
     167                 :            : 
     168                 :            :         // receive created note from cell (insertNew does not return the note)
     169 [ +  - ][ +  - ]:          3 :         Reference< XSheetAnnotationAnchor > xAnnoAnchor( getCell( aNotePos ), UNO_QUERY_THROW );
     170 [ +  - ][ +  - ]:          3 :         Reference< XSheetAnnotation > xAnno( xAnnoAnchor->getAnnotation(), UNO_SET_THROW );
                 [ +  - ]
     171         [ +  - ]:          3 :         Reference< XSheetAnnotationShapeSupplier > xAnnoShapeSupp( xAnno, UNO_QUERY_THROW );
     172 [ +  - ][ +  - ]:          3 :         Reference< XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), UNO_SET_THROW );
                 [ +  - ]
     173                 :            : 
     174                 :            :         // convert shape formatting and visibility
     175                 :          3 :         sal_Bool bVisible = sal_True;
     176   [ +  -  -  - ]:          3 :         switch( getFilterType() )
                 [ +  - ]
     177                 :            :         {
     178                 :            :             case FILTER_OOXML:
     179                 :            :                 {
     180                 :            :                     // Add shape formatting properties (autoFill, colHidden and rowHidden are dropped)
     181         [ +  - ]:          3 :                     PropertySet aCommentPr( xAnnoShape );
     182         [ +  - ]:          3 :                     aCommentPr.setProperty( PROP_TextFitToSize, maModel.mbAutoScale );
     183         [ +  - ]:          3 :                     aCommentPr.setProperty( PROP_MoveProtect, maModel.mbLocked );
     184         [ +  - ]:          3 :                     aCommentPr.setProperty( PROP_TextHorizontalAdjust, lcl_ToHorizAlign( maModel.mnTHA ) );
     185         [ +  - ]:          3 :                     aCommentPr.setProperty( PROP_TextVerticalAdjust, lcl_ToVertAlign( maModel.mnTVA ) );
     186 [ -  + ][ #  # ]:          3 :                     if( maModel.maAnchor.Width > 0 && maModel.maAnchor.Height > 0 )
     187                 :            :                     {
     188 [ #  # ][ #  # ]:          0 :                         xAnnoShape->setPosition( Point( maModel.maAnchor.X, maModel.maAnchor.Y ) );
     189 [ #  # ][ #  # ]:          0 :                         xAnnoShape->setSize( Size( maModel.maAnchor.Width, maModel.maAnchor.Height ) );
     190                 :            :                     }
     191                 :            : 
     192                 :            :                     // convert shape formatting
     193 [ +  - ][ +  - ]:          3 :                     if( const ::oox::vml::ShapeBase* pNoteShape = getVmlDrawing().getNoteShape( aNotePos ) )
                 [ +  - ]
     194                 :            :                     {
     195                 :            :                         // position and formatting
     196         [ +  - ]:          3 :                         pNoteShape->convertFormatting( xAnnoShape );
     197                 :            :                         // visibility
     198                 :          3 :                         bVisible = pNoteShape->getTypeModel().mbVisible;
     199         [ +  - ]:          3 :                     }
     200                 :            :                 }
     201                 :          3 :             break;
     202                 :            :             case FILTER_BIFF:
     203                 :          0 :                 bVisible = maModel.mbVisible;
     204                 :          0 :             break;
     205                 :            :             case FILTER_UNKNOWN:
     206                 :          0 :             break;
     207                 :            :         }
     208 [ +  - ][ +  - ]:          3 :         xAnno->setIsVisible( bVisible );
     209                 :            : 
     210                 :            :         // insert text and convert text formatting
     211         [ +  - ]:          3 :         maModel.mxText->finalizeImport();
     212         [ +  - ]:          3 :         Reference< XText > xAnnoText( xAnnoShape, UNO_QUERY_THROW );
     213 [ +  - ][ #  # ]:          3 :         maModel.mxText->convert( xAnnoText, true );
     214                 :            :     }
     215         [ #  # ]:          0 :     catch( Exception& )
     216                 :            :     {
     217                 :            :     }
     218                 :          3 : }
     219                 :            : 
     220                 :            : // private --------------------------------------------------------------------
     221                 :            : 
     222                 :         60 : CommentsBuffer::CommentsBuffer( const WorksheetHelper& rHelper ) :
     223 [ +  - ][ +  - ]:         60 :     WorksheetHelper( rHelper )
     224                 :            : {
     225                 :         60 : }
     226                 :            : 
     227                 :          0 : void CommentsBuffer::appendAuthor( const OUString& rAuthor )
     228                 :            : {
     229                 :          0 :     maAuthors.push_back( rAuthor );
     230                 :          0 : }
     231                 :            : 
     232                 :          3 : CommentRef CommentsBuffer::createComment()
     233                 :            : {
     234 [ +  - ][ +  - ]:          3 :     CommentRef xComment( new Comment( *this ) );
     235         [ +  - ]:          3 :     maComments.push_back( xComment );
     236                 :          3 :     return xComment;
     237                 :            : }
     238                 :            : 
     239                 :         60 : void CommentsBuffer::finalizeImport()
     240                 :            : {
     241                 :         60 :     maComments.forEachMem( &Comment::finalizeImport );
     242                 :         60 : }
     243                 :            : 
     244                 :            : // ============================================================================
     245                 :            : 
     246                 :            : } // namespace xls
     247 [ +  - ][ +  - ]:         24 : } // namespace oox
     248                 :            : 
     249                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10