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

Generated by: LCOV version 1.10