LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - commentsbuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 87 77.0 %
Date: 2012-12-27 Functions: 13 15 86.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10