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

Generated by: LCOV version 1.10