LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - notesuno.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 103 69.9 %
Date: 2015-06-13 12:38:46 Functions: 18 30 60.0 %
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 "notesuno.hxx"
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : #include <svl/smplhint.hxx>
      24             : #include <editeng/unotext.hxx>
      25             : #include <editeng/unoprnms.hxx>
      26             : #include <svx/svdpool.hxx>
      27             : #include <svx/svdobj.hxx>
      28             : #include <svx/unoshape.hxx>
      29             : #include <svx/svdocapt.hxx>
      30             : 
      31             : #include "postit.hxx"
      32             : #include "cellsuno.hxx"
      33             : #include "docsh.hxx"
      34             : #include "docfunc.hxx"
      35             : #include "hints.hxx"
      36             : #include "editsrc.hxx"
      37             : #include "miscuno.hxx"
      38             : 
      39             : using namespace com::sun::star;
      40             : 
      41           6 : static const SvxItemPropertySet* lcl_GetAnnotationPropertySet()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aAnnotationPropertyMap_Impl[] =
      44             :     {
      45         150 :         SVX_UNOEDIT_CHAR_PROPERTIES,
      46           3 :         SVX_UNOEDIT_FONT_PROPERTIES,
      47          42 :         SVX_UNOEDIT_PARA_PROPERTIES,
      48           6 :         SVX_UNOEDIT_NUMBERING_PROPERTIE,    // for completeness of service ParagraphProperties
      49             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      50         210 :     };
      51           6 :     static SvxItemPropertySet aAnnotationPropertySet_Impl( aAnnotationPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
      52           6 :     return &aAnnotationPropertySet_Impl;
      53             : }
      54             : 
      55           0 : SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" )
      56             : //SC_SIMPLE_SERVICE_INFO( ScAnnotationShapeObj, "ScAnnotationShapeObj", "com.sun.star.sheet.CellAnnotationShape" )
      57             : 
      58          14 : ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) :
      59             :     pDocShell( pDocSh ),
      60             :     aCellPos( rPos ),
      61          14 :     pUnoText( NULL )
      62             : {
      63          14 :     pDocShell->GetDocument().AddUnoObject(*this);
      64             : 
      65             :     //  pUnoText is allocated on demand (GetUnoText)
      66             :     //  can't be aggregated because getString/setString is handled here
      67          14 : }
      68             : 
      69          42 : ScAnnotationObj::~ScAnnotationObj()
      70             : {
      71          14 :     SolarMutexGuard g;
      72             : 
      73          14 :     if (pDocShell)
      74          13 :         pDocShell->GetDocument().RemoveUnoObject(*this);
      75             : 
      76          14 :     if (pUnoText)
      77           6 :         pUnoText->release();
      78          28 : }
      79             : 
      80           8 : void ScAnnotationObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      81             : {
      82           8 :     if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
      83             :     {
      84             : //        const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
      85             : 
      86             :         //! Ref-Update
      87             :     }
      88          16 :     else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
      89           8 :             static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
      90             :     {
      91           1 :         pDocShell = NULL;       // ungueltig geworden
      92             :     }
      93           8 : }
      94             : 
      95             : // XChild
      96             : 
      97           0 : uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent() throw(uno::RuntimeException, std::exception)
      98             : {
      99           0 :     SolarMutexGuard aGuard;
     100             : 
     101             :     //  Parent der Notiz ist die zugehoerige Zelle
     102             :     //! existierendes Objekt finden und zurueckgeben ???
     103             : 
     104           0 :     if (pDocShell)
     105           0 :         return static_cast<cppu::OWeakObject*>(new ScCellObj( pDocShell, aCellPos ));
     106             : 
     107           0 :     return NULL;
     108             : }
     109             : 
     110           0 : void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /* Parent */ )
     111             :                                     throw(lang::NoSupportException, uno::RuntimeException, std::exception)
     112             : {
     113             :     //  hamma nich
     114             :     //! Exception oder so ??!
     115           0 : }
     116             : 
     117             : // XSimpleText
     118             : 
     119           0 : uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor()
     120             :                                                     throw(uno::RuntimeException, std::exception)
     121             : {
     122           0 :     SolarMutexGuard aGuard;
     123             :     //  Notizen brauchen keine Extrawurst
     124           0 :     return GetUnoText().createTextCursor();
     125             : }
     126             : 
     127           0 : uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange(
     128             :                                     const uno::Reference<text::XTextRange>& aTextPosition )
     129             :                                                     throw(uno::RuntimeException, std::exception)
     130             : {
     131           0 :     SolarMutexGuard aGuard;
     132             :     //  Notizen brauchen keine Extrawurst
     133           0 :     return GetUnoText().createTextCursorByRange(aTextPosition);
     134             : }
     135             : 
     136           4 : OUString SAL_CALL ScAnnotationObj::getString() throw(uno::RuntimeException, std::exception)
     137             : {
     138           4 :     SolarMutexGuard aGuard;
     139           4 :     return GetUnoText().getString();
     140             : }
     141             : 
     142           2 : void SAL_CALL ScAnnotationObj::setString( const OUString& aText ) throw(uno::RuntimeException, std::exception)
     143             : {
     144           2 :     SolarMutexGuard aGuard;
     145           2 :     GetUnoText().setString(aText);
     146           2 : }
     147             : 
     148           0 : void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange,
     149             :                                             const OUString& aString, sal_Bool bAbsorb )
     150             :                                 throw(uno::RuntimeException, std::exception)
     151             : {
     152           0 :     SolarMutexGuard aGuard;
     153           0 :     GetUnoText().insertString( xRange, aString, bAbsorb );
     154           0 : }
     155             : 
     156           0 : void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange,
     157             :                                             sal_Int16 nControlCharacter, sal_Bool bAbsorb )
     158             :                                 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     159             : {
     160           0 :     SolarMutexGuard aGuard;
     161           0 :     GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb );
     162           0 : }
     163             : 
     164           0 : uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText() throw(uno::RuntimeException, std::exception)
     165             : {
     166           0 :     SolarMutexGuard aGuard;
     167           0 :     return GetUnoText().getText();
     168             : }
     169             : 
     170           0 : uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart() throw(uno::RuntimeException, std::exception)
     171             : {
     172           0 :     SolarMutexGuard aGuard;
     173           0 :     return GetUnoText().getStart();
     174             : }
     175             : 
     176           0 : uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd() throw(uno::RuntimeException, std::exception)
     177             : {
     178           0 :     SolarMutexGuard aGuard;
     179           0 :     return GetUnoText().getEnd();
     180             : }
     181             : 
     182             : // XSheetAnnotation
     183             : 
     184           5 : table::CellAddress SAL_CALL ScAnnotationObj::getPosition() throw(uno::RuntimeException, std::exception)
     185             : {
     186           5 :     SolarMutexGuard aGuard;
     187           5 :     table::CellAddress aAdr;
     188           5 :     aAdr.Sheet  = aCellPos.Tab();
     189           5 :     aAdr.Column = aCellPos.Col();
     190           5 :     aAdr.Row    = aCellPos.Row();
     191           5 :     return aAdr;
     192             : }
     193             : 
     194           1 : OUString SAL_CALL ScAnnotationObj::getAuthor()
     195             :     throw(uno::RuntimeException, std::exception)
     196             : {
     197           1 :     SolarMutexGuard aGuard;
     198           1 :     const ScPostIt* pNote = ImplGetNote();
     199           1 :     return pNote ? pNote->GetAuthor() : OUString();
     200             : }
     201             : 
     202           1 : OUString SAL_CALL ScAnnotationObj::getDate()
     203             :     throw(uno::RuntimeException, std::exception)
     204             : {
     205           1 :     SolarMutexGuard aGuard;
     206           1 :     const ScPostIt* pNote = ImplGetNote();
     207           1 :     return pNote ? pNote->GetDate() : OUString();
     208             : }
     209             : 
     210           2 : sal_Bool SAL_CALL ScAnnotationObj::getIsVisible() throw(uno::RuntimeException, std::exception)
     211             : {
     212           2 :     SolarMutexGuard aGuard;
     213           2 :     const ScPostIt* pNote = ImplGetNote();
     214           2 :     return pNote && pNote->IsCaptionShown();
     215             : }
     216             : 
     217           4 : void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible ) throw(uno::RuntimeException, std::exception)
     218             : {
     219           4 :     SolarMutexGuard aGuard;
     220             :     // show/hide note with undo action
     221           4 :     if( pDocShell )
     222           4 :         pDocShell->GetDocFunc().ShowNote( aCellPos, bIsVisible );
     223           4 : }
     224             : 
     225             : // XSheetAnnotationShapeSupplier
     226           4 : uno::Reference < drawing::XShape > SAL_CALL ScAnnotationObj::getAnnotationShape()
     227             :                                 throw(::com::sun::star::uno::RuntimeException,
     228             :                                       std::exception)
     229             : {
     230           4 :     SolarMutexGuard aGuard;
     231           4 :     uno::Reference < drawing::XShape > xShape;
     232           4 :     if( const ScPostIt* pNote = ImplGetNote() )
     233           4 :         if( SdrObject* pCaption = pNote->GetOrCreateCaption( aCellPos ) )
     234           4 :             xShape.set( pCaption->getUnoShape(), uno::UNO_QUERY );
     235           4 :     return xShape;
     236             : }
     237             : 
     238           6 : SvxUnoText& ScAnnotationObj::GetUnoText()
     239             : {
     240           6 :     if (!pUnoText)
     241             :     {
     242           6 :         ScAnnotationEditSource aEditSource( pDocShell, aCellPos );
     243             :         pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertySet(),
     244           6 :                                     uno::Reference<text::XText>() );
     245           6 :         pUnoText->acquire();
     246             :     }
     247           6 :     return *pUnoText;
     248             : }
     249             : 
     250           8 : const ScPostIt* ScAnnotationObj::ImplGetNote() const
     251             : {
     252           8 :     return pDocShell ? pDocShell->GetDocument().GetNote(aCellPos) : 0;
     253         156 : }
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11